結果
問題 | No.1654 Binary Compression |
ユーザー |
|
提出日時 | 2021-08-21 02:42:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 629 bytes |
コンパイル時間 | 1,641 ms |
コンパイル使用メモリ | 170,296 KB |
実行使用メモリ | 42,056 KB |
最終ジャッジ日時 | 2024-10-14 11:19:52 |
合計ジャッジ時間 | 5,863 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int mod = 924844033; int main() { ios::sync_with_stdio(false), cin.tie(0); string s; cin >> s; int n = s.length(); vector<int> dist(n); for (int i = 0; i < n; ++i) if (s[i] == '0') dist[i] = (i ? dist[i-1] : 0) + 1; vector<int> dp(n + 2), nxt(n+2, n); auto get = [&](int i) { return nxt[i] < n ? dp[nxt[i]] : 0; }; for (int i = n-1; i >= 0; --i) { dp[i] = ((dist[i] <= dist.back()) + get(0) + get(dist[i] + 1)) % mod; nxt[dist[i]] = i; } int ans = n; if (nxt[0] < n) ans = ((long long)get(0) * (nxt[0] + 1)) % mod; cout << ans << "\n"; return 0; }