Can a virgin get pregnant without having sex

Patient: Am a virgin and my y boyfriend masturbated near the vaginal area and am not sure whether or not the sperm was transported to my uterus so to avoid risk i took the morning after pill so can i have the possibility of getting pregnant and if the sperm didn’t get near the vaginal opening and it wasn’t transported to the uterus can the pill have any effect on me

Doctor: