結果

問題 No.2119 一般化百五減算
ユーザー H3PO4H3PO4
提出日時 2022-11-05 08:41:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 85,888 KB
最終ジャッジ日時 2023-09-26 09:19:37
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
75,952 KB
testcase_01 AC 78 ms
76,020 KB
testcase_02 AC 79 ms
75,984 KB
testcase_03 AC 78 ms
75,868 KB
testcase_04 AC 78 ms
75,932 KB
testcase_05 AC 79 ms
75,808 KB
testcase_06 AC 77 ms
75,636 KB
testcase_07 AC 78 ms
75,960 KB
testcase_08 AC 79 ms
75,888 KB
testcase_09 AC 79 ms
75,948 KB
testcase_10 AC 79 ms
75,776 KB
testcase_11 AC 80 ms
75,864 KB
testcase_12 AC 77 ms
75,936 KB
testcase_13 AC 78 ms
75,816 KB
testcase_14 AC 78 ms
75,912 KB
testcase_15 AC 77 ms
75,852 KB
testcase_16 AC 78 ms
75,820 KB
testcase_17 AC 77 ms
75,844 KB
testcase_18 AC 79 ms
75,892 KB
testcase_19 AC 78 ms
75,820 KB
testcase_20 AC 121 ms
82,180 KB
testcase_21 AC 101 ms
81,064 KB
testcase_22 AC 128 ms
83,900 KB
testcase_23 AC 128 ms
83,968 KB
testcase_24 AC 145 ms
85,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline


def solve(N, V):
    MAX = 10 ** 5
    mod_table = [None] * (MAX + 1)
    for c, b in V:
        if mod_table[b] is None:
            mod_table[b] = c
        elif mod_table[b] != c:
            return "NaN"

    ct = 0
    res_table = [0] * (N + 1)
    for i, mod in enumerate(mod_table):
        if mod is None:
            continue
        ct += 1
        for x in range(mod, N + 1, i):
            res_table[x] += 1
    for i in range(N + 1):
        if res_table[i] == ct:
            return i
    return "NaN"


N = int(input())
M = int(input())
V = []
for _ in range(M):
    b, c = map(int, input().split())
    c %= b
    V.append((c, b))
print(solve(N, V))
0