ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210936 | #2067. 肉夹馍 | mengxiangjia | 30 | 17ms | 1720kb | C++11 | 4.6kb | 2024-08-08 11:48:21 | 2024-08-08 14:29:09 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef ONLINE_JUDGE
#define getchar getchar_unlocked
#endif
namespace FastIO
{
char write_cache[40];
template <class T>
inline const T read() noexcept
{
T x(0);
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
template <class T>
inline const void read(T &x) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = f ? -x : x;
}
template <class T, class... P>
inline const void read(T &x, P &...ark) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = f ? -x : x;
read(ark...);
}
template <class T>
inline const void readu(T &x) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}
template <class T>
inline const T readu() noexcept
{
T x(0);
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return x;
}
template <class T, class... P>
inline const void readu(T &x, P &...ark) noexcept
{
x = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
readu(ark...);
}
template <class T>
inline const void readArr(T *begin, T *end) noexcept
{
while (begin < end)
{
*begin = 0;
char ch(getchar());
bool f(0);
while (ch < '0' || ch > '9')
f ^= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
*begin = (*begin << 1) + (*begin << 3) + (ch ^ 48), ch = getchar();
*begin = f ? -*begin : *begin;
}
}
template <class T>
inline const void readArr(T *begin, int cnt) noexcept
{
while (cnt--)
{
read(*begin);
++begin;
}
}
template <class T>
inline const void write(T x) noexcept
{
if (x < 0)
putchar('-'), x = -x;
int cnt = 0;
while (x)
write_cache[cnt++] = x % 10 ^ 48, x /= 10;
if (!cnt)
putchar('0');
else
while (cnt--)
putchar(write_cache[cnt]);
}
template <char end = ' ', class T, class... ARK>
inline const void write(T &x, ARK &...ark) noexcept
{
write(x);
putchar(end);
write(ark...);
}
template <char end = '\n', class T>
inline const void println(T &x) noexcept
{
write(x);
putchar(end);
}
template <char sep = ' ', char endl = '\n', class T>
inline const void writeArr(T *begin, T *end) noexcept
{
while (begin < end)
write(*begin), putchar(sep), ++begin;
putchar(endl);
}
template <char sep = ' ', char end = '\n', class T>
inline const void writeArr(T *arr, int cnt)
{
while (cnt--)
{
write(*arr);
putchar(sep);
++arr;
}
putchar(end);
}
}
#define maxl 2000005
int dp[maxl], j;
string ss;
int main()
{
cin >> ss;
int len = ss.length();
ss = " " + ss;
for (int i = 2; i <= len; ++i)
{
while (j && ss[i] != ss[j + 1])
j = dp[j];
if (ss[j + 1] == ss[i])
j++;
dp[i] = j;
}
int ans = 0;
for (int i = 1; i <= len; ++i)
{
ans = dp[i];
while (ans > (((i - 1) >> 1)))
ans = dp[ans];
FastIO::println<' '>(ans);
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 1204kb
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: 1204kb
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: 1208kb
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: 5ms
memory: 1228kb
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: 3ms
memory: 1224kb
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: 1ms
memory: 1220kb
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: 0
Time Limit Exceeded
Test #7:
score: 30
Accepted
time: 8ms
memory: 1720kb
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: -30
Time Limit Exceeded
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:
Subtask #4:
score: 0
Skipped