mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 19:08:47 +00:00
#1731. 【2022.11.02 联考】字符串生成(monkey)
https://sjzezoj.com/submission/63219
This commit is contained in:
parent
45b3499a20
commit
7a99b6b16e
55
S2OJ/1731/1731.cpp
Normal file
55
S2OJ/1731/1731.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e6 + 5;
|
||||
const int mod = 1e9 + 7;
|
||||
|
||||
int nxt[N], f[N][2], p[N], a[N], b[N];
|
||||
std::string s;
|
||||
|
||||
int binpow(int a, int b) {
|
||||
int res = 1;
|
||||
|
||||
while (b) {
|
||||
if (b & 1) res = static_cast<long long>(res) * a % mod;
|
||||
a = static_cast<long long>(a) * a % mod;
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
signed main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> s;
|
||||
|
||||
s = ' ' + s;
|
||||
|
||||
for (int i = 2, j = 0; i < s.size(); i++) {
|
||||
while (j && s[i] != s[j + 1]) j = nxt[j];
|
||||
if (s[i] == s[j + 1]) j++;
|
||||
nxt[i] = j;
|
||||
}
|
||||
|
||||
for (int i = 1; i < s.size(); i++) {
|
||||
bool x = s[i] - '0';
|
||||
f[i - 1][x] = i;
|
||||
p[i - 1] = f[i - 1][x ^ 1] = f[nxt[i - 1]][x ^ 1];
|
||||
}
|
||||
|
||||
a[0] = 1;
|
||||
|
||||
for (int i = 1; i < s.size(); i++) {
|
||||
a[i] = (static_cast<long long>(a[i - 1]) * 2 - a[p[i - 1]]) % mod;
|
||||
b[i] = (static_cast<long long>(b[i - 1]) * 2 - b[p[i - 1]] - 2) % mod;
|
||||
}
|
||||
|
||||
cout << (mod - (static_cast<long long>(b[s.size() - 1]) * binpow(a[s.size() - 1], mod - 2)) % mod) % mod << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1731/data/monkey1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/monkey9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/monkey9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1731/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1731/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user