提出 #73347455


ソースコード 拡げる

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<sys/time.h>
// #include<atcoder/segtree>
// #include<atcoder/modint>

using namespace std;

// using mint = atcoder::modint998244353;

using P = pair<int, int>;
const int M = 998244353;
const long long LM = 1LL << 60;


const int W = 10;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int T;
    cin >> T;
    for (int _ = 0; _ < T; ++_) {
        int n, m;
        string x, y, z;
        cin >> n >> m >> x >> y >> z;
        reverse(x.begin(), x.end());
        reverse(y.begin(), y.end());
        reverse(z.begin(), z.end());
        vector<bitset<W * 2 + 1>> dp(n + 1);
        dp[0][W] = true;
        bool found_zero = false;
        for (int k = 0; k < n; ++k) {
            vector<bitset<W * 2 + 1>> nex(n + 1);
            for (int i = 0; i < n + 1; ++i) {
                for (int j = -W; j <= W; ++j) {
                    if (!dp[i][W + j]) {
                        continue;
                    }
                    for (int p = 0; p < 2; ++p) {
                        if (x[k] == '0' + (p ^ 1)) {
                            continue;
                        }
                        for (int q = 0; q < 2; ++q) {
                            if (y[k] == '0' + (q ^ 1)) {
                                continue;
                            }
                            if (p == 1 && q == 0) {
                                found_zero = true;
                                continue;
                            }
                            for (int r = 0; r < 2; ++r) {
                                if (z[k] == '0' + (r ^ 1)) {
                                    continue;
                                }
                                int ni = i + (p < q ? 1 : 0);
                                int nj = j + r - p * 2 - q;
                                if (nj % 2 != 0 && p == q) {
                                    found_zero = true;
                                    continue;
                                }
                                if (nj >= 0) {
                                    nj /= 2;
                                }
                                else {
                                    nj = (nj - 1) / 2;
                                }
                                if (-W <= nj && nj <= W) {
                                    nex[ni][W + nj] = true;
                                }
                                else {
                                    found_zero = true;
                                }
                            }
                        }
                    }

                }
            }
            swap(dp, nex);
            // cerr << k << '\n';
            // for (int i = 0; i < n; ++i) {
            //     for (int j = 0; j < W * 2 + 1; ++j) {
            //         cerr << dp[i][j];
            //     }
            //     cerr << '\n';
            // }
            // cerr << '\n';
        }
        for (int i = 0; i < n + 1; ++i) {
            for (int j = 0; j < W * 2 + 1; ++j) {
                if (j != W && dp[i][j]) {
                    found_zero = true;
                }
            }
        }
        string ans(m, '0');
        if (found_zero) {
            ans[0] = '1';
        }
        for (int i = 0, p = 1 % m; i < n + 1; ++i, p = p * 3 % m) {
            if (dp[i][W]) {
                ans[p] = '1';
            }
        }
        cout << ans << '\n';
    }

    return 0;
}

提出情報

提出日時
問題 O - Three Constraints
ユーザ riantkb
言語 C++23 (GCC 15.2.0)
得点 100
コード長 3683 Byte
結果 AC
実行時間 150 ms
メモリ 4556 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 1
AC × 51
セット名 テストケース
Sample 00_example_01
All 00_example_01, 01_test_01, 01_test_02, 01_test_03, 01_test_04, 01_test_05, 01_test_06, 01_test_07, 01_test_08, 01_test_09, 01_test_10, 01_test_11, 01_test_12, 01_test_13, 01_test_14, 01_test_15, 01_test_16, 01_test_17, 01_test_18, 01_test_19, 01_test_20, 01_test_21, 01_test_22, 01_test_23, 01_test_24, 01_test_25, 01_test_26, 01_test_27, 01_test_28, 01_test_29, 01_test_30, 01_test_31, 01_test_32, 01_test_33, 01_test_34, 01_test_35, 01_test_36, 01_test_37, 01_test_38, 01_test_39, 01_test_40, 01_test_41, 01_test_42, 01_test_43, 01_test_44, 01_test_45, 01_test_46, 01_test_47, 01_test_48, 01_test_49, 01_test_50
ケース名 結果 実行時間 メモリ
00_example_01 AC 1 ms 3596 KiB
01_test_01 AC 2 ms 3732 KiB
01_test_02 AC 2 ms 3728 KiB
01_test_03 AC 2 ms 3808 KiB
01_test_04 AC 3 ms 3652 KiB
01_test_05 AC 3 ms 3736 KiB
01_test_06 AC 6 ms 3668 KiB
01_test_07 AC 6 ms 3676 KiB
01_test_08 AC 2 ms 3664 KiB
01_test_09 AC 2 ms 3748 KiB
01_test_10 AC 2 ms 3736 KiB
01_test_11 AC 2 ms 3660 KiB
01_test_12 AC 72 ms 4124 KiB
01_test_13 AC 91 ms 3688 KiB
01_test_14 AC 90 ms 3816 KiB
01_test_15 AC 99 ms 4368 KiB
01_test_16 AC 99 ms 4456 KiB
01_test_17 AC 99 ms 4436 KiB
01_test_18 AC 99 ms 4520 KiB
01_test_19 AC 99 ms 4476 KiB
01_test_20 AC 99 ms 4452 KiB
01_test_21 AC 99 ms 4308 KiB
01_test_22 AC 99 ms 4456 KiB
01_test_23 AC 99 ms 4336 KiB
01_test_24 AC 99 ms 4464 KiB
01_test_25 AC 2 ms 3716 KiB
01_test_26 AC 2 ms 3508 KiB
01_test_27 AC 2 ms 3548 KiB
01_test_28 AC 2 ms 3616 KiB
01_test_29 AC 2 ms 3736 KiB
01_test_30 AC 101 ms 4448 KiB
01_test_31 AC 102 ms 4308 KiB
01_test_32 AC 149 ms 4332 KiB
01_test_33 AC 101 ms 4436 KiB
01_test_34 AC 102 ms 4264 KiB
01_test_35 AC 149 ms 4204 KiB
01_test_36 AC 101 ms 4380 KiB
01_test_37 AC 115 ms 4212 KiB
01_test_38 AC 150 ms 4452 KiB
01_test_39 AC 101 ms 4556 KiB
01_test_40 AC 102 ms 3952 KiB
01_test_41 AC 149 ms 3944 KiB
01_test_42 AC 101 ms 4520 KiB
01_test_43 AC 105 ms 4052 KiB
01_test_44 AC 149 ms 4136 KiB
01_test_45 AC 101 ms 4432 KiB
01_test_46 AC 101 ms 3728 KiB
01_test_47 AC 148 ms 3652 KiB
01_test_48 AC 101 ms 4436 KiB
01_test_49 AC 102 ms 3612 KiB
01_test_50 AC 149 ms 3652 KiB