Submission #65038489


Source Code Expand

Copy
import sys
import pypyjit
sys.setrecursionlimit(10**6)
pypyjit.set_param('max_unroll_recursion=-1')
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
p = pow(10, N, M)
ans = 0
for k in range(1, N + 1):
i = k
j = N + 1 - k
A_set = set()
def f(t, x, y, s_mod):
if t == N - 1:
if (x, y) == (i, j):
A_set.add(s_mod)
return
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys
import pypyjit

sys.setrecursionlimit(10**6)
pypyjit.set_param('max_unroll_recursion=-1')

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
p = pow(10, N, M)
ans = 0

for k in range(1, N + 1):
    i = k
    j = N + 1 - k
    A_set = set()

    def f(t, x, y, s_mod):
        if t == N - 1:
            if (x, y) == (i, j):
                A_set.add(s_mod)
            return
        s_mod = (s_mod * 10 + A[x - 1][y - 1]) % M
        if x < N:
            f(t + 1, x + 1, y, s_mod)
        if y < N:
            f(t + 1, x, y + 1, s_mod)

    f(0, 1, 1, 0)

    B_set = set()

    def g(t, x, y, s_mod):
        if t == N - 1:
            if (x, y) == (N, N):
                s_mod = (s_mod * 10 + A[N - 1][N - 1]) % M
                B_set.add(s_mod)
            return
        s_mod = (s_mod * 10 + A[x - 1][y - 1]) % M
        if x < N:
            g(t + 1, x + 1, y, s_mod)
        if y < N:
            g(t + 1, x, y + 1, s_mod)

    g(0, i, j, 0)

    for a in A_set:
        for b in B_set:
            val = (a * p + b) % M
            ans = max(ans, val)

print(ans)

Submission Info

Submission Time
Task F - Path to Integer
User juntenbanana
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1178 Byte
Status TLE
Exec Time 2212 ms
Memory 97600 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 525
Status
AC × 3
AC × 28
TLE × 16
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 57 ms 76472 KB
00_sample_01.txt AC 57 ms 76628 KB
00_sample_02.txt AC 57 ms 76504 KB
01_handmade_00.txt AC 57 ms 76524 KB
01_handmade_01.txt AC 57 ms 76332 KB
01_handmade_02.txt AC 57 ms 76560 KB
01_handmade_03.txt AC 57 ms 76332 KB
01_handmade_04.txt AC 68 ms 81552 KB
01_handmade_05.txt AC 213 ms 83340 KB
01_handmade_06.txt AC 1258 ms 87996 KB
01_handmade_07.txt AC 1339 ms 88412 KB
01_handmade_08.txt AC 1265 ms 88116 KB
01_handmade_09.txt AC 1334 ms 88292 KB
01_handmade_10.txt AC 57 ms 76752 KB
01_handmade_11.txt AC 90 ms 82612 KB
01_handmade_12.txt AC 1305 ms 88944 KB
01_handmade_13.txt TLE 2212 ms 94920 KB
01_handmade_14.txt AC 1283 ms 88368 KB
01_handmade_15.txt AC 1310 ms 88504 KB
02_random_00.txt AC 57 ms 76448 KB
02_random_01.txt AC 78 ms 82704 KB
02_random_02.txt AC 67 ms 81744 KB
02_random_03.txt AC 85 ms 82640 KB
02_random_04.txt AC 56 ms 76628 KB
02_random_05.txt AC 74 ms 82816 KB
02_random_06.txt AC 61 ms 81048 KB
02_random_07.txt AC 78 ms 82412 KB
02_random_08.txt AC 1355 ms 86624 KB
02_random_09.txt AC 74 ms 82836 KB
02_random_10.txt TLE 2212 ms 95844 KB
02_random_11.txt TLE 2212 ms 96724 KB
02_random_12.txt TLE 2211 ms 93908 KB
02_random_13.txt TLE 2212 ms 96304 KB
02_random_14.txt TLE 2212 ms 93744 KB
02_random_15.txt TLE 2212 ms 94316 KB
02_random_16.txt TLE 2212 ms 97600 KB
02_random_17.txt TLE 2212 ms 94392 KB
02_random_18.txt TLE 2212 ms 95300 KB
02_random_19.txt TLE 2212 ms 95248 KB
02_random_20.txt TLE 2212 ms 96660 KB
02_random_21.txt TLE 2212 ms 95624 KB
02_random_22.txt TLE 2212 ms 95156 KB
02_random_23.txt TLE 2212 ms 97120 KB
02_random_24.txt TLE 2212 ms 93380 KB


2025-04-26 (Sat)
20:50:48 +09:00