提出 #62301407


ソースコード 拡げる

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

const int mod = 998244353;

void add(int &x, int y) {
    x += y;
    if (x >= mod)  x -= mod;
}
int mul(int x, int y) {
    return (long long) x * y % mod;
}

int n;
string s;
vector<int> pos[26];

vector<int> add_to_state(vector<int> s, int x) {
   for (int i = n - 1; i >= 0; --i) {
       int last = -1;
       if (i) last = min(n, s[i - 1] + 1);
       s[i] = min(s[i], *lower_bound(pos[x].begin(), pos[x].end(), last));
   }
   return s;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    
    int N = 1;
    for (int i = 0; i < n; ++i) N *= 3;
    
    vector<int> ppl;
    vector<int> dp(N, 1);
    for (int i = 0; i < N; ++i) ppl.push_back(s[i] - '0');
    while (N != 1) {
        vector<int> npl;
        vector<int> ndp;
        for (int i = 0; i < N; i += 3) {
            npl.push_back((ppl[i] + ppl[i + 1] + ppl[i + 2]) / 2);
            vector<int> bads;
            for (int j = 0; j < 3; ++j) if (ppl[i + j] == npl.back()) bads.push_back(dp[i + j]);
            sort(bads.begin(), bads.end());
            if (bads.size() == 3) ndp.push_back(bads[0] + bads[1]);
            else ndp.push_back(bads[0]);
        }
        N /= 3;
        dp = ndp;
        ppl = npl;
    }
    cout << dp[0] << endl;
}

提出情報

提出日時
問題 E - Hierarchical Majority Vote
ユーザ jklepec
言語 C++ 20 (gcc 12.2)
得点 450
コード長 1331 Byte
結果 AC
実行時間 81 ms
メモリ 26848 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 32
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3532 KiB
00_sample_02.txt AC 1 ms 3444 KiB
01_random_01.txt AC 2 ms 3812 KiB
01_random_02.txt AC 80 ms 26768 KiB
01_random_03.txt AC 1 ms 3604 KiB
01_random_04.txt AC 80 ms 26848 KiB
01_random_05.txt AC 4 ms 4128 KiB
01_random_06.txt AC 80 ms 26672 KiB
01_random_07.txt AC 10 ms 5596 KiB
01_random_08.txt AC 81 ms 26844 KiB
01_random_09.txt AC 1 ms 3536 KiB
01_random_10.txt AC 79 ms 26768 KiB
01_random_11.txt AC 1 ms 3492 KiB
01_random_12.txt AC 79 ms 26672 KiB
01_random_13.txt AC 1 ms 3540 KiB
01_random_14.txt AC 80 ms 26844 KiB
01_random_15.txt AC 2 ms 3708 KiB
01_random_16.txt AC 80 ms 26756 KiB
01_random_17.txt AC 2 ms 3804 KiB
01_random_18.txt AC 79 ms 26772 KiB
01_random_19.txt AC 1 ms 3560 KiB
01_random_20.txt AC 79 ms 26728 KiB
02_handmade_01.txt AC 65 ms 26768 KiB
02_handmade_02.txt AC 65 ms 26728 KiB
02_handmade_03.txt AC 80 ms 26848 KiB
02_handmade_04.txt AC 65 ms 26792 KiB
02_handmade_05.txt AC 66 ms 26768 KiB
02_handmade_06.txt AC 65 ms 26772 KiB
02_handmade_07.txt AC 65 ms 26676 KiB
02_handmade_08.txt AC 66 ms 26844 KiB
02_handmade_09.txt AC 66 ms 26792 KiB
02_handmade_10.txt AC 79 ms 26728 KiB