Unprotected sex !!!

How long after unprotected sex should one take a pill ? And can I still get pregnant if it last for really short and he didn't come at all ? 
EMERGENCY!!