結果

問題 No.910 素数部分列
ユーザー gew1fw
提出日時 2025-06-12 16:36:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 54,504 KB
最終ジャッジ日時 2025-06-12 16:36:30
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 16 TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    S = input[1]

    primes_2digit = {11, 13, 17, 19, 31, 37, 53, 59, 71, 73, 79, 97}

    count_single = 0
    used = [False] * N
    for i in range(N):
        c = S[i]
        if c in {'3', '5', '7'}:
            count_single += 1
            used[i] = True

    intervals = []
    for i in range(N):
        if used[i]:
            continue
        for j in range(i + 1, N):
            if used[j]:
                continue
            num = int(S[i] + S[j])
            if num in primes_2digit:
                intervals.append((i, j))
                used[i] = True
                used[j] = True
                break

    total = count_single + len(intervals)
    print(total)

if __name__ == '__main__':
    main()
0