Codeforcesç¨èªåãã§ãã«ã¼
Codeforcesã¨ããæ°é²æ°éã®ããã°ã©ãã³ã°ã³ã³ãã¹ãããããããã®ã§åå ãã¦ã¿ããã¨ã«ãããPracticeããã£ã¦ã¿ãã¨ãããICPCã¨ã»ã¼åãå½¢å¼ã ã£ããå ¥åºåãèªåã§ã³ããããã®ãé¢åã ã£ãã®ã§èªååãã¦ã¿ããã¶ã£ã¡ããåã«ä½ã£ãPKUç¨ã®èªåãã§ãã¯ã¹ã¯ãªããã¨ã»ã¨ãã©åããTLEã¨ãMLEã¨ã対å¿ãã¦ããªãã®ã§ããã®ãã¡å¯¾å¿ãããããããªãã
#!/usr/bin/python import os import re import subprocess import sys import urllib def generateInputFileName(contestId, problemId, index): return contestId + problemId + '.' + str(index) + '.in.txt' def generateOutputFileName(contestId, problemId, index): return contestId + problemId + '.' + str(index) + '.out.txt' def format_pre(s): s = s.replace('<br />', '\n') if not s.endswith('\n'): s += '\n' return s def download(contestId, problemId): url = 'http://codeforces.com/contest/' + contestId + '/problem/' + problemId html = urllib.urlopen(url).read() p = re.compile('<pre class="content">(.+?)</pre>', re.M | re.S) result = p.findall(html) n = len(result) / 2; for index in range(n): inputFileName = generateInputFileName(contestId, problemId, index) outputFileName = generateOutputFileName(contestId, problemId, index) open(inputFileName, 'w').write(format_pre(result[index * 2 + 0])) open(outputFileName, 'w').write(format_pre(result[index * 2 + 1])) return True def compile(id): return subprocess.call(['g++', '-O2', problemId + '.cpp']) == 0 contestId = sys.argv[1] problemId = sys.argv[2] print('compiling...') if not compile(problemId): print('CompileError') exit(-1) if not os.path.exists(generateInputFileName(contestId, problemId, 0)) or not os.path.exists(generateOutputFileName(contestId, problemId, 0)): print('downloading...') download(contestId, problemId) for index in range(100): inputFilePath = generateInputFileName(contestId, problemId, index) outputFilePath = generateOutputFileName(contestId, problemId, index) if not os.path.exists(inputFilePath): break print('TestCase ' + str(index) + ' ' + inputFilePath + ' ' + outputFilePath) p = subprocess.Popen(['./a.exe'], stdin=open(inputFilePath, 'r'), stdout=open('out.txt', 'w')) if p.wait() != 0: print('RuntimeError?') exit(-1) if os.path.exists(outputFilePath): if subprocess.call(['diff', outputFilePath, 'out.txt', '-wy', '-W', '79']) != 0: print('WrongAnswer') exit(-1) else: for line in open(outputFilePath): print(line) print('OK')
追è¨(2010/03/12 19:22)
æ¹è¡ã®å¦çãééãã¦ããã®ã§ä¿®æ£
追è¨(2010/05/06 22:56)
ãã¡ã¤ã«æ«å°¾ã®æ¹è¡ã®å¦çãééãã¦ããã®ã§ä¿®æ£
追è¨(2010/05/07 01:10)
ãã¡ã¤ã«æ«å°¾ã®æ¹è¡ã®å¦çãééãã¦ããã®ã§ä¿®æ£