SlideShare a Scribd company logo
AtCoder Regular Contest 038
解説
AtCoder株式会社
2015/5/2 1
i eo i d[
i ]u d e
r
+ n
0 81
G e
3
s 5 h 5 uc
d h ] ac
a h u i ye
eo i y [ Re e
i y rh
C C
N N
d ~∼ i uk
ac iR uc ioiA
h [c
         n
d s
c R rk i ~∼d[ R
r
+ n
0 81
0, (
g
6
-‐‑‒
B1k uC d k j
C y k j WC j
C d d d k ^ k
k C j y g W
y c k
g kh d
H H
O 1 O
 
O 1 O
ge
 
y
6    g
g y ksRj g j un
judge(i,)j):)#)(i,j)に駒がある状態から開始したときの勝敗)
))if)(i,j))が盤外)or)障害物:)return)勝ち)
))if)judge(i+1,j))==)負け:)return)勝ち)
))if)judge(i+1,j+1))==)負け:)return)勝ち)
))if)judge(i,j+1))==)負け:)return)勝ち)
))return)負け
  0 3
2 k   
k a C
uj oC
k j R
O 1 O
W
j
mem[1000][1000])を「未定」で初期化)
judge(i,)j):)#)(i,j)に駒がある状態から開始したときの勝敗)
))if)(i,j))が盤外)or)障害物:)return)勝ち)
))if)mem[i][j])!=)未定:)return)mem[i][j])
))result)=)負け)
))if)judge(i+1,j))==)負け:)result)=)勝ち)
))if)judge(i+1,j+1))==)負け:)result)=)勝ち)
))if)judge(i,j+1))==)負け:)result)=)勝ち)
))return)mem[i][j])=)result
0 3
k y 1   g W
1   g uC j R
C d k rR
x
A y o
3 8 4 y d
G G k e sRj n
C j e k xk k C
x g R gj e n
051 1
C
3 ic O 1 i h d
0 i x d
] { O h y { ns dk
h 1 } h
~∼ k xu l
} i yhR
3 8)
0 8,
4   
3
0
d
4   
= C
-‐‑‒
= C
te {O o o
c h { l
= C d
-‐‑‒
i y l
1 2 1 2 4 3
= C 0 0 0 0 0 0 0
[ ] ^ a
-‐‑‒
[ y ic = C
im { du O
-‐‑‒
G [ {O
m = C
1 2 1 2 4 3
= C 0 0 0 0 0 0
[ ] ^ a
y ic = C
h [ s u O
-‐‑‒
G {O
m = C 4
-‐‑‒
1 2 1 2 4 3
= C 4 0 0 0 0 0
[ ] ^ a
] y ic = C
]h [ s u O
-‐‑‒ 4
G ] {O
m = C
-‐‑‒
1 2 1 2 4 3
= C 4 0 0 0 0
[ ] ^ a
^ y ic = C
^h ] s u O
-‐‑‒
G [ {O
m = C
-‐‑‒
1 2 1 2 4 3
= C 4 0 0 0
[ ] ^ a
y ic = C
h ] ^ s u O
-‐‑‒
G {O
m = C 4
-‐‑‒
1 2 1 2 4 3
= C 4 4 0 0
[ ] ^ a
y ic = C
h ] ^ s u O
-‐‑‒ 4
G ^ {O
m = C 6
-‐‑‒
1 2 1 2 4 3
= C 4 4 6 0
[ ] ^ a
a y ic = C
ah ^ s u O
-‐‑‒ 4 6
G ] {O
m = C
-‐‑‒
1 2 1 2 4 3
= C 4 4 6
[ ] ^ a
m e o = C m i{
-‐‑‒
1 2 1 2 4 3
= C 4 4 6
[ ] ^ a
i]y c }e dd{o eh
-‐‑‒
1 2 1 2 4 3
= C 4 4 6
[ ] ^ a
}g dl O
= C m i{
ohoO t e m o k
-‐‑‒
1 2 1 2 4 3
= C 4 4 6
[ ] ^ a
y ic = C 4
^ y ic = C
a y ic = C
m im = C x d
y O4 6im = C {
-‐‑‒
1 2 1 2 4 3
= C 4 4 6
[ ] ^ a
-‐‑‒
= C i od {o ehR
= C i[{ d h O

N r= C i[ {
= C i[ h O

N= C i[ { d
de h Oc = C i
[{ d
[
dem i {
4   
y ic = C
N h 3 { O
yd = C
m i[{ d {O[
4   
y ic = C =
= O
= 1 = d [
ic
[i h i h
~∼ dl 38    { m i{
i h ~∼
G } d m {O 3 A = 3   3   {
4   
= 38    hlu O
~∼ = 38   
uO { 9 0    3    {O
= C 9 0    3  
Om { d
 
3
0 8,
diO d
 
O
~∼ = 38   
{ d{ iO
= C 9 0    3  
{ d s
 
o O
de ic
O {O ,, ,, {
 
= C O
x d
0 ) O
= = = = =
de o d iOm O
= = = O
=
{
m e ]yry ns m
 
y O0 i} e {c e O
0 oh d {
 
= C O
0 i {c e = l {
3   { dm O
m d
3 8)
0 8,
d
l g l {
= x l s
= O
= 1 = d [
{ou
= = A i ~∼ e
de xu =G oyy= dk
yd O u y
m =G { em O

A = 3   { = m i{
3 A = 3   O d
1 O]y {o eh
h
2 C
9 yl
-‐‑‒ () 0
F C
0
3 x a[
B y 89B a r
M X M s r
s
ag M a * hn s
R a hMlx x[ r
a R x
a h ] hM a h
] M R x y d
  -‐‑‒
3
a g
 
R a * s * s y
R a d dr M M

au s h e
] M R y R ss
R x y 9 a[ 9 s M
i ] yM ]
xs a
 
9 R 9 a[ 9 ] ^rM
l m x x
a x yM x x x]o M
a x yM x x x]o
]
S BF s
  3
a R   
a R   
r n M y 3     M
x sy ]
-‐‑‒
3
a
N x o

N x o
] R x s n
a ge g u a o dM
a e u a o d n M
x s as
N x o

N x o
] R yM
r a x d M
r a x d n ^ M
N s x o

N s x o
] R
N s x o

N s x o
] R x s d n
a 9 x[ 9 x ^
x
2
3
1
4
1先
2先
3先
4先
2後
1後
4後
3後
x x
O Rx o
O
O Rx e
h
1先
2先
3先
4先
2後
1後
4後
3後
h ysu^ l
S l u c
1先
2先
3先
4先
2後
1後
4後
3後
M
N a[
N a r
] R l rM
ehr
1先
2先
3先
4先
2後
1後
4後
3後
M
N a[
N a r
] R l rM
ehr
1先
2先
3先
4先
2後
1後
4後
3後
M
N a[
N a r
] R l rM
ehr
1先
2先
3先
4先
2後
1後
4後
3後
M
N a[
N a r
] R l rM
ehr
1先
2先
3先
4先
2後
1後
4後
3後
x R s r n M
x O o
x O e
x O e
S x x y
1先
2先
3先
4先
2後
1後
4後
3後
x y ^ x ] s r
x x as r M
R s k
1先
2先
3先
4先
2後
1後
4後
3後
x sy R a[ xsM
eS R y h ^ a[
n M Ry
x R xsM x R a[
M e R yM
e R hr ] s
h y M 1 ^ l
c u ^ M
c ^ u l
X c u u i^
h y l
n l
x e yx u^ l
3
yM s
3   DG 8    
0 yMX x sh ]
N
N2 F
N AG e

More Related Content

AtCoder Regular Contest 038 解説