problem_id stringlengths 6 6 | user_id stringlengths 10 10 | time_limit float64 1k 8k | memory_limit float64 262k 1.05M | problem_description stringlengths 48 1.55k | codes stringlengths 35 98.9k | status stringlengths 28 1.7k | submission_ids stringlengths 28 1.41k | memories stringlengths 13 808 | cpu_times stringlengths 11 610 | code_sizes stringlengths 7 505 |
|---|---|---|---|---|---|---|---|---|---|---|
p02734 | u619819312 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['import numpy as np\nn,s=map(int,input().split())\nt=np.zeros(s+1)\nm=10**9+7\na=list(map(int,input().split()))\nans=0\nfor i in range(n):\n t[a[i]:]+=t[:-a[i]]\n if a[i]<s:\n t[a[i]]+=i+1\n ans+=t[-1]\n ans%=m\nprint(int(ans))', 'n,s=map(int,input().split())\nt=[0]*(s+1)\nm=998244353\na=list(map(int,input().split()))\nans=0\nfor i in range(n):\n d=t.copy()\n if a[i]<=s:\n for j in range(a[i],s+1):\n t[j]+=d[j-a[i]]\n t[a[i]]+=i+1\n ans+=t[-1]\n ans%=m\nprint(int(ans))'] | ['Runtime Error', 'Accepted'] | ['s006657110', 's366675738'] | [12512.0, 3808.0] | [192.0, 1793.0] | [233, 266] |
p02734 | u627803856 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['import numpy as np\n\nn, s = map(int, input().split())\nA = list(map(int, input().split()))\nMOD = 998244353\n\nU = 3010\ncount = 0\nF = np.zeros(U + 1, np.int64)\nfor a in A:\n F[0] += 1\n \n # FF = F\n # FF[a:] += FF[:-a]\n # FF %= MOD\n # F = FF\n F[a:] += F[:-a].copy()\n F %= MOD # forgot\n count += F[s]\n print(F[0:10])\n\ncount %= MOD\nprint(count)', 'import numpy as np\n\nn, s = map(int, input().split())\nA = list(map(int, input().split()))\nMOD = 998244353\n\nU = 3010\ncount = 0\nF = np.zeros(U + 1, np.int64)\nfor a in A:\n F[0] += 1\n F[a:] += F[:-a].copy()\n F %= MOD\n count += F[s]\n\ncount %= MOD\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s019019614', 's355514770'] | [12768.0, 14428.0] | [1298.0, 302.0] | [398, 265] |
p02734 | u671861352 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['#!python3\n\nimport numpy as np\n\n# input\nN, S = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nMOD = 998244353\n\n\ndef add_elements(w, i):\n a = A[i]\n w[a:] += w[:-a]\n if a <= S:\n w[a] += i + 1\n w %= MOD\n\n\ndef main():\n w = np.zeros(S + 1, dtype=int)\n ans = 0\n for i in range(N):\n add_elements(w, i)\n ans = (ans + w[S]) % MOD\n print(i, w)\n \n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', '#!python3\n\nimport numpy as np\n\n# input\nN, S = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nMOD = 998244353\n\n\ndef add_elements(w, i):\n a = A[i]\n w[a:] += w[:-a].copy()\n if a <= S:\n w[a] += i + 1\n w %= MOD\n\n\ndef main():\n w = np.zeros(S + 1, dtype=int)\n ans = 0\n for i in range(N):\n add_elements(w, i)\n ans = (ans + w[S]) % MOD\n \n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s270362175', 's730727320'] | [15288.0, 14412.0] | [2108.0, 309.0] | [464, 451] |
p02734 | u704284486 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['from sys import stdin\nmod = 998244353\ndef solveAsPolynomial():\n from numpy import *\n N,S = map(int,stdin.readline().split())\n a = list(map(int,stdin.readline().split()))\n ans = 0\n f = np.zeros(S+1,int64)\n for A in a:\n \n f[0] += 1#f+1\n f[A:] += f[:-A].copy()#f*(1+x**A)\n f %= mod\n ans += f[S]\n \n ans %= mod\n return ans\ndef main():\n ans = solveAsPolynomial()\n print(ans)\nif __name__ =="__main__":\n main()', 'import numpy as np\nmod = 998244353\ndef main():\n N,S = map(int,input().split())\n a = list(map(int,input().split()))\n a = np.asarray(a)\n dp = np.zeros((N+1,S+1,3))\n dp[0][0][0] = 1\n for i in range(N):\n for j in range(S+1):\n dp[i+1][j][0] += dp[i][j][0] ;dp[i+1][j][0] %= mod\n dp[i+1][j][1] += dp[i][j][0]+dp[i][j][1];dp[i+1][j][1] %= mod\n dp[i+1][j][2] += dp[i][j][0]+dp[i][j][1]+dp[i][j][2];dp[i+1][j][2]%= mod\n if j+a[i] <= S:\n dp[i+1][j+a[i]][1] += dp[i][j][0]+dp[i][j][1];dp[i+1][j+a[i]][1] %= mod\n dp[i+1][j+a[i]][2] += dp[i][j][0]+dp[i][j][1];dp[i+1][j+a[i]][2] %= mod\n print(dp[N][S][2])\nif __name__ == "__main__":\n main()', 'from sys import stdin\nmod = 998244353\ndef solveAsPolynomial():\n import numpy as np\n N,S = map(int,stdin.readline().split())\n a = list(map(int,stdin.readline().split()))\n ans = 0\n f = np.zeros(S+1,np.int64)\n for A in a:\n \n f[0] += 1#f+1\n f[A:] += f[:-A].copy()#f*(1+x**A)\n f %= mod\n ans += f[S]\n \n ans %= mod\n return ans\ndef main():\n ans = solveAsPolynomial()\n print(ans)\nif __name__ =="__main__":\n main()\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s223218019', 's357102928', 's928558182'] | [3064.0, 17240.0, 13748.0] | [17.0, 2108.0, 305.0] | [645, 732, 648] |
p02734 | u726285999 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['import numpy as np\n\nN, S = map(int, input().split())\nx = [int(x) for x in input().split()]\n \n\nm = np.zeros((S+1,3))\np = np.zeros((S+1,3))\np[0,0] = 1\n\n\nfor i in range(1,N+1):\n \n \n m[:,0] = p[:,0]\n m[:,1] = p[:,0] + p[:,1] \n m[:,2] = p[:,0] + p[:,1] + p[:,2] \n\n \n m[x[i]:,1] += p[:-x[i-1],0] + p[:-x[i-1],1]\n m[x[i]:,2] += p[:-x[i-1],0] + p[:-x[i-1],1]\n\n p[:,0] = m[:,0] % 998244353\n p[:,1] = m[:,1] % 998244353\n p[:,2] = m[:,2] % 998244353\n \nprint(int(p[S,2]))', 'import numpy as np\n\nN, S = map(int, input().split())\nx = [int(x) for x in input().split()]\n \n\nm = np.zeros((S+1,3))\np = np.zeros((S+1,3))\np[0,0] = 1\n\n\nfor i in range(1,N+1):\n \n \n m[:,0] = p[:,0]\n m[:,1] = p[:,0] + p[:,1] \n m[:,2] = p[:,0] + p[:,1] + p[:,2] \n\n \n m[x[i-1]:,1] += p[:-x[i-1],0] + p[:-x[i-1],1]\n m[x[i-1]:,2] += p[:-x[i-1],0] + p[:-x[i-1],1]\n\n p[:,0] = m[:,0] % 998244353\n p[:,1] = m[:,1] % 998244353\n p[:,2] = m[:,2] % 998244353\n \nprint(int(p[S,2]))'] | ['Runtime Error', 'Accepted'] | ['s407574627', 's596292570'] | [12664.0, 12664.0] | [152.0, 1015.0] | [809, 813] |
p02734 | u814986259 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['def main():\n N, S = map(int, input().split())\n A = list(map(int, input().split()))\n mod = 998244353\n ans = 0\n dp = [0]*S\n\n for i, a in enumerate(A):\n if a > S:\n continue\n ans += dp[S-a]*(N-i)\n dp[0] += 1\n for j in range(S-a-1, -1, -1):\n dp[j+a] += dp[j]\n print(ans % mod)\n\nmain()\n', 'def main():\n N, S = map(int, input().split())\n A = list(map(int, input().split()))\n mod = 998244353\n ans = 0\n dp = [0]*S\n\n for i, a in enumerate(A):\n if a > S:\n continue\n dp[0] += i+1\n ans += dp[S-a]*(N-i)\n\n for j, x in enumerate(dp[:S-a]):\n dp[j+a] += x\n print(ans % mod)\n\n\nmain()\n', 'def main():\n N, S = map(int, input().split())\n A = list(map(int, input().split()))\n mod = 998244353\n ans = 0\n dp = [0]*S\n\n for i, a in enumerate(A):\n dp[0] +=1\n if a > S:\n continue\n\n ans += dp[S-a]*(N-i)\n\n for j, x in enumerate(dp[:S-a]):\n dp[j+a] += x\n print(ans % mod)\n\n\nmain()\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s563640979', 's783567207', 's656672121'] | [3444.0, 3804.0, 3816.0] | [967.0, 1077.0, 1063.0] | [351, 353, 351] |
p02734 | u864197622 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['def setM():\n K2 = K // 2\n k = K // 2\n while k:\n m = int(("1" * (K2 - k) + "0" * (K2 + k)) * 3001, 2)\n M.append((k, m, ~m, (1 << K2 + k) % P))\n k //= 2\n\ndef modp(n):\n K2 = K // 2\n k = K // 2\n for k, m, tm, a in M:\n n = (n & tm) + (n & m >> K2 + k) * a\n return n\n\nK = 64\nP = 998244353\nmm = (1 << K * 3001) - 1\nmmm = (1 << K) - 1\nM = []\nsetM()\nN, S = map(int, input().split())\nA = [int(a) for a in input().split()]\ns = 0\nans = 0\nfor a in A:\n s += 1\n s += s << a * K\n s &= mm\n s = modp(s)\n ans += (s >> S * K) & mmm\n\nprint(ans % P)', 'K = 32\nP = 998244353\nm = int(("1" * 2 + "0" * 30) * 3001, 2)\nmm = (1 << K * 3001) - 1\npa = (1 << 30) - ((1 << 30) % P)\n\nM = []\nN, S = map(int, input().split())\nA = [int(a) for a in input().split()]\ns = 0\nans = 0\nfor a in A:\n s += 1\n s += s << a * K\n s &= mm\n s -= ((s & m) >> 30) * pa\n ans += s >> S * K\n\nprint(ans % P)', 'K = 32\nP = 998244353\nm = int(("1" * 2 + "0" * 30) * (S + 1), 2)\nmm = (1 << K * (S + 1)) - 1\npa = (1 << 30) - ((1 << 30) % P)\n\nM = []\nN, S = map(int, input().split())\nA = [int(a) for a in input().split()]\ns = 0\nans = 0\nfor a in A:\n s += 1\n s += s << a * K\n s &= mm\n s -= ((s & m) >> 30) * pa\n ans += s >> S * K\n\nprint(ans % P)', 'K = 32\nP = 998244353\npa = (1 << 30) - ((1 << 30) % P)\nM = []\nN, S = map(int, input().split())\nm = int(("1" * 2 + "0" * 30) * (S + 1), 2)\nmm = 1 << K * S\nmmm = (1 << K) - 1\nA = [int(a) for a in input().split()]\ns = 0\nans = 0\nfor a in A:\n s += mm\n s += s >> a * K\n s -= ((s & m) >> 30) * pa\n ans += s & mmm\n\nprint(ans % P)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s022251351', 's402688290', 's484628135', 's078045053'] | [3640.0, 3316.0, 3064.0, 3316.0] | [809.0, 126.0, 17.0, 100.0] | [591, 334, 340, 332] |
p02734 | u893063840 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['n, s = map(int, input().split())\na = list(map(int, input().split()))\nmod = 998244353\n\ndp1 = [[0] * (s + 1) for _ in range(n + 1)]\ndp1[0][0] = 1\n\nfor i, e in enumerate(a, 1):\n for j in range(1, s + 1):\n if j - e >= 0:\n dp1[i][j] = dp1[i-1][j] + dp1[i-1][j-e]\n else:\n dp1[i][j] = dp1[i-1][j]\n\n dp1[i][j] %= mod\n\ndp2 = [[0] * (s + 1) for _ in range(n + 1)]\ndp2[0][0] = 1\n\nfor i, e in enumerate(a[::-1], 1):\n for j in range(1, s + 1):\n if j - e >= 0:\n dp2[i][j] = dp2[i - 1][j] + dp2[i - 1][j - e]\n else:\n dp2[i][j] = dp2[i - 1][j]\n\n dp2[i][j] %= mod\n\nans = 0\nall = dp1[n][s]\nfor l in range(1, n + 1):\n for r in range(l, n + 1):\n cnt = all - dp1[l-1][s] - dp2[n-r][s]\n ans += cnt\n ans %= mod\n\nprint(ans)\n\n', 'import numpy as np\n\nn, s = map(int, input().split())\na = list(map(int, input().split()))\nmod = 998244353\n\ndp = np.zeros((s + 1, 3), dtype=np.int64)\ndp[0][0] = 1\n\nfor i, e in enumerate(a):\n cp = dp.copy()\n\n dp[:, 1] += cp[:, 0]\n dp[:, 2] += cp[:, 0] + cp[:, 1]\n\n dp[e:, 1] += cp[:-e, 0] + cp[:-e, 1]\n dp[e:, 2] += cp[:-e, 0] + cp[:-e, 1]\n\n dp %= mod\n\nans = dp[s][2]\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s957949157', 's539825406'] | [157936.0, 20856.0] | [2114.0, 703.0] | [817, 394] |
p02734 | u987164499 | 2,000 | 1,048,576 | Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: * f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353. | ['import numpy as np\n\nn,s = map(int,input().split())\na = list(map(int,input().split()))\nans = 0\nmod = 998244353\n\n\nf = np.zeros(s+1)\n\nfor i in a:\n f[0] += 1\n f[i:] += f[:-i].copy()\n f %= mod\n ans += f[s]\n\nprint(ans)', 'import numpy as np\n\nn,s = map(int,input().split())\na = list(map(int,input().split()))\nans = 0\nmod = 998244353\n\n\nf = np.zeros(s+1,int)\n\nfor i in a:\n f[0] += 1\n f[i:] += f[:-i].copy()\n f %= mod\n ans += f[s]\n\nprint(ans%mod)'] | ['Wrong Answer', 'Accepted'] | ['s699084688', 's965745912'] | [12760.0, 12420.0] | [300.0, 298.0] | [261, 269] |
p02735 | u021019433 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["from itertools import count, repeat\n\nh = int(input().split()[0])\na0 = repeat('.')\nr0 = list(range(w))\nfor i in range(h):\n a = input()\n r = [i]\n for x, y, z, u in zip(a0, '.' + a, a, r0):\n r.append(min(u + (x + z == '.\n a0 = a\n r0 = r[1:]\nprint(r[-1])\n", "from itertools import count, repeat\n\nh = int(input().split()[0])\na0 = repeat('.')\nr0 = count()\nfor i in range(h):\n a = input()\n r = [i]\n for x, y, z, u in zip(a0, '.' + a, a, r0):\n r.append(min(u + (x > z), r[-1] + (y > z)))\n a0 = a\n r0 = r[1:]\nprint(r[-1])\n"] | ['Runtime Error', 'Accepted'] | ['s629467674', 's455055096'] | [3060.0, 3060.0] | [18.0, 24.0] | [289, 266] |
p02735 | u035901835 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import numpy as np\n\nH,W = input().split()\nH,W=int(H),int(W)\nP=[0]*H\nfor i in range(H):\n P[i] = input()\n\ndp=np.zeros((H,W),dtype='u8')\nif P[0][0]=='#':\n dp[0][0]=1\nelse:\n dp[0][0]=0\n\ndef DP(x,y):\n global dp\n if 0<=x<=W-1 and 0<=y<=H-1:\n return dp[y][x]\n else:\n return 9999999\n\nfor l in range(1,H+W):\n for i in range(l+1):\n if i<H and l-i<W:\n if P[i][l-i]=='#':\n a=DP(i-1,l-i)\n b=DP(i,l-i-1)\n if a < 9999999:\n if P[i-1][l-i]=='.':\n a+=1\n if b < 9999999:\n if P[i][l-i-1]=='.':\n b+=1\n dp[i][l-i]=min(a,b)\n else:\n #print(i,l-i,DP(i-1,l-i),DP(i,l-i-1))\n dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))\nprint(dp[H-1][W-1])", "H,W = input().split()\nH,W=int(H),int(W)\nsw=[[0]*W]*H\n\nfor i in range(W):\n sw[i] = input()\n\ncount=0\nif sw[0][0]=='#':\n sw[0]='.'+sw[0][1:]\n count+=1\nif sw[H-1][W-1]=='#':\n sw[H-1]=sw[H-1][:W-1]+'.'\n count+=1\n\ndef search(h,v):\n global H,W\n global sw\n if h>=H-1 and v>=W-1:\n return -2,-2\n elif v>=H-1:\n if sw[h+1][W-1]=='.':\n return h+1,v\n else:\n return -1,-1\n elif h>=W-1:\n if sw[H-1][v+1]=='.':\n return h,v+1\n else:\n return -1,-1\n else:\n if sw[h+1][v]=='.':\n return h+1,v\n elif sw[h][v+1]=='.':\n return h,v+1\n else:\n return -1,-1\n\nh=0\nv=0\ni=0\nwhile(1):\n flag=True\n for j in range(i+1):\n result = search(h+i-j,v+j)\n if result == (-2,-2):\n print(count)\n exit()\n if result!=(-1,-1):\n flag = False\n h,v=result\n break\n if flag:\n count+=1\n i+=1\n else:\n i=1", "import numpy as np\n\nH,W = input().split()\nH,W=int(H),int(W)\nP=[0]*H\nfor i in range(H):\n P[i] = input()\n\ndp=np.zeros((H,W),dtype='u8')\nif P[0][0]=='#':\n dp[0][0]=1\nelse:\n dp[0][0]=0\n\ndef DP(x,y):\n global dp\n if 0<=x<=W-1 and 0<=y<=H-1:\n return dp[y][x]\n else:\n return 9999999\n\nfor l in range(1,H+W):\n for i in range(l):\n if i<H and l-i<W:\n if P[i][l-i]=='#':\n #print(i,l-i, DP(i-1,l-i),DP(i,l-i-1))\n dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))+1\n else:\n #print(i,l-i,DP(i-1,l-i),DP(i,l-i-1))\n dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))\nprint(dp[H-1][W-1])", "H,W = input().split()\nH,W=int(H),int(W)\nsw=[[0]*W]*H\n\nfor i in range(W):\n sw[i] = input()\n\ncount=0\nif sw[0][0]=='#':\n sw[0]='.'+sw[0][1:]\n count+=1\nif sw[H-1][W-1]=='#':\n sw[H-1]=sw[H-1][:W-1]+'.'\n count+=1\n\ndef search(h,v):\n global H,W\n global sw\n if h>=H-1 and v>=W-1:\n return -2,-2\n elif v>=H-1:\n if sw[h+1][W-1]=='.':\n return h+1,v\n else:\n return -1,-1\n elif h>=W-1:\n if sw[H-1][v+1]=='.':\n return h,v+1\n else:\n return -1,-1\n else:\n if sw[h+1][v]=='.':\n return h+1,v\n elif sw[h][v+1]=='.':\n return h,v+1\n else:\n return -1,-1\n\nh=0\nv=0\ni=0\nwhile(1):\n flag=True\n for j in range(i+1):\n result = search(h+i-j,v+j)\n if result == (-2,-2):\n exit()\n if result!=(-1,-1):\n i=0\n flag = False\n h,v=result\n break\n if flag:\n count+=1\n i+=1", "H,W = input().split()\nH,W=int(H),int(W)\nsw=[[0]*W]*H\n\nfor i in range(W):\n sw[i] = input()\n\ncount=0\nif sw[0][0]=='#':\n sw[0]='.'+sw[0][1:]\n count+=1\nif sw[H-1][W-1]=='#':\n sw[H-1]=sw[H-1][:W-1]+'.'\n count+=1\n\ndef search(h,v):\n global H,W\n global sw\n if h==H-1 and v==W-1:\n return -2,-2\n elif v>=H-1 or h>=W-1:\n return -1,-1\n else:\n if sw[h+1][v]=='.':\n return h+1,v\n elif sw[h][v+1]=='.':\n return h,v+1\n else:\n return -1,-1\n\nP=[[0,0]]\nnext=[]\ni=0\nplus=True\nwhile(1):\n flag=False\n for p in P:\n for j in range(i+1):\n if p[0]+i-j>=W or p[1]+j>=H:\n continue\n result=search(p[0]+i-j,p[1]+j)\n #print('search',p[0]+i-j,p[1]+j,count)\n if result==(-2,-2):\n print(count)\n exit()\n elif result!=(-1,-1):\n next.append(result)\n flag=True\n i=0\n \n if not flag:\n #print('yaa')\n i+=1\n if plus:\n count+=1\n plus=False\n else:\n plus=True\n #print('next',next,count)\n P=[]\n P=next\n next=[]\n", "import numpy as np\n\nH,W = input().split()\nH,W=int(H),int(W)\nP=[0]*H\nfor i in range(H):\n P[i] = input()\n\ndp=np.zeros((H,W),dtype='u8')\nif P[0][0]=='#':\n dp[0][0]=1\nelse:\n dp[0][0]=0\n\ndef DP(y,x):\n global dp\n if 0<=x<=W-1 and 0<=y<=H-1:\n return dp[y][x]\n else:\n return 9999999\n\nfor l in range(1,H+W):\n for i in range(l+1):\n if i<H and l-i<W:\n if P[i][l-i]=='#':\n a=DP(i-1,l-i)\n b=DP(i,l-i-1)\n if a < 9999999:\n if P[i-1][l-i]=='.':\n a+=1\n if b < 9999999:\n if P[i][l-i-1]=='.':\n b+=1\n dp[i][l-i]=min(a,b)\n else:\n #print(i,l-i,DP(i-1,l-i),DP(i,l-i-1))\n dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))\nprint(dp[H-1][W-1])"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s057657797', 's465561521', 's546715635', 's758321119', 's899304671', 's003323632'] | [21760.0, 3064.0, 14548.0, 3192.0, 3064.0, 13444.0] | [465.0, 30.0, 246.0, 30.0, 31.0, 307.0] | [861, 1024, 671, 993, 1216, 861] |
p02735 | u044220565 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["# coding: utf-8\nH, W = list(map(int, input().split()))\nS = []\nfor _ in range(H):\n S.append(list(input()))\n\ngrid = [[0 for _ in range(W)] for _ in range(H)]\n\nfor h in range(1,H):\n if S[h-1][0] == '#' and S[h][0] == '.':\n grid[h][0] = grid[h-1][0] + 1\n else:\n grid[h][0] = grid[h-1][0]\n \nfor w in range(1,W):\n if S[0][w-1] == '#' and S[0][w] == '.':\n grid[0][w] = grid[0][w-1] + 1\n else:\n grid[0][w] = grid[0][w-1]\nfor w in range(1,W):\n for h in range(1,H):\n if S[h-1][w] == '#' and S[h][w] == '.':\n next_h = grid[h-1][w] + 1\n else:\n next_h = grid[h-1][w] \n if S[h][w-1] == '#' and S[h][w] == '.':\n next_w = grid[h][w-1] + 1\n else:\n next_w = grid[h][w-1]\n grid[h][w] = min([next_w, next_h])\nif S[H-1][W-1] == '#':\n grid[H-1][W-1] += 1\nprint(grid[H-1][W-1])\nfor x in grid:\n print(x)", "# coding: utf-8\nH, W = list(map(int, input().split()))\nS = []\nfor _ in range(H):\n S.append(list(input()))\n\ngrid = [[0 for _ in range(W)] for _ in range(H)]\n\nfor h in range(1,H):\n if S[h-1][0] == '#' and S[h][0] == '.':\n grid[h][0] = grid[h-1][0] + 1\n else:\n grid[h][0] = grid[h-1][0]\n \nfor w in range(1,W):\n if S[0][w-1] == '#' and S[0][w] == '.':\n grid[0][w] = grid[0][w-1] + 1\n else:\n grid[0][w] = grid[0][w-1]\nfor w in range(1,W):\n for h in range(1,H):\n if S[h-1][w] == '#' and S[h][w] == '.':\n next_h = grid[h-1][w] + 1\n else:\n next_h = grid[h-1][w] \n if S[h][w-1] == '#' and S[h][w] == '.':\n next_w = grid[h][w-1] + 1\n else:\n next_w = grid[h][w-1]\n grid[h][w] = min([next_w, next_h])\nif S[H-1][W-1] == '#':\n grid[H-1][W-1] += 1\nprint(grid[H-1][W-1])"] | ['Wrong Answer', 'Accepted'] | ['s355439546', 's206984440'] | [3316.0, 3316.0] | [31.0, 29.0] | [844, 818] |
p02735 | u060736237 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['black = 1\ncount = 0\nflag = False\ndef check(board, now):\n global flag, count\n if now[0] > len(board) -2 or board[now[0]+1][now[1]]==black:\n if now[1] > len(board[0]) -2 or board[now[0]][now[1]+1]==black:\n if flag == False:\n count += 1\n flag = True\n if now[1] < len(board[0]) -1:\n return [now[0], now[1]+1]\n elif now[0] < len(board) -1:\n return [now[0]+1, now[1]]\n else:\n flag = False\n return [now[0], now[1]+1]\n else:\n flag = False\n return [now[0]+1, now[1]]\ndef main():\n global count, flag\n H, W = map(int, input().split())\n board = [[white for i in range(W)] for j in range(H)]\n for i in range(H):\n s = input()\n for j in range(W):\n if s[j] == ".":\n board[i][j] = white\n else:\n board[i][j] = black\n if board[0][0] == black:\n count += 1\n flag = True\n now = [0, 0]\n while now != [H-1, W-1]:\n now = check(board, now)\n print(count)\nif __name__ == "__main__":\n main()', 'def calc2(array):\n temp = []\n for x, y in zip(array[:-1], array[1:]):\n temp.append(abs(x-y))\n if len(temp) == 1:\n print(temp[0])\n else:\n calc2(temp)\ndef main():\n N = int(input())\n array = [0 for i in range(N+1)]\n s = input()\n for j in range(N):\n array[j+1] = int(s[j])\n calc2(array)\nif __name__ == "__main__":\n main()\n', 'import sys\nsys.setrecursionlimit(10**6)\ndef main():\n h, w = map(int, input().split())\n s = [input() for _ in range(h)]\n dp = [[10**5] * w for _ in range(h)]\n def func(temp, now, flag):\n x, y = now\n if y > h - 1 or x > w - 1:\n return 10**6\n if s[y][x] == "#":\n if not flag:\n temp += 1\n flag = True\n else:\n flag = False\n if x == w-1 and y == h-1:\n return temp\n if dp[y][x] <= temp:\n return 10**6\n dp[y][x] = temp\n piyo = []\n return min(func(temp, (x + 1, y), flag), func(temp, (x, y + 1), flag))\n print(func(0, (0, 0), False))\nmain()'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s372701813', 's753124158', 's153383316'] | [3172.0, 3060.0, 3316.0] | [18.0, 18.0, 345.0] | [1128, 376, 690] |
p02735 | u105709022 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['memory = [[-1 for i in range(W)] for j in range(H)]\ndef flip_count_mem(r, c):\n if memory[r][c] < 0:\n memory[r][c] = flip_coumt(r, c)\n return memory[r][c]\n\ndef flip_count (r, c):\n if r == H - 1 and c == W - 1:\n if s[r][c] == "#":\n return 1\n else:\n return 0\n \n if c == W - 1:\n count_right = 10000\n else:\n count_right = flip_count_mem (r, c + 1)\n if s[r][c] == "#" and s[r][c + 1] == ".":\n count_right += 1\n \n if r == H - 1:\n count_down = 10000\n else:\n count_down = flip_count_mem (r + 1, c)\n if s[r][c] == "#" and s[r + 1][c] == ".":\n count_down += 1\n return min(count_right, count_down)\n\nH, W = input().split()\nW = int (W)\nH = int (H)\ns = []\nfor i in range(H):\n s.append(input())\nprint (flip_count(0, 0))\n', 'def flip_count_mem(r, c):\n if memory[r][c] < 0:\n memory[r][c] = flip_count(r, c)\n return memory[r][c]\n\ndef flip_count (r, c):\n if r == H - 1 and c == W - 1:\n if s[r][c] == "#":\n return 1\n else:\n return 0\n \n if c == W - 1:\n count_right = 10000\n else:\n count_right = flip_count_mem (r, c + 1)\n if s[r][c] == "#" and s[r][c + 1] == ".":\n count_right += 1\n \n if r == H - 1:\n count_down = 10000\n else:\n count_down = flip_count_mem (r + 1, c)\n if s[r][c] == "#" and s[r + 1][c] == ".":\n count_down += 1\n return min(count_right, count_down)\n\nH, W = input().split()\nW = int (W)\nH = int (H)\ns = []\nfor i in range(H):\n s.append(input())\nmemory = [[-1 for i in range(W)] for j in range(H)]\nprint (flip_count(0, 0))\n'] | ['Runtime Error', 'Accepted'] | ['s707797927', 's316749748'] | [3064.0, 3316.0] | [18.0, 31.0] | [806, 806] |
p02735 | u110199424 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import queue\n\nH, W = map(int, input().split())\n\ns = [list(map(int, input().split())) for _ in range(H)]\n\nini = 0\nif s[0][0] == \'#\':\n ini = 1\n\ndist = [[ini for _ in range(W)] for _ in range(H)]\nstart = (0,0)\n\nqq = queue.Queue()\n\nfor i in range(H):\n for j in range(W):\n tgt = []\n if j == 0:\n pass\n else:\n if s[i][j-1] == \'.\' and s[i][j] == \'#\':\n tgt.append(dist[i][j-1] + 1)\n\n else:\n tgt.append(dist[i][j-1])\n\n if i == 0:\n pass\n else:\n if s[i-1][j] == \'.\' and s[i][j] == "#":\n tgt.append(dist[i-1][j] + 1)\n else:\n tgt.append(dist[i-1][j])\n if i + j == 0:\n continue\n dist[i][j] = min(tgt)\n\nprint(dist[H-1][W-1])\n\n', 'import queue\n\nH, W = map(int, input().split())\n\ns = [list(input()) for _ in range(H)]\n\nini = 0\nif s[0][0] == \'#\':\n ini = 1\n\ndist = [[ini for _ in range(W)] for _ in range(H)]\nstart = (0,0)\n\nqq = queue.Queue()\n\nfor i in range(H):\n for j in range(W):\n tgt = []\n if j == 0:\n pass\n else:\n if s[i][j-1] == \'.\' and s[i][j] == \'#\':\n tgt.append(dist[i][j-1] + 1)\n\n else:\n tgt.append(dist[i][j-1])\n\n if i == 0:\n pass\n else:\n if s[i-1][j] == \'.\' and s[i][j] == "#":\n tgt.append(dist[i-1][j] + 1)\n else:\n tgt.append(dist[i-1][j])\n if i + j == 0:\n continue\n dist[i][j] = min(tgt)\n\nprint(dist[H-1][W-1])\n\n'] | ['Runtime Error', 'Accepted'] | ['s604381587', 's359879736'] | [3952.0, 4080.0] | [26.0, 41.0] | [802, 784] |
p02735 | u113971909 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\nimport sys\nfrom collections import deque\n\ndef main():\n input = sys.stdin.readline\n H,W = map(int,input().split())\n Gd = [list(input()) for _ in range(H)]\n INF = H*W\n direc = [[1,0],[0,1]]\n def dfs(start):\n Dis = [[INF]*W for _ in range(H)]\n Dis[start[0]][start[1]]= (Gd[start[0]][start[1]] == '#')\n q = deque([]) \n q.append(start)\n while len(q)!=0:\n h,w = q.popleft() 取りだし(先頭)\n for d in direc:\n hs, ws = h + d[0], w + d[1]\n if not (0<=hs<H and 0<=ws<W):\n continue\n else:\n q.append([hs,ws])\n Dis[hs][ws] = min(Dis[hs][ws], Dis[h][w] + (Gd[hs][ws]=='#'))\n print(Dis[H-1][W-1])\n dfs([0, 0])\n\nif __name__=='__main__':\n main()\n", "#!/usr/bin python3\n# -*- coding: utf-8 -*-\n\ndef main():\n H, W = map(int,input().split())\n sth, stw = 0, 0\n glh, glw = H-1, W-1\n\n INF = 10000\n Gmap = [list(input()) for _ in range(H)]\n Dist = [[INF]*W for _ in range(H)]\n direc = {(1,0), (0,1)}\n\n if Gmap[0][0]=='#':\n Dist[0][0]=1\n else:\n Dist[0][0]=0\n\n for h in range(H):\n for w in range(W):\n nw = Gmap[h][w]\n for d in direc:\n hs, ws = h + d[0], w + d[1]\n if 0<=hs<H and 0<=ws<W:\n cr = Gmap[hs][ws]\n Dist[hs][ws] = min(Dist[hs][ws], Dist[h][w] + (cr=='#' and nw=='.'))\n print(Dist[glh][glw])\n\nif __name__ == '__main__':\n main()"] | ['Time Limit Exceeded', 'Accepted'] | ['s596701019', 's439224589'] | [109300.0, 9356.0] | [2114.0, 41.0] | [907, 723] |
p02735 | u139112865 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import heapq\nh, w = map(int, input().split())\nc = [input() for _ in range(h)]\n \nd=[[100000]*w for _ in range(h)]\n \ndef bfs():\n if c[0][0] == '.':\n que = [(0, (0, 0))]\n heapq.heapify(que)\n d[0][0] = 0\n else:\n que = [(1, (0, 0))]\n heapq.heapify(que)\n d[0][0] = 1\n while len(que):\n _, (qx, qy) = heapq.heappop(que)\n if qx == h-1 and qy == w-1:\n return d[h-1][w-1]\n for dx,dy in [[1,0], [0,1]]:\n px, py = qx+dx, qy+dy\n if 0<=px<h and 0<=py<w:\n d[px][py]=min(d[px][py], d[qx][qy] + (c[px][py]=='#'))\n heapq.heappush(que, (d[px][py], (px , py)))\n\nprint(bfs())\nprint(d)", "import sys\nfrom heapq import heappop, heappush\nsys.setrecursionlimit(10000000)\n\nh, w = map(int, input().split())\nc = [input() for _ in range(h)]\nd = [[10000]*w for _ in range(h)]\n\nque = []\nif c[0][0] == '.':\n heappush(que, (0, 0, 0, True))\n d[0][0] = 0\nelse:\n heappush(que, (1, 0, 0, False))\n d[0][0] = 1\n\nwhile len(que):\n dist, px, py, flg = heappop(que)\n if d[h-1][w-1] < dist:\n break\n for dx, dy in [(0, 1), (1, 0)]:\n qx, qy = px + dx, py + dy\n if not (0 <= qx < h and 0 <= qy < w):\n continue\n if d[qx][qy] > dist + (flg and c[qx][qy]=='#'):\n if flg:\n d[qx][qy] = min(d[qx][qy], dist + (c[qx][qy]=='#'))\n heappush(que, (d[qx][qy], qx, qy, False))\n else:\n d[qx][qy] = min(d[qx][qy], dist)\n heappush(que, (d[qx][qy], qx, qy, True))\n\nprint(d[h-1][w-1])", "import sys\nfrom heapq import heappop, heappush\nsys.setrecursionlimit(10000000)\n\nh, w = map(int, input().split())\nc = [input() for _ in range(h)]\nd = [[10000]*w for _ in range(h)]\n\nque = []\nif c[0][0] == '.':\n heappush(que, (0, 0, 0))\n d[0][0] = 0\nelse:\n heappush(que, (1, 0, 0))\n d[0][0] = 1\n\nwhile len(que):\n dist, px, py = heappop(que)\n if d[h-1][w-1] < dist:\n break\n for dx, dy in [(0, 1), (1, 0)]:\n qx, qy = px + dx, py + dy\n if not (0 <= qx < h and 0 <= qy < w):\n continue\n if d[qx][qy] > dist:\n if c[px][py]=='.' and c[qx][qy]=='#':\n d[qx][qy] = dist + 1\n heappush(que, (d[qx][qy], qx, qy))\n else:\n d[qx][qy] = dist\n heappush(que, (d[qx][qy], qx, qy))\nprint(d[h-1][w-1])"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s248368817', 's346222969', 's328564725'] | [79092.0, 3188.0, 3188.0] | [2108.0, 48.0, 55.0] | [697, 882, 818] |
p02735 | u177411511 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip() # ignore trailing spaces\n\nh, w = na()\nm = []\nm = [ns() for _ in range(h)]\ndp = [[inf] * w for _ in range(h)]\ndp[0][0] = int(m[0][0] == \'#\')\nfor x in range(1, w):\n dp[0][x] = dp[0][x-1] + (int(m[0][x]=="#") if m[0][x-1]=="." else 0)\nfor y in range(1, h):\n dp[y][0] = dp[y-1][0] + (int(S[y][0]=="#") if S[y-1][0]=="." else 0)\n for x in range(1, W):\n dp[y][x] = min(\n dp[y][x-1] + (int(S[y][x]=="#") if S[y][x-1]=="." else 0),\n dp[y-1][x] + (int(S[y][x]=="#") if S[y-1][x]=="." else 0)\n )\nprint(dp[-1][-1])', 'import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline().rstrip() # ignore trailing spaces\n\nh, w = na()\nm = []\nm = [ns() for _ in range(h)]\ndp = [[inf] * w for _ in range(h)]\ndp[0][0] = int(m[0][0] == \'#\')\nfor x in range(1, w):\n dp[0][x] = dp[0][x-1] + (int(m[0][x]=="#") if m[0][x-1]=="." else 0)\nfor y in range(1, h):\n dp[y][0] = dp[y-1][0] + (int(m[y][0]=="#") if m[y-1][0]=="." else 0)\n for x in range(1, w):\n dp[y][x] = min(\n dp[y][x-1] + (int(m[y][x]=="#") if m[y][x-1]=="." else 0),\n dp[y-1][x] + (int(m[y][x]=="#") if m[y-1][x]=="." else 0)\n )\nprint(dp[-1][-1])'] | ['Runtime Error', 'Accepted'] | ['s730463682', 's111830958'] | [11012.0, 10928.0] | [36.0, 49.0] | [839, 839] |
p02735 | u185948224 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import sys\ninput = sys.stdin.readline\n\nH, W = map(int, input().split())\ns = ['0' * (W+2)]\nfor _ in range(H):\n s.append('0' + input().rstrip() + '0')\ns.append('0' * (W+2))\n\nans = []\nif s[1][1] == '#': a = 1\nelse: a = 0\ntemp = [[1, 1, a]]\n\nwhile temp:\n p = temp.pop()\n for y, x in [[p[0]+1, p[1]], [p[0], p[1]+1]]:\n if s[y][x] == '0':continue\n if s[y][x] == '#' and s[p[0]][p[1]] == '.':\n d = p[2] + 1\n if y == H and x == W:\n ans.append(d)\n else:\n temp.append([y, x, d])\n \nprint(min(ans))", "import sys\ninput = sys.stdin.readline\n\nH, W = map(int, input().split())\ns = [input().rstrip() for _ in range(H)]\n\ndp = [[1000]*W for _ in range(H)]\n\nif s[0][0] == '#': dp[0][0] = 1\nelse: dp[0][0] = 0\n\nfor j in range(W):\n for i in range(H):\n if i <= H - 2:\n\n if s[i][j] == '.' and s[i+1][j] == '#':\n dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)\n else: dp[i+1][j] = min(dp[i+1][j], dp[i][j])\n if j <= W - 2:\n\n if s[i][j] == '.' and s[i][j+1] == '#':\n dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)\n else: dp[i][j+1] = min(dp[i][j+1], dp[i][j])\n\n\nprint(dp[H-1][W-1])"] | ['Runtime Error', 'Accepted'] | ['s880900227', 's317925518'] | [4960.0, 3188.0] | [2104.0, 33.0] | [567, 648] |
p02735 | u188745744 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H,W=list(map(int,input().split()))\nl=[list(input()) for i in range(H)]\nDP=[[201]*W for i in range(H)]\nDP[0][0]=0\nfor y in range(H):\n for x in range(W):\n if x ==0 and y==0:\n DP[y][x] += 1 if l[y][x] == "#" else 0\n continue\n elif x == 0:\n DP[y][x] = DP[y-1][x]\n elif y == 0:\n DP[y][x] = DP[y][x-1]\n else:\n DP[y][x] = min(DP[y][x-1],DP[y-1][x])\n DP[y][x] += 1 if l[y][x] == "#" else 0\nprint(DP[H-1][W-1])\nprint(DP)', 'H,W=list(map(int,input().split()))\nl=[list(input()) for i in range(H)]\ninf=10**9\nDP=[[inf]*W for i in range(H)]\nDP[0][0]=0 if l[0][0]=="." else 1\nfor i in range(H):\n for j in range(W):\n if i>0:\n DP[i][j]=min(DP[i][j],DP[i-1][j]+1) if l[i-1][j] == "." and l[i][j]=="#" else min(DP[i][j],DP[i-1][j])\n if j>0:\n DP[i][j]=min(DP[i][j],DP[i][j-1]+1) if l[i][j-1] == "." and l[i][j]=="#" else min(DP[i][j],DP[i][j-1])\nprint(DP[H-1][W-1])'] | ['Wrong Answer', 'Accepted'] | ['s716510221', 's211435430'] | [3444.0, 9392.0] | [27.0, 41.0] | [478, 458] |
p02735 | u204616996 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import sys\ninput = sys.stdin.readline\nH,W=map(int,input().split())\nS=[list(input()) for i in range(H)]\ndp=[0]*W\nif S[0][0]=='#':\n dp[0]=1\nfor j in range(1,W):\n if S[0][j]!=S[0][j-1]:\n dp[j]=dp[j-1]+1\n else:\n dp[j]=dp[j-1]\n\nfor i in range(1,H):\n print(dp)\n if S[i][0]!=S[i-1][0]:\n dp[0]=dp[0]+1\n for j in range(1,W):\n hidari=1 if S[i][j]!=S[i][j-1] and S[i][j-1]=='#' else 0\n ue=1 if S[i][j]!=S[i-1][j] and S[i-1][j]=='#' else 0\n dp[j]=min(dp[j-1]+hidari,dp[j]+ue)\nprint(dp)\nprint(dp[-1])", "import sys\ninput = sys.stdin.readline\nH,W=map(int,input().split())\nS=[list(input()) for i in range(H)]\ndp=[0]*W\nif S[0][0]=='#':\n dp[0]=1\nfor j in range(1,W):\n if S[0][j]!=S[0][j-1] and S[0][j-1]=='.':\n dp[j]=dp[j-1]+1\n else:\n dp[j]=dp[j-1]\nfor i in range(1,H):\n if S[i][0]!=S[i-1][0] and S[i-1][0]=='.':\n dp[0]=dp[0]+1\n for j in range(1,W):\n hidari=1 if S[i][j]!=S[i][j-1] and S[i][j-1]=='.' else 0\n ue=1 if S[i][j]!=S[i-1][j] and S[i-1][j]=='.' else 0\n dp[j]=min(dp[j-1]+hidari,dp[j]+ue)\nprint(dp[-1])"] | ['Wrong Answer', 'Accepted'] | ['s779120617', 's906992638'] | [3188.0, 3188.0] | [30.0, 29.0] | [511, 526] |
p02735 | u210827208 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import heapq\n \nh,w=map(int,input().split())\nS=[]\nfor i in range(h):\n S.append(input())\n \nvisited=[[0]*w for _ in range(h)]\n \nq=[(0,0,0)]\n \nheapq.heapify(q)\nvisited=[[0]*w for _ in range(h)]\ncnt=0\nD=[[0]*w for _ in range(h)]\nwhile q:\n cnt,px,py=heapq.heappop(q)\n D[px][py]=min(cnt,D[px][py])\n if visited[px][py]==1:\n continue\n visited[px][py]=1\n\n for x,y in [(1,0),(0,1)]:\n if x+px>=h or y+py>=w:\n continue\n if S[px+x][py+y]!=S[px][py]:\n heapq.heappush(q,(cnt+1,px+x,py+y))\n else:\n heapq.heappush(q,(cnt,px+x,py+y))\nif D[h-1][w-1]==0 and S[0][0]=='#':\n print(1)\nelse:\n print(D[h-1][w-1]+1//2)", "h,w=map(int,input().split())\nS=[]\nfor i in range(h):\n S.append(input())\n \ncnt=0\nD=[[10**9]*w for _ in range(h)]\nD[0][0]=0\nfor i in range(h):\n for j in range(w):\n for x,y in [(0,1),(1,0)]:\n if i+x>=h or j+y>=w:\n continue\n if S[i][j]!=S[i+x][j+y]:\n D[i+x][j+y]=min(D[i][j]+1,D[i+x][j+y])\n else:\n D[i+x][j+y]=min(D[i][j],D[i+x][j+y])\n \n \nif S[0][0]=='#':\n print(1+D[h-1][w-1]//2)\nelse:\n print(D[h-1][w-1]//2+(S[0][0]!=S[h-1][w-1]))"] | ['Wrong Answer', 'Accepted'] | ['s514489326', 's571310894'] | [3316.0, 3064.0] | [64.0, 43.0] | [680, 558] |
p02735 | u230117534 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['def flip_sq(sy, sx):\n gy = sy\n gx = sx\n while True:\n if sx == W - 1:\n if tiles[sy+1][sx] == "#":\n sy += 1\n else:\n break\n elif tiles[sy][sx+1] == "#":\n sx += 1\n if sy == H - 1:\n break\n if tiles[sy+1][sx] == "#":\n sy += 1\n else:\n break\n for y in range(gy, sy+1):\n for x in range(gx, sx+1):\n tiles[y][x] = flip[tiles[y][x]]\n\n print(tiles)\n\nH, W = [int(i) for i in input().strip().split(" ")]\ntiles = []\nfor i in range(H):\n tiles.append([i for i in input().strip()])\n\ntile = {"#":1, ".":0}\nflip = {"#":".", ".":"#"}\ncount = []\nfor i in range(H):\n count.append([])\n for j in range(W):\n count[i].append(0)\n\ncount[0][0] = tile[tiles[0][0]]\nif tile[tiles[0][0]]:\n flip_sq(0, 0)\n\nfor y in range(H):\n for x in range(W):\n if y == 0:\n if x == 0:\n continue\n count[y][x] = count[y][x-1] + tile[tiles[y][x]]\n else:\n if x == 0:\n count[y][x] = count[y-1][x] + tile[tiles[y][x]]\n else:\n count[y][x] = min(count[y-1][x], count[y][x-1]) + tile[tiles[y][x]]\n if tile[tiles[y][x]]:\n flip_sq(y, x)\n\nprint(count[H-1][W-1])', 'H, W = map(int, input().split())\ngrid = [list(input().strip()) for _ in range(H)]\n\nans = [[0] * W for _ in range(H)]\n\nif grid[0][0] == "#":\n ans[0][0] = 1\n\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n continue\n\n r = H*W\n d = H*W\n if j > 0 and grid[i][j] != grid[i][j-1] and grid[i][j-1] == ".":\n r = 1 + ans[i][j-1]\n elif j > 0:\n r = ans[i][j-1]\n\n if i > 0 and grid[i][j] != grid[i-1][j] and grid[i-1][j] == ".":\n d = 1 + ans[i-1][j]\n elif i > 0:\n d = ans[i-1][j]\n ans[i][j] = min(r, d)\n\nprint(ans[H-1][W-1])'] | ['Runtime Error', 'Accepted'] | ['s644555006', 's509022789'] | [134572.0, 3188.0] | [1890.0, 33.0] | [1321, 643] |
p02735 | u231189826 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['from collections import deque\n\nH,W = list(map(int, input().split()))\nmaze = [input() for _ in range(H)]\n\ndef bfs(maze,visited,gx,gy):\n stack = deque([[0,0]])\n if maze[0][0] == \'#\':\n visited[0][0] = 1 \n else:\n visited[0][0] = 0 \n while stack:\n print(stack)\n print(visited)\n y,x = stack.pop()\n count = visited[y][x]\n \n for j,k in ([1,0],[0,1]):\n new_y,new_x = y+j,x+k\n if new_x >= gx or new_y >= gy:\n continue\n elif maze[new_y][new_x] == "#" and maze[y][x] == \'#\':\n visited[new_y][new_x] = min(count,visited[new_y][new_x])\n stack.appendleft([new_y, new_x])\n elif maze[new_y][new_x] == "#" and maze[y][x] == \'.\':\n visited[new_y][new_x] = min(count+1,visited[new_y][new_x])\n stack.appendleft([new_y, new_x])\n else:\n visited[new_y][new_x] = min(count,visited[new_y][new_x])\n stack.appendleft([new_y, new_x])\n return visited[gy-1][gx-1]\n\ninf = float(\'inf\')\nvisited = [[inf]*W for _ in range(H)]\nprint(bfs(maze,visited,W,H))\n', 'from collections import deque\n\nH,W = list(map(int, input().split()))\nmaze = [input() for _ in range(H)]\n\ndef bfs(maze,visited,gx,gy):\n stack = deque([[0,0]])\n if maze[0][0] == \'#\':\n visited[0][0] = 1 \n else:\n visited[0][0] = 0 \n while stack:\n y,x = stack.pop()\n count = visited[y][x]\n \n for j,k in ([1,0],[0,1]):\n new_y,new_x = y+j,x+k\n if new_x >= gx or new_y >= gy:\n continue\n elif maze[new_y][new_x] == "#" and maze[y][x] == \'.\' and visited[new_y][new_x] > count+1:\n visited[new_y][new_x] = count+1\n stack.appendleft([new_y, new_x])\n elif maze[new_y][new_x] == "#" and maze[y][x] == \'.\' and visited[new_y][new_x] <= count+1:\n continue\n elif visited[new_y][new_x] > count:\n visited[new_y][new_x] = count\n stack.appendleft([new_y, new_x])\n return visited[gy-1][gx-1]\n\ninf = float(\'inf\')\nvisited = [[inf]*W for _ in range(H)]\nprint(bfs(maze,visited,W,H))\n'] | ['Wrong Answer', 'Accepted'] | ['s686612698', 's174583425'] | [77588.0, 3572.0] | [2104.0, 128.0] | [1151, 1059] |
p02735 | u239528020 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import numpy as np\nH, W = map(int, input().split())\n\nS = [list(str(input())) for i in range(H)]\nS = np.array(S)\n\ndp = np.zeros((H,W), dtype=np.int)\n\ndp[0,:] = np.cumsum(S[0,:]=="#")\ndp[:,0] = np.cumsum(S[:,0]=="#")\n\nfor i in range(1, H):\n for j in range(1, W):\n if S[i,j] == "#":\n dp[i,j]+=1\n dp[i,j]+=min(dp[i-1,j], dp[i,j-1])\n\nprint(int(dp[-1,-1]))', '# Code for A - Range Flip Find Route\n# Use input() to fetch data from STDIN\n\nimport numpy as np\nH, W = map(int, input().split())\n\nS = [list(str(input())) for i in range(H)]\nS = np.array(S)\n\ndp = np.zeros((H, W), dtype=np.int)\n\ndp[0, :] = np.cumsum(S[0, :] == "#")\ndp[:, 0] = np.cumsum(S[:, 0] == "#")\n\nfor i in range(1, H):\n for j in range(1, W):\n if S[i, j] == "#":\n dp[i, j] += 1\n dp[i, j] += min(dp[i-1, j], dp[i, j-1])\n\nprint(dp[-1, -1])\n', '# Code for A - Range Flip Find Route\n# Use input() to fetch data from STDIN\n\nimport numpy as np\nH, W = map(int, input().split())\n\nS = [list(str(input())) for i in range(H)]\nS = np.array(S)\n\ndp = np.zeros((H, W), dtype=np.int)\n\n# init\nif S[0, 0] == "#":\n dp[0, 0] = 1\nelse:\n dp[0, 0] = 0\n\nfor i in range(1, W):\n if S[0, i] == "#":\n if S[0, i] == S[0, i-1]:\n dp[0, i] = dp[0, i-1]\n else:\n dp[0, i] = dp[0, i-1]+1\n else:\n dp[0, i] = dp[0, i-1]\n S[0, i] = "."\nfor i in range(1, H):\n if S[i, 0] == "#":\n if S[i, 0] == S[i-1, 0]:\n dp[i, 0] = dp[i-1, 0]\n else:\n dp[i, 0] = dp[i-1, 0]+1\n else:\n dp[i, 0] = dp[i-1, 0]\n S[i, 0] = "."\n\n\nfor i in range(1, H):\n for j in range(1, W):\n # tmp1 = dp[i-1, j]\n # if S[i, j] == "#":\n # tmp1 += 1\n\n if S[i, j] == "#":\n if S[i, j] == S[i-1, j]:\n tmp1 = dp[i-1, j]\n else:\n tmp1 = dp[i-1, j]+1\n else:\n tmp1 = dp[i-1, j]\n\n if S[i, j] == "#":\n if S[i, j] == S[i, j-1]:\n tmp2 = dp[i, j-1]\n else:\n tmp2 = dp[i, j-1]+1\n else:\n tmp2 = dp[i, j-1]\n\n dp[i, j] = min(tmp1, tmp2)\n# print(dp)\nprint(dp[-1, -1])\n', '# Code for A - Range Flip Find Route\n# Use input() to fetch data from STDIN\n\nimport numpy as np\nH, W = map(int, input().split())\n\nS = [list(str(input())) for i in range(H)]\nS = np.array(S)\n\ndp = np.zeros((H, W), dtype=np.int)\n\n# init\nif S[0, 0] == "#":\n dp[0, 0] = 1\nelse:\n dp[0, 0] = 0\n\nfor i in range(1, W):\n if S[0, i] == "#":\n if S[0, i] == S[0, i-1]:\n dp[0, i] = dp[0, i-1]\n else:\n dp[0, i] = dp[0, i-1]+1\n else:\n dp[0, i] = dp[0, i-1]\nfor i in range(1, H):\n if S[i, 0] == "#":\n if S[i, 0] == S[i-1, 0]:\n dp[i, 0] = dp[i-1, 0]\n else:\n dp[i, 0] = dp[i-1, 0]+1\n else:\n dp[i, 0] = dp[i-1, 0]\n\n# print(dp)\n\nfor i in range(1, H):\n for j in range(1, W):\n tmp1 = dp[i-1, j]\n if S[i, j] == "#":\n tmp1 += 1\n\n tmp2 = dp[i, j-1]\n if S[i, j] == "#":\n tmp2 += 1\n\n # if S[i, j] == "#":\n # if S[i, j] == S[i, j-1]:\n # tmp2 = dp[i, j-1]\n # else:\n # tmp2 = dp[i, j-1]+1\n # else:\n # tmp2 = dp[i, j-1]\n # if S[i, 0] == "#":\n # tmp2 += 1\n\n dp[i, j] = min(tmp1, tmp2)\n# print(dp)\nprint(dp[-1, -1])\n', '# Code for A - Range Flip Find Route\n# Use input() to fetch data from STDIN\n\nimport numpy as np\nH, W = map(int, input().split())\n\nS = [list(str(input())) for i in range(H)]\nS = np.array(S)\n\ndp = np.zeros((H, W), dtype=np.int)\n\n# init\nif S[0, 0] == "#":\n dp[0, 0] = 1\nelse:\n dp[0, 0] = 0\n\nfor i in range(1, W):\n if S[0, i] == "#":\n if S[0, i] == S[0, i-1]:\n dp[0, i] = dp[0, i-1]\n else:\n dp[0, i] = dp[0, i-1]+1\n else:\n dp[0, i] = dp[0, i-1]\nfor i in range(1, H):\n if S[i, 0] == "#":\n if S[i, 0] == S[i-1, 0]:\n dp[i, 0] = dp[i-1, 0]\n else:\n dp[i, 0] = dp[i-1, 0]+1\n else:\n dp[i, 0] = dp[i-1, 0]\n\n# print(dp)\n\nfor i in range(1, H):\n for j in range(1, W):\n tmp1 = dp[i-1, j]\n if S[i, j] == "#":\n tmp1 += 1\n\n if S[i, j] == "#":\n if S[i, j] == S[i, j-1]:\n dp[i, j] = dp[i, j-1]\n else:\n dp[i, j] = dp[i, j-1]+1\n else:\n dp[i, j] = dp[i, j-1]\n\n dp[i, j] = min(dp[i, j], tmp1)\n# print(dp)\nprint(dp[-1, -1])\n', 'import numpy as np\nH, W = map(int, input().split())\n\nS = [np.array(list(str(input())))=="\nS = np.array(S)\nprint(S)\n\ndp = np.zeros((H,W), dtype=np.int)\n\ndp[0,:] = np.cumsum(S[0,:])\ndp[:,0] = np.cumsum(S[:,0])\n\nfor i in range(1, H):\n for j in range(1, W):\n if S[i,j] == True:\n dp[i,j]+=1\n dp[i,j]+=min(dp[i-1,j], dp[i,j-1])\n\nprint(int(dp[H-1,W-1]))', 'import numpy as np\nH, W = map(int, input().split())\n\nS = [np.array(list(str(input())))=="\nS = np.array(S)\n\ndp = np.zeros((H,W), dtype=np.int)\n\ndp[0,:] = np.cumsum(S[0,:])\ndp[:,0] = np.cumsum(S[:,0])\n\nfor i in range(1, H):\n for j in range(1, W):\n if S[i,j] == True:\n dp[i,j]+=1\n dp[i,j]+=min(dp[i-1,j], dp[i,j-1])\n\nprint(int(dp[H-1,W-1]))', '#!/usr/bin/env python3\n\nh, w = list(map(int, input().split()))\n\nss = [list(str(input())) for _ in range(h)]\n\ndp = [[100*100 for _ in range(w)] for i in range(h)] # dp[h][w]\n\nif ss[0][0] == "#":\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n# print(dp)\n\nfor h_tmp in range(0, h):\n for w_tmp in range(0, w):\n if w_tmp > 0:\n # print(dp[h_tmp][w_tmp-1])\n if ss[h_tmp][w_tmp-1] == "." and ss[h_tmp][w_tmp] == "#":\n dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp][w_tmp-1]+1)\n else:\n dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp][w_tmp-1])\n if h_tmp > 0:\n # print(dp[h_tmp][w_tmp-1])\n if ss[h_tmp-1][w_tmp] == "." and ss[h_tmp][w_tmp] == "#":\n dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp-1][w_tmp]+1)\n else:\n dp[h_tmp][w_tmp] = min(dp[h_tmp][w_tmp], dp[h_tmp-1][w_tmp])\n\n# print(dp)\nprint(dp[-1][-1])\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s169568945', 's374284737', 's779143847', 's788613021', 's800519510', 's836501685', 's868882444', 's071777133'] | [21960.0, 21944.0, 12640.0, 12616.0, 14416.0, 21580.0, 12484.0, 3188.0] | [362.0, 974.0, 190.0, 190.0, 194.0, 1574.0, 219.0, 32.0] | [378, 470, 1325, 1241, 1114, 395, 386, 947] |
p02735 | u290187182 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import sys\nimport copy\nimport math\nimport fractions\n\nimport bisect\nimport pprint\nimport bisect\nfrom functools import reduce\nfrom copy import deepcopy\nfrom collections import deque\nimport numpy as np\nfrom decimal import *\nsys.setrecursionlimit(10 ** 6)\n\ndef CalcList(list):\n bfnum = -1\n afterList =[]\n for i in list:\n if bfnum == -1:\n bfnum = i\n else:\n now = abs(i -bfnum)\n if now >0:\n afterList.append(now)\n bfnum = i\n return afterList\n\ndef CheckList(list):\n bfnum = -1\n count = 0\n afterList =[]\n for i in list:\n if bfnum == -1:\n bfnum = i\n afterList.append(i)\n else:\n if i == bfnum:\n count = count +1\n if count < 3:\n afterList.append(i)\n else:\n afterList.append(i)\n return afterList\n\n\nif __name__ == '__main__':\n n = int(input())\n s = input()\n list =list(map(lambda x: int(x), s))\n\n while(len(list) >1):\n list = CalcList(list)\n\n if len(list) ==0:\n print(0)\n else:\n print(list[0])", 'import sys\nimport copy\nimport math\nimport fractions\n\nimport bisect\nimport pprint\nimport bisect\nfrom functools import reduce\nfrom copy import deepcopy\nfrom collections import deque\nimport numpy as np\nfrom decimal import *\n\nmaiz = []\nmaxh = 0\nmaxw = 0\n\n\ndef CheckCost(h, w):\n if h + 1 < maxh:\n if costList[h + 1][w] == -1 or costList[h + 1][w] > costList[h][w] + CheckColum(h + 1, w ,maiz[h][w]):\n costList[h + 1][w] = costList[h][w] + CheckColum(h + 1, w ,maiz[h][w])\n CheckCost(h + 1, w)\n\n if w + 1 < maxw:\n if costList[h][w + 1] == -1 or costList[h][w + 1] > costList[h][w] + CheckColum(h, w + 1,maiz[h][w]):\n costList[h][w + 1] = costList[h][w] + CheckColum(h, w + 1,maiz[h][w])\n CheckCost(h, w + 1)\n\n\ndef CheckColum(h, w ,s):\n if maiz[h][w] == "#" and s == ".":\n return 1\n else:\n return 0\n\n\nif __name__ == \'__main__\':\n h, w = map(int, input().split())\n maxh = h\n maxw = w\n costList = []\n for i in range(h):\n costList.append([-1] * w)\n\n for i in range(h):\n s = input()\n maiz.append(list(map(lambda x: x, s)))\n if maiz[0][0] == "#":\n costList[0][0] = 1\n else:\n costList[0][0] = 0\n\n CheckCost(0, 0)\n\n print(costList[h - 1][w - 1])\n'] | ['Runtime Error', 'Accepted'] | ['s927526706', 's266728979'] | [21996.0, 13672.0] | [292.0, 654.0] | [1141, 1280] |
p02735 | u291988695 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h,w=map(int,input().split())\nli=[[]]*h\nfor i in range(h):\n li[i]=[str(k) for k in input()]\n \nlil=[[0 for i in range(w)] for j in range(h)]\n\nfor i in range(h):\n for j in range(w):\n if i==0 and j==0:\n if li[0][0]==".":\n lil[0][0]=0\n else:\n lil[0][0]=1\n elif i==0:\n if li[i][j]==li[i][j-1]:\n lil[i][j]=lil[i][j-1]\n else :\n lil[i][j]=lil[i][j-1]+1\n elif j==0:\n if li[i][j]==li[i-1][j]:\n lil[i][j]=lil[i-1][j]\n else:\n lil[i][j]=lil[i-1][j]+1\n else:\n if li[i][j]==li[i-1][j]:\n ko=lil[i-1][j]\n else:\n ko=lil[i-1][j]+1\n if li[i][j]==li[i][j-1]:\n ks=lil[i][j-1]\n else :\n ks=lil[i][j-1]+1\n lil[i][j]=min(ko,ks)\nprint(lil[h-1][w-1]) ', 'h,w=map(int,input().split())\nli=[[]]*h\nfor i in range(h):\n li[i]=[str(k) for k in input()]\n \nlil=[[0 for i in range(w)] for j in range(h)]\n\nfor i in range(h):\n for j in range(w):\n if i==0 and j==0:\n if li[0][0]==".":\n lil[0][0]=0\n else:\n lil[0][0]=1\n elif i==0:\n if li[i][j]==li[i][j-1] or li[i][j]==".":\n lil[i][j]=lil[i][j-1]\n elif li[i][j]=="#":\n lil[i][j]=lil[i][j-1]+1\n elif j==0:\n if li[i][j]==li[i-1][j] or li[i][j]==".":\n lil[i][j]=lil[i-1][j]\n elif li[i][j]=="#":\n lil[i][j]=lil[i-1][j]+1\n else:\n if li[i][j]==li[i-1][j] or li[i][j]==".":\n ko=lil[i-1][j]\n elif li[i][j]=="#":\n ko=lil[i-1][j]+1\n if li[i][j]==li[i][j-1] or li[i][j]==".":\n ks=lil[i][j-1]\n elif li[i][j]=="#":\n ks=lil[i][j-1]+1\n lil[i][j]=min(ko,ks)\nprint(lil[h-1][w-1]) '] | ['Wrong Answer', 'Accepted'] | ['s032810901', 's371365992'] | [3316.0, 3316.0] | [31.0, 33.0] | [806, 926] |
p02735 | u311379832 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import copy\nH, W = map(int, input().split())\ns = [[0] * W]\nminus = 0\ntmp = [list(input()) for _ in range(H)]\nfor i in range(H):\n s.append(tmp[i])\nif s[1][0] == '#':\n minus = 1\n for i in range(W):\n s[0][i] = 1\nelse:\n s[0][0] = 0\n\nscopy = copy.deepcopy(s)\nfor i in range(1, H + 1):\n for j in range(W):\n if s[i][j] == '#':\n if j != 0 and i == 1:\n s[i][j] = s[i][j - 1] + 1\n elif j != 0:\n s[i][j] = min(s[i - 1][j] + 1, s[i][j - 1] + 1)\n else:\n s[i][j] = s[i - 1][j] + 1\n for k in range(i, H + 1):\n if k == i:\n for l in range(j, W):\n if l == j: continue\n if s[k][l] != '.':\n s[k][l] = s[i][j]\n else:\n break\n else:\n if s[k][j] != '.':\n s[k][j] = s[i][j]\n else:\n break\n elif s[i][j] == '.':\n index = 0\n if scopy[i][j] == '#':\n index += 1\n if j != 0 and i == 1:\n s[i][j] = s[i][j - 1] + index\n elif j != 0:\n s[i][j] = min(s[i - 1][j] + index, s[i][j - 1] + index)\n else:\n s[i][j] = s[i - 1][j] + index\nprint(s)\nprint(s[-1][-1] - minus)", "\nINF = 10 ** 9\nH, W = map(int, input().split())\ns = [list(input()) for _ in range(H)]\ndp = [[INF for _ in range(W)] for _ in range(H)]\nif s[0][0] == '#':\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(H):\n for j in range(W):\n if j != 0:\n cnt = 0\n if s[i][j] == '#' and s[i][j - 1] == '.':\n cnt += 1\n dp[i][j] = min(dp[i][j], dp[i][j - 1] + cnt)\n\n if i != 0:\n cnt = 0\n if s[i][j] == '#' and s[i - 1][j] == '.':\n cnt += 1\n dp[i][j] = min(dp[i][j], dp[i - 1][j] + cnt)\n\nprint(dp[-1][-1])"] | ['Wrong Answer', 'Accepted'] | ['s292432583', 's771992801'] | [3828.0, 3316.0] | [46.0, 34.0] | [1424, 606] |
p02735 | u321035578 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["def main():\n h,w = map(int, input().split())\n s = []\n for i in range(h):\n ss = list(input())\n s.append(ss)\n\n now = [0,0]\n cnt = 0\n if s[0][0] == '#':\n cnt += 1\n # s[0][0] = '.'\n if s[h-1][w-1] == '#':\n # cnt += 1\n # s[h-1][w-1] = '.'\n\n dp = [[-1] * w for i in range(h)]\n dp[0][0] = cnt\n\n for i in range(h):\n for j in range(w):\n tmp_up = 100000\n tmp_left = 100000\n change = 0\n if s[i][j] == '#':\n change = 1\n if i == 0 and j == 0:\n continue\n if i != 0:\n if s[i-1][j] == '#' and s[i][j] == '#':\n tmp_up = dp[i-1][j]\n else:\n tmp_up = dp[i-1][j] + change\n if j != 0:\n if s[i][j-1] == '#' and s[i][j] == '#':\n tmp_left = dp[i][j-1]\n else:\n\n tmp_left = dp[i][j-1] + change\n\n dp[i][j] = min(tmp_up,tmp_left)\n\n\n print(dp[h-1][w-1])\n print(dp)\n\nif __name__ == '__main__':\n main()\n", "def main():\n h,w = map(int, input().split())\n s = []\n for i in range(h):\n ss = list(input())\n s.append(ss)\n\n now = [0,0]\n cnt = 0\n if s[0][0] == '#':\n cnt += 1\n # s[0][0] = '.'\n \n\n dp = [[-1] * w for i in range(h)]\n dp[0][0] = cnt\n\n for i in range(h):\n for j in range(w):\n tmp_up = 100000\n tmp_left = 100000\n change = 0\n if s[i][j] == '#':\n change = 1\n if i == 0 and j == 0:\n continue\n if i != 0:\n if s[i-1][j] == '#' and s[i][j] == '#':\n tmp_up = dp[i-1][j]\n else:\n tmp_up = dp[i-1][j] + change\n if j != 0:\n if s[i][j-1] == '#' and s[i][j] == '#':\n tmp_left = dp[i][j-1]\n else:\n\n tmp_left = dp[i][j-1] + change\n\n dp[i][j] = min(tmp_up,tmp_left)\n\n\n print(dp[h-1][w-1])\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s424465837', 's576015191'] | [2940.0, 3188.0] | [17.0, 26.0] | [1114, 1031] |
p02735 | u329407311 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H,W=map(int,input().split())\n\ndp = [[0 for i in range(W)] for j in range(H)]\n\narr = []\nfor h in range(H):\n s = list(input())\n arr.append(s)\n\nif arr[0][0] == "#":\n dp[0][0] = 1\n \nfor h in range(H):\n for w in range(W):\n if h == 0:\n if w != 0:\n a = arr[h][w]\n b = arr[h][w-1]\n if a == b or a == ".":\n dp[h][w] = dp[h][w-1]\n else:\n dp[h][w] = dp[h][w-1] + 1\n \n else: \n if w == 0:\n a = arr[h][w]\n b = arr[h-1][w]\n if a == b or a == ".":\n dp[h][w] = dp[h-1][w]\n else:\n dp[h][w] = dp[h-1][w] + 1\n\n else:\n a = arr[h][w] \n b = arr[h][w-1]\n c = arr[h-1][w]\n if a == b or a == "." or a == c:\n dp[h][w] = min(dp[h][w-1],dp[h-1][w])\n else:\n dp[h][w] = min(dp[h][w-1] + 1,dp[h-1][w]+1)\n \nprint(dp[H-1][W-1])', 'H,W=map(int,input().split())\n\ndp = [[0 for i in range(W)] for j in range(H)]\n\narr = []\nfor h in range(H):\n s = list(input())\n arr.append(s)\n\nif arr[0][0] == "#":\n dp[0][0] = 1\n \nfor h in range(H):\n for w in range(W):\n if h == 0:\n if w != 0:\n a = arr[h][w]\n b = arr[h][w-1]\n if a == b or a == ".":\n dp[h][w] = dp[h][w-1]\n else:\n dp[h][w] = dp[h][w-1] + 1\n \n else: \n if w == 0:\n a = arr[h][w]\n b = arr[h-1][w]\n if a == b or a == ".":\n dp[h][w] = dp[h-1][w]\n else:\n dp[h][w] = dp[h-1][w] + 1\n\n else:\n a = arr[h][w] \n b = arr[h][w-1]\n c = arr[h-1][w]\n if a == "." or (a == b and a == c):\n dp[h][w] = min(dp[h][w-1],dp[h-1][w])\n elif a == b:\n dp[h][w] = dp[h][w-1]\n elif a == c:\n dp[h][w] = dp[h-1][w]\n else:\n dp[h][w] = min(dp[h][w-1] + 1,dp[h-1][w]+1)\n \nprint(dp[H-1][W-1])'] | ['Wrong Answer', 'Accepted'] | ['s955199786', 's097492872'] | [3316.0, 3316.0] | [29.0, 30.0] | [873, 982] |
p02735 | u354126779 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h,w=map(int,input().split())\n\nm=[input() for i in range(w)]\n\ncnt=[[1000000 for i in range(h)] for j in range(w)]\n\n\n\nprint(0)\n', 'print(0)\n', 'h,w=map(int,input().split())\n\nm=[input() for i in range(w)]\n\nprint("A")\ncnt=[[1000000 for i in range(h)] for j in range(w)]\n\nif m[0][0]=="#":\n cnt[0][0]=1\nelse:\n cnt[0][0]=0\n\nfor y in range(w):\n for x in range(h):\n if x>0:\n if m[y][x-1]=="." and m[y][x]=="#":\n cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)\n else:\n cnt[y][x]=min(cnt[y][x],cnt[y][x-1])\n if y>0:\n if m[y-1][x]=="." and m[y][x]=="#":\n cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)\n else:\n cnt[y][x]=min(cnt[y][x],cnt[y-1][x])\n\n\nprint(cnt[w-1][h-1])\n', 'h,w=map(int,input().split())\n\nm=[input() for i in range(w)]\n\n\ncnt=[[1000000 for i in range(h)] for j in range(w)]\n\nprint(cnt)\nif m[0][0]=="#":\n cnt[0][0]=1\nelse:\n cnt[0][0]=0\n\nfor y in range(w):\n for x in range(h):\n if x>0:\n if m[y][x-1]=="." and m[y][x]=="#":\n cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)\n else:\n cnt[y][x]=min(cnt[y][x],cnt[y][x-1])\n if y>0:\n if m[y-1][x]=="." and m[y][x]=="#":\n cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)\n else:\n cnt[y][x]=min(cnt[y][x],cnt[y-1][x])\n\n\nprint(cnt[w-1][h-1])', 'h,w=map(int,input().split())\n\nm=[input() for i in range(w)]\n\ncnt=[[1000000 for i in range(h)] for j in range(w)]\n\nif m[0][0]=="#":\n cnt[0][0]=1\nelse:\n cnt[0][0]=0\n\n\nprint(0)\n', 'h,w=map(int,input().split())\n\nm=[input() for i in range(w)]\n\n\n\n\nprint(0)\n', 'h,w=map(int,input().split())\n\nm=[input() for i in range(h)]\n\n\ncnt=[[1000000 for i in range(w)] for j in range(h)]\n\nif m[0][0]=="#":\n cnt[0][0]=1\nelse:\n cnt[0][0]=0\n\nfor y in range(h):\n for x in range(w):\n if x>0:\n if m[y][x-1]=="." and m[y][x]=="#":\n cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)\n else:\n cnt[y][x]=min(cnt[y][x],cnt[y][x-1])\n if y>0:\n if m[y-1][x]=="." and m[y][x]=="#":\n cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)\n else:\n cnt[y][x]=min(cnt[y][x],cnt[y-1][x])\n\n\nprint(cnt[h-1][w-1])'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s066706461', 's306753701', 's413189908', 's468572139', 's682715578', 's838493153', 's819128921'] | [3060.0, 2940.0, 3188.0, 3444.0, 3316.0, 3056.0, 3188.0] | [18.0, 17.0, 31.0, 32.0, 21.0, 17.0, 32.0] | [125, 9, 626, 626, 180, 73, 615] |
p02735 | u357949405 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H, W = map(int, input().split())\nS = [input() for _ in range(H)]\n\ndp = [[0 for _ in range(W)] for _ in range(H)]\n\nif S[0][0] == '#':\n dp[0][0] = 1\n\nfor i in range(1, W):\n if S[0][i] == '#':\n dp[0][i] = dp[0][i-1] + 1\n else:\n dp[0][i] = dp[0][i-1]\n\nfor j in range(1, H):\n if S[j][0] == '#':\n dp[j][0] = dp[j-1][0] + 1\n else:\n dp[j][0] = dp[j-1][0]\n\nfor j in range(1, H):\n for i in range(1, W):\n v = min(dp[j-1][i], dp[j][i-1])\n if S[j][i] == '#':\n dp[j][i] = v + 1\n else:\n dp[j][i] = v\n\nprint(dp[H-1][W-1]-1)\n", "H, W = map(int, input().split())\nS = [input() for _ in range(H)]\n\ndp = [[float('inf') for _ in range(W)] for _ in range(H)]\n\nif S[0][0] == '#':\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(1, W):\n if S[0][i] == '.':\n dp[0][i] = dp[0][i-1]\n else:\n if S[0][i-1] == '.':\n dp[0][i] = dp[0][i-1] + 1\n else:\n dp[0][i] = dp[0][i-1]\n\nfor j in range(1, H):\n if S[j][0] == '.':\n dp[j][0] = dp[j-1][0]\n else:\n if S[j-1][0] == '.':\n dp[j][0] = dp[j-1][0] + 1\n else:\n dp[j][0] = dp[j-1][0]\n\nfor j in range(1, H):\n for i in range(1, W):\n if S[j][i-1] == '.' and S[j][i] == '#':\n dp[j][i] = min(dp[j][i], dp[j][i-1] + 1)\n else:\n dp[j][i] = min(dp[j][i], dp[j][i-1])\n if S[j-1][i] == '.' and S[j][i] == '#':\n dp[j][i] = min(dp[j][i], dp[j-1][i] + 1)\n else:\n dp[j][i] = min(dp[j][i], dp[j-1][i])\n\nprint(dp[H-1][W-1])\n"] | ['Wrong Answer', 'Accepted'] | ['s203619589', 's479157820'] | [3188.0, 3316.0] | [24.0, 33.0] | [597, 984] |
p02735 | u371763408 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H, W = map(int,input().split())\nS = [input() for i in range(H)]\ndp = [[0 for _ in range(W)] for _ in range(H)]\ndp[0][0] = 1 if S[0][0] == "#" else 0\n\nfor i in range(1,H):\n for j in range(1,W):\n up = dp[i-1][j] + (1 if S[i-1][j] != "#" and S[i][j] == "#" else 0) \n left = dp[i][j-1] + (1 if S[i][j-1] != "#" and S[i][j] == "#" else 0)\n dp[i][j] = min(up, left)\nprint(dp[-1][-1])', 'from collections import deque\n\nH, W = map(int,input().split())\nS = [input() for i in range(H)]\ndp = [[0 for _ in range(W)] for _ in range(H)]\ndp[0][0] = 1 if S[0][0] == "#" else 0\nfor i in range(1, H):\n if S[i][0] == "#":\n if S[i-1][0] == "#":\n dp[i][0] = dp[i-1][0]\n else:\n dp[i][0] = dp[i-1][0] + 1\n else:\n dp[i][0] = dp[i-1][0]\n\nfor j in range(1, W):\n if S[0][j] == "#":\n if S[0][j-1] == "#":\n dp[0][j] = dp[0][j-1]\n else:\n dp[0][j] = dp[0][j-1] + 1\n else:\n dp[0][j] = dp[0][j-1]\n\nfor i in range(1,H):\n for j in range(1,W):\n up = dp[i-1][j] + (1 if S[i-1][j] != "#" and S[i][j] == "#" else 0) \n left = dp[i][j-1] + (1 if S[i][j-1] != "#" and S[i][j] == "#" else 0)\n dp[i][j] = min(up, left)\nprint(dp[-1][-1])'] | ['Wrong Answer', 'Accepted'] | ['s285530989', 's082661125'] | [3064.0, 3436.0] | [28.0, 32.0] | [401, 839] |
p02735 | u374531474 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H, W = map(int, input().split())\ns = [input() for i in range(H)]\n\ndp = [[0] * W for i in range(H)]\n\nfor i in range(H):\n for j in range(W):\n c = []\n if 0 <= i - 1 < H:\n c.append(dp[i - 1][j])\n if 0 <= j - 1 < W:\n c.append(dp[i][j - 1])\n if len(c) > 0:\n dp[i][j] = min(c)\n if s[i][j] == '#':\n dp[i][j] += 1\nprint(dp)\nprint(dp[H - 1][W - 1])\n", "H, W = map(int, input().split())\ns = [input() for i in range(H)]\n\ndp = [[0] * W for i in range(H)]\n\nfor i in range(H):\n for j in range(W):\n if i == j == 0:\n if s[i][j] == '#':\n dp[i][j] = 1\n continue\n c = []\n if 0 <= i - 1 < H:\n c.append(dp[i - 1][j]\n + (1 if s[i - 1][j] == '.' and s[i][j] == '#' else 0))\n if 0 <= j - 1 < W:\n c.append(dp[i][j - 1]\n + (1 if s[i][j - 1] == '.' and s[i][j] == '#' else 0))\n if len(c) > 0:\n dp[i][j] = min(c)\n\nprint(dp[H - 1][W - 1])\n"] | ['Wrong Answer', 'Accepted'] | ['s489894818', 's623326927'] | [3316.0, 3064.0] | [33.0, 33.0] | [421, 614] |
p02735 | u379716238 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H, W = map(int, input().split())\ns = []\nfor _ in range(H):\n s.append(input())\n \ndef main(H, W, s):\n \n \n INF = float('inf')\n dp = [[INF]*W for _ in range(H)]\n if s[0][0] == '#':\n dp[0][0] = 1\n else:\n dp[0][0] = 0\n\n dx = (1, 0)\n dy = (0, 1)\n for i in range(H):\n for j in range(W):\n for dir_ in range(2): \n ni = i + dx[dir_]\n nj = j + dy[dir_]\n if ni >= H or nj >= W:\n continue\n add = 0\n if s[ni][nj] == '#' and s[i][j] == '.':\n add = 1\n dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add)\n \n print(dp)\n\n return dp[H-1][W-1]\n\nprint(main(H, W, s))", "H, W = map(int, input().split())\ns = []\nfor _ in range(H):\n s.append(input())\n \ndef main(H, W, s):\n \n \n INF = float('inf')\n dp = [[INF]*W for _ in range(H)]\n if s[0][0] == '#':\n dp[0][0] = 1\n else:\n dp[0][0] = 0\n\n dx = (1, 0)\n dy = (0, 1)\n for i in range(H):\n for j in range(W):\n for dir_ in range(2): \n ni = i + dx[dir_]\n nj = j + dy[dir_]\n if ni >= H or nj >= W:\n continue\n add = 0\n if s[ni][nj] == '#' and s[i][j] == '.':\n add = 1\n dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add)\n\n return dp[H-1][W-1]\n\nprint(main(H, W, s))"] | ['Wrong Answer', 'Accepted'] | ['s969603715', 's735305171'] | [3316.0, 3064.0] | [36.0, 35.0] | [690, 669] |
p02735 | u442877951 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["ans = 0\nH,W = map(int,input().split())\ns = [list(input()) for _ in range(W)]\nif s[H-1][W-1] == '#':\n ans += 1\nif s[0][0] == '#':\n ans += 1\nfor i in range(H):\n for j in range(W):\n if s[i][j] == '.':\n s[i][j] = 0\n else:\n s[i][j] = 1\n \n\nprint(ans)", 'ans = 0\nH,W = map(int,input().split())\ns = [list(input()) for _ in range(W)]\n\nprint(ans)', 'H,W = map(int,input().split())\ns = [list(input()) for _ in range(H)]\ndp = [[0] * W for _ in range(H)]\ndp[0][0] = int(s[0][0]=="#")\n\nfor i in range(1, W):\n dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)\nfor h in range(1,H):\n dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)\n for w in range(1,W):\n dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), \n dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))\nprint(dp[-1][-1])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s527887675', 's864486120', 's904683075'] | [3064.0, 3060.0, 3188.0] | [20.0, 18.0, 28.0] | [268, 88, 497] |
p02735 | u446774692 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H,W = map(int,input().split())\ns = [input() for _ in range(H)]\nimport math\nDP = [[math.inf]+[0]*W for _ in range(H+1)]\nre = [[0]*(W+1) for _ in range(H+1)]\nDP[0] = [math.inf]*(W+1)\nDP[0][1] = DP[1][0] = 0\n\nfor i in range(1,H+1):\n for j in range(1,W+1):\n if s[i-1][j-1] == ".":\n DP[i][j] = min(DP[i-1][j],DP[i][j-1])\n else:\n u = DP[i-1][j]+1-re[i-1][j]\n l = DP[i][j-1]+1-re[i][j-1]\n DP[i][j] = min(u, l)\n re[i][j] = 1\n if u < l and re[i-1][j] == 0:\n DP[i][j] += 1\n elif u > l and re[i][j-1] == 0:\n count += 1\n elif u == l:\n count += 1 - re[i-1][j]*re[i][j-1]\n \nprint(DP[H][W])\n\n', 'H,W = map(int,input().split())\ns = [input() for _ in range(H)]\n\nDP = [[1000]+[0]*W for _ in range(H+1)]\nre = [[0]*(W+1) for _ in range(H+1)]\nDP[0] = [1000]*(W+1)\nDP[0][1] = DP[1][0] = 0\n\nfor i in range(1,H+1):\n for j in range(1,W+1):\n if s[i-1][j-1] == ".":\n DP[i][j] = min(DP[i-1][j],DP[i][j-1])\n else:\n u = DP[i-1][j]+1-re[i-1][j]\n l = DP[i][j-1]+1-re[i][j-1]\n DP[i][j] = min(u, l)\n re[i][j] = 1\n\nprint(DP[H][W])\n'] | ['Runtime Error', 'Accepted'] | ['s079853824', 's046023567'] | [3064.0, 3188.0] | [17.0, 28.0] | [742, 487] |
p02735 | u447899880 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h,w=map(int,input().split())\ns=list()\nfor i in range(h):\n line=str(input())\n s.append(line)\n \nresult=[[0]*w]*h\ndef se(x,y):\n if x==0 and y==0:\n if s[0][0]=="#":\n result[x][y]=1\n else:\n result[x][y]=0\n if x==0:\n if s[x][y-1]!=s[x][y]:\n result[x][y]=result[x][y-1]+1\n else:\n result[x][y]=result[x][y-1]\n if y==0:\n if s[x-1][y]!=s[x][y]:\n result[x][y]=result[x-1][y]+1\n else:\n result[x][y]=result[x-1][y]\n else:\n if s[x][y-1]!=s[x][y]:\n a=result[x][y-1]+1\n else:\n a=result[x][y-1]\n if s[x-1][y]!=s[x][y]:\n b=result[x-1][y]+1\n else:\n b=result[x-1][y]\n result[x][y]=min(a,b)\n \nfor i in range(h):\n for j in range(w):\n se(i,j)\n \nif s[h-1][w-1]=="#":\n result[h-1][w-1]+=1\nelse:\n pass\n \nprint(int(result[h-1][w-1]/2))\n', 'h,w=map(int,input().split())\ns=list()\nfor i in range(h):\n line=str(input())\n s.append(line)\n\nresult=list()\nfor i in range(h):\n line=list()\n for j in range(w):\n line.append(0)\n result.append(line)\ndef se(x,y):\n if x==0 and y==0:\n if s[0][0]=="#":\n result[x][y]=1\n else:\n result[x][y]=0\n if x==0:\n if s[x][y-1]!=s[x][y]:\n result[x][y]=result[x][y-1]+1\n else:\n result[x][y]=result[x][y-1]\n if y==0:\n if s[x-1][y]!=s[x][y]:\n result[x][y]=result[x-1][y]+1\n else:\n result[x][y]=result[x-1][y]\n else:\n if s[x][y-1]!=s[x][y]:\n a=result[x][y-1]+1\n else:\n a=result[x][y-1]\n if s[x-1][y]!=s[x][y]:\n b=result[x-1][y]+1\n else:\n b=result[x-1][y]\n result[x][y]=min(a,b)\n \nfor i in range(h):\n for j in range(w):\n se(i,j)\n \nif s[h-1][w-1]=="#":\n result[h-1][w-1]+=1\nelse:\n pass\n\nprint(result)\nprint(int(result[h-1][w-1]/2))\n', 'h,w=map(int,input().split())\ns=list()\nfor i in range(h):\n line=str(input())\n s.append(line)\n\n\nresult=list()\nfor i in range(h):\n line=list()\n for j in range(w):\n line.append(0)\n result.append(line)\ndef se(x,y):\n if x==0 and y==0:\n if s[0][0]=="#":\n result[x][y]=1\n else:\n result[x][y]=0\n elif x==0:\n if s[x][y-1]!=s[x][y]:\n result[x][y]=result[x][y-1]+1\n else:\n result[x][y]=result[x][y-1]\n elif y==0:\n if s[x-1][y]!=s[x][y]:\n result[x][y]=result[x-1][y]+1\n else:\n result[x][y]=result[x-1][y]\n else:\n if s[x][y-1]!=s[x][y]:\n a=result[x][y-1]+1\n else:\n a=result[x][y-1]\n if s[x-1][y]!=s[x][y]:\n b=result[x-1][y]+1\n else:\n b=result[x-1][y]\n result[x][y]=min(a,b)\n \nfor i in range(h):\n for j in range(w):\n se(i,j)\n \nif s[h-1][w-1]=="#":\n result[h-1][w-1]+=1\nelse:\n pass\n\n\nprint(int(result[h-1][w-1]/2))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s804131921', 's860960445', 's850629295'] | [3064.0, 3316.0, 3188.0] | [28.0, 30.0, 29.0] | [958, 1058, 1049] |
p02735 | u450983668 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["h,w=map(int,input().split())\nc=[[1000]*w]*h\ns=[[+(i=='#') for i in input()] for _ in range(h)]\nc[0][0]=s[0][0]\nfor i in range(h):\n for j in range(w):\n for k,l in [[i-1,j],[i,j-1]]:\n if k<0 or l<0:continue\n if s[i][j]==0:\n c[i][j]=min(c[i][j],c[k][l])\n else:\n if s[k][l]==0:\n c[i][j]=min(c[i][j],c[k][l]+1)\n t=j+1\n if t<w:\n while s[i][t]==1:\n c[i][t]=min(c[i][t],c[i][j])\n t+=1\n if t==w:break\n t=i+1\n if t<h:\n while s[t][j]==1:\n c[t][j]=min(c[t][j],c[i][j])\n t+=1\n if t==h:break\nprint(c[h-1][w-1])", "h,w=map(int,input().split())\ns=[[+(i=='#')for i in input()]for j in range(h)]\nc=[1000]*w*h\nc[0]=s[0][0]\nfor i in range(h):\n for j in range(w):\n for k,l in [[i-1,j],[i,j-1]]:\n if k<0 or l<0:continue\n c[i*w+j]=min(c[i*w+j],c[k*w+l]+(s[k][l]==0)*(s[i][j]==1))\nprint(c[-1])"] | ['Wrong Answer', 'Accepted'] | ['s501680344', 's910789984'] | [3188.0, 3188.0] | [1155.0, 43.0] | [650, 283] |
p02735 | u457901067 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H,W = list(map(int, input().split()))\nB = []\nfor _ in range(H):\n B.append(input())\n \nA = [[999999 for _ in range(W)] for _ in range(H)]\nA[0][0] = 0 if B[0][0] == "." else 1\n\nfor i in range(H):\n for j in range(W):\n if i+j == 0:\n continue\n X,Y = 999999, 999999\n if i > 0:\n X = A[i-1][j] \n X += 1 if B[i-1][j] != B[i][j] else 0\n if j > 0:\n Y = A[i][j-1]\n Y += 1 if B[i][j-1] != B[i][j] else 0\n A[i][j] = min(X,Y)\n \nprint(A[H-1][W-1])', 'H,W = list(map(int, input().split()))\nB = []\nfor _ in range(H):\n B.append(input())\n \nA = [[999999 for _ in range(W)] for _ in range(H)]\nA[0][0] = 0 if B[0][0] == "." else 1\n\nfor i in range(H):\n for j in range(W):\n if i+j == 0:\n continue\n X,Y = 999999, 999999\n if i > 0:\n X = A[i-1][j] \n X += 1 if B[i-1][j] == \'.\' and B[i][j] == \'#\' else 0\n if j > 0:\n Y = A[i][j-1]\n Y += 1 if B[i][j-1] == \'.\' and B[i][j] == \'#\' else 0\n A[i][j] = min(X,Y)\n \nprint(A[H-1][W-1])\n\n# print(A[i])'] | ['Wrong Answer', 'Accepted'] | ['s119015343', 's739869318'] | [3188.0, 3064.0] | [32.0, 31.0] | [476, 541] |
p02735 | u476604182 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H,W,*L = open('0').read().split()\nH,W = map(int, (H,W))\ndp = [[0]*W for i in range(H)]\nif L[0][0]=='#':\n dp[0][0] = 1\nfor i in range(1,H):\n if L[i][0]=='#':\n dp[i][0] = dp[i-1][0]+1\n else:\n dp[i][0] = dp[i-1][0]\nfor j in range(1,W):\n if L[0][j]=='#':\n dp[0][j] = dp[0][j-1]+1\n else:\n dp[0][j] = dp[0][j-1]\nfor i in range(1,H):\n for j in range(1,W):\n if L[i][j]=='#':\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1\n else:\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])\nprint(dp[H-1][W-1])", "H,W,*L = open(0).read().split()\nH,W = map(int, (H,W))\ndp = [[0]*W for i in range(H)]\nfor i in range(1,H):\n if L[i][0]!=L[i-1][0]:\n dp[i][0] = dp[i-1][0]+1\n else:\n dp[i][0] = dp[i-1][0]\nfor j in range(1,W):\n if L[0][j]!=L[0][j-1]:\n dp[0][j] = dp[0][j-1]+1\n else:\n dp[0][j] = dp[0][j-1]\nfor i in range(1,H):\n for j in range(1,W):\n if L[i][j]!=L[i-1][j] and L[i][j]!=L[i][j-1]:\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1\n elif L[i][j]!=L[i-1][j]:\n dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1])\n elif L[i][j]!=L[i][j-1]:\n dp[i][j] = min(dp[i-1][j],dp[i][j-1]+1)\n else:\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])\nif L[0][0]=='.':\n ans = (dp[H-1][W-1]+1)//2\nelse:\n ans = (dp[H-1][W-1]+2)//2\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s164006698', 's441358358'] | [3064.0, 3188.0] | [17.0, 29.0] | [507, 734] |
p02735 | u478266845 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import numpy as np\n\nH,W = [int(i) for i in input().split()]\n\ns=[]\n\nfor i in range(H):\n s.append(str(input()))\n \n# s[i][0] to s[i][W-1] \n\npat_mat=[]\n\nfor i in range(H):\n if i ==0:\n if s[0][0] == ".":\n pat_mat.append([0])\n else:\n pat_mat.append([1])\n if W>1:\n for j in range(1,W):\n if s[0][j] == ".":\n pat_mat[0].append(pat_mat[0][j-1])\n else:\n if s[0][j-1]==s[0][j]:\n pat_mat[0].append(int(pat_mat[0][j-1]))\n else:\n pat_mat[0].append(int(pat_mat[0][j-1]+1))\n else:\n if s[i][0] == ".":\n pat_mat.append([pat_mat[i-1][0]])\n else:\n if s[i-1][j]==s[i][j]:\n pat_mat.append([pat_mat[i-1][0]])\n else:\n pat_mat.append([pat_mat[i-1][0]+1])\n if W>1:\n for j in range(1,W):\n if s[i][j] == ".":\n pat_mat[i].append(min(pat_mat[i][j-1],pat_mat[i-1][j]))\n else:\n if s[i][j-1]==s[i][j]:\n cand_l = pat_mat[i][j-1]\n else:\n cand_l = pat_mat[i][j-1]+1\n if s[i][j]==s[i-1][j]:\n cand_t= pat_mat[i-1][j]\n else:\n cand_t= pat_mat[i-1][j]+1\n\n pat_mat[i].append(min(cand_l,cand_t))\n \n \nprint(int(pat_mat[H-1][W-1]))', 'import numpy as np\n\nH,W = [int(i) for i in input().split()]\n\ns=[]\n\nfor i in range(H):\n s.append(str(input()))\n \n# s[i][0] to s[i][W-1] \n\npat_mat=[]\n\nfor i in range(H):\n if i ==0:\n if s[0][0] == ".":\n pat_mat.append([0])\n else:\n pat_mat.append([1])\n if W>1:\n for j in range(1,W):\n if s[0][j] == ".":\n pat_mat[0].append(pat_mat[0][j-1])\n else:\n if s[0][j-1]==s[0][j]:\n pat_mat[0].append(int(pat_mat[0][j-1]))\n else:\n pat_mat[0].append(int(pat_mat[0][j-1]+1))\n else:\n if s[i][0] == ".":\n pat_mat.append([pat_mat[i-1][0]])\n else:\n if s[i-1][j]==s[i][j]:\n pat_mat.append([pat_mat[i-1][0]])\n else:\n pat_mat.append([pat_mat[i-1][0]+1])\n if W>1:\n for j in range(1,W):\n if s[i][j] == ".":\n pat_mat[i].append(min(pat_mat[i][j-1],pat_mat[i-1][j]))\n else:\n if s[i][j-1]==s[i][j]:\n cand_l = pat_mat[i][j-1]\n else:\n cand_l = pat_mat[i][j-1]+1\n if s[i][j]==s[i-1][j]:\n cand_t= pat_mat[i-1][j]\n else:\n cand_t= pat_mat[i-1][j]+1\n\n pat_mat[i].append(min(cand_l,cand_t))\n \n \nprint(int(pat_mat[H-1][W-1]))', 'import numpy as np\n\nH,W = [int(i) for i in input().split()]\n\ns=[]\n\nfor i in range(H):\n s.append(str(input()))\n \n# s[i][0] to s[i][W-1] \n\npat_mat=[]\n\nfor i in range(H):\n if i ==0:\n if s[0][0] == ".":\n pat_mat.append([0])\n else:\n pat_mat.append([1])\n if W>1:\n for j in range(1,W):\n if s[0][j] == ".":\n pat_mat[0].append(pat_mat[0][j-1])\n else:\n if s[0][j-1]==s[0][j]:\n pat_mat[0].append(int(pat_mat[0][j-1]))\n else:\n pat_mat[0].append(int(pat_mat[0][j-1]+1))\n else:\n if s[i][0] == ".":\n pat_mat.append([pat_mat[i-1][0]])\n else:\n if s[i-1][0]==s[i][0]:\n pat_mat.append([pat_mat[i-1][0]])\n else:\n \n pat_mat.append([pat_mat[i-1][0]+1])\n if W>1:\n for j in range(1,W):\n if s[i][j] == ".":\n pat_mat[i].append(min(pat_mat[i][j-1],pat_mat[i-1][j]))\n else:\n if s[i][j-1]==s[i][j]:\n cand_l = pat_mat[i][j-1]\n else:\n cand_l = pat_mat[i][j-1]+1\n if s[i][j]==s[i-1][j]:\n cand_t= pat_mat[i-1][j]\n else:\n cand_t= pat_mat[i-1][j]+1\n\n pat_mat[i].append(min(cand_l,cand_t))\n \n \nprint(int(pat_mat[H-1][W-1]))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s626308428', 's729835500', 's041960644'] | [12404.0, 12644.0, 14436.0] | [165.0, 163.0, 160.0] | [1557, 1557, 1574] |
p02735 | u496815777 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import numpy\nh, w = map(int, input().split())\ns = [input() for _ in range(h)]\n\ndp = np.zeros(h * w).reshape(h, w)\n\nif s[0][0] == "#":\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n \nfor i in range(h - 1):\n if s[i + 1][0] == "." or s[i][0] == s[i + 1][0]:\n dp[i + 1][0] = dp[i][0]\n else:\n dp[i + 1][0] = dp[i][0] + 1\nfor j in range(w - 1):\n if s[0][j + 1] == "." or s[0][j] == s[0][j + 1]:\n dp[0][j + 1] = dp[0][j]\n else:\n dp[0][j + 1] = dp[0][j] + 1\n\nfor i in range(h - 1):\n for j in range(w - 1):\n if s[i + 1][j + 1] == "." or (s[i][j + 1] == s[i + 1][j + 1] and s[i + 1][j + 1] == s[i + 1][j]):\n dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j])\n elif s[i][j + 1] == s[i + 1][j + 1] and s[i + 1][j + 1] != s[i + 1][j]:\n dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j] + 1)\n elif s[i][j + 1] != s[i + 1][j + 1] and s[i + 1][j + 1] == s[i + 1][j]:\n dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, dp[i + 1][j])\n else:\n dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, dp[i + 1][j] + 1)\n \nif s[h - 1][w - 1] == "#" and (dp[h - 2][w - 1] != 1 and dp[h - 2][w - 1] != 1):\n dp[h- 1][w - 1] += 1\n\nprint(int(dp[h - 1][w - 1]))', 'zimport numpy as np\nh, w = map(int, input().split())\ns = [input() for _ in range(h)]\n\ndp = np.zeros(h * w).reshape(h, w)\n\nif s[0][0] == "#":\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n \nfor i in range(h - 1):\n if s[i + 1][0] == "." or s[i][0] == s[i + 1][0]:\n dp[i + 1][0] = dp[i][0]\n else:\n dp[i + 1][0] = dp[i][0] + 1\nfor j in range(w - 1):\n if s[0][j + 1] == "." or s[0][j] == s[0][j + 1]:\n dp[0][j + 1] = dp[0][j]\n else:\n dp[0][j + 1] = dp[0][j] + 1\n\nfor i in range(h - 1):\n for j in range(w - 1):\n if s[i + 1][j + 1] == "." or (s[i][j + 1] == s[i + 1][j + 1] and s[i + 1][j + 1] == s[i + 1][j]):\n dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j])\n elif s[i][j + 1] == s[i + 1][j + 1] and s[i + 1][j + 1] != s[i + 1][j]:\n dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j] + 1)\n elif s[i][j + 1] != s[i + 1][j + 1] and s[i + 1][j + 1] == s[i + 1][j]:\n dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, dp[i + 1][j])\n else:\n dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, dp[i + 1][j] + 1)\n \nif s[h - 1][w - 1] == "#" and (s[0][0] == "#" and dp[h - 2][w - 1] != 1 and dp[h - 1][w - 2] != 1):\n dp[h- 1][w - 1] += 1\n\nprint(int(dp[h - 1][w - 1]))', 'import numpy as np\nh, w = map(int, input().split())\ns = [input() for _ in range(h)]\n\ndp = np.zeros(h * w).reshape(h, w)\n\nif s[0][0] == "#":\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n \nfor i in range(h - 1):\n if s[i + 1][0] == "." or s[i][0] == s[i + 1][0]:\n dp[i + 1][0] = dp[i][0]\n else:\n dp[i + 1][0] = dp[i][0] + 1\nfor j in range(w - 1):\n if s[0][j + 1] == "." or s[0][j] == s[0][j + 1]:\n dp[0][j + 1] = dp[0][j]\n else:\n dp[0][j + 1] = dp[0][j] + 1\n\nfor i in range(h - 1):\n for j in range(w - 1):\n if s[i + 1][j + 1] == "." or (s[i][j + 1] == s[i + 1][j + 1] and s[i + 1][j + 1] == s[i + 1][j]):\n dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j])\n elif s[i][j + 1] == s[i + 1][j + 1] and s[i + 1][j + 1] != s[i + 1][j]:\n dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j] + 1)\n elif s[i][j + 1] != s[i + 1][j + 1] and s[i + 1][j + 1] == s[i + 1][j]:\n dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, dp[i + 1][j])\n else:\n dp[i + 1][j + 1] = min(dp[i][j + 1] + 1, dp[i + 1][j] + 1)\n \n# if h == 1 and w == 1:\n# if s[0][0] == "#":\n# dp[0][0] == 1\n# else:\n# dp[0][0] == 0\n# elif h == 1:\n# if s[h - 1][w - 1] == "#" and (s[0][0] == "#" and dp[h - 1][w - 2] != 1):\n# dp[h- 1][w - 1] += 1\n# elif w == 1:\n# if s[h - 1][w - 1] == "#" and (s[0][0] == "#" and dp[h - 2][w - 1] != 1):\n# dp[h- 1][w - 1] += 1\n# else:\n# if s[h - 1][w - 1] == "#" and (s[0][0] == "#" and (dp[h - 2][w - 1] != 1 and dp[h - 1][w - 2] != 1)):\n# dp[h- 1][w - 1] += 1\n \n\n# print(dp[0][i])\n\nprint(int(dp[h - 1][w - 1]))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s044542369', 's449661352', 's700220088'] | [12508.0, 3064.0, 12516.0] | [152.0, 17.0, 186.0] | [1226, 1252, 1684] |
p02735 | u497046426 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["from itertools import product\nfrom heapq import heappush, heappop\n\nclass Dijkstra:\n def __init__(self, N):\n self.N = N # #vertices\n self.E = [[] for _ in range(N)]\n\n def add_edge(self, init, end, weight, undirected=False):\n self.E[init].append((end, weight))\n if undirected: self.E[end].append((init, weight))\n \n def distance(self, s):\n INF = float('inf')\n self.dist = [INF] * self.N # the distance of each vertex from s\n self.prev = [-1] * self.N # the previous vertex of each vertex on a shortest path from s\n visited = [False] * self.N\n n_visited = 0 # #(visited vertices)\n heap = []\n heappush(heap, (0, -1, s))\n while heap:\n d, p, v = heappop(heap)\n if visited[v]: continue # (s,v)-shortest path is already calculated\n self.dist[v] = d; self.prev[v] = p; self.visited[v] = True\n n_visited += 1\n if n_visited == self.N: break\n for u, c in self.E[v]:\n if visited[u]: continue\n temp = d + c\n if self.dist[u] > temp: heappush(heap, (temp, v, u))\n return self.dist\n \n def shortest_path(self, t):\n P = []\n prev = self.prev\n while True:\n P.append(t)\n t = prev[t]\n if t == -1: break\n return P[::-1]\n\nH, W = map(int, input().split())\ndijkstra = Dijkstra(H * W)\n\ndef vtx(i, j): return i*W + j\ndef coord(n): return divmod(n, W)\n\ngrid = [input() for _ in range(H)] # |string| = W\nE = [[] for _ in range(H * W)]\nans = 0 if grid[0][0] == '.' else 1\nfor i, j in product(range(H), range(W)):\n v = vtx(i, j)\n check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]\n for u in check:\n x, y = coord(u)\n if grid[i][j] == '.' and grid[x][y] == '#':\n dijkstra.add_edge(v, u, 1)\n else:\n dijkstra.add_edge(v, u, 0)\ndist = dijkstra.distance(0)\nans += dist[vtx(H-1, W-1)]\nprint(ans)\n", "from itertools import product\nfrom collections import deque\n\nclass ZeroOneBFS:\n def __init__(self, N):\n self.N = N # #vertices\n self.E = [[] for _ in range(N)]\n \n def add_edge(self, init, end, weight, undirected=False):\n assert weight in [0, 1]\n self.E[init].append((end, weight))\n if undirected: self.E[end].append((init, weight))\n \n def distance(self, s):\n INF = float('inf')\n E, N = self.E, self.N\n dist = [INF] * N # the distance of each vertex from s\n prev = [-1] * N # the previous vertex of each vertex on a shortest path from s\n dist[s] = 0\n dq = deque([(0, s)]) \n n_visited = 0 # #(visited vertices)\n while dq:\n d, v = dq.popleft() \n if dist[v] < d: continue # (s,v)-shortest path is already calculated\n for u, c in E[v]:\n temp = d + c\n if dist[u] > temp:\n dist[u] = temp; prev[u] = v\n if c == 0: dq.appendleft((temp, u))\n else: dq.append((temp, u))\n n_visited += 1\n if n_visited == N: break\n self.dist, self.prev = dist, prev\n return dist\n \n def shortest_path(self, t):\n P = []\n prev = self.prev\n while True:\n P.append(t)\n t = prev[t]\n if t == -1: break\n return P[::-1]\n\nH, W = map(int, input().split())\nzobfs = ZeroOneBFS(H * W)\n \ndef vtx(i, j): return i*W + j\ndef coord(n): return divmod(n, W)\n \ngrid = [input() for _ in range(H)] # |string| = W\nE = [[] for _ in range(H * W)]\nans = 0 if grid[0][0] == '.' else 1\nfor i, j in product(range(H), range(W)):\n v = vtx(i, j)\n check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]\n for u in check:\n x, y = coord(u)\n if grid[i][j] == '.' and grid[x][y] == '#':\n zobfs.add_edge(v, u, 1)\n else:\n zobfs.add_edge(v, u, 0)\ndist = zobfs.distance(0)\nans += dist[vtx(H-1, W-1)]\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s136262450', 's491633230'] | [7156.0, 7284.0] | [59.0, 72.0] | [2025, 2073] |
p02735 | u497952650 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['\ndef ans_dp(H,W,M):\n dp = [[0 for i in range(W)] for j in range(H)]\n flag = [[0 for i in range(W)] for j in range(H)]\n if M[0][0] == "#":\n dp[0][0] = 1\n flag[0][0] = 1\n else:\n dp[0][0] == 0\n for i in range(1,W):\n if M[i][0] == "#":\n flag[i][0] = 1\n if flag[i-1][0] == 1:\n dp[i][0] = dp[i-1][0]\n else:\n dp[i][0] = dp[i-1][0] + 1 \n else:##M[0][i] = "."\n dp[i][0] = dp[i-1][0]\n for j in range(1,H):\n if M[0][j] == "#":\n flag[0][j] = 1\n if flag[0][j-1] == 1:\n dp[0][j] = dp[0][j-1]\n else:\n dp[0][j] = dp[0][j-1] + 1 \n else:##M[0][i] = "."\n dp[0][j] = dp[0][j-1]\n \n for i in range(1,W):\n for j in range(1,H):\n if M[i][j] == "#":\n flag[i][j] = 1\n if flag[i-1][j] == 1 or flag[i][j-1] == 1:\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])\n else:\n dp[i][j] = min(dp[i-1][j],dp[i][j-1]) + 1\n else:#M[i][j] == "."\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])\n \n return dp[-1][-1]\n\ndef main():\n H,W = map(int,input().split())\n M = []\n for i in range(H):\n M.append(list(input()))\n print(ans_dp(H,W,M))\n \nif __name__ == "__main__":\n main()', 'def ans_dp(H,W,M):\n dp = [[0 for i in range(W)] for j in range(H)]\n flag = [[0 for i in range(W)] for j in range(H)]\n if M[0][0] == "#":\n dp[0][0] = 1\n flag[0][0] = 1\n else:\n dp[0][0] == 0\n for i in range(1,W):\n if M[0][i] == "#":\n flag[0][i] = 1\n if flag[0][i-1] == 1:\n dp[0][i] = dp[0][i-1]\n else:\n dp[0][i] = dp[0][i-1] + 1 \n else:##M[0][i] = "."\n dp[0][i] = dp[0][i-1]\n for j in range(1,H):\n if M[j][0] == "#":\n flag[j][0] = 1\n if flag[j-1][0] == 1:\n dp[j][0] = dp[j-1][0]\n else:\n dp[j][0] = dp[j-1][0] + 1 \n else:##M[0][i] = "."\n dp[j][0] = dp[j-1][0]\n \n for i in range(1,H):\n for j in range(1,W):\n if M[i][j] == "#":\n flag[i][j] = 1\n dp[i][j] = min(dp[i-1][j]+int(not flag[i-1][j]),dp[i][j-1]+int(not flag[i][j-1]))\n else:#M[i][j] == "."\n dp[i][j] = min(dp[i-1][j],dp[i][j-1])\n return dp[-1][-1]\n\ndef main():\n H,W = map(int,input().split())\n M = []\n for i in range(H):\n M.append(list(input()))\n print(ans_dp(H,W,M))\n \nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s589997415', 's554614414'] | [3444.0, 3444.0] | [24.0, 27.0] | [1488, 1278] |
p02735 | u522973286 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["#!/usr/bin/env python3\n\n\ndef main() -> None:\n H, W = rmi()\n s = []\n for h in range(H):\n line = list(map(lambda c: c == '.', list(r())))\n s.append(line)\n dp = []\n for _ in range(H):\n dp.append([-1] * W)\n dp[0][0] = 0 if s[0][0] else 1\n for h in range(1, H):\n dp[h][0] = dp[h - 1][0] if s[h][0] else dp[h - 1][0] + 1\n for w in range(1, W):\n dp[0][w] = dp[0][w - 1] if s[0][w] else dp[0][w - 1] + 1\n for h in range(1, H):\n for w in range(1, W):\n minimum = min(dp[h - 1][w], dp[h][w - 1])\n dp[h][w] = minimum if s[h][w] else minimum + 1\n print(dp[H][W])\n\n\ndef r() -> str:\n return input().strip()\n\n\ndef ri() -> int:\n return int(r())\n\n\ndef rmi(delim: str = ' ') -> tuple:\n return tuple(map(int, input().split(delim)))\n\n\ndef w(data) -> None:\n print(data)\n\n\ndef wm(*data, delim: str = ' ') -> None:\n print(delim.join(map(str, data)))\n\n\nif __name__ == '__main__':\n import sys\n sys.setrecursionlimit(10 ** 9)\n main()\n", "#!/usr/bin/env python3\n\n\ndef main() -> None:\n H, W = rmi()\n s = []\n for h in range(H):\n line = list(map(lambda c: c == '.', list(r())))\n s.append(line)\n dp = []\n for _ in range(H):\n dp.append([H + W + 1] * W)\n dp[0][0] = 0 if s[0][0] else 1\n for h in range(1, H):\n dp[h][0] = dp[h - 1][0] + int(s[h - 1][0] != s[h][0] and not s[h][0])\n for w in range(1, W):\n dp[0][w] = dp[0][w - 1] + int(s[0][w - 1] != s[0][w] and not s[0][w])\n for h in range(1, H):\n for w in range(1, W):\n dp[h][w] = min(dp[h - 1][w] + int(s[h - 1][w] != s[h][w] and not s[h][w]),\n dp[h][w - 1] + int(s[h][w - 1] != s[h][w] and not s[h][w]))\n print(dp[H - 1][W - 1])\n\n\ndef r() -> str:\n return input().strip()\n\n\ndef ri() -> int:\n return int(r())\n\n\ndef rmi(delim: str = ' ') -> tuple:\n return tuple(map(int, input().split(delim)))\n\n\ndef w(data) -> None:\n print(data)\n\n\ndef wm(*data, delim: str = ' ') -> None:\n print(delim.join(map(str, data)))\n\n\nif __name__ == '__main__':\n import sys\n sys.setrecursionlimit(10 ** 9)\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s633280555', 's977653575'] | [3316.0, 3316.0] | [24.0, 29.0] | [1025, 1127] |
p02735 | u533885955 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['#A\nH,W = map(int,input().split())\nG = [list(str(input())) for _ in range(H)]\ninf = float("inf")\n\ndist = [[inf for w in range(W)] for h in range(H)]\n\nif G[0][0] == "#":\n dist[0][0] = 1\nelse:\n dist[0][0] = 0\n\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n pass\n elif j == 0:\n dist[i][j] = dist[i-1][j]\n if G[i][j] == "#" and G[i-1][j] != "#":\n dist[i][j]+=1\n elif i == 0:\n dist[i][j] = dist[i][j-1]\n if G[i][j] == "#" and G[i-1][j] != "#":\n dist[i][j]+=1\n else:\n d1 = dist[i-1][j]\n d2 = dist[i][j-1]\n if G[i][j] == "#" and G[i-1][j] != "#":\n d1+=1\n if G[i][j] == "#" and G[i-1][j] != "#":\n d2+=1\n dist[i][j] = min(d1,d2)\n \n\nprint(dist[H-1][W-1])\n\n', '#A\nH,W = map(int,input().split())\nG = [list(str(input())) for _ in range(H)]\ninf = float("inf")\n\ndist = [[inf for w in range(W)] for h in range(H)]\n\nif G[0][0] == "#":\n dist[0][0] = 1\nelse:\n dist[0][0] = 0\n\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n pass\n elif j == 0:\n dist[i][j] = dist[i-1][j]\n if G[i][j] == "#" and G[i-1][j] != "#":\n dist[i][j]+=1\n elif i == 0:\n dist[i][j] = dist[i][j-1]\n if G[i][j] == "#" and G[i][j-1] != "#":\n dist[i][j]+=1\n else:\n d1 = dist[i-1][j]\n d2 = dist[i][j-1]\n if G[i][j] == "#" and G[i-1][j] != "#":\n d1+=1\n if G[i][j] == "#" and G[i][j-1] != "#":\n d2+=1\n dist[i][j] = min(d1,d2)\n \n\nprint(dist[H-1][W-1])\n\n'] | ['Wrong Answer', 'Accepted'] | ['s553904878', 's152528025'] | [3316.0, 3316.0] | [30.0, 29.0] | [875, 875] |
p02735 | u556069480 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import itertools\n \nH,W=map(int, input().split())\ngarden=[]\n \nfor i in range(H):\n garden.append(list(input().replace(".","1").replace("#","0")))\n \n\ndct=[(1,0),(0,1),(-1,0),(0,-1)]\n\n#H,W=5,5\nstart=(0,0)\ngoal=(H-1,W-1)\npath=[start]\nd=[ [i+j for i in range(W)] for j in range(H)]\n#print(d)\ndone=[(0,0)]\nfor i, j in itertools.product(range(H),range(W)):\n color=garden[i][j]\n for each in dct:\n di,dj=each[0],each[1]\n if i+di<H and j+dj< W and i+di>=0 and j+dj>=0 and garden[i+di][j+dj]==color:\n d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j])\n done.append((i+di,j+dj))\n #print((i,j),(i+di,j+dj))\n #print("same")\n elif i+di<H and j+dj< W and i+di>=0 and j+dj>=0 :\n d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]+1)\n done.append((i+di,j+dj))\n #print((i,j),(i+di,j+dj))\n #print("not same")\n #print(d)\nif int(garden[0][0])+int(garden[H-1][W-1])==0:\n print(int((d[H-1][W-1]+1)/2)+1)\nelse:\n print(int((d[H-1][W-1]+1)/2))import itertools\n \nH,W=map(int, input().split())\ngarden=[]\n \nfor i in range(H):\n garden.append(list(input().replace(".","1").replace("#","0")))\n \n\ndct=[(1,0),(0,1)]\n\n#H,W=5,5\nstart=(0,0)\ngoal=(H-1,W-1)\npath=[start]\nd=[ [i+j for i in range(W)] for j in range(H)]\n#print(d)\ndone=[(0,0)]\nfor i, j in itertools.product(range(H),range(W)):\n color=garden[i][j]\n for each in dct:\n di,dj=each[0],each[1]\n if i+di<H and j+dj< W and i+di>=0 and j+dj>=0 and garden[i+di][j+dj]==color:\n d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j])\n done.append((i+di,j+dj))\n #print((i,j),(i+di,j+dj))\n #print("same")\n elif i+di<H and j+dj< W and i+di>=0 and j+dj>=0 :\n d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]+1)\n done.append((i+di,j+dj))\n #print((i,j),(i+di,j+dj))\n #print("not same")\n #print(d)\nif int(garden[0][0])+int(garden[H-1][W-1])==0:\n print(int((d[H-1][W-1]+1)/2)+1)\nelse:\n print(int((d[H-1][W-1]+1)/2))', 'import itertools\n \nH,W=map(int, input().split())\ngarden=[]\n \nfor i in range(H):\n garden.append(list(input().replace(".","1").replace("#","0")))\n \ndct=[(1,0),(0,1)]\nd=[ [i+j for i in range(W)] for j in range(H)]\n\nfor i, j in itertools.product(range(H),range(W)):\n color=garden[i][j]\n for each in dct:\n di,dj=each[0],each[1]\n if i+di<H and j+dj< W and garden[i+di][j+dj]==color:\n d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j])\n\n elif i+di<H and j+dj< W:\n d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]+1)\n\nif int(garden[0][0])+int(garden[H-1][W-1])==0:\n print(int((d[H-1][W-1]+1)/2)+1)\nelse:\n print(int((d[H-1][W-1]+1)/2))'] | ['Runtime Error', 'Accepted'] | ['s848740889', 's895782578'] | [3064.0, 3316.0] | [17.0, 46.0] | [2188, 662] |
p02735 | u579699847 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import bisect,collections,copy,itertools,math,string\ndef I(): return int(input())\ndef S(): return input()\ndef LI(): return list(map(int,input().split()))\ndef LS(): return list(input().split())\n##################################################\nH,W = LI()\nS = [S() for _ in range(H)]\ndp = [[-1]*W for _ in range(H)]\nfor i in range(H):\n for j in range(W):\n judge = 1 if S[i][j]=='#' else 0\n if i==0: \n if j==0:\n dp[0][0] = judge\n else:\n dp[0][j] = dp[0][j-1]+judge\n else: 意外\n if j==0:\n dp[i][0] = dp[i-1][0]+judge\n else:\n dp[i][j] = min(dp[i][j-1],dp[i-1][j])+judge\nprint(dp[-1][-1])\n", "import itertools,sys\ndef S(): return sys.stdin.readline().rstrip()\ndef LI(): return list(map(int,sys.stdin.readline().rstrip().split()))\nH,W = LI()\nS = [S() for _ in range(H)]\ndp = [[float('INF')]*W for _ in range(H)]\nfor i,j in itertools.product(range(H),range(W)):\n if i==0:\n if j==0:\n dp[i][j] = 1 if S[i][j]=='#' else 0\n else:\n dp[i][j] = dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0)\n else:\n if i==0:\n dp[i][j] = dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0)\n else:\n dp[i][j] = min(dp[i][j],dp[i][j-1]+(1 if S[i][j]=='#' and S[i][j-1]=='.' else 0))\n dp[i][j] = min(dp[i][j],dp[i-1][j]+(1 if S[i][j]=='#' and S[i-1][j]=='.' else 0))\nprint(dp[-1][-1])\n"] | ['Wrong Answer', 'Accepted'] | ['s184345751', 's113706419'] | [3952.0, 3188.0] | [35.0, 33.0] | [730, 766] |
p02735 | u651109406 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["h, w = map(int, input().split())\ns = [] # h, w\nfor i in range(h):\n s += [','.join(input()).split(',')]\n\ncost = [[1 if s[0][0] == '#' else 0 for i in range(h + 1)] for j in range(w + 1)]\n\nfor i in range(1, h + w - 1):\n for j in range(w if h < w else h):\n if j < h and i - j < w and j >= 0 and i - j >= 0:\n print(j, i - j)\n if j == 0:\n cost[j][i - j] = cost[j][i - j - 1]\n elif i - j == 0:\n cost[j][i - j] = cost[j - 1][i - j]\n else:\n cost[j][i - j] = cost[j - 1][i - j] if cost[j - 1][i - j] < cost[j][i - j - 1] else cost[j][i - j - 1]\n\n if s[j][i - j] == '#':\n cost[j][i - j] += 1\n\nprint(cost[h - 1][w - 1])\n", "h, w = map(int, input().split())\ns = [] # h, w\nfor i in range(h):\n s += [','.join(input()).split(',')]\n\ncost = [[10000 for i in range(w)] for j in range(h)]\n\n\nfor hh in range(h):\n for ww in range(w):\n \n if hh == ww == 0:\n cost[0][0] = 0 if s[0][0] == '.' else 1\n\n if hh < h - 1:\n if s[hh][ww] == '.' and s[hh + 1][ww] == '#':\n cost[hh + 1][ww] = min(cost[hh][ww] + 1, cost[hh + 1][ww])\n else:\n cost[hh + 1][ww] = min(cost[hh][ww], cost[hh + 1][ww])\n if ww < w - 1:\n if s[hh][ww] == '.' and s[hh][ww + 1] == '#':\n cost[hh][ww + 1] = min(cost[hh][ww] + 1, cost[hh][ww + 1])\n else:\n cost[hh][ww + 1] = min(cost[hh][ww], cost[hh][ww + 1])\n\nprint(cost[h - 1][w - 1])"] | ['Runtime Error', 'Accepted'] | ['s011473121', 's970857608'] | [3860.0, 3188.0] | [47.0, 34.0] | [737, 841] |
p02735 | u694665829 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["h,w=map(int,input().split())\ns=[]\nfor i in range(h):\n s.append(list(input()))\n\n#solution:dp\n\ndp=[[float('inf') for _ in range(w)] for _ in range(h)]\ndp[0][0] = 0 if s[0][0] == '.' else 1\n\ndef update(dp, i, j, ni, nj):\n if s[ni][nj]=='.':\n dp[ni][nj]=min(dp[i][j],dp[ni][nj])\n elif s[i][j]=='#':\n dp[ni][nj]=min(dp[i][j],dp[ni][nj])\n else:\n dp[ni][nj]=min(dp[i][j]+1,dp[ni][nj])\n \nfor i in range(h):\n for j in range(w):\n if i+1<h:\n update(dp,i,j,i+1,j)\n if j+1<w:\n update(dp,i,j,i,j+1)\nprint(dp[h-1][w-1])\nprint(dp)", "h,w=map(int,input().split())\ns=[]\nfor i in range(h):\n s.append(list(input()))\n\n#solution:dp\n\ndp=[[float('inf') for _ in range(w)] for _ in range(h)]\ndp[0][0] = 0 if s[0][0] == '.' else 1\n\ndef update(dp, i, j, ni, nj):\n if s[ni][nj]=='.':\n dp[ni][nj]=min(dp[i][j],dp[ni][nj])\n elif s[i][j]=='#':\n dp[ni][nj]=min(dp[i][j],dp[ni][nj])\n else:\n dp[ni][nj]=min(dp[i][j]+1,dp[ni][nj])\n \nfor i in range(h):\n for j in range(w):\n if i+1<h:\n update(dp,i,j,i+1,j)\n if j+1<w:\n update(dp,i,j,i,j+1)\nprint(dp[h-1][w-1])"] | ['Wrong Answer', 'Accepted'] | ['s868826868', 's580093087'] | [9668.0, 9476.0] | [43.0, 41.0] | [589, 579] |
p02735 | u709304134 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H, W = map(int,input().split())\nboard = []\nfor h in range(H):\n board.append(input())\n\ndp=[[1000 for i in range(W+1)] for j in range(H+1)]\ndp[0][1] = 0\ndp[1][0] = 0\n\nfor h in range(H):\n for w in range(W):\n dp[h+1][w+1] = min(dp[h][w+1] + (board[h][w]=='#' and (h==0 or board[h-1][w]=='')), dp[h+1][w] + (board[h][w]=='#' and (w==0 or board[h][w-1]=='')))\n \n \n\nprint (dp[-1][-1])\n\n", "H, W = map(int,input().split())\nboard = []\nfor h in range(H):\n board.append(input())\n\ndp=[[1000 for i in range(W+1)] for j in range(H+1)]\ndp[0][1] = 0\ndp[1][0] = 0\n\nfor h in range(H):\n for w in range(W):\n dp[h+1][w+1] = min(dp[h][w+1] + (board[h][w]=='#' and (h==0 or board[h-1][w]=='.')), dp[h+1][w] + (board[h][w]=='#' and (w==0 or board[h][w-1]=='.')))\n \n \n\nprint (dp[-1][-1])\n\n"] | ['Wrong Answer', 'Accepted'] | ['s721614896', 's464278781'] | [3064.0, 3064.0] | [29.0, 30.0] | [403, 405] |
p02735 | u726285999 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H, W = map(int, input().split())\ntable = []\nfor i in range(H):\n table.append([(True if x == "." else False) for x in list(input())])\n\ncolormap = [[0 for _ in range(W)] for _ in range(H)]\ncolormap[0][0] = 0 if table[0][0] else 1\n\ndef update(i,j):\n\n tmp_A = 200\n tmp_B = 200\n \n if 0 < i < H and j < W:\n if table[i-1][j] == table[i][j]:\n tmp_A = colormap[i-1][j]\n else:\n tmp_A = colormap[i-1][j] + 1\n \n if i < H and 0 < j < W:\n if table[i][j-1] == table[i][j]:\n tmp_B = colormap[i][j-1]\n else:\n tmp_B = colormap[i][j-1] + 1\n \n colormap[i][j] = min(tmp_A, tmp_B)\n\nfor k in range(1, H + W - 1):\n # print("k={}".format(k))\n for i in range(k + 1):\n if i < H and k - i < W:\n \n update(i, k - i)\n # print()\n\nprint(colormap[H-1][W-1])', 'import numpy as np\n\nN = int(input())\nan = [int(x) for x in list(input())]\n\narr = np.array(an)\n\nfor i in range(N-1,0,-1):\n arr2 = abs(arr[0:-1] - arr[1:])\n arr = arr2\n\nprint(arr[0])', 'def update(i,j):\n\n tmp_A = 200\n tmp_B = 200\n \n if 0 < i < H and j < W:\n if table[i-1][j] == table[i][j]:\n tmp_A = colormap[i-1][j]\n else:\n if table[i-1][j]:\n tmp_A = colormap[i-1][j] + 1\n else:\n tmp_A = colormap[i-1][j]\n if i < H and 0 < j < W:\n if table[i][j-1] == table[i][j]:\n tmp_B = colormap[i][j-1]\n else:\n if table[i][j-1]:\n tmp_B = colormap[i][j-1] + 1\n else:\n tmp_B = colormap[i][j-1]\n \n colormap[i][j] = min(tmp_A, tmp_B)\n\nH, W = map(int, input().split())\ntable = []\nfor i in range(H):\n table.append([(True if x == "." else False) for x in list(input())])\n\ncolormap = [[0 for _ in range(W)] for _ in range(H)]\ncolormap[0][0] = 0 if table[0][0] else 1\n\nfor i in range(H):\n for j in range(W):\n if not(i == 0 and j ==0):\n update(i, j)\n # print(colormap)\n\n\nprint(colormap[H-1][W-1])'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s134360691', 's753097729', 's419806356'] | [3188.0, 21396.0, 3188.0] | [32.0, 396.0, 33.0] | [906, 186, 1010] |
p02735 | u727148417 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import numpy as np\n\nH, W = map(int, input().split())\ntemp = [list(input().replace("\nmasu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]\n\n\ndp = np.zeros((H, W))\ndp_flag = np.zeros((H, W))\n\nif masu[0][0] == 0:\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(0,H):\n for j in range(0,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] != masu[i-1][j]:\n if dp_flag[i-1][j] == 1:\n a = dp[i-1][j]\n else:\n dp_flag[i][j] = 1\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] != masu[i][j-1]:\n if dp_flag[i][j-1] == 1:\n b = dp[i][j-1]\n else:\n dp_flag[i][j] = 1\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n if a != 100000 or b != 100000:\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n', 'import numpy as np\n\nH, W = map(int, input().split())\ntemp = [list(input().replace("\nmasu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]\n\n\ndp = np.zeros((H, W))\ndp_flag = np.zeros((H, W))\n\nif masu[0][0] == 0:\n dp[0][0] = 1\n masu[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(0,H):\n for j in range(0,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] != masu[i-1][j]:\n if dp_flag[i-1][j] == 1:\n a = dp[i-1][j]\n else:\n dp_flag[i][j] = 1\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] != masu[i][j-1]:\n if dp_flag[i][j-1] == 1:\n b = dp[i][j-1]\n else:\n dp_flag[i][j] = 1\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n if a != 100000 or b != 100000:\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n', 'import numpy as np\n\nH, W = map(int, input().split())\ntemp = [list(input().replace("\nmasu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]\n\n\ndp = np.zeros((H, W))\ndp[0][0] = 0\n\nfor i in range(1,H):\n for j in range(1,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] != masu[i-1][j]:\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] != masu[i][j-1]:\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n', 'H, W = map(int, input().split())\ns = ""\nfor i in range(0, H):\n temp = input().replace("#", "0")\n l_bit = temp.replace(".", "1")\n s = s + l_bit\n\nroute1 = []\nroute = [[]]\nfor j in range(0, W-1):\n route[0].append(j)\nprint(route)\ncount = len(route)\n\n#k :0~W-1\nbest = (H - 1) + (W - 1)\nfor k in range(0, W-1): \n for num in range(0, count):\n for p in range(0, (H*W)-(W-k)):\n route1 = route[num]\n route1[W-2-k] = route1[W-1-k-1] + p\n if W > 2:\n if route1[W-k-3] % W <= route1[W-k-2] % W: \n route.append(route1) \n count += 1\n block = (H - 1) + (W - 1)\n print(route1)\n for q in range(0, len(route1)):\n if q+1 != len(route1)+1:\n print(q)\n if s[route1[q+1]] == s[route1[q]] and ((route1[q+1] == route1[q] + 1) or (route1[q] % W == (route1[q] + 1) % W)):\n block = block - 1\n best = min([best, block])\n else:\n route.append(route1) \n count += 1\n block = (H - 1) + (W - 1)\n print(route1)\n for q in range(0, len(route1)):\n if q+1 != len(route1):\n if s[route1[q+1]] == s[route1[q]] and ((route1[q+1] == route1[q] + 1) or (route1[q] % W == (route1[q] + 1) % W)):\n block = block - 1\n best = min([best, block])\n\nprint(best)', 'import numpy as np\n\nH, W = map(int, input().split())\ntemp = [list(input().replace("\nmasu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]\n\n\ndp = np.zeros((H, W))\n\nif masu[0][0] == 0:\n dp[0][0] = 1\n masu[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(0,H):\n for j in range(0,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] != masu[i-1][j]:\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] != masu[i][j-1]:\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n if a != 100000 or b != 100000:\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n', 'import numpy as np\n\nH, W = map(int, input().split())\ntemp = [list(input().replace("\nmasu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]\n\n\ndp = np.zeros((H, W))\ndp_flag = np.zeros((H, W))\n\nif masu[0][0] == 0:\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(0,H):\n for j in range(0,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] != masu[i-1][j]:\n if dp_flag[i-1][j] == 1:\n dp_flag[i][j] = 0\n a = dp[i-1][j]\n else:\n dp_flag[i][j] = 1\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] != masu[i][j-1]:\n if dp_flag[i][j-1] == 1:\n dp_flag[i][j] = 0\n b = dp[i][j-1]\n else:\n dp_flag[i][j] = 1\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n if not(a == 100000 and b == 100000):\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n', ' route.append(route1) \n count += 1\n block = (H - 1) + (W - 1)\n print(route1)\n for q in range(0, len(route1)):\n if q+1 != len(route1):\n if s[route1[q+1]] == s[route1[q]] and ((route1[q+1] == route1[q] + 1) or (route1[q] % W == (route1[q] + 1) % W)):\n block = block - 1\n best = min([best, block])', 'import numpy as np\n\nH, W = map(int, input().split())\ntemp = [list(input().replace("\nmasu = [[int(temp[i][j]) for j in range(W)] for i in range(H)]\n\n\ndp = np.zeros((H, W))\n\nif masu[0][0] == 0:\n dp[0][0] = 1\n masu[0][0] = 1\nelse:\n dp[0][0] = 0\n\nfor i in range(1,H):\n for j in range(1,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] != masu[i-1][j]:\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] != masu[i][j-1]:\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n', 'import numpy as np\n\nH, W = map(int, input().split())\nmasu = [input() for i in range(H)]\n\n\n\n\ndp = [[0]*W for i in range(H)]\nif masu[0][0] == "#":\n dp[0][0] = 1\n\nfor i in range(0,H):\n for j in range(0,W):\n if i == 0:\n a = 100000\n else:\n if masu[i][j] == "#" and masu[i-1][j] == ".":\n a = dp[i-1][j] + 1\n else:\n a = dp[i-1][j]\n if j == 0:\n b = 100000\n else:\n if masu[i][j] == "#" and masu[i][j-1] == ".":\n b = dp[i][j-1] + 1\n else:\n b = dp[i][j-1]\n if a != 100000 or b != 100000:\n dp[i][j] = min([a, b])\nprint(int(dp[H-1][W-1]))\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s158143017', 's178591648', 's218638639', 's322942527', 's576559520', 's669889596', 's739739504', 's745874376', 's083991774'] | [12744.0, 14788.0, 12676.0, 3192.0, 14584.0, 21984.0, 2940.0, 12664.0, 12452.0] | [230.0, 224.0, 196.0, 18.0, 207.0, 570.0, 17.0, 199.0, 161.0] | [1095, 1114, 697, 1580, 807, 1177, 489, 764, 864] |
p02735 | u728483880 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H,W=map(int,input().split())\n\na=[[0]*W for i in range(H)]\nb=[[0]*W for i in range(H)]\n\n\nfor i in range(H):\n\ta[i]=input().split(",")\n\nfor j in range(1,W):\n\tb[0][j]=b[0][j-1]+int(not(a[0][j]==a[0][j-1]))\n\nfor i in range(1,H):\n\tb[i][0]=b[i-1][0]+int(not(a[i-1][0]==a[i][0]))\n\tfor j in range(1,W):\n\t\tb[i][j]=min(b[i-1][j]+int(not(a[i-1][j]==a[i][j])),b[i][j-1]+int(not(a[i][j-1]==a[i][j])))\n\t\nprint(b[H-1][W-1])\n', 'H,W=map(int,input().split())\n\na=[[0]*W for i in range(H)]\nb=[[0]*W for i in range(H)]\n\n#print(b)\n\nfor i in range(H):\n\ta[i]=list(input())\n#print(a)\n \nfor j in range(1,W):\n\tb[0][j]=b[0][j-1]+int(not(a[0][j]==a[0][j-1]))\n\nfor i in range(1,H):\n\tb[i][0]=b[i-1][0]+int(not(a[i-1][0]==a[i][0]))\n\tfor j in range(1,W):\n\t\tb[i][j]=min(b[i-1][j]+int(not(a[i-1][j]==a[i][j])),b[i][j-1]+int(not(a[i][j-1]==a[i][j])))\n\t\nprint(b[H-1][W-1]/2)\n', 'H,W=map(int,input().split())\n\na=[[0]*W for i in range(H)]\nb=[[0]*W for i in range(H)]\n\n#print(b)\n\nfor i in range(H):\n\ta[i]=list(input())\n#print(a)\n \nfor j in range(1,W):\n\tb[0][j]=b[0][j-1]+int(not(a[0][j]==a[0][j-1]))\n\nfor i in range(1,H):\n\tb[i][0]=b[i-1][0]+int(not(a[i-1][0]==a[i][0]))\n\tfor j in range(1,W):\n\t\tb[i][j]=min(b[i-1][j]+int(not(a[i-1][j]==a[i][j])),b[i][j-1]+int(not(a[i][j-1]==a[i][j])))\n\nif(a[0][0]=="." and a[H-1][W-1]=="."):\n\tprint(int(b[H-1][W-1]/2))\nelif(a[0][0]=="#" and a[H-1][W-1]=="#"):\n print(int(b[H-1][W-1]/2+1))\nelse:\n print(int((b[H-1][W-1]+1)/2))\n#print(int(b[H-1][W-1]/2))\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s682142225', 's817330309', 's377689175'] | [3188.0, 3316.0, 3316.0] | [18.0, 29.0, 28.0] | [408, 429, 609] |
p02735 | u745514010 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h, w = map(int, input().split())\ns = []\nfor _ in range(h):\n s.append(list(input()))\n\nbefore = s[0][0]\nans = [[0 for i in range(w)] for j in range(h)]\nfor i, row in enumerate(s):\n for j, index in enumerate(row):\n if i == j == 0:\n if before == "#":\n ans[i][j] = 1\n elif i == 0:\n if s[i][j] == s[i][j - 1]:\n ans[i][j] = ans[i][j - 1]\n else:\n ans[i][j] = ans[i][j - 1] + 1\n elif j == 0:\n if s[i][j] == s[i - 1][j]:\n ans[i][j] = ans[i - 1][j]\n else:\n ans[i][j] = ans[i - 1][j] + 1\n else:\n if s[i][j] == s[i - 1][j]:\n a1 = ans[i - 1][j]\n else:\n a1 = ans[i - 1][j] + 1\n if s[i][j] == s[i][j - 1]:\n a2 = ans[i][j - 1]\n else:\n a2 = ans[i][j - 1] + 1\n s[i][j] = min(a1, a2)\n before = index\nprint(ans[-1][-1])\n ', 'h, w = map(int, input().split())\ns = []\nfor _ in range(h):\n s.append(list(input()))\n\nbefore = s[0][0]\nfor i, row in enumerate(s):\n for j, index in enumerate(row):\n if i == j == 0:\n if before == "#":\n s[i][j] = 1\n else:\n s[i][j] = 0\n elif i == 0:\n s[i][j] = s[i][j - 1]\n elif j == 0:\n s[i][j] = s[i - 1][j]\n else:\n s[i][j] = min(s[i - 1][j], s[i][j - 1])\n if index != before:\n s[i][j] += 1\n before = index\nprint(s[-1][-1])\n ', 'h, w = map(int, input().split())\ns = []\nfor _ in range(h):\n s.append(list(input()))\n\nans = [[0 for i in range(w)] for j in range(h)]\nfor i, row in enumerate(s):\n for j, index in enumerate(row):\n if i == j == 0:\n if s[i][j] == "#":\n ans[i][j] = 1\n elif i == 0:\n if s[i][j] == s[i][j - 1]:\n ans[i][j] = ans[i][j - 1]\n else:\n ans[i][j] = ans[i][j - 1] + 1\n elif j == 0:\n if s[i][j] == s[i - 1][j]:\n ans[i][j] = ans[i - 1][j]\n else:\n ans[i][j] = ans[i - 1][j] + 1\n else:\n if s[i][j] == s[i - 1][j]:\n a1 = ans[i - 1][j]\n else:\n a1 = ans[i - 1][j] + 1\n if s[i][j] == s[i][j - 1]:\n a2 = ans[i][j - 1]\n else:\n a2 = ans[i][j - 1] + 1\n ans[i][j] = min(a1, a2)\n\nprint((ans[-1][-1] + 1) // 2)\n '] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s018637347', 's961296036', 's793052770'] | [3316.0, 3064.0, 3316.0] | [30.0, 26.0, 30.0] | [993, 574, 968] |
p02735 | u750651325 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import sys\nsys.stdin.readline\n\nH, W = map(int, input().split())\nboard = [[[0,1][a == "#"] for a in input()] for i in range(H)]\nY = [[0]*W for _ in range(H)]\n\nfor i in range(H):\n for j in range(W):\n a = []\n if j == 0:\n pass\n else:\n if board[i][j-1] == False and board[i][j]:\n a.append(Y[i][j-1] + 1)\n else:\n a.append(Y[i][j-1])\n if i == 0:\n pass\n else:\n if board[i-1][j] == False and board[i][j]:\n a.append(Y[i-1][j] + 1)\n else:\n a.append(Y[i-1][j])\n if i + j == 0:\n a.append(0)\n Y[i][j] = min(a)\n print(Y[i][j])\n\nprint(Y[H-1][W-1])\n', 'import sys\nsys.stdin.readline\n\nH, W = map(int, input().split())\nboard = [[[0,1][a == "#"] for a in input()] for i in range(H)]\nY = [[0]*W for _ in range(H)]\n\nfor i in range(H):\n for j in range(W):\n a = []\n if j == 0:\n pass\n else:\n if board[i][j-1] == False and board[i][j] == True:\n a.append(Y[i][j-1] + 1)\n else:\n a.append(Y[i][j-1])\n if i == 0:\n pass\n else:\n if board[i-1][j] == False and board[i][j] == True:\n a.append(Y[i-1][j] + 1)\n else:\n a.append(Y[i-1][j])\n if i + j == 0:\n if board[i][j]:\n a.append(1)\n else:\n continue\n Y[i][j] = min(a)\n\n\nprint(Y[H-1][W-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s348391428', 's555685168'] | [9552.0, 9388.0] | [34.0, 35.0] | [728, 797] |
p02735 | u780962115 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['##!/usr/bin/env python\n## -*- coding: utf-8 -*-\n#import sys\n#import os\n#f = open(\'input.txt\', \'r\')\n\n#input = sys.stdin.readline\n\n\nh, w = map(int, input().split())\n\ndp = [[0 for i in range(w)] for j in range(h)]\n\nmaze = []\nfor i in range(h):\n sub = list(input())[:-1]\n maze.append(sub)\n\nif maze[0][0] == "#":\n dp[0][0] = 1\nfor i in range(1, w):\n if maze[0][i - 1] == "." and maze[0][i] == "#":\n dp[0][i] = dp[0][i - 1] + 1\n\n else:\n dp[0][i] = dp[0][i - 1]\nfor j in range(1, h):\n if maze[j - 1][0] == "." and maze[j][0] == "#":\n dp[j][0] = dp[j - 1][0] + 1\n else:\n dp[j][0] = dp[j - 1][0]\n\nfor i in range(1, h):\n for j in range(1, w):\n d = dp[i - 1][j]\n e = dp[i][j - 1]\n if maze[i - 1][j] == "." and maze[i][j] == "#":\n d += 1\n if maze[i][j - 1] == "." and maze[i][j] == "#":\n e += 1\n dp[i][j] = min(d, e)\nprint(dp[h - 1][w - 1])\n', '##!/usr/bin/env python\n## -*- coding: utf-8 -*-\n#import sys\n#import os\n#f = open(\'input.txt\', \'r\')\n\n#input = sys.stdin.readline\n\n\nh, w = map(int, input().split())\n\ndp = [[0 for i in range(w)] for j in range(h)]\n\nmaze = []\nfor i in range(h):\n sub = list(input())\n maze.append(sub)\n\nif maze[0][0] == "#":\n dp[0][0] = 1\nfor i in range(1, w):\n if maze[0][i - 1] == "." and maze[0][i] == "#":\n dp[0][i] = dp[0][i - 1] + 1\n\n else:\n dp[0][i] = dp[0][i - 1]\nfor j in range(1, h):\n if maze[j - 1][0] == "." and maze[j][0] == "#":\n dp[j][0] = dp[j - 1][0] + 1\n else:\n dp[j][0] = dp[j - 1][0]\n\nfor i in range(1, h):\n for j in range(1, w):\n d = dp[i - 1][j]\n e = dp[i][j - 1]\n if maze[i - 1][j] == "." and maze[i][j] == "#":\n d += 1\n if maze[i][j - 1] == "." and maze[i][j] == "#":\n e += 1\n dp[i][j] = min(d, e)\nprint(dp[h - 1][w - 1])\n'] | ['Runtime Error', 'Accepted'] | ['s876878881', 's940845406'] | [3188.0, 3316.0] | [18.0, 29.0] | [979, 974] |
p02735 | u798818115 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['# coding: utf-8\n# Your code here!\nH,W=map(int,input().split())\n\nmeizu=[]\nfor _ in range(H):\n meizu.append(list(input()))\n\ndp=[[10**9 for w in range(W)] for h in range(H)]\ndp[0][0]=1 if meizu[0][0]=="#" else 0\n\nfor h in range(H):\n for w in range(W):\n if h!=H-1:\n dp[h+1][w]=min(dp[h+1][w],dp[h][w]+1 if meizu[h+1][w]=="\n if w!=W-1:\n dp[h][w+1]=min(dp[h][w+1],dp[h][w]+1 if meizu[h][w+1]=="\n \nprint(dp[-1][-1])\n', '# coding: utf-8\n# Your code here!\n\n# coding: utf-8 \n# Your code here! \nH,W=map(int,input().split()) \nS=[] \n\nfor _ in range(H):\n S.append(list(input()))\n\n\ndef dfs(h,w,num):\n if h==H-1 and w==W-1:\n ans.append(num)\n \n if h!=H-1: \n if S[h+1][w]=="#": \n dfs(h+1,w,num+1)\n else:\n dfs(h+1,w,num)\n\n if w!=W-1: \n if S[h][w+1]=="#": \n dfs(h,w+1,num+1)\n else:\n dfs(h,w+1,num)\n\nans=[]\ndfs(0,0,1) if S[0][0]=="\n\nprint(min(ans))\n\n', '# coding: utf-8\n# Your code here!\nH,W=map(int,input().split())\n\nmeizu=[]\nfor _ in range(H):\n meizu.append(list(input()))\n\ndp=[[10**9 for w in range(W)] for h in range(H)]\ndp[0][0]=1 if meizu[0][0]=="#" else 0\n\nfor h in range(H):\n for w in range(W):\n if h!=H-1:\n dp[h+1][w]=min(dp[h+1][w],dp[h][w]+1 if meizu[h+1][w]=="#" and meizu[h][w]=="." else dp[h][w])\n if w!=W-1:\n dp[h][w+1]=min(dp[h][w+1],dp[h][w]+1 if meizu[h][w+1]=="#" and meizu[h][w]=="." else dp[h][w])\n \nprint(dp[-1][-1])\n'] | ['Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s776600802', 's830066742', 's540829743'] | [3188.0, 4844.0, 3188.0] | [32.0, 2108.0, 33.0] | [488, 528, 530] |
p02735 | u801049006 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H, W = map(int, input().split())\ns = [list(input()) for _ in range(H)]\n\ndp = [1000 for _ in range(W+1) for _ in range(H+1)]\ndp[0][1] = 0\ndp[1][0] = 0\n\nfor y in range(W):\n for x in range(H):\n dp[y+1][x+1] = min(\n dp[y][x+1] + (s[y][x] == '#' and (y == 0 or s[y-1][x] == '.')),\n dp[y+1][x] + (s[y][x] == '#' and (x == 0 or s[y][x-1] == '.'))\n )\n\nprint(dp[-1][-1])\n", 'H, W = map(int, input().split())\ns = [list(input()) for _ in range(H)]\n\ndp = [[float("inf")] * W for _ in range(H)]\nif s[0][0] == "#":\n dp[0][0] = 1\nelse:\n dp[0][0] = 0\n\ndxdy = [(1, 0), (0, 1)]\nfor y in range(H):\n for x in range(W):\n for dx, dy in dxdy:\n nx = x + dx\n ny = y + dy\n if nx >= W or ny >= H: continue\n if s[ny][nx] == \'#\' and s[y][x] == \'.\':\n dp[ny][nx] = min(dp[ny][nx], dp[y][x] + 1)\n else:\n dp[ny][nx] = min(dp[ny][nx], dp[y][x])\n\nprint(dp[-1][-1])\n'] | ['Runtime Error', 'Accepted'] | ['s561986972', 's960673294'] | [3188.0, 3188.0] | [19.0, 37.0] | [401, 565] |
p02735 | u810787773 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H,W = map(int,input().split())\nmap = []\nINF = 10**8\nfor _ in range(H):\n map.append(input())\n\ndp = [[0 for i in range(W)] for i in range(H)]\n\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n if map[i][j] == \'#\':\n dp[i][j] = 1\n elif i == 0:\n flag = 0\n if map[i][j] == \'#\' and map[i][j-1] == \'.\':\n flag = 1\n dp[i][j] = flag + dp[i][j-1]\n elif j == 0:\n flag = 0\n if MAP[i][j] == "#" and MAP[i-1][j] == ".":\n flag = 1\n dp[i][j] = flag + dp[i-1][j]\n else:\n flag1 = 0\n flag2 = 0\n if MAP[i][j] == "#" and MAP[i][j-1] == ".":\n flag1 = 1\n if MAP[i][j] == "#" and MAP[i-1][j] == ".":\n flag2 = 1\n dp[i][j] = min(dp[i][j-1]+flag1,dp[i-1][j]+flag2)\n\npritn(dp[H-1][W-1])\n', 'H,W = map(int,input().split())\nmap = []\nINF = 10**8\nfor _ in range(H):\n map.append(input())\n\ndp = [[0 for i in range(W)] for i in range(H)]\n\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n if map[i][j] == \'#\':\n dp[i][j] = 1\n elif i == 0:\n flag = 0\n if map[i][j] == \'#\' and map[i][j-1] == \'.\':\n flag = 1\n dp[i][j] = flag + dp[i][j-1]\n elif j == 0:\n flag = 0\n if map[i][j] == "#" and map[i-1][j] == ".":\n flag = 1\n dp[i][j] = flag + dp[i-1][j]\n else:\n flag1 = 0\n flag2 = 0\n if map[i][j] == "#" and map[i][j-1] == ".":\n flag1 = 1\n if map[i][j] == "#" and map[i-1][j] == ".":\n flag2 = 1\n dp[i][j] = min(dp[i][j-1]+flag1,dp[i-1][j]+flag2)\n\npritn(dp[H-1][W-1])\n', 'H,W = map(int,input().split())\nmap = []\nINF = 10**8\nfor _ in range(H):\n map.append(input())\n\ndp = [[0 for i in range(W)] for i in range(H)]\n\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n if map[i][j] == \'#\':\n dp[i][j] = 1\n elif i == 0:\n flag = 0\n if map[i][j] == \'#\' and map[i][j-1] == \'.\':\n flag = 1\n dp[i][j] = flag + dp[i][j-1]\n elif j == 0:\n flag = 0\n if map[i][j] == "#" and map[i-1][j] == ".":\n flag = 1\n dp[i][j] = flag + dp[i-1][j]\n else:\n flag1 = 0\n flag2 = 0\n if map[i][j] == "#" and map[i][j-1] == ".":\n flag1 = 1\n if map[i][j] == "#" and map[i-1][j] == ".":\n flag2 = 1\n dp[i][j] = min(dp[i][j-1]+flag1,dp[i-1][j]+flag2)\n\nprint(dp[H-1][W-1])\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s255557102', 's347494737', 's419980332'] | [9332.0, 9360.0, 9284.0] | [27.0, 39.0, 39.0] | [911, 911, 911] |
p02735 | u811817592 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['# -*- coding: utf-8 -*-\nH, W = map(int, input().split())\nHW_list = []\n\nfor i in range(H):\n HW_list.append(str(input()))\n\ndp = [[H * W] * H] * W\n\ndp[0][0] = 0\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n continue\n if i == 0:\n min_num_h = H * W\n else:\n min_num_h = dp[i - 1][j] + (0 if HW_list[i][j] == HW_list[i - 1][j] else 1)\n if j == 0:\n min_num_w = H * W\n else:\n min_num_w = dp[i][j - 1] + (0 if HW_list[i][j] == HW_list[i][j - 1] else 1)\n dp[i][j] = min(min_num_h, min_num_w)\n\nprint(dp[H - 1][W - 1] // 2 + (1 if HW_list[0][0] == "#" or HW_list[H - 1][W - 1] else 0))', '# -*- coding: utf-8 -*-\nH, W = map(int, input().split())\nHW_list = []\n\nfor i in range(H):\n HW_list.append(str(input()))\n\ndp = [[H * W] * W] * H\n\ndp[0][0] = 0\nfor i in range(H):\n for j in range(W):\n if i == 0 and j == 0:\n continue\n if i == 0:\n min_num_h = H * W\n else:\n min_num_h = dp[i - 1][j] + (0 if HW_list[i][j] == HW_list[i - 1][j] else 1)\n if j == 0:\n min_num_w = H * W\n else:\n min_num_w = dp[i][j - 1] + (0 if HW_list[i][j] == HW_list[i][j - 1] else 1)\n dp[i][j] = min(min_num_h, min_num_w)\n\nprint(dp[H - 1][W - 1] // 2 + (1 if HW_list[0][0] == "#" or HW_list[H - 1][W - 1] == "#" else 0))'] | ['Runtime Error', 'Accepted'] | ['s198987723', 's371529816'] | [3064.0, 3064.0] | [29.0, 29.0] | [692, 699] |
p02735 | u830054172 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h, w = map(int, input().split())\ns = []\nfor _ in range(h):\n s.append(input())\n\ndp = [[h*w for i in range(w+1)] for j in range(h+1)]\n\ndp[0][1] = 0\ndp[1][0] = 0\n\nfor i in range(h):\n for j in range(w):\n print("i", i, "j", j, "s[i][j]", s[i][j])\n print(s[i][j] == \'#\' and (i == 0 or s[i-1][j] == \'.\'))\n \n \n \n dp[i+1][j+1] = min(\n dp[i][j+1] + (s[i][j] == \'#\' and (i == 0 or s[i-1][j] == \'.\')),\n dp[i+1][j] + (s[i][j] == \'#\' and (j == 0 or s[i][j-1] == \'.\'))\n )\n\nprint(dp[-1][-1])\n', 'h, w = map(int, input().split())\ns = []\nfor _ in range(h):\n s.append(input())\n\ndp = [[h*w for i in range(w+1)] for j in range(h+1)]\n\ndp[0][1] = 0\ndp[1][0] = 0\n\nfor i in range(h):\n for j in range(w):\n # print("i", i, "j", j, "s[i][j]", s[i][j])\n # print(s[i][j] == \'#\' and (i == 0 or s[i-1][j] == \'.\'))\n \n \n \n dp[i+1][j+1] = min(\n dp[i][j+1] + (s[i][j] == \'#\' and (i == 0 or s[i-1][j] == \'.\')),\n dp[i+1][j] + (s[i][j] == \'#\' and (j == 0 or s[i][j-1] == \'.\'))\n )\n\nprint(dp[-1][-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s269350309', 's310532909'] | [4100.0, 3444.0] | [67.0, 30.0] | [722, 726] |
p02735 | u851469594 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["import copy\nimport heapq\nH, W = map(int, input().split())\nS = []\ncnt_list = []\nfor _ in range(H):\n S.append(list(input()))\n\ndef move(i,j,cnt,frag):\n c_cnt = copy.deepcopy(cnt)\n c_frag = copy.deepcopy(frag)\n if frag != S[i][j]:\n c_cnt = cnt + 1\n c_frag = S[i][j]\n if i != H-1:\n move(i+1,j,c_cnt,c_frag)\n if j != W-1:\n move(i,j+1,c_cnt,c_frag)\n if i == H-1 and j == W-1:\n print(c_cnt)\n cnt_list.append(c_cnt)\n\nif S[0][0] =='#':\n a = 1\nelse :\n a = 0\n\nmove(0,0,0,S[0][0])\n\nprint(cnt_list)\nheapq.heapify(cnt_list)\nprint((heapq.heappop(cnt_list))//2 + a)", "import copy\nimport heapq\nH, W = map(int, input().split())\nS = [['.'] * (W+1)]\nfor _ in range(H):\n s = list(input())\n s.insert(0,'.')\n S.append(s)\n\ninf = float('inf')\n\ndp = []\nfor _ in range(H+1):\n dp.append([inf] * (W+1))\n\nif S[1][1] == '.':\n dp[1][1] = 0\nelse:\n dp[1][1] = 1\n\nfor i in range(1,H+1):\n for j in range(1,W+1):\n right = dp[i][j-1]\n down = dp[i-1][j]\n if S[i][j] == '#':\n if S[i-1][j] == '.':\n down += 1\n if S[i][j-1] == '.':\n right += 1\n\n dp[i][j] = min(dp[i][j],right,down)\n\nprint(dp[H][W])"] | ['Wrong Answer', 'Accepted'] | ['s022648402', 's620392526'] | [4804.0, 3700.0] | [2104.0, 33.0] | [613, 605] |
p02735 | u852210959 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef change(val):\n \n if val == '#':\n return 1\n\n \n return 0\n\n\n\n\n\ndef main():\n h, w = map(int, input().split())\n board = [[change(s) for s in input()] for i in range(h)]\n\n cnt = 200\n for move in itertools.product(range(0, 2), repeat=h + w - 2):\n\n if sum(move) != h - 1:\n continue\n\n x, y, z = 0, 0, board[0][0]\n temp_root = [(x, y, z)]\n change_cnt = 0\n if board[y][x] == 1:\n change_cnt += 1\n\n x_cnt = 0\n y_cnt = 0\n sum_x_cnt = 1\n sum_y_cnt = 1\n for hko in move:\n now_z = 0\n \n if hko == 0:\n x += 1\n now_z = board[y][x]\n if now_z == 1:\n x_cnt += 1\n else:\n x_cnt = 0\n y_cnt = 0\n else:\n y += 1\n now_z = board[y][x]\n if now_z == 1:\n y_cnt += 1\n else:\n y_cnt = 0\n x_cnt = 0\n\n sum_x_cnt = max(sum_x_cnt, x_cnt)\n sum_y_cnt = max(sum_y_cnt, y_cnt)\n z += now_z\n temp_root.append((x, y, z))\n\n print((move, z, sum_x_cnt, sum_y_cnt))\n cnt = min(cnt, z - sum_x_cnt - sum_y_cnt + 2)\n\n print(cnt)\n\n\nif __name__ == '__main__':\n main()\n", "# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef change(val):\n \n if val == '#':\n return 1\n\n \n return 0\n\n\n\n\n\ndef main():\n h, w = map(int, input().split())\n board = [[s for s in input()] for i in range(h)]\n\n cnt = 200\n dp = [[200] * w for i in range(h)]\n\n for i_row, row in enumerate(dp):\n for i_col, col in enumerate(row):\n if i_row == 0 and i_col == 0:\n dp[i_row][i_col] = change(board[i_row][i_col])\n continue\n\n if i_row >= 1:\n if board[i_row][i_col] == '#' and board[i_row - 1][i_col] == '.':\n dp[i_row][i_col] = min(dp[i_row - 1][i_col] + 1, dp[i_row][i_col])\n else:\n dp[i_row][i_col] = min(dp[i_row - 1][i_col], dp[i_row][i_col])\n\n if i_col >= 1:\n if board[i_row][i_col] == '#' and board[i_row][i_col - 1] == '.':\n dp[i_row][i_col] = min(dp[i_row][i_col - 1] + 1, dp[i_row][i_col])\n else:\n dp[i_row][i_col] = min(dp[i_row][i_col - 1], dp[i_row][i_col])\n\n print(dp[-1][-1])\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s895776146', 's694420733'] | [3188.0, 3316.0] | [2104.0, 29.0] | [1479, 1205] |
p02735 | u865298224 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['H, W = map(int, input().split())\n\nS = [""] * H\n\nfor i in range(H):\n S[i] = input()\n\ndist = [[1000000 for i in range(W)] for j in range(H)]\n\ndist[0][0] = 0 if S[0][0] == "." else 1\n\nfor i in range(H):\n for j in range(W):\n if i > 0:\n if S[i][j] == "#":\n dist[i][j] = min(dist[i][j], dist[i - 1][j] +\n (1 if S[i - 1][j] == "." else 0))\n else:\n dist[i][j] = min(dist[i][j], dist[i - 1][j])\n if j > 0:\n if S[i][j] == "#":\n dist[i][j] = min(dist[i][j], dist[i][j - 1] +\n (1 if S[i][j - 1] == "." else 0))\n else:\n dist[i][j] = min(dist[i][j], dist[i][j - 1])\n\nprint(dist[H - 1][W - 1])\nprint(dist)\n', 'H, W = map(int, input().split())\n\nS = [""] * H\n\nfor i in range(H):\n S[i] = input()\n\ndist = [[1000000 for i in range(W)] for j in range(H)]\n\ndist[0][0] = 0 if S[0][0] == "." else 1\n\nfor i in range(H):\n for j in range(W):\n if i > 0:\n if S[i][j] == "#":\n dist[i][j] = min(dist[i][j], dist[i - 1][j] +\n (1 if S[i - 1][j] == "." else 0))\n else:\n dist[i][j] = min(dist[i][j], dist[i - 1][j])\n if j > 0:\n if S[i][j] == "#":\n dist[i][j] = min(dist[i][j], dist[i][j - 1] +\n (1 if S[i][j - 1] == "." else 0))\n else:\n dist[i][j] = min(dist[i][j], dist[i][j - 1])\n\nprint(dist[H - 1][W - 1])\n'] | ['Wrong Answer', 'Accepted'] | ['s015722889', 's367740869'] | [3316.0, 3188.0] | [33.0, 33.0] | [779, 767] |
p02735 | u871841829 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ["H,W = map(int, input().split())\ng = []\nfor _ in range(H):\n g.append(list(input()))\n\ndp = [[10**9 for _ in range(W)] for __ in range(H)]\n\n#solve\ndef dfs(i, j, score, lc):\n if i < H and i >= 0 and j < W and j >= 0:\n if lc == '.' and g[i][j] == '#':\n score += 1\n dp[i][j] = min(dp[i][j], score)\n\n dfs(i+1, j, score, g[i][j])\n dfs(i, j+1, score, g[i][j]) \n \ndfs(0, 0, 0, '.')\nprint(dp)\nprint(dp[H-1][W-1])", "H,W = map(int, input().split())\ng = []\nfor _ in range(H):\n g.append(list(input()))\n\ndp = [[10**9 for _ in range(W)] for __ in range(H)]\n\ndp[0][0] = 1 if g[0][0] == '#' else 0\nd = ([0,1], [1,0])\nfor ix in range(H):\n for jx in range(W):\n for dx,dy in d:\n ni = ix + dx\n nj = jx + dy\n if ni >= H or nj >= W:\n continue\n add = 0\n if g[ix][jx] == '.' and g[ni][nj] == '#':\n add += 1\n dp[ni][nj] = min(dp[ni][nj], dp[ix][jx] + add)\n\n\nprint(dp[H-1][W-1])"] | ['Wrong Answer', 'Accepted'] | ['s257862522', 's577674815'] | [9232.0, 9348.0] | [2206.0, 47.0] | [456, 554] |
p02735 | u879309973 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['INF = 10**9\ndef solve(h, w, s):\n dp = [[INF] * w for r in range(h)]\n dp[0][0] = int(s[0][0] == "#")\n for r in range(h):\n for c in range(w): \n for dr, dc in [(-1, 0), (0, -1)]:\n nr, nc = r+dr, c+dc\n if (0 <= nr < h) and (0 <= nc < w):\n dp[r][c] = min(dp[r][c], dp[nr][nc] + (s[r][c] != s[nr][nc]))\n return dp[h-1][w-1]\n\nh, w = map(int, input().split())\ns = [input() for r in range(h)]\nprint(solve(h, w, s))', 'INF = 10**9\ndef solve(h, w, s):\n dp = [[INF] * w for r in range(h)]\n dp[0][0] = int(s[0][0] == "#")\n for r in range(h):\n for c in range(w):\n for dr, dc in [(-1, 0), (0, -1)]:\n nr, nc = r+dr, c+dc\n if (0 <= nr < h) and (0 <= nc < w):\n dp[r][c] = min(dp[r][c], dp[nr][nc] + (s[r][c] != s[nr][nc]))\n return (dp[h-1][w-1] + 1) // 2\n\nh, w = map(int, input().split())\ns = [input() for r in range(h)]\nprint(solve(h, w, s))\n'] | ['Wrong Answer', 'Accepted'] | ['s103005717', 's123204366'] | [9296.0, 9236.0] | [38.0, 40.0] | [484, 495] |
p02735 | u905203728 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h,w=map(int,input().split())\nD=[[0]*w for _ in range(h)]\n\nS=[list(input()) for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n for x,y in ((1,0),(0,1)):\n X,Y=i+x,j+y\n if 0<=X<=h and 0<=Y<=w:\n if S[i][j]=="." and S[X][Y]=="#":\n D[X][Y]=D[i][j]+1\n\nans=D[h-1][w-1]\nprint(ans if S[0][0]!="#" else ans+1)', 'h,w=map(int,input().split())\nD=[[0]*w for _ in range(h)]\n\nS=[list(input()) for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n for x,y in ((1,0),(0,1)):\n X,Y=i+x,j+y\n if 0<=X<=h-1 and 0<=Y<w-1:\n if S[i][j]=="." and S[X][Y]=="#":D[X][Y]=D[i][j]+1\n else:D[X][Y]=D[i][j]\n\nans=D[h-1][w-1]\nprint(ans if S[0][0]!="#" else ans+1)', 'h,w=map(int,input().split())\nD=[[0]*w for _ in range(h)]\n\nS=[list(input()) for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n for x,y in ((1,0),(0,1)):\n X,Y=i+x,j+y\n if 0<=X<=h and 0<=Y<=w:\n if S[i][j]=="." and S[X][Y]=="#":\n D[X][Y]=D[i][j]+1\n \nans=D[h-1][w-1]\nprint(ans if S[0][0]!="#" else ans+1)', 'h,w=map(int,input().split())\nD=[[0]*w for _ in range(h)]\n\nS=[list(input()) for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n for x,y in ((1,0),(0,1)):\n X,Y=i+x,j+y\n if 0<=X<h and 0<=Y<w:\n if S[i][j]=="." and S[X][Y]=="#":\n D[X][Y]=D[i][j]+1\n\nans=D[h-1][w-1]\nprint(ans if S[0][0]!="#" else ans+1)', 'inf=float("inf")\nh,w=map(int,input().split())\nD=[[inf]*w for _ in range(h)]\nD[0][0]=0\n\nS=[list(input()) for _ in range(h)]\nfor i in range(h):\n for j in range(w):\n for x,y in ((1,0),(0,1)):\n X,Y=i+x,j+y\n if 0<=X<h and 0<=Y<w:\n if S[i][j]=="." and S[X][Y]=="#":D[X][Y]=min(D[i][j]+1,D[X][Y])\n else:D[X][Y]=min(D[i][j],D[X][Y])\n\n#import numpy as np\n#print(np.array(D))\nans=D[h-1][w-1]\nprint(ans if S[0][0]!="#" else ans+1)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s145360576', 's556123418', 's583830116', 's815434340', 's626166363'] | [3316.0, 3188.0, 3188.0, 3188.0, 3188.0] | [28.0, 35.0, 28.0, 32.0, 39.0] | [372, 391, 392, 370, 481] |
p02735 | u906501980 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['h, w = map(int, input().split())\nS = [list(input()) for _ in range(h)]\ninf = 10*3\ndp = [[inf]*w for _ in range(h)]\n\ndp[0][0] = int(S[0][0]=="#")\nfor i in range(1, w):\n dp[0][i] = dp[0][i-1] + (S[0][i-1]!=S[0][i])\nfor i in range(1, h):\n dp[i][0] = dp[i-1][0] + (S[i-1][0]!=S[i][0])\nfor i in range(1, h):\n for j in range(1, w):\n dp[i][j] = min(dp[i-1][j]+(S[i-1][j]!=S[i][j]), dp[i][j-1]+(S[i][j-1]!=S[i][j]))\nprint(dp[-1][-1])', 'h, w = map(int, input().split())\na = lambda x: 1 if x=="#" else 0\nS = [list(map(a, list(input()))) for _ in range(h)]\ninf = 10*3\ndp = [[inf]*w for _ in range(h)]\ndp[0][0] = S[0][0]\nfor i in range(1, w):\n dp[0][i] = dp[0][i-1] + S[0][i]*(S[0][i]!=S[0][i-1])\nfor i in range(1, h):\n dp[i][0] = dp[i-1][0] + S[i][0]*(S[i][0]!=S[i-1][0])\nfor i in range(1, h):\n for j in range(1, w):\n dp[i][j] = min(dp[i-1][j]+S[i][j]*(S[i-1][j]!=S[i][j]), dp[i][j-1]+S[i][j]*(S[i][j]!=S[i][j-1]))\nprint(dp[-1][-1])'] | ['Wrong Answer', 'Accepted'] | ['s777422059', 's254089707'] | [3188.0, 3188.0] | [26.0, 30.0] | [441, 509] |
p02735 | u918935103 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['from collections import deque\nh,w = map(int,input().split())\ns = []\nfor i in range(h):\n s0 = list(input())\n s.append(s0)\nd = deque()\nrl = [[h*w+1 for i in range(w)] for i in range(h)]\nif s[0][0] == ".":\n d.append([0,0])\n rl[0][0] = 0\nelse:\n d.append([0,0])\n rl[0][0] = 1\nwhile len(d):\n a,b = d.popleft()\n print(a,b,rl)\n if a == h-1:\n if b < w-1:\n if rl[a][b+1] == h*w+1:\n if s[a][b+1] == "#":\n rl[a][b+1] = rl[a][b] + 1\n else:\n rl[a][b+1] = rl[a][b]\n d.append([a,b+1])\n else:\n if s[a][b+1] == "#":\n rl[a][b+1]= min(rl[a][b+1],rl[a][b] + 1)\n else:\n rl[a][b+1] = min(rl[a][b+1],rl[a][b])\n else:\n if b == w-1:\n if rl[a+1][b] == h*w+1:\n if s[a+1][b] == "#":\n rl[a+1][b] = rl[a][b] + 1\n else:\n rl[a+1][b] = rl[a][b]\n d.append([a+1,b])\n else:\n if s[a+1][b] == "#":\n rl[a+1][b]= min(rl[a+1][b],rl[a][b] + 1)\n else:\n rl[a+1][b] = min(rl[a+1][b],rl[a][b])\n else:\n if rl[a][b+1] == h*w+1:\n if s[a][b+1] == "#":\n rl[a][b+1] = rl[a][b] + 1\n else:\n rl[a][b+1] = rl[a][b]\n d.append([a,b+1])\n else:\n if s[a][b+1] == "#":\n rl[a][b+1]= min(rl[a][b+1],rl[a][b] + 1)\n else:\n rl[a][b+1] = min(rl[a][b+1],rl[a][b])\n if rl[a+1][b] == h*w+1:\n if s[a+1][b] == "#":\n rl[a+1][b] = rl[a][b] + 1\n else:\n rl[a+1][b] = rl[a][b]\n d.append([a+1,b])\n else:\n if s[a+1][b] == "#":\n rl[a+1][b]= min(rl[a+1][b],rl[a][b] + 1)\n else:\n rl[a+1][b] = min(rl[a+1][b],rl[a][b])\nprint(rl[h-1][w-1])', 'from collections import deque\nh,w = map(int,input().split())\ns = []\nfor i in range(h):\n s0 = list(input())\n s.append(s0)\nd = deque()\nrl = [[h*w+1 for i in range(w)] for i in range(h)]\nif s[0][0] == ".":\n d.append([0,0,0])\n rl[0][0] = 0\nelse:\n d.append([0,0,1])\n rl[0][0] = 1\nwhile len(d):\n a,b,c = d.popleft()\n #print(a,b,rl)\n if a == h-1:\n if b < w-1:\n if rl[a][b+1] == h*w+1:\n if s[a][b+1] == "#":\n if c > 0:\n rl[a][b+1] = rl[a][b]\n d.append([a,b+1,1])\n else:\n rl[a][b+1] = rl[a][b]+1\n d.append([a,b+1,0])\n else:\n rl[a][b+1] = rl[a][b]\n d.append([a,b+1,0])\n else:\n if s[a][b+1] == "#":\n if c > 0:\n rl[a][b+1]= min(rl[a][b+1],rl[a][b])\n else:\n rl[a][b+1]= min(rl[a][b+1],rl[a][b]+1)\n else:\n rl[a][b+1] = min(rl[a][b+1],rl[a][b])\n else:\n if b == w-1:\n if rl[a+1][b] == h*w+1:\n if s[a+1][b] == "#":\n if c > 0:\n rl[a+1][b] = rl[a][b]\n d.append([a+1,b,1])\n else:\n rl[a+1][b] = rl[a][b]+1\n d.append([a+1,b,1])\n else:\n rl[a+1][b] = rl[a][b]\n d.append([a+1,b,0])\n else:\n if s[a+1][b] == "#":\n if c > 0:\n rl[a+1][b]= min(rl[a+1][b],rl[a][b])\n else:\n rl[a+1][b]= min(rl[a+1][b],rl[a][b] + 1)\n else:\n rl[a+1][b] = min(rl[a+1][b],rl[a][b])\n else:\n if rl[a][b+1] == h*w+1:\n if s[a][b+1] == "#":\n if c > 0:\n rl[a][b+1] = rl[a][b]\n d.append([a,b+1,1])\n else:\n rl[a][b+1] = rl[a][b]+1\n d.append([a,b+1,0])\n else:\n rl[a][b+1] = rl[a][b]\n d.append([a,b+1,0])\n else:\n if s[a][b+1] == "#":\n if c > 0:\n rl[a][b+1]= min(rl[a][b+1],rl[a][b])\n else:\n rl[a][b+1]= min(rl[a][b+1],rl[a][b]+1)\n else:\n rl[a][b+1] = min(rl[a][b+1],rl[a][b])\n if rl[a+1][b] == h*w+1:\n if s[a+1][b] == "#":\n if c > 0:\n rl[a+1][b] = rl[a][b]\n d.append([a+1,b,1])\n else:\n rl[a+1][b] = rl[a][b]+1\n d.append([a+1,b,1])\n else:\n rl[a+1][b] = rl[a][b]\n d.append([a+1,b,0])\n else:\n if s[a+1][b] == "#":\n if c > 0:\n rl[a+1][b]= min(rl[a+1][b],rl[a][b])\n else:\n rl[a+1][b]= min(rl[a+1][b],rl[a][b] + 1)\n else:\n rl[a+1][b] = min(rl[a+1][b],rl[a][b])\nprint(rl[h-1][w-1])'] | ['Runtime Error', 'Accepted'] | ['s014529548', 's517989969'] | [135188.0, 3800.0] | [2036.0, 44.0] | [2096, 3375] |
p02735 | u935558307 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['import sys\nimport heapq\n\nH,W = map(int,input().split())\nmaze = [list(input()) for i in range(H)]\n\ndef removeWalls(wallPointH,wallPointW):\n if maze[wallPointH][wallPointW]=="#":\n changeTo = "."\n elif maze[wallPointH][wallPointW]=="1":\n changeTo = "0"\n if maze[wallPointH][wallPointW]=="#" or maze[wallPointH][wallPointW]=="1":\n maze[wallPointH][wallPointW]=changeTo\n if wallPointH+1 <= H-1:\n removeWalls(wallPointH+1,wallPointW)\n if wallPointW+1 <= W-1:\n removeWalls(wallPointH,wallPointW+1)\n\nque = [[0,0,0]]\nheapq.heapify(que)\ncount = 0\n \nwhile que:\n qu = heapq.heappop(que)\n if qu[0]==1:\n heapq.heappush(que, qu)\n count += 1\n for q in que:\n q[0]=0\n removeWalls(q[1],q[2])\n else:\n nowH = qu[1]\n nowW = qu[2]\n if nowH==H-1 and nowW==W-1:\n print(count)\n sys.exit()\n else:\n \n if nowH+1 <= H-1:\n if maze[nowH+1][nowW]=="\n maze[nowH+1][nowW]=="1"\n heapq.heappush(que, [1,nowH+1,nowW])\n elif maze[nowH+1][nowW]==".":\n maze[nowH+1][nowW]=="0"\n heapq.heappush(que, [0,nowH+1,nowW])\n if nowW+1 <= W-1:\n if maze[nowH][nowW+1]=="\n maze[nowH][nowW+1]=="1"\n heapq.heappush(que, [1,nowH,nowW+1])\n elif maze[nowH][nowW+1]==".":\n maze[nowH][nowW+1]=="0"\n heapq.heappush(que, [0,nowH,nowW+1])\n \n\n', 'import sys\n\nH,W = map(int,input().split())\nmaze = [list(input()) for i in range(H)]\n\n\n\ndef removeWalls(wallPointH,wallPointW):\n if maze[wallPointH][wallPointW]=="#":\n maze[wallPointH][wallPointW]="."\n if wallPointH+1 <= H-1:\n removeWalls(wallPointH+1,wallPointW)\n if wallPointW+1 <= W-1:\n removeWalls(wallPointH,wallPointW+1)\n\nque = [[0,0,0]]\ncount = 0\n \nwhile que:\n #print(que)\n if que[0][0]==1:\n que.sort()\n if que[0][0]==1:\n count += 1\n for q in que:\n q[0]=0\n removeWalls(q[1],q[2])\n else:\n now = que.pop(0)\n nowH = now[1]\n nowW = now[2]\n if maze[nowH][nowW]=="\n que.append([1,nowH,nowW])\n continue\n elif nowH==H-1 and nowW==W-1:\n print(count)\n sys.exit()\n else:\n \n if nowH+1 <= H-1:\n que.append([0,nowH+1,nowW])\n if nowW+1 <= W-1:\n que.append([0,nowH,nowW+1])\n\n', 'import sys\nimport heapq\n\nH,W = map(int,input().split())\nmaze = [list(input()) for i in range(H)]\n\ndef removeWalls(wallPointH,wallPointW):\n if maze[wallPointH][wallPointW]=="#":\n maze[wallPointH][wallPointW]="."\n if wallPointH+1 <= H-1:\n removeWalls(wallPointH+1,wallPointW)\n if wallPointW+1 <= W-1:\n removeWalls(wallPointH,wallPointW+1)\n\nque = [[0,0,0]]\nheapq.heapify(que)\ncount = 0\n \nwhile que:\n qu = heapq.heappop(que)\n #print(que)\n if qu[0]==1:\n heapq.heappush(que, qu)\n count += 1\n for q in que:\n q[0]=0\n removeWalls(q[1],q[2])\n else:\n now = qu\n nowH = now[1]\n nowW = now[2]\n if maze[nowH][nowW]=="\n heapq.heappush(que, [1,nowH,nowW])\n continue\n elif nowH==H-1 and nowW==W-1:\n print(count)\n sys.exit()\n else:\n \n if nowH+1 <= H-1:\n heapq.heappush(que, [0,nowH+1,nowW])\n if nowW+1 <= W-1:\n heapq.heappush(que, [0,nowH,nowW+1])\n \n\n', 'import sys\n\nH,W = map(int,input().split())\nmaze = [list(input()) for i in range(H)]\n\ndef removeWalls(wallPointH,wallPointW):\n if maze[wallPointH][wallPointW]=="#":\n maze[wallPointH][wallPointW]="."\n if wallPointH+1 <= H-1:\n removeWalls(wallPointH+1,wallPointW)\n if wallPointW+1 <= W-1:\n removeWalls(wallPointH,wallPointW+1)\n\nque = [[0,0,0]]\ncount = 0\n \nwhile que:\n #print(que)\n if que[0][0]==1:\n que.sort()\n if que[0][0]==1:\n count += 1\n for q in que:\n q[0]=0\n removeWalls(q[1],q[2])\n else:\n now = que.pop(0)\n nowH = now[1]\n nowW = now[2]\n if maze[nowH][nowW]=="\n que.append([1,nowH,nowW])\n continue\n elif nowH==H-1 and nowW==W-1:\n print(count)\n sys.exit()\n else:\n \n if nowH+1 <= H-1:\n que.append([0,nowH+1,nowW])\n if nowW+1 <= W-1:\n que.append([0,nowH,nowW+1])\n\n', 'import sys\nimport heapq\n\nH,W = map(int,input().split())\nmaze = [list(input()) for i in range(H)]\n\ndef removeWalls(wallPointH,wallPointW):\n if maze[wallPointH][wallPointW]=="#":\n changeTo = "."\n elif maze[wallPointH][wallPointW]=="1":\n changeTo = "0"\n if maze[wallPointH][wallPointW]=="#" or maze[wallPointH][wallPointW]=="1":\n maze[wallPointH][wallPointW]=changeTo\n if wallPointH+1 <= H-1:\n removeWalls(wallPointH+1,wallPointW)\n if wallPointW+1 <= W-1:\n removeWalls(wallPointH,wallPointW+1)\n\nif maze[0][0]=="#":\n flag=1\nelse:\n flag=0\n \nque = [[flag,0,0]]\nheapq.heapify(que)\ncount = 0\n \nwhile que:\n qu = heapq.heappop(que)\n if qu[0]==1:\n heapq.heappush(que, qu)\n count += 1\n for q in que:\n q[0]=0\n removeWalls(q[1],q[2])\n else:\n nowH = qu[1]\n nowW = qu[2]\n if nowH==H-1 and nowW==W-1:\n print(count)\n sys.exit()\n else:\n \n if nowH+1 <= H-1:\n if maze[nowH+1][nowW]=="#":\n maze[nowH+1][nowW]="1"\n heapq.heappush(que, [1,nowH+1,nowW])\n elif maze[nowH+1][nowW]==".":\n maze[nowH+1][nowW]="0"\n heapq.heappush(que, [0,nowH+1,nowW])\n if nowW+1 <= W-1:\n if maze[nowH][nowW+1]=="#":\n maze[nowH][nowW+1]="1"\n heapq.heappush(que, [1,nowH,nowW+1])\n elif maze[nowH][nowW+1]==".":\n maze[nowH][nowW+1]="0"\n heapq.heappush(que, [0,nowH,nowW+1])\n \n\n'] | ['Wrong Answer', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s005324533', 's126726472', 's313858545', 's369940137', 's490917807'] | [66036.0, 14708.0, 69364.0, 14580.0, 3316.0] | [2108.0, 2104.0, 2108.0, 2104.0, 47.0] | [2050, 1603, 1177, 1101, 1640] |
p02735 | u987164499 | 2,000 | 1,048,576 | Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be _good_ if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one square **right or down** repeatedly, while always being on a white square. Note that (1, 1) and (H, W) must be white if the grid is good. Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations. * Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) \- that is, from white to black and vice versa. | ['from sys import stdin,setrecursionlimit\nsetrecursionlimit(10**6) \nh,w = map(int,stdin.readline().rstrip().split())\nli = [stdin.readline().rstrip() for _ in range(h)]\ninf = 10**10\nlin = [[0 for i in range(w)]for j in range(h)]\nfor i in range(h):\n for j in range(w):\n if li[i][j] == "#":\n lin[i][j] += 1\n if i == 0 and j == 0:\n continue\n if j-1 >= 0:\n k = lin[i][j-1]\n else:\n k = inf\n if i-1 >= 0:\n l = lin[i-1][j]\n else:\n l = inf\n lin[i][j] += min(k,l)\nprint(lin[h-1][w-1]-1)\n', 'from sys import stdin,setrecursionlimit\nfrom collections import deque\nh,w = [int(x) for x in stdin.readline().rstrip().split()]\nli = [["" for i in range(w)]for j in range(h)]\npoint = 0\nfor i in range(h):\n s = stdin.readline().rstrip()\n point += s.count(".")\n for j in range(w):\n li[i][j] = s[j]\ndx = [1,0,-1,0]\ndy = [0,1,0,-1]\nque = deque()\nlin = [[inf for i in range(w)]for j in range(h)]\nlin[0][0] = 0\nque.append([0,0])', 'from sys import stdin,setrecursionlimit\nsetrecursionlimit(10**6) \nh,w = map(int,stdin.readline().rstrip().split())\nli = [stdin.readline().rstrip() for _ in range(h)]\ninf = 10**10\nlin = [[0 for i in range(w)]for j in range(h)]\nfor i in range(h):\n for j in range(w):\n flag = False\n if li[i][j] == "#":\n lin[i][j] += 1\n if i == 0 and j == 0:\n continue\n if j-1 >= 0:\n k = lin[i][j-1]\n if lin[i][j-1] == "#" and lin[i][j] == "#":\n flag = True\n else:\n k = inf\n if i-1 >= 0:\n l = lin[i-1][j]\n if lin[i-1][j] == "#" and lin[i][j] == "#":\n flag = True\n else:\n l = inf\n lin[i][j] += min(k,l)\n if flag:\n lin[i][j] -= 1\nprint(lin[h-1][w-1]+1)\n', 'print(0)', 'from queue import deque\n\nh,w = map(int,input().split())\nli = [input() for _ in range(h)]\n\ninf = 10**10\ndx = [1,0]\ndy = [0,1]\nque = deque()\n\n\nflip_count = [[inf for i in range(w)]for j in range(h)]\n\nif li[0][0] == "#":\n flip_count[0][0] = 1\nelse:\n flip_count[0][0] = 0\n\nque.append([0,0])\n\nwhile que:\n k = que.popleft()\n x = k[0]\n y = k[1]\n for i,j in zip(dx,dy):\n nx = x + i\n ny = y + j\n if nx >= w or ny >= h:\n continue\n if flip_count[ny][nx] == inf:\n que.append([nx,ny])\n if li[ny][nx] != li[y][x]:\n flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x]+1)\n else:\n flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x])\n\nif li[-1][-1] == "#":\n flip_count[-1][-1] += 1\n\nprint(flip_count[-1][-1]//2)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s080400209', 's841444620', 's930310604', 's988167564', 's135883933'] | [3064.0, 3560.0, 3188.0, 2940.0, 4080.0] | [28.0, 92.0, 32.0, 17.0, 55.0] | [593, 486, 826, 8, 916] |
p02736 | u021548497 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['import sys\nn = int(input())\na = input()\nif n == 2:\n print(abs(int(a[0]-int(a[1]))))\n sys.exit()\n\nkey = [0]*(n-1)\njudge = False\nfor i in range(n-1):\n key[i] = abs(int(a[i])-int(a[i+1]))\n if key[i] == 1:\n judge = True\n\ncomb = 1\nans = 0\nfor i in range(n-1):\n ans += comb*key[i]\n ans %= 2\n comb *= (n-3-i)\n comb *= pow(i+1, 7, 2)\nif ans == 0 and judge == False:\n ans = 2\nprint(ans)', 'import sys\nimport random\ninput = sys.stdin.readline\n\n\ndef solve(n, s):\n sub = [int(s[i])-1 for i in range(n)]\n \n table = [0]*(n+1)\n p = 2\n for i in range(len(bin(n))-1):\n for j in range(p, n+1, p):\n table[j] += 1\n p *= 2\n \n for i in range(n):\n table[i+1] += table[i]\n \n ans = 0\n for i in range(n):\n if sub[i]%2:\n judge = table[n-1]-table[n-1-i]-table[i]\n if not judge:\n ans += 1\n \n \n if ans%2:\n res = 1\n else:\n if 1 in sub:\n res = 0\n else:\n res = 0\n for i in range(n):\n if sub[i]:\n judge = table[n-1]-table[n-1-i]-table[i]\n if not judge:\n res += 1\n return res%2*2\n \n return res\n \n \ndef main():\n n = int(input())\n s = input()\n \n ans = solve(n, s)\n print(ans)\n \n \nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s808085853', 's412503034'] | [12572.0, 58056.0] | [1993.0, 603.0] | [389, 992] |
p02736 | u203843959 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['print(0)', 'print(2)', 'N=int(input())\nslist=input()\n\ndef fact_mod2(n,r):\n if n==(r|(n-r)):\n return 1\n else:\n return 0\n\nalist=[]\nfor s in slist:\n alist.append(int(s)-1) \n#print(alist)\n\nparity=0\nfor i in range(N):\n parity+=fact_mod2(N-1,i)*alist[i]\n#print(parity)\n\nif parity%2==1:\n print(1)\nelse:\n if 1 in alist:\n print(0)\n else:\n for i in range(N):\n alist[i]//=2\n \n parity=0\n for i in range(N):\n parity+=fact_mod2(N-1,i)*alist[i]\n if parity%2==1:\n print(2)\n else:\n print(0)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s012019688', 's209157940', 's891116180'] | [2940.0, 2940.0, 13624.0] | [18.0, 17.0, 1193.0] | [8, 8, 504] |
p02736 | u218843509 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['n = int(input())\nb = input()\ntwo = True\nif "2" in b:\n\ttwo = False\nans = 0\na = ""\nfor i in range(n):\n\tif b[i] != "1":\n\t\tans ^= ((n-1) == ( i | (n-1 - i)))\nif ans:\n\tif two:\n\t\tprint(2)\n\telse:\n\t\tprint(1)\nelse:\n\tprint(0)\n', 'n = int(input())\na = input()\n\nif "2" in a:\n\tans = 0\n\tfor i in range(n):\n\t\tif a[i] == "2":\n\t\t\tans ^= ((n-1) == ( i | (n-1 - i)))\n\tif ans:\n\t\tprint(1)\n\telse:\n\t\tprint(0)\n\nelse:\n\tans = 0\n\tfor i in range(n):\n\t\tif a[i] == "3":\n\t\t\tans ^= ((n-1) == ( i | (n-1 - i)))\n\tif ans:\n\t\tprint(2)\n\telse:\n\t\tprint(0)'] | ['Wrong Answer', 'Accepted'] | ['s269664060', 's190404848'] | [5132.0, 5612.0] | [483.0, 476.0] | [216, 295] |
p02736 | u227082700 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['n=int(input())\ns=input()\nif set(list(s))=={"1","3"}:print(2)', 'n=int(input())\ns=input()\nif set(list(s))=={"1","3"}:print(0)\n', 'from random import randint\nn=int(input())\ns=input()\nif set(list(s))=={"1","3"}:print(randint(0,1)*2)\nelse:print(randint(0,1))', 'from random import randint\nprint(randint(0,2))', 'print(2)', 'print(0)', 'n=int(input())\ndef f(n,r):\n return n==r|(n-r)\ns=list(map(int,list(input())))\nb=[]\nfor i in range(n-1):b.append(abs(s[i]-s[i+1]))\nif (0 in b and len(set(b))==2) or len(set(b))==1:\n ans=0\n anss=0\n for i in range(n-1):\n if b[i]:\n anss=b[i]\n ans+=f(n-2,i)\n if ans%2==0:\n print(0)\n else:\n print(anss)\n quit()\nans=0\nfor i in range(n-1):\n if b[i]%2==1:\n anss=b[i]\n ans+=f(n-2,i)\nif ans%2==0:\n print(0)\nelse:\n print(1)\n '] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s274619050', 's345280471', 's373044893', 's399216119', 's568587002', 's689387361', 's529973265'] | [12864.0, 12908.0, 12624.0, 4208.0, 2940.0, 3068.0, 32096.0] | [47.0, 46.0, 52.0, 33.0, 18.0, 17.0, 583.0] | [60, 61, 125, 46, 8, 8, 502] |
p02736 | u268554510 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['N = int(input())\na = list(map(int,list(input())))\na = list(map(lambda x:x-1,a))\nx = 0\nnum_mod = [0]*N\nfor i in range(1,N):\n tmp = 0\n while i%2==0:\n i//=2\n tmp+=1\n num_mod[i] = num_mod[i-1]+tmp\n \n\nfor i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):\n x+=1\n\nif x%2!=0:\n print(1)\n \nelif 1 in a:\n print(0)\n\nelse:\n a = [x//2 for x in a]\n x = 0\n for i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):\n x+=1\n if x%2!=0:\n print(2)\n else:\n print(0)\n', 'N = int(input())\na = list(map(int,list(input())))\na = list(map(lambda x:x-1,a))\nx = 0\nnum_mod = [0]*N\nfor i in range(1,N):\n x = 0\n while i%2==0:\n i//=2\n x+=1\n num_mod[i] = num_mod[i-1]+x\n \n\nfor i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):\n x+=1\n\nif x%2!=0:\n print(1)\n \nelif 1 in a:\n print(0)\n\nelse:\n a = [x//2 for x in a]\n x = 0\n for i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):\n x+=1\n if x%2!=0:\n print(2)\n else:\n print(0)\n', 'N = int(input())\na = list(map(int,list(input())))\na = list(map(lambda x:x-1,a))\nx = 0\nfor i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if ((N-1)^i)&i==0:\n x+=1\n\nif x%2!=0:\n print(1)\n \nif 1 in a:\n print(0)', 'N = int(input())\na = list(map(int,list(input())))\na = list(map(lambda x:x-1,a))\nx = 0\nnum_mod = [0]*N\nfor i in range(1,N):\n tmp = 0\n t = i\n while t%2==0:\n t//=2\n tmp+=1\n num_mod[i] = num_mod[i-1]+tmp\n \nfor i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):\n x+=1\n\nif x%2!=0:\n print(1)\n \nelif 1 in a:\n print(0)\n\nelse:\n a = [x//2 for x in a]\n x = 0\n for i,n in enumerate(a):\n if n%2==0:\n continue\n else:\n if num_mod[N-1]==(num_mod[i]+num_mod[N-1-i]):\n x+=1\n if x%2!=0:\n print(2)\n else:\n print(0)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s096357437', 's351337889', 's547001971', 's028667694'] | [28700.0, 28756.0, 21092.0, 58228.0] | [1417.0, 1476.0, 537.0, 1493.0] | [594, 588, 226, 600] |
p02736 | u377370946 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['n = int(input())\na = input()\nx = []\nx.extend([int(i) for i in a])\n\nif len(x) > 1:\n x = [abs(x[i] - x[i + 1]) for i in range(len(x) - 1)]\n\n\n\n\n\nif 1 in x:\n flag = True\n x = [1 if i == 1 else 0 for i in x]\nelse:\n flag = False\n x = [1 if i == 2 else 0 for i in x]\nc=0\nn=len(x)\nn_b=bin(n)\nif x[0]==1:\n c+=1\nfor i in range(1,n):\n tmp_nck = int(n_b == (bin(r) or bin(n-r)))\n if x[i] == 1:\n c+=tmp_nck\nif flag:\n print(c%2)\nelse:\n if c%2 == 1:\n print(2)\n else:\n print(0)', 'n = int(input())\na = input()\nx = []\nx.extend([int(i) for i in a])\n\n\n\n\n\nif 2 in x:\n flag = True\n x = [1 if i == 2 else 0 for i in x]\nelse:\n flag = False\n x = [1 if i == 3 else 0 for i in x]\nc=0\nn=len(x)\nn_b=bin(n-1)\nif x[0]==1:\n c+=1\nfor i in range(1,n-1):\n tmp_nck = int((n-1) == (i | (n-1-i)))\n if x[i] == 1:\n c+=tmp_nck\nif x[n-1]==1:\n c+=1\nif flag:\n print(c%2)\nelse:\n if c%2 == 1:\n print(2)\n else:\n print(0)\n\n'] | ['Runtime Error', 'Accepted'] | ['s980394037', 's212180310'] | [23856.0, 22460.0] | [420.0, 752.0] | [710, 763] |
p02736 | u392319141 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['import random\nprint(random.randint() % 2)', 'import random\nprint(random.randint() % 2)', 'N = int(input())\nA = list(map(int, input()))\nA = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]\n\ncnt = 0\nfor i in range(len(A)):\n if A[i: i + 3] == [0, 1, 0]:\n cnt += 1\n\nprint(cnt % 2)', 'import random\nprint(random.randint(0, 1) % 2)', 'N = int(input())\nA = list(map(int, input()))\nA = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]\n\ncnt = 0\nfor i in range(len(A)):\n if A[i: i + 4] == [0, 1, 0]:\n cnt += 1\n\nprint(cnt % 2)', 'N = int(input())\nA = list(map(int, input()))\nA = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]\n\nprint(sum(A) % 2)\n', 'N = int(input())\nA = list(map(int, input()))\nA = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]\n\nprint((sum(A) + len(A) + 1) % 2)', 'N = int(input())\nA = list(map(int, input()))\nA = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]\n\nprint(1 if len(A) >= 10000 else 0)\n', 'print(0)', 'N = int(input())\nA = list(map(int, input()))\nA = [abs(A[i] - A[i + 1]) % 2 for i in range(len(A) - 1)]\n\nprint((A.count(1) - A.count(0) + 1) % 2)', 'N = int(input())\nA = list(map(lambda a: int(a) - 1, input()))\n\nprd = 1\nif all(a % 2 == 0 for a in A):\n prd = 2\n A = [a // 2 for a in A]\n\nans = 0\nfor i in range(N):\n if (N - 1) & i == i:\n ans ^= A[i] % 2\n\nprint(prd * ans)\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s093978274', 's195569589', 's261004674', 's294270876', 's469759540', 's483840155', 's509546113', 's560303835', 's702642939', 's865071985', 's206396436'] | [3316.0, 4208.0, 20460.0, 3444.0, 20464.0, 20464.0, 20460.0, 20460.0, 3064.0, 20460.0, 20460.0] | [26.0, 34.0, 734.0, 23.0, 707.0, 388.0, 379.0, 372.0, 19.0, 398.0, 551.0] | [41, 41, 201, 45, 201, 122, 136, 139, 8, 144, 237] |
p02736 | u520276780 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['\n\n\nimport numpy as np\nn=int(input())\na_ = list(map(int, list(input())))\na = np.array(a_)-1\ndiv2=[0]\ncnt=0\nex1 = False\n\nif 1 in a:\n ex1 = True\nelse:\n a//=2\ntst=1\ntsts=[1]\nfor i in range(n-1):\n p=int(((n-1)&i)==i)\n div2.append(p)\ndiv2=np.array(div2)\ndv2=1-(div2>0)\ntmp= (a*dv2).sum()%2\nif tmp:\n if ex1:\n print(1)\n else:\n print(2)\n\nelse:\n print(0)\n', "\n\n\nimport numpy as np\nimport sys\ninput = sys.stdin.readline\nn=int(input())\na_ = list(map(int, list(input())))\na = np.array(a_)\ndiv2=[1]\ncnt=0\nex1 = False\n\nif 1 in a:\n ex1 = True\nelse:\n a//=2\nfor i in range(1,n):\n cnt += bin(n-i)[::-1].find('1')\n cnt -= bin(i)[::-1].find('1')\n div2.append(cnt)\n\ndiv2=np.array(div2)\n\ntmp= (a*div2%2).sum()%2\nif tmp:\n if ex1:\n print(1)\n else:\n print(2)\n\nelse:\n print(0)\n", '\n\n\nimport numpy as np\nn=int(input())\na_ = list(map(int, list(input())))\na = np.array(a_)-1\ndiv2=[1]\ncnt=0\nex1 = False\n\nif 1 in a:\n ex1 = True\nelse:\n a//=2\nfor i in range(n-1):\n p=int(((n-1)&i)==i)\n div2.append(p)\ndiv2=np.array(div2)\nprint(div2)\ntmp= (a*div2).sum()%2\nif tmp:\n if ex1:\n print(1)\n else:\n print(2)\n\nelse:\n print(0)\n', "\n\n\nimport numpy as np\nn=int(input())\na_ = list(map(int, list(input())))\na = np.array(a_)-1###\ndiv2=[0]\ncnt=0\nex1 = False\n\nif 1 in a:\n ex1 = True\nelse:\n a//=2\ntst=1\ntsts=[1]\nfor i in range(n-1):\n cnt += bin(n-i-1)[::-1].find('1')\n cnt -= bin(i+1)[::-1].find('1')\n \n \n div2.append(cnt)\n tsts.append(tst)\n\ndiv2=np.array(div2)\ndv2=1-(div2>0)\n#print(a)\n\n#print(dv2)\ntmp= (a*dv2).sum()%2\nif tmp:\n if ex1:\n print(1)\n else:\n print(2)\n\nelse:\n print(0)\n"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s149793675', 's779553779', 's997371096', 's176383368'] | [52492.0, 29984.0, 44436.0, 64692.0] | [870.0, 291.0, 863.0, 1880.0] | [542, 462, 449, 622] |
p02736 | u561231954 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ["import sys\nINF = 10 ** 9\nMOD = 10 ** 9 + 7\nfrom collections import deque\nsys.setrecursionlimit(100000000)\n\ndef main():\n n = int(input())\n a = list(input())\n print(0)\nif __name__=='__main__':\n main()\n\n", "import sys\nINF = 10 ** 9\nMOD = 10 ** 9 + 7\nfrom collections import deque\nsys.setrecursionlimit(100000000)\n\n\ndef nxor(x,n,k):\n if (n&k) == k:\n return x\n else:\n return 0\n\n\ndef main():\n n = int(input())\n a = [int(i) - 1 for i in list(input())]\n \n cumxor = 0\n amod = [i%2 for i in a]\n for i in range(n):\n cumxor ^= nxor(amod[i],n - 1,i)\n \n if cumxor == 1:\n ans = 1\n else:\n if 1 in a:\n ans = 0\n else:\n cumxor = 0\n adiv = [i//2 for i in a]\n for i in range(n):\n cumxor ^= nxor(adiv[i],n - 1,i)\n if cumxor == 0:\n ans = 0\n else:\n ans = 2\n \n print(ans)\n\nif __name__=='__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s302186925', 's588373019'] | [13116.0, 31092.0] | [34.0, 786.0] | [212, 771] |
p02736 | u693378622 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['N=int(input())\nA=[int(a)-1 for a in input()]\nr=1-(1 in A)\nprint(sum([A[i]&r and (N-1&i)==i for i in range(N)])%2*r)', 'N=int(input())\nA=[int(a)-1 for a in input()]\nr=2-(1 in A)\nprint(sum([A[i]&r and (N-1&i)==i for i in range(N)])%2*r)'] | ['Wrong Answer', 'Accepted'] | ['s162435559', 's571905994'] | [20460.0, 20460.0] | [345.0, 429.0] | [115, 115] |
p02736 | u801570811 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['n = int(input())\na = list(map(int,input().split()))\n\nwhile n != 0:\n\tx = 1\n\twhile x < n // 2:\n\t\tx *= 2\n\tb = []\n\tfor i in range(x, n):\n\t\tb.append(abs(a[i - x] - a[i]))\n\ta = b\n\tn -= digit\n\tif len(b) == 1:\n\t\tbreak\nprint(a[0])\n', 'N = int(input())\na = list(map(int, list(input())))\n \nwhile N != 0:\n\tdigit = 1\n\twhile digit < N // 2:\n\t\tdigit *= 2\n \n\tx = []\n\tfor i in range(digit, N):\n\t\tx.append(abs(a[i - digit] - a[i]))\n \n\ta = x\n\tN -= digit\n\tif len(x) == 1:\n\t\tbreak\n \nprint(a[0])'] | ['Runtime Error', 'Accepted'] | ['s696510611', 's684411420'] | [5132.0, 21348.0] | [2104.0, 374.0] | [222, 247] |
p02736 | u837673618 | 2,000 | 1,048,576 | Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find x_{N,1}. | ['import sys\n\nN = int(input()) - 1\ntwo = False\nS = 0\nfor i, a in zip(range(N+1), sys.stdin):\n a = int(a)\n if not two:\n two = a == 2\n if i & N == i:\n S ^= a-1\n\nif two:\n S &= ~2\n\nprint(S)\n', 'import sys\n\nN = int(input()) - 1\ntwo = False\nS = 0\nfor i in range(N+1):\n a = int(sys.stdin.read(1))\n if not two:\n two = a == 2\n if i & N == i:\n S ^= a-1\n\nif two:\n S &= ~2\n\nprint(S)\n'] | ['Wrong Answer', 'Accepted'] | ['s300674958', 's112489005'] | [4980.0, 3060.0] | [2108.0, 566.0] | [194, 191] |
p02737 | u837673618 | 2,000 | 1,048,576 | Given are simple undirected graphs X, Y, Z, with N vertices each and M_1, M_2, M_3 edges, respectively. The vertices in X, Y, Z are respectively called x_1, x_2, \dots, x_N, y_1, y_2, \dots, y_N, z_1, z_2, \dots, z_N. The edges in X, Y, Z are respectively (x_{a_i}, x_{b_i}), (y_{c_i}, y_{d_i}), (z_{e_i}, z_{f_i}). Based on X, Y, Z, we will build another undirected graph W with N^3 vertices. There are N^3 ways to choose a vertex from each of the graphs X, Y, Z. Each of these choices corresponds to the vertices in W one-to-one. Let (x_i, y_j, z_k) denote the vertex in W corresponding to the choice of x_i, y_j, z_k. We will span edges in W as follows: * For each edge (x_u, x_v) in X and each w, l, span an edge between (x_u, y_w, z_l) and (x_v, y_w, z_l). * For each edge (y_u, y_v) in Y and each w, l, span an edge between (x_w, y_u, z_l) and (x_w, y_v, z_l). * For each edge (z_u, z_v) in Z and each w, l, span an edge between (x_w, y_l, z_u) and (x_w, y_l, z_v). Then, let the weight of the vertex (x_i, y_j, z_k) in W be 1,000,000,000,000,000,000^{(i +j + k)} = 10^{18(i + j + k)}. Find the maximum possible total weight of the vertices in an ) in W, and print that total weight modulo 998,244,353. | ['from collections import defaultdict\n\nM = 998244353\nB = pow(10, 18, M)\nN = int(input())\n\ndef ext_euc(a, b):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, b\n while z1 != 1:\n d, m = divmod(z2,z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1, y1\n\ndef inv_mod(a, b, m):\n x, y = ext_euc(a, m)\n return (x * b % m)\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n g = {}\n sum_g = defaultdict(int)\n sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n x = 1\n for i in range(1, N+1)\n x = (x * B) % M\n if g[i]:\n sum_g[g[i]] += x\n sum_g[0] -= x\n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(set)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].add(b)\n return e\n\ndef solve(N, edge):\n sum_g = list(map(calc_grundy, edge))\n ret = 0\n for gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ret += (sx*sy*sz) % M\n return ret%M\n\n\nedge = [read_edge() for i in range(3)]\n\nprint(solve(N, edge))', 'from collections import defaultdict\n\nM = 998244353\nB = pow(10, 18, M)\nN = int(input())\n\ndef ext_euc(a, b):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, b\n while z1 != 1:\n d, m = divmod(z2,z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1, y1\n\ndef inv_mod(a, b, m):\n x, y = ext_euc(a, m)\n return (x * b % m)\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n g = {}\n sum_g = defaultdict(int)\n sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n x = 1\n for i in range(1, N+1):\n x = (x * B) % M\n if g[i]:\n sum_g[g[i]] += x\n sum_g[0] -= x\n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(set)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].add(b)\n return e\n\ndef solve(N, edge):\n sum_g = list(map(calc_grundy, edge))\n ret = 0\n for gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ret += (sx*sy*sz) % M\n return ret%M\n\n\nedge = [read_edge() for i in range(3)]\n\nprint(solve(N, edge))', 'from collections import defaultdict\n\nM = 998244353\nB = pow(10, 18, M)\nN = int(input())\n\ndef geometric_mod(a, r, m, n):\n x = a\n for i in range(n):\n yield x\n x = (x*r)%m\n\nBB = list(geometric_mod(1, B, M, N+2))\n\ndef ext_euc(a, b):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, b\n while z1 != 1:\n d, m = divmod(z2,z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1, y1\n\ndef inv_mod(a, b, m):\n x, y = ext_euc(a, m)\n return (x * b % m)\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n e = set(e)\n g = {}\n sum_g = defaultdict(int)\n sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M\n sum_g[0] = (sum_g[0] - BB[i]) % M\n\n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(list)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].append(b)\n return e\n\ndef solve(N, edge):\n sum_g = list(map(calc_grundy, edge))\n ret = 0\n for gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ret = (ret + sx*sy*sz) % M\n return ret\n\n\nedge = [read_edge() for i in range(3)]\n\nprint(solve(N, edge))', 'from collections import defaultdict\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip()\n\nM = 998244353\nB = pow(10, 18, M)\nN = int(input())\n\ndef ext_euc(a, b):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, b\n while z1 != 1:\n d, m = divmod(z2,z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1, y1\n\ndef inv_mod(a, b, m):\n x, y = ext_euc(a, m)\n return (x * b % m)\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n g = {}\n sum_g = defaultdict(int)\n sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n prev_i = 1\n prev_W = B\n for i in range(1, N+1):\n if i in g:\n W = (W * pow(B, i-prev_i, M)) % M\n sum_g[g[i]] = (sum_g[g[i]] + W) % M\n sum_g[0] = (sum_g[0] - W) % M\n prev_i, prev_W = i, W\n \n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(list)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].append(b)\n return e\n\ndef solve(N, edge):\n sum_g = list(map(calc_grundy, edge))\n ret = 0\n for gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ret = (ret + sx*sy*sz) % M\n return ret\n\nedge = [read_edge() for i in range(3)]\n\nprint(solve(N, edge))', 'from collections import defaultdict\nimport sys\ninput = lambda: sys.stdin.readline().rstrip()\n\nM = 998244353\nB = pow(10, 18, M)\nN = int(input())\n\ndef geometric_mod(a, r, m, n):\n x = a\n for i in range(n):\n yield x\n x = (x*r)%m\n\nBB = list(geometric_mod(1, B, M, N+2))\n\ndef ext_euc(a, b):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, b\n while z1 != 1:\n d, m = divmod(z2,z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1, y1\n\ndef inv_mod(a, b, m):\n x, y = ext_euc(a, m)\n return (x * b % m)\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n g = {}\n sum_g = defaultdict(int)\n sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M\n sum_g[0] = (sum_g[0] - BB[i]) % M\n\n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(list)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].add(b)\n return e\n\ndef solve(N, edge):\n sum_g = list(map(calc_grundy, edge))\n ret = 0\n for gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ret = (ret + sx*sy*sz) % M\n return ret\n\n\nedge = [read_edge() for i in range(3)]\n\nprint(solve(N, edge))', 'from collections import defaultdict\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip()\n\nM = 998244353 # < (1 << 30)\n\ndef mod_inv(a, M=M):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, M\n while abs(z1) != 1:\n d, m = divmod(z2, z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1*z1%M\n\nR_bits = 30\nR = 1 << R_bits\nR_dec = R - 1\nR2 = pow(R, 2, M)\nM_neg_inv = mod_inv(-M, R)\n\ndef MR(x):\n b = (x * M_neg_inv) & R_dec\n t = x + b * M\n c = t >> R_bits\n d = c - M\n return d if 0 <= d else c\n\ndef Montgomery(x):\n return MR(x*R2)\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(edge):\n grundy = [{} for i in range(3)]\n sum_g = [defaultdict(int, {0:M_W_sum}) for i in range(3)]\n M_W = M_W_last\n for i in range(N, 0, -1):\n for g, s, e in zip(grundy, sum_g, edge):\n if i in e:\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n s[g[i]] += M_W\n s[0] += M - M_W\n M_W = MR(M_W * M_B_inv)\n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(list)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].append(b)\n return e\n\nN = int(input())\nB = pow(10, 18, M)\nM_B_inv = Montgomery(mod_inv(B))\nM_W_last = Montgomery(pow(B, N, M))\nM_W_sum = MR((M_W_last + Montgomery(-1)) * Montgomery(B * mod_inv(B-1) % M))\n\nedge = [read_edge() for i in range(3)]\nsum_g = calc_grundy(edge)\nans = 0\nfor gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ans += Montgomery(MR(sx)*MR(sy)*MR(sz))\nprint(MR(ans))\n', 'from collections import defaultdict\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef ext_euc(a, b):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, b\n while z1 != 1:\n d, m = divmod(z2,z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1, y1\n\nclass mod_int(int):\n def __new__(cls, i=0, *args, **kwargs):\n return int.__new__(cls, i%M, *args, **kwargs)\n \n def __add__(self, x):\n return self.__class__(int.__add__(self, x))\n \n def __sub__(self, x):\n return self.__class__(int.__sub__(self, x))\n \n def __neg__(self):\n return self.__class__(int.__neg__(self, x))\n \n def __mul__(self, x):\n return self.__class__(int.__mul__(self, x))\n \n def __floordiv__(self, x):\n a, b = ext_euc(x, M)\n return self * a\n \n def __inv__(self):\n a, b = ext_euc(self, M)\n return self.__class__(a)\n \n def __pow__(self, x):\n return self.__class__(int.__pow__(self, x, M))\n\ndef mex(s):\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n g = {}\n sum_g = defaultdict(mod_int)\n sum_g[0] = (B**(N+1) - B) // (B-1)\n prev = N\n W = B**N\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex({g.get(j, 0) for j in e[i]})\n if m:\n g[i] = m\n W *= B_inv**(prev-i)\n sum_g[g[i]] += W\n sum_g[0] -= W\n prev, W = i, W\n \n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(list)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].append(b)\n return e\n\ndef solve(N, edge):\n sum_g = list(map(calc_grundy, edge))\n ret = mod_int(0)\n for gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n sz = sum_g[2][gz]\n if sz:\n ret += sx*sy*sz\n return ret\n\n\nM = 998244353\nB = mod_int(10) ** 18\nB_inv = ~B\nN = int(input())\n\nedge = [read_edge() for i in range(3)]\n\nprint(solve(N, edge))\n', 'from collections import defaultdict\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip()\n\ndef mod_inv(a):\n x1, y1, z1 = 1, 0, a\n x2, y2, z2 = 0, 1, M\n while z1 != 1:\n d, m = divmod(z2, z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1%M\n\ndef mex(s):\n s = set(s)\n for i in range(N+1):\n if i not in s:\n return i\n\ndef calc_grundy(e):\n g = {}\n for i in range(N, 0, -1):\n if i not in e:\n continue\n m = mex(map(lambda x:g.get(x, 0), e[i]))\n if m:\n g[i] = m\n return g\n\ndef sum_grundy(grundy):\n sum_g = [defaultdict(int, {0:B_sum}) for i in range(3)]\n W, prev = B, 1\n for i in range(1, N+1):\n for s, g in zip(sum_g, grundy):\n if i in g:\n if prev != i:\n W, prev = W * pow(B, i-prev, M) % M, i\n s[g[i]] = (s[g[i]] + W) % M\n s[0] = (s[0] - W) % M\n return sum_g\n\ndef read_edge():\n M = int(input())\n e = defaultdict(list)\n for i in range(M):\n a, b = sorted(map(int, input().split()))\n e[a].append(b)\n return e\n\nN = int(input())\nM = 998244353\nB = pow(10, 18, M)\nB_sum = (pow(B, N+1, M) - B) * mod_inv(B-1) % M\n\nedge = [read_edge() for i in range(3)]\ngrundy = list(map(calc_grundy, edge))\nsum_g = sum_grundy(grundy)\nans = 0\nfor gx, sx in sum_g[0].items():\n for gy, sy in sum_g[1].items():\n gz = gx^gy\n if gz in sum_g[2]:\n ans = (ans + sx*sy*sum_g[2][gz]) % M\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s220260337', 's309892359', 's623791211', 's740135734', 's780135605', 's866701709', 's960391324', 's989867155'] | [3064.0, 73404.0, 60648.0, 61280.0, 7432.0, 68568.0, 62564.0, 70288.0] | [17.0, 1401.0, 1248.0, 927.0, 40.0, 1335.0, 1943.0, 1274.0] | [1228, 1229, 1356, 1400, 1397, 1625, 1892, 1399] |
p02738 | u423585790 | 6,000 | 1,048,576 | Given is a positive integer N. Find the number of permutations (P_1,P_2,\cdots,P_{3N}) of (1,2,\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number M. * Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N exactly once. * Let P be an empty sequence, and do the following operation 3N times. * Among the elements that are at the beginning of one of the sequences A_i that is non-empty, let the smallest be x. * Remove x from the sequence, and add x at the end of P. | ['from numpy import*\nn,M=map(int,input().split())\nl=n*3+1\nd=zeros((l,n*5))\nd[0][0]=1\nfor i in range(1,l):j,k=i-1,i-2;d[i]=(d[i-3]*k*j+roll(d[k],-1)*j+roll(d[j],1))%M\nprint(sum(d[-1][:l])%M)\n', 'import numpy as p\nn,M=map(int,input().split())\nl=n*3+1\nd=p.zeros((l,n*5),p.int64)\nd[0][0]=d[1][1]=d[2][2]=d[2][-1]=1\nfor i in range(3,l):\n d[i]=(d[i-3]*(i-2)*(i-1)+p.roll(p[i-2],-1)*(i-1)+p.roll(d[i-1],1))%M\nprint(d[-1][:l].sum()%M)', 'import numpy as p\nn,M=map(int,input().split())\nl=n*3+1\nr=p.roll\nd=p.zeros((l,n*5),p.int64)\nd[0][0]=1\nfor i in range(l):j,k=i-1,i-2;d[i]=(d[i-3]*k*j+r(d[k],-1)*j+r(d[j],1))%M\nprint(d[-1][:l].sum()%M)\n', 'from numpy import*\nn,M=map(int,input().split())\nl=n*3+1\nd=zeros(l,n*5)\nd[0][0]=1\nfor i in range(1,l):j,k=i-1,i-2;d[i]=(d[i-3]*k*j+roll(d[k],-1)*j+roll(d[j],1))%M\nprint(sum(d[-1][:l])%M)\n', 'import numpy as p\nn,M=map(int,input().split())\nl=n*3+1\nd=p.zeros((l,n*5),p.int64)\nd[0][0]=d[1][1]=d[2][2]=d[2][-1]=1\nfor i in range(3,l):j,k=i-1,j-1;d[i]=(d[i-3]*(k)*(j)+p.roll(d[k],-1)*(i-1)+p.roll(d[j],1))%M\nprint(d[-1][:l].sum()%M)', 'from numpy import*\nn,M=map(int,input().split())\nl=n*3+1\nd=zeros((l,n*5),int64)\nd[0][0]=1\nfor i in range(1,l):j,k=i-1,i-2;d[i]=((d[i-3]*k+roll(d[k],-1))*j+roll(d[j],1))%M\nprint(sum(d[-1][:l])%M)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s102570766', 's116652558', 's590033247', 's600479045', 's928009385', 's659257359'] | [481516.0, 14556.0, 481492.0, 12488.0, 14428.0, 481520.0] | [3623.0, 152.0, 2691.0, 148.0, 147.0, 2584.0] | [188, 233, 199, 186, 234, 193] |
p02738 | u837673618 | 6,000 | 1,048,576 | Given is a positive integer N. Find the number of permutations (P_1,P_2,\cdots,P_{3N}) of (1,2,\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number M. * Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N exactly once. * Let P be an empty sequence, and do the following operation 3N times. * Among the elements that are at the beginning of one of the sequences A_i that is non-empty, let the smallest be x. * Remove x from the sequence, and add x at the end of P. | ['\u3000from functools import lru_cache, reduce\nfrom itertools import accumulate\n\nN, M = map(int, input().split())\n\n@lru_cache(maxsize=None)\ndef mod_inv(x):\n x1, y1, z1 = 1, 0, x\n x2, y2, z2 = 0, 1, M\n while z1 != 1:\n d, m = divmod(z2, z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1%M\n\ndef gen_Y(i, A):\n yield A\n # sC2/1, (s-2)C2/2, (s-4)C2/3 ...\n s = 3*(N-i)\n r = s*(s-1)>>1\n d_r = (s<<1)-3\n for j in range(1, N-i+1):\n yield r * mod_inv(j)\n r -= d_r\n d_r -= 4\n\ndef gen_X():\n # sC3*2/1, (s-3)C3*2/2, (s-6)C3*2/3 ...\n yield 1\n a = N\n b = 3*N - 1\n for i in range(1, N+1):\n yield a * b * (b-1) * mod_inv(i)\n a -= 1\n b -= 3\n\ndef mul_mod(x, y):\n return x * y % M\n\ndef acc_mod(it):\n return accumulate(it, mul_mod)\n\nans = sum(sum(acc_mod(gen_Y(i, A))) for i, A in enumerate(acc_mod(gen_X())))%M\n\nprint(ans)', 'from functools import lru_cache\n\nN, M = map(int, input().split())\n\n@lru_cache(maxsize=None)\ndef mod_inv(x):\n x1, y1, z1 = 1, 0, x\n x2, y2, z2 = 0, 1, M\n while z1 != 1:\n d, m = divmod(z2, z1)\n x1, x2 = x2-d*x1, x1\n y1, y2 = y2-d*y1, y1\n z1, z2 = m, z1\n return x1%M\n\ndef gen_Y(i):\n # sC2/1, (s-2)C2/2, (s-4)C2/3 ...\n s = 3*(N-i)\n r = s*(s-1)>>1\n d_r = (s<<1)-3\n for j in range(1, N-i+1):\n yield r * mod_inv(j)\n r -= d_r\n d_r -= 4\n\ndef gen_X():\n # sC3*2/1, (s-3)C3*2/2, (s-6)C3*2/3 ...\n a = N\n b = 3*N - 1\n for i in range(1, N+1):\n yield a * b * (b-1) * mod_inv(i)\n a -= 1\n b -= 3\n\ndef acc_mulmod(it, init=1):\n x = init\n yield x\n for y in it:\n x = x*y % M\n yield x\n\nans = sum(sum(acc_mulmod(gen_Y(i), A)) for i, A in enumerate(acc_mulmod(gen_X())))%M\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s609956452', 's189751471'] | [3188.0, 3808.0] | [18.0, 2549.0] | [871, 814] |
p02753 | u001495709 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ["s = input()\nif s[0] == s[1] and s[1] == s[2]:\n print('Yes')\nelse :\n print('No')", "s = input()\nif s[0] == s[1] and s[1] == s[2]:\n print('No')\nelse :\n print('Yes')"] | ['Wrong Answer', 'Accepted'] | ['s233995162', 's028268059'] | [2940.0, 2940.0] | [18.0, 17.0] | [81, 81] |
p02753 | u004823354 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['S = list(input())\nif S[0]== S[1] == S[2]:\n print("No")\nelse:\n print("Yes")', "s = list(input())\nif s[0] == s[1] == s[2]:\n print('No')\nelse:\n print('Yes')"] | ['Runtime Error', 'Accepted'] | ['s167328630', 's367356826'] | [8928.0, 9028.0] | [28.0, 26.0] | [84, 81] |
p02753 | u006817280 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['\nimport collections\n\n\nclass Solution:\n def solve(self, string):\n counts = collections.Counter(string)\n return counts["A"] > 0 and counts["B"] > 0\n\n\nsol = Solution()\n\nstring = input().strip()\n\nprint(sol.solve(string))\n', '\nimport collections\n\n\nclass Solution:\n def solve(self, string):\n counts = collections.Counter(string)\n\n return counts["A"] and counts["B"]\n\n\nsol = Solution()\n\nstring = input().strip()\n\nprint("Yes" if sol.solve(string) else "No")\n'] | ['Wrong Answer', 'Accepted'] | ['s007396159', 's655688935'] | [3444.0, 3316.0] | [83.0, 21.0] | [234, 246] |
p02753 | u006880673 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ["s = input()\n\nif s == 'AAA' or 'BBB':\n print('No')\nelse:\n print('Yes')", "s = input()\n\nif s == 'AAA' or 'BBB':\n print('No')\nelse:\n print('Yes')", "s = input()\n\nif s = 'AAA' or 'BBB':\n print('No')\nelse:\n print('Yes')", "s = input()\n\nif s == 'AAA' or s == 'BBB':\n print('No')\nelse:\n print('Yes')"] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s221633656', 's478619342', 's526157793', 's874626548'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0] | [75, 75, 74, 80] |
p02753 | u007738720 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['S = input()\nif S == "AAA" or S == "BBB":\n print("Yes")\nelse:\n print(\'No\')', "S=input()\nif S[0] in S[1] in S[2]:\n print('Yes')\nelse:\n print('No')", "S=input()\nif S[0] == S[1] == S[2]:\n print('Yes')\nelse:\n print('No')", "S=input()\nif S[0] in S[1] in S[2]:\n print('Yes')\nelse:\n print('No')", 's = input()\n \nif s=="AAA" or s=="BBB":\n print("No")\nelse:\n print("Yes")'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s435306937', 's466339485', 's913243169', 's914444369', 's668480964'] | [2940.0, 2940.0, 2940.0, 3064.0, 3064.0] | [18.0, 17.0, 17.0, 17.0, 17.0] | [75, 69, 69, 69, 77] |
p02753 | u010439424 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['s = input()\nif \'A\' in s and \'B\' in s:\n print("YES")\nelse:\n print("NO")\n', 's = input()\nif \'A\' in s and \'B\' in s:\n print("Yes")\nelse:\n print("No")\n'] | ['Wrong Answer', 'Accepted'] | ['s155102201', 's917282211'] | [2940.0, 2940.0] | [17.0, 17.0] | [77, 77] |
p02753 | u011277545 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['n=input()\n\nif n="AAA" or n="BBB":\n print("No")\nelse:\n print("Yes")', 'S=input()\nif S=="AAA" or S=="BBB":\n print("No")\nelse:\n print("No")', 'n=input()\n\nif n=="AAA" or n=="BBB":\n print("Yes")\nelse:\n print("No")', 'S=input()\nif S=="AAA" or S=="BBB":\n print("No")\nelse:\n print("Yes")'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s059546653', 's348497668', 's811975488', 's167277754'] | [2940.0, 2940.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0, 17.0] | [68, 72, 70, 73] |
p02753 | u013202780 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['s=input()\nprint("YNeos"[s != len(s) * s[0]::2])', 's=input()\nprint("YNeos"[s == len(s) * s[0]::2])'] | ['Wrong Answer', 'Accepted'] | ['s745565790', 's024465025'] | [9032.0, 8960.0] | [26.0, 27.0] | [47, 47] |
p02753 | u015418292 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['s = input()\n\nif s[0] == s[1] == s[2]:\n print("Yes")\nelse:\n print("No")\n', 's = input()\n\nif s[0] == s[1] == s[2]:\n print("No")\nelse:\n print("Yes")\n'] | ['Wrong Answer', 'Accepted'] | ['s023873976', 's066965902'] | [2940.0, 2940.0] | [17.0, 17.0] | [77, 77] |
p02753 | u015993380 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ["print('Yes' if all(input().count(c) > 0 for c in 'AB') else 'No')", "s = input()\nprint('No' if (s == 'AAA' or s == 'BBB') else 'Yes')"] | ['Runtime Error', 'Accepted'] | ['s688861324', 's345363715'] | [2940.0, 2940.0] | [18.0, 17.0] | [65, 64] |
p02753 | u016182925 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['S = input()\nS_list = [S]\nif S_list[1] = S_list[2] = S_list[3] :\n print("No")\nelse :\n print("Yes")\n\t', 'S = input()\nS_list = [S]\nif S_list[1] == S_list[2] == S_list[3] :\n print("No")\nelse :\n print("Yes")\n\t', 'S = input()\nif S[0] == S[1] == S[2] :\n print("No")\nelse :\n print("Yes")\n\t'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s355387086', 's402369225', 's071894394'] | [2940.0, 2940.0, 2940.0] | [18.0, 17.0, 17.0] | [101, 103, 75] |
p02753 | u017050982 | 2,000 | 1,048,576 | In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i. To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. | ['a = input()\nif a = "AAA" or a = "BBB":\n print("No")\nelse:\n print("Yes")', 'a = input()\nif a == "AAA" or a == "BBB":\n print("No")\nelse:\n print("Yes")'] | ['Runtime Error', 'Accepted'] | ['s625985118', 's375252500'] | [2940.0, 2940.0] | [17.0, 17.0] | [73, 75] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.