0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 19:45:24 +00:00

E - Strange Operation

https://codeforces.com/contest/1383/submission/190440602
This commit is contained in:
Baoshuo Ren 2023-01-25 10:47:59 +08:00
parent 4ebd0ccbb2
commit 99a1b17cff
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

57
Codeforces/1383/E/E.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <iostream>
#include <algorithm>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int n, cnt = 1,
pre[N], w[N], sum[N], f[N];
std::string s;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s;
n = s.size();
for (char c : s) {
if (c == '0') pre[cnt]++;
else cnt++;
}
if (cnt == 1) {
cout << n << endl;
exit(0);
}
std::fill(w, w + 1 + n, 1);
sum[1] = f[1] = 1;
for (int i = 2; i < cnt; i++) {
int l = w[0];
for (int j = 0; j <= pre[i]; j++) {
l = w[j];
f[i] = (static_cast<long long>(f[i]) + sum[i - 1] - sum[l - 1] + mod) % mod;
}
for (int j = 0; j <= pre[i]; j++) {
w[j] = i;
}
sum[i] = (static_cast<long long>(sum[i - 1]) + f[i]) % mod;
}
cout << static_cast<long long>(pre[1] + 1) * (pre[cnt] + 1) % mod * sum[cnt - 1] % mod << endl;
return 0;
}