結果
| 問題 |
No.1654 Binary Compression
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-21 02:41:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 630 bytes |
| コンパイル時間 | 1,589 ms |
| コンパイル使用メモリ | 170,736 KB |
| 実行使用メモリ | 42,532 KB |
| 最終ジャッジ日時 | 2024-10-14 11:19:25 |
| 合計ジャッジ時間 | 6,417 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 12 WA * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
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;
}