結果

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

ソースコード

diff #

# coding: utf-8
import sys

def solve():
    # 標準入力から N と S を受け取る
    # Read N and S from standard input
    n = int(sys.stdin.readline())
    s = sys.stdin.readline().strip()

    # 条件を満たす部分文字列の数をカウントする変数
    # Variable to count the number of subsequences that meet the criteria
    count = 0

    # 5つのインデックスを選ぶための5重ループ
    # i1 < i2 < i3 < i4 < i5 となるように選ぶ
    # 5 nested loops to choose 5 indices such that i1 < i2 < i3 < i4 < i5
    for i1 in range(n):
        for i2 in range(i1 + 1, n):
            for i3 in range(i2 + 1, n):
                for i4 in range(i3 + 1, n):
                    for i5 in range(i4 + 1, n):
                        # 選ばれた5文字
                        # The 5 chosen characters
                        c1 = s[i1]
                        c2 = s[i2]
                        c3 = s[i3]
                        c4 = s[i4]
                        c5 = s[i5]

                        # CPCTF的条件のチェック
                        # Check CPCTF conditions:
                        # 1. 1st and 3rd characters are the same
                        # 2. All other pairs of characters (among 1st/3rd, 2nd, 4th, 5th) are different
                        if (c1 == c3 and      # S[i1] == S[i3]
                            c1 != c2 and      # S[i1] != S[i2]
                            c1 != c4 and      # S[i1] != S[i4]
                            c1 != c5 and      # S[i1] != S[i5]
                            c2 != c4 and      # S[i2] != S[i4]
                            c2 != c5 and      # S[i2] != S[i5]
                            c4 != c5):        # S[i4] != S[i5]
                            # 条件を満たせばカウントを増やす
                            # If conditions are met, increment the count
                            count += 1

    # 結果を出力
    # Print the result
    print(count)

# 関数を実行
# Execute the function
solve()
0