QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94963#2343. First of Her NameDaiRuiChen007AC ✓890ms281992kbC++141.3kb2023-04-08 14:49:432023-04-08 14:49:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-08 14:49:46]
  • 评测
  • 测评结果:AC
  • 用时:890ms
  • 内存:281992kb
  • [2023-04-08 14:49:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e6+1;
struct node {
	int fail,son[26];
	inline int& operator [](const int &i) { return son[i]; }
	inline int& operator [](const char &ch) { return son[ch-'A']; }
}	tr[MAXN];
int siz=0;
inline int insert(string str) {
	int pos=0;
	for(auto ch:str) {
		if(!tr[pos][ch]) tr[pos][ch]=++siz;
		pos=tr[pos][ch];
	}
	return pos;
}
inline void build() {
	queue <int> q;
	for(int ch=0;ch<26;++ch) if(tr[0][ch]) q.push(tr[0][ch]);
	while(!q.empty()) {
		int pos=q.front(); q.pop();
		for(int ch=0;ch<26;++ch) {
			if(tr[pos][ch]) {
				tr[tr[pos][ch]].fail=tr[tr[pos].fail][ch];
				q.push(tr[pos][ch]);
			} else tr[pos][ch]=tr[tr[pos].fail][ch];
		}
	}
}
vector <int> G[MAXN];
int sum[MAXN],id[MAXN];
inline void dfs(int p) {
	for(int v:G[p]) {
		dfs(v);
		sum[p]+=sum[v];
	}
}
signed main() {
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;++i) {
		char c;
		int x;
		cin>>c>>x;
		tr[x][c]=i;
	}
	siz=n;
	for(int i=1;i<=k;++i) {
		string str;
		cin>>str;
		reverse(str.begin(),str.end());
		id[i]=insert(str);
	}
	build();
	for(int i=1;i<=siz;++i) G[tr[i].fail].push_back(i);
	for(int i=1;i<=n;++i) ++sum[i];
	dfs(0);
	for(int i=1;i<=k;++i) printf("%d\n",sum[id[i]]);
	return 0;
}

Details

Test #1:

score: 100
Accepted
time: 10ms
memory: 52660kb

Test #2:

score: 0
Accepted
time: 1ms
memory: 54728kb

Test #3:

score: 0
Accepted
time: 6ms
memory: 52664kb

Test #4:

score: 0
Accepted
time: 6ms
memory: 52800kb

Test #5:

score: 0
Accepted
time: 3ms
memory: 52672kb

Test #6:

score: 0
Accepted
time: 1ms
memory: 52816kb

Test #7:

score: 0
Accepted
time: 4ms
memory: 52760kb

Test #8:

score: 0
Accepted
time: 9ms
memory: 52800kb

Test #9:

score: 0
Accepted
time: 9ms
memory: 50744kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 52736kb

Test #11:

score: 0
Accepted
time: 341ms
memory: 220184kb

Test #12:

score: 0
Accepted
time: 8ms
memory: 52816kb

Test #13:

score: 0
Accepted
time: 7ms
memory: 52804kb

Test #14:

score: 0
Accepted
time: 7ms
memory: 50612kb

Test #15:

score: 0
Accepted
time: 5ms
memory: 52684kb

Test #16:

score: 0
Accepted
time: 7ms
memory: 52740kb

Test #17:

score: 0
Accepted
time: 3ms
memory: 52808kb

Test #18:

score: 0
Accepted
time: 5ms
memory: 52800kb

Test #19:

score: 0
Accepted
time: 3ms
memory: 52656kb

Test #20:

score: 0
Accepted
time: 10ms
memory: 52776kb

Test #21:

score: 0
Accepted
time: 7ms
memory: 52816kb

Test #22:

score: 0
Accepted
time: 7ms
memory: 52780kb

Test #23:

score: 0
Accepted
time: 10ms
memory: 55428kb

Test #24:

score: 0
Accepted
time: 10ms
memory: 53364kb

Test #25:

score: 0
Accepted
time: 7ms
memory: 54968kb

Test #26:

score: 0
Accepted
time: 13ms
memory: 53276kb

Test #27:

score: 0
Accepted
time: 11ms
memory: 54904kb

Test #28:

score: 0
Accepted
time: 10ms
memory: 53232kb

Test #29:

score: 0
Accepted
time: 9ms
memory: 52824kb

Test #30:

score: 0
Accepted
time: 16ms
memory: 55168kb

Test #31:

score: 0
Accepted
time: 16ms
memory: 53336kb

Test #32:

score: 0
Accepted
time: 15ms
memory: 57572kb

Test #33:

score: 0
Accepted
time: 31ms
memory: 59944kb

Test #34:

score: 0
Accepted
time: 383ms
memory: 222140kb

Test #35:

score: 0
Accepted
time: 645ms
memory: 169656kb

Test #36:

score: 0
Accepted
time: 890ms
memory: 281992kb

Test #37:

score: 0
Accepted
time: 366ms
memory: 182164kb

Test #38:

score: 0
Accepted
time: 433ms
memory: 167844kb

Test #39:

score: 0
Accepted
time: 396ms
memory: 212084kb

Test #40:

score: 0
Accepted
time: 394ms
memory: 209644kb

Test #41:

score: 0
Accepted
time: 455ms
memory: 210732kb

Test #42:

score: 0
Accepted
time: 570ms
memory: 240212kb

Test #43:

score: 0
Accepted
time: 399ms
memory: 170844kb

Test #44:

score: 0
Accepted
time: 535ms
memory: 225208kb

Test #45:

score: 0
Accepted
time: 576ms
memory: 173700kb

Test #46:

score: 0
Accepted
time: 7ms
memory: 52688kb

Test #47:

score: 0
Accepted
time: 4ms
memory: 52752kb

Test #48:

score: 0
Accepted
time: 7ms
memory: 52664kb

Test #49:

score: 0
Accepted
time: 3ms
memory: 50616kb

Test #50:

score: 0
Accepted
time: 4ms
memory: 54708kb

Test #51:

score: 0
Accepted
time: 7ms
memory: 52812kb

Test #52:

score: 0
Accepted
time: 2ms
memory: 52744kb

Test #53:

score: 0
Accepted
time: 4ms
memory: 53912kb

Test #54:

score: 0
Accepted
time: 18ms
memory: 54432kb

Test #55:

score: 0
Accepted
time: 8ms
memory: 52704kb

Test #56:

score: 0
Accepted
time: 12ms
memory: 54916kb