[PS] 10944 랜덤 게임~~

spring·2022년 5월 8일
0

이 문제는 10000번 제출을 하라고 만든 문제이다.

50만번 제출에 46개의 정답이니 1/10000 이 맞다.

저 50만번 제출한 사람들이 손으로 제출하진 않았을테니

Selenium을 이용해서 10000번 제출하는 코드를 짜서 돌리면 된다.

import chromedriver_autoinstaller

chromedriver_autoinstaller.install()
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
import time
import pyperclip
from tqdm import tqdm

ID = '아이디를 입력하세요'
PW = '비밀번호를 입력하세요'
headless = True

chrome_options = webdriver.ChromeOptions()
if headless:
    chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
caps = DesiredCapabilities.CHROME
caps["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(options=chrome_options, desired_capabilities=caps)
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': 'alert = function() {};'})
driver.get('https://www.acmicpc.net/login?next=%2Fproblem%2F10944')

WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.NAME, 'login_user_id')))
driver.find_element(By.NAME, 'login_user_id').send_keys(ID)
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.NAME, 'login_password')))
driver.find_element(By.NAME, 'login_password').send_keys(PW)
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, 'submit_button')))
driver.find_element(By.ID, 'submit_button').click()

WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, 'problem_title')))
action = webdriver.ActionChains(driver)
for i in tqdm(range(10000)):
    driver.get('https://www.acmicpc.net/submit/10944')
    while True:
        try:
            WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'CodeMirror-scroll')))
            code_area = driver.find_element(By.CLASS_NAME, 'CodeMirror-scroll')
            x = code_area.location['x'] + 50
            y = code_area.location['y'] + 50
            action.move_to_element_with_offset(code_area, 100, 100).click().send_keys('777').perform()
            WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'CodeMirror-line')))
            digit = driver.find_element(By.CLASS_NAME, 'CodeMirror-line').find_element(By.TAG_NAME, 'span').text
            if digit == '777':
                break
        except:
            pass
        time.sleep(1)
    WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, 'submit_button')))
    driver.find_element(By.ID, 'submit_button').click()
    time.sleep(3)
profile
Researcher & Developer @ NAVER Corp | Designer @ HONGIK Univ.

0개의 댓글