Submission #75459542


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
const int MOD = 998244353;
const int MAX = 200005;
long long fact[MAX], invFact[MAX], pow2[MAX];
long long power(long long base, long long exp) {
long long res = 1;
base %= MOD;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % MOD;
base = (base * base) % MOD;
exp /= 2;
}
return res;
}
void precompute() {
fact[0] = 1;
invFact[0] = 1;
pow2[0] = 1;
for (int i = 1; i < MAX; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
pow2[i] = (pow2[i - 1] * 2) % MOD;
}
invFact[MAX - 1] = power(fact[MAX - 1], MOD - 2);
for (int i = MAX - 2; i >= 1; i--) {
invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
}
}
long long nCr(int n, int r) {
if (r < 0 || r > n) return 0;
return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

const int MOD = 998244353;
const int MAX = 200005;

long long fact[MAX], invFact[MAX], pow2[MAX];

long long power(long long base, long long exp) {
    long long res = 1;
    base %= MOD;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res;
}

void precompute() {
    fact[0] = 1;
    invFact[0] = 1;
    pow2[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
        pow2[i] = (pow2[i - 1] * 2) % MOD;
    }
    invFact[MAX - 1] = power(fact[MAX - 1], MOD - 2);
    for (int i = MAX - 2; i >= 1; i--) {
        invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;
    }
}

long long nCr(int n, int r) {
    if (r < 0 || r > n) return 0;
    return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    precompute();

    int N;
    if (!(cin >> N)) return 0;
    string S;
    cin >> S;

    map<int, int> L_counts;
    int total_dot = 0;
    int current_len = 0;
    int max_L = 0;

    auto add_len = [&](int l) {
        if (l > 0) {
            L_counts[l]++;
            total_dot += l;
            if (l > max_L) max_L = l;
        }
    };

    for (int i = 0; i < N; i++) {
        if (S[i] == '.') {
            current_len++;
        } else {
            add_len(current_len);
            current_len = 0;
        }
    }
    add_len(current_len);

    long long f_prev = 1;

    for (int k = 1; k <= N; k++) {
        long long f_curr = 1;
        if (k >= max_L) {
            f_curr = pow2[total_dot];
        } else {
            for (auto const& [L, c] : L_counts) {
                long long ways = 0;
                if (L <= k) {
                    ways = pow2[L];
                } else {
                    long long res1 = 0;
                    int limit1 = L / (k + 2);
                    for (int i = 0; i <= limit1; i++) {
                        long long term = nCr(L - i * (k + 1), i) * pow2[L - i * (k + 2)] % MOD;
                        if (i % 2 == 1) {
                            res1 = (res1 - term + MOD) % MOD;
                        } else {
                            res1 = (res1 + term) % MOD;
                        }
                    }

                    long long res2 = 0;
                    int L2 = L - k - 1;
                    if (L2 >= 0) {
                        int limit2 = L2 / (k + 2);
                        for (int i = 0; i <= limit2; i++) {
                            long long term = nCr(L2 - i * (k + 1), i) * pow2[L2 - i * (k + 2)] % MOD;
                            if (i % 2 == 1) {
                                res2 = (res2 - term + MOD) % MOD;
                            } else {
                                res2 = (res2 + term) % MOD;
                            }
                        }
                    }
                    ways = (res1 - res2 + MOD) % MOD;
                }
                if (c == 1) {
                    f_curr = (f_curr * ways) % MOD;
                } else {
                    f_curr = (f_curr * power(ways, c)) % MOD;
                }
            }
        }

        long long ans = (f_curr - f_prev + MOD) % MOD;
        cout << ans << "\n";
        f_prev = f_curr;
    }

    return 0;
}

Submission Info

Submission Time
Task G - Count Holidays
User th0629
Language C++23 (GCC 15.2.0)
Score 600
Code Size 3551 Byte
Status AC
Exec Time 45 ms
Memory 8488 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 44
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.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, 02_max_01.txt, 02_max_02.txt, 02_max_03.txt, 02_max_04.txt, 02_max_05.txt, 02_max_06.txt, 02_max_07.txt, 02_max_08.txt, 02_max_09.txt, 02_max_10.txt, 02_max_11.txt, 02_max_12.txt, 02_max_13.txt, 02_max_14.txt, 02_max_15.txt, 03_corner_01.txt, 03_corner_02.txt, 03_corner_03.txt, 03_corner_04.txt, 04_hand_01.txt, 04_hand_02.txt, 04_hand_03.txt, 04_hand_04.txt, 04_hand_05.txt, 04_hand_06.txt, 04_hand_07.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 4 ms 8116 KiB
00_sample_02.txt AC 4 ms 8136 KiB
00_sample_03.txt AC 4 ms 8144 KiB
01_random_01.txt AC 7 ms 8256 KiB
01_random_02.txt AC 12 ms 8312 KiB
01_random_03.txt AC 6 ms 8204 KiB
01_random_04.txt AC 8 ms 8304 KiB
01_random_05.txt AC 12 ms 8308 KiB
01_random_06.txt AC 12 ms 8452 KiB
01_random_07.txt AC 13 ms 8488 KiB
01_random_08.txt AC 11 ms 8400 KiB
01_random_09.txt AC 23 ms 8320 KiB
01_random_10.txt AC 21 ms 8328 KiB
01_random_11.txt AC 22 ms 8388 KiB
01_random_12.txt AC 19 ms 8304 KiB
01_random_13.txt AC 10 ms 8228 KiB
01_random_14.txt AC 31 ms 8452 KiB
01_random_15.txt AC 10 ms 8244 KiB
02_max_01.txt AC 36 ms 8368 KiB
02_max_02.txt AC 40 ms 8308 KiB
02_max_03.txt AC 31 ms 8332 KiB
02_max_04.txt AC 29 ms 8320 KiB
02_max_05.txt AC 31 ms 8308 KiB
02_max_06.txt AC 28 ms 8328 KiB
02_max_07.txt AC 27 ms 8308 KiB
02_max_08.txt AC 27 ms 8312 KiB
02_max_09.txt AC 28 ms 8276 KiB
02_max_10.txt AC 21 ms 8336 KiB
02_max_11.txt AC 17 ms 8356 KiB
02_max_12.txt AC 14 ms 8308 KiB
02_max_13.txt AC 13 ms 8312 KiB
02_max_14.txt AC 12 ms 8452 KiB
02_max_15.txt AC 12 ms 8316 KiB
03_corner_01.txt AC 4 ms 8116 KiB
03_corner_02.txt AC 5 ms 8116 KiB
03_corner_03.txt AC 45 ms 8292 KiB
03_corner_04.txt AC 12 ms 8276 KiB
04_hand_01.txt AC 23 ms 8312 KiB
04_hand_02.txt AC 23 ms 8308 KiB
04_hand_03.txt AC 23 ms 8316 KiB
04_hand_04.txt AC 11 ms 8308 KiB
04_hand_05.txt AC 12 ms 8264 KiB
04_hand_06.txt AC 12 ms 8168 KiB
04_hand_07.txt AC 12 ms 8300 KiB


2026-05-02 (Sat)
22:50:58 +09:00