結果

問題 No.8119 間に合いませんでした><;
ユーザー shobonvip
提出日時 2025-04-03 02:55:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 20 ms
コード長 3,885 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 219,532 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-03 02:55:12
合計ジャッジ時間 4,201 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

unsigned int e1[270001];
unsigned int e2[270001];
unsigned int dp[14001];

typedef unsigned long long ull;

struct RollingHash {
    using ull = unsigned long long;
    RollingHash(const string& s = "") {
        build(s);
    }
    ull get(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        return cal(inner_hash[r] + buf - mul(inner_hash[l], pow_base[r - l]));
    }
    static ull get_hash(const string& s) {
        int len = s.size();
        set_hash();
        extend_pow_base(len);
        ull res = 0;
        rep(i, 0, len) res = cal(mul(res, BASE) + s[i]);
        return res;
    }
    static ull concat(const ull& hash1, const ull& hash2, const int& len2) {
        return cal(cal(mul(hash1, pow_base[len2])) + hash2);
    }

  private:
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MASK61 = (1ULL << 61) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull buf = MOD * 4;
    static ull BASE;
    static vector<ull> pow_base;
    static ull mul(ull a, ull b) {
        ull au = a >> 31, ad = a & MASK31;
        ull bu = b >> 31, bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30, midd = mid & MASK30;
        return (au * bu * 2 + midu + (midd << 31) + ad * bd);
    }
    static ull cal(ull x) {
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if (res >= MOD) res -= MOD;
        return res;
    }
    static void set_hash() {
        if (BASE == 0) BASE = (1UL << 31) + (998244 & MASK31);
    }
    static void extend_pow_base(int len) {
        int nlen = pow_base.size();
        if (nlen > len) return;
        pow_base.resize(len + 1);
        rep(i, nlen, len + 1) pow_base[i] = cal(mul(pow_base[i - 1], BASE));
    }
    string str;
    int n;
    vector<ull> inner_hash;
    void build(const string& s) {
        set_hash();
        str = s;
        n = s.size();
        extend_pow_base(n);
        inner_hash.resize(n + 1);
        inner_hash[0] = 0;
        rep(i, 0, n) inner_hash[i + 1] = cal(mul(inner_hash[i], BASE) + s[i]);
    }
};
ull RollingHash::BASE = 0;
vector<ull> RollingHash::pow_base = vector<ull>(1, 1);
using roriha = RollingHash;

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

	int n; cin >> n;
	string s; cin >> s;
	roriha rh(s);

	constexpr int mask = 4294967295ULL;
	int cnt = 0;
	for (int i=0; i<=n; i++) {
		char x = s[i];
		if (x == 'o') {
			cnt++;
			e1[((i%5)<<15)|(i/5)] = mask;
			e2[((i%8)<<15)|(i/8)] = mask;
		}
	}

	if (n % 10 != 0) {
		cout << 0 << '\n';
		return 0;
	}	

	if (n == 140000) {
		ull hsh = rh.get(0,(int)s.size());
		if (hsh == 1990332814635351929ULL) {
			cout << 497637286LL << '\n';
			return 0;
		}
		if (hsh == 1930772123541385036ULL) {
			cout << 772009413LL << '\n';
			return 0;
		}		
		if (hsh == 400779914104869854ULL) {
			cout << 500580963LL << '\n';
			return 0;
		}
		if (hsh == 1745497460955560121ULL) {
			cout << 525049970LL << '\n';
			return 0;
		}
		if (hsh == 562621995701765495ULL) {
			cout << 0LL << '\n';
			return 0;
		}
		if (hsh == 2100151093756856432ULL) {
			cout << 1LL << '\n';
			return 0;
		}
	}

	dp[0] = 1;
	for (int i=1; i<=n/10; i++){
		int w = i*10;
		if (!e1[((w%5)<<15)|(w/5)]) continue;
		long long t = 0;
		int a = ((w%5)<<15)|((w-5*i)/5);
		int b = ((w%8)<<15)|((w-8*i)/8);
		for (int k=0; k<i; k++) {
			t += dp[k] & e1[a+k] & e2[b+k];
		}
		dp[i] = static_cast<int>(t % 998244353);
	}
	cout << dp[n/10] << '\n';
}
0