...
 
Commits (2)
# User files
/main
### https://raw.github.com/github/gitignore/9d7ff09c7d38dce9ef03e7ea4dc908a622546757/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
import argparse
import os
import subprocess
proc = None
stop_flag = False
def stop():
global proc
global stop_flag
stop_flag = True
if not proc is None:
proc.terminate()
print('stopped')
def solve(params):
global proc
global stop_flag
stop_flag = False
# 必要な変数があるか確認
assert('problem' in params)
problem = params['problem']
pl = problem.splitlines()
for l in pl:
if "SIZE" in l:
board_size_str = l.strip().split()[1]
bx, by = [int(v) for v in board_size_str.split('X')]
break
basedir = os.path.abspath(os.path.dirname(__file__))
cmds = f'{basedir}/main'.split()
proc = subprocess.Popen(
cmds,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE
)
try:
outs, errs = proc.communicate(problem.encode())
status = 'done'
except Exception as ex:
status = 'failed'
finally:
returncode = proc.returncode
outs = outs.decode()
errs = errs.decode()
print(outs)
print(errs)
solution = ''
if returncode == 0: # 10 when SAT
status = 'done'
lines = outs.splitlines()
state = 0
for l in lines:
if "SIZE" in l:
board_size_str = l.strip().split()[1]
sx, sy = [int(v) for v in board_size_str.split('X')]
if sx > by or sy > by:
status = 'failed'
break
elif 'ANSWER' in l:
state = 1
continue
elif state == 1:
if l.strip() == '':
break
else:
solution += l + '\n'
else:
status = 'failed'
return {
'status': status,
'solution': solution
}
def main(args):
with open(args['problem'], 'r') as fp:
problem = fp.read()
params = {
'problem': problem,
}
ret = solve(params)
print(ret)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Wrapper Script for ADC2019 Solver')
parser.add_argument('problem', type=str, help='File path to the problem file')
parser.add_argument('-t', '--timeout', type=int, default=10, help='Timeout for the process of the solver')
args = vars(parser.parse_args())
main(args)
File deleted