結果

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

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    S = input[1]
    
    two_digit_primes = {
        11, 13, 17, 19, 23, 29,
        31, 37, 41, 43, 47, 53,
        59, 61, 67, 71, 73, 79,
        83, 89, 97
    }
    
    selected = [False] * N
    count_single = 0
    for i in range(N):
        c = S[i]
        if c in {'3', '5', '7'}:
            count_single += 1
            selected[i] = True
    
    # 分割区间
    intervals = []
    i = 0
    while i < N:
        if selected[i]:
            i += 1
            continue
        j = i
        while j < N and not selected[j]:
            j += 1
        intervals.append((i, j - 1))
        i = j
    
    has_two_digit = False
    for (start, end) in intervals:
        length = end - start + 1
        if length < 2:
            continue
        for i in range(start, end):
            num = int(S[i] + S[i+1])
            if num in two_digit_primes:
                has_two_digit = True
                break
        if has_two_digit:
            break
    
    total = count_single + (1 if has_two_digit else 0)
    print(total)
    
if __name__ == '__main__':
    main()
0