結果

問題 No.3110 Like CPCTF?
ユーザー ako yas
提出日時 2025-04-19 10:54:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 755 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2025-04-19 10:54:15
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

def is_ok(s, input):

    a, b, c, d, e = input
    chars = [s[a], s[b], s[c], s[d], s[e]]
    
    # 1文字目と3文字目が同じ
    if chars[0] != chars[2]:
        return False

    # 1文字目と3文字目以外が全部異なる
    other_chars = [chars[1], chars[3], chars[4]]
    if len(set(other_chars)) != 3:
        return False
    
    # 1文字目と3文字目以外が、1文字目と3文字目とは違う
    if chars[0] in other_chars:
        return False
    return True

def count_cpstf(S):
    N = len(S)
    count = 0
    for input in combinations(range(N), 5):
        if is_ok(S, input):
            count += 1
    return count

N = int(input())
S = input().strip()

print(count_cpstf(S))
0