結果

問題 No.3753 Certainly a Cretan
コンテスト
ユーザー marc2825
提出日時 2026-08-19 00:40:45
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,613 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,017 ms
コンパイル使用メモリ 212,000 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-10-02 20:56:14
合計ジャッジ時間 7,626 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1
other -- * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    while (Q--) {
        int t, x;
        cin >> t >> x;

        if (t == 1) {
            int i = x - 1;
            S[i] = (S[i] == 'Y' ? 'N' : 'Y');
        } else {
            int K = x;
            long long ans = 0;

            for (long long mask = 0; mask < (1LL << N); ++mask) {
                if (__builtin_popcountll(mask) != K) continue;

                int liar = 0;
                bool ok = true;

                for (int i = 0; i < N; ++i) {
                    bool is_liar = (mask >> i) & 1;

                    if (is_liar) {
                        ++liar;
                    }

                    int honest = (i + 1) - liar;

                    int same;
                    if (is_liar) {
                        same = liar;
                    } else {
                        same = honest;
                    }

                    bool correct_yes = same * 2 > i + 1;

                    bool answer_yes;
                    if (is_liar) {
                        answer_yes = !correct_yes;
                    } else {
                        answer_yes = correct_yes;
                    }

                    if (answer_yes != (S[i] == 'Y')) {
                        ok = false;
                        break;
                    }
                }

                if (ok) {
                    ++ans;
                }
            }

            cout << ans << '\n';
        }
    }
}
0