ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210916 | #2067. 肉夹馍 | _Alexande_ | 100 | 2423ms | 182796kb | C++11 | 1.8kb | 2024-08-08 10:18:28 | 2024-08-08 14:28:22 |
answer
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
char _c; bool _f; template < class type > inline void read ( type &x ) {
_f = 0, x = 0;
while ( _c = getchar (), !isdigit ( _c ) ) if ( _c == '-' ) _f = 1;
while ( isdigit ( _c ) ) x = x * 10 + _c - '0', _c = getchar (); if ( _f ) { x = -x; }
}
template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }
const int N = 3e6 + 5;
int n;
int nxt[N], f[N][22];
string s;
int query ( int x ) {
int maxlen = ( x & 1 ? x / 2 : x / 2 - 1 );
for ( int i = 21; i >= 0; i -- ) {
if ( f[x][i] > maxlen ) {
x = f[x][i];
}
}
return f[x][0];
}
void Solve () {
ios :: sync_with_stdio ( false );
cin.tie ( 0 ), cout.tie ( 0 );
cin >> s;
n = s.size ();
s = " " + s;
for ( int i = 2, j = 0; i <= n; 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 <= n; i ++ ) {
f[i][0] = nxt[i];
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= 21; j ++ ) {
f[i][j] = f[f[i][j - 1]][j - 1];
}
}
for ( int i = 1; i <= n; i ++ ) {
cout << query ( i ) << " ";
}
}
signed main () {
#ifdef judge
freopen ( "Code.in", "r", stdin );
freopen ( "Code.out", "w", stdout );
freopen ( "Code.err", "w", stderr );
#endif
Solve ();
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 1264kb
input:
qpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavdfnfninqpbvqpbvqpbvavdqpbvqpbvqpbvavdqpbvqpbvqpbvavd
output:
0 0 0 0 1 2 3 0 1 2 3 4 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
result:
ok 96 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 1264kb
input:
wfalgbgweavpwhfahfewhavweahuwbvbqvuivhuiaehufuaeuvdafuivjafislfhbibcuuiabcuibsv
output:
0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 79 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 1264kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 100 tokens
Subtask #2:
score: 20
Accepted
Test #4:
score: 20
Accepted
time: 0ms
memory: 1536kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 3000 tokens
Test #5:
score: 0
Accepted
time: 1ms
memory: 1532kb
input:
cjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcjcj...
output:
0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...
result:
ok 3000 tokens
Test #6:
score: 0
Accepted
time: 0ms
memory: 1516kb
input:
ckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcckckcsdvhckcckckcckcckckcckcckckcckcc...
output:
0 0 1 1 2 1 2 3 4 2 3 4 5 6 7 3 4 5 6 4 5 6 7 8 9 10 11 12 13 14 15 8 0 0 0 0 1 2 3 4 5 6 7 8 9 10 1...
result:
ok 2828 tokens
Subtask #3:
score: 30
Accepted
Test #7:
score: 30
Accepted
time: 17ms
memory: 10388kb
input:
aocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabcdoawaocnsaosashoicfaaocnsaosashoicfaqowfwpqgvqvhoabc...
output:
0 0 0 0 0 1 2 0 1 0 0 0 0 0 0 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 ...
result:
ok 100000 tokens
Test #8:
score: 0
Accepted
time: 30ms
memory: 10384kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 100000 tokens
Test #9:
score: 0
Accepted
time: 25ms
memory: 10384kb
input:
vivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivivi...
output:
0 0 1 0 1 2 3 2 3 4 5 4 5 6 7 6 7 8 9 8 9 10 11 10 11 12 13 12 13 14 15 14 15 16 17 16 17 18 19 18 1...
result:
ok 100000 tokens
Subtask #4:
score: 40
Accepted
Test #10:
score: 40
Accepted
time: 530ms
memory: 182792kb
input:
aoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhdiohraoifcpiapdpsahfahiofhd...
output:
0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
result:
ok 2000000 tokens
Test #11:
score: 0
Accepted
time: 486ms
memory: 182792kb
input:
abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabac...
output:
0 0 1 0 1 2 3 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
result:
ok 2000000 tokens
Test #12:
score: 0
Accepted
time: 691ms
memory: 182792kb
input:
gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 ...
result:
ok 2000000 tokens
Test #13:
score: 0
Accepted
time: 643ms
memory: 182796kb
input:
duududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuududuudu...
output:
0 0 0 1 2 1 2 3 4 2 1 2 3 4 5 6 7 8 9 5 6 7 8 9 10 11 12 13 14 10 11 12 13 14 15 16 17 18 19 15 16 1...
result:
ok 2000000 tokens