Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nszw-solver
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
adc2019
nszw-solver
Commits
849bed35
Commit
849bed35
authored
Aug 25, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a script for the ADC2019 system
parent
fcb645e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
0 deletions
+114
-0
nszw_solver.py
nszw_solver.py
+114
-0
No files found.
nszw_solver.py
0 → 100644
View file @
849bed35
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}/solve'
.
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
:
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
:
if
not
l
.
startswith
(
'BLOCK'
):
tmp
=
[
int
(
v
.
strip
())
for
v
in
l
.
rstrip
()
.
split
(
','
)]
for
i
,
v
in
enumerate
(
tmp
):
if
v
==
-
1
:
tmp
[
i
]
=
0
l
=
','
.
join
([
str
(
v
)
for
v
in
tmp
])
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment