Submission #600863
Source Code Expand
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
typedef pair<char,int> pci;
vector<vector<pci> > T;
vector<int> sborder, ans;
vector<char> str;
int dummy;
void dfs(char c, int u, int prevu, int f){
if(!str.empty()){
char b = str.back();
while(f >= 0 && str[f] != b){
f = sborder[f];
}
++f;
ans[prevu] = (int)str.size() - f;
if(str[f] == c){
sborder.push_back(sborder[f]);
}
else{
sborder.push_back(f);
}
}
str.push_back(c);
for(const auto &q : T[u]){
dfs(q.first, q.second, u, f);
}
if(u != dummy && T[u].empty()){
dfs('$', dummy, u, f);
}
str.pop_back();
if(!str.empty()){
sborder.pop_back();
}
}
int main(){
static char buf[500010];
int n;
scanf("%d", &n);
vector<int> a(n);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
scanf("%s", buf);
dummy = n + 6;
T.resize(n + 9);
for(int i = 0; i < n; ++i){
T[a[i]].emplace_back(buf[i], i + 1);
}
ans.assign(n + 9, -9);
sborder.reserve(n + 9);
str.reserve(n + 9);
sborder = {-1};
for(const auto &p : T[0]){
dfs(p.first, p.second, dummy, -1);
}
for(int i = 1; i <= n; ++i){
printf("%d\n", ans[i]);
}
}
Submission Info
Submission Time |
|
Task |
D - Destroy the Duplicated Poem |
User |
climpet |
Language |
C++11 (GCC 4.9.2) |
Score |
100 |
Code Size |
1237 Byte |
Status |
AC |
Exec Time |
629 ms |
Memory |
59684 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:48:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:51:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
./Main.cpp:53:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", buf);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
btree_01.txt, btree_02.txt, btree_03.txt, deep_01.txt, deep_02.txt, deep_03.txt, deep_rand_01.txt, deep_rand_02.txt, deep_rand_03.txt, deep_rand_04.txt, hand_01.txt, hand_02.txt, kmp_killer_01.txt, kmp_killer_02.txt, kmp_killer_03.txt, periodic_01.txt, periodic_02.txt, periodic_03.txt, periodic_04.txt, random_01.txt, random_02.txt, random_03.txt |
Case Name |
Status |
Exec Time |
Memory |
btree_01.txt |
AC |
498 ms |
24796 KB |
btree_02.txt |
AC |
474 ms |
24760 KB |
btree_03.txt |
AC |
483 ms |
24792 KB |
deep_01.txt |
AC |
568 ms |
49184 KB |
deep_02.txt |
AC |
588 ms |
49212 KB |
deep_03.txt |
AC |
593 ms |
45732 KB |
deep_rand_01.txt |
AC |
567 ms |
49212 KB |
deep_rand_02.txt |
AC |
579 ms |
49212 KB |
deep_rand_03.txt |
AC |
575 ms |
45624 KB |
deep_rand_04.txt |
AC |
572 ms |
57780 KB |
hand_01.txt |
AC |
25 ms |
928 KB |
hand_02.txt |
AC |
27 ms |
924 KB |
kmp_killer_01.txt |
AC |
580 ms |
59684 KB |
kmp_killer_02.txt |
AC |
556 ms |
49724 KB |
kmp_killer_03.txt |
AC |
529 ms |
39824 KB |
periodic_01.txt |
AC |
533 ms |
27468 KB |
periodic_02.txt |
AC |
549 ms |
27428 KB |
periodic_03.txt |
AC |
546 ms |
26940 KB |
periodic_04.txt |
AC |
535 ms |
28120 KB |
random_01.txt |
AC |
629 ms |
26296 KB |
random_02.txt |
AC |
580 ms |
26296 KB |
random_03.txt |
AC |
574 ms |
26296 KB |
sample_01.txt |
AC |
26 ms |
924 KB |
sample_02.txt |
AC |
25 ms |
928 KB |