QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200670#7345. Circular ShiftDelay_for_five_minutesWA 3ms16556kbC++113.2kb2023-10-04 18:20:362023-10-04 18:20:36

Judging History

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

  • [2023-10-04 18:20:36]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16556kb
  • [2023-10-04 18:20:36]
  • 提交

answer

#include<bits/stdc++.h>
#define maxn 600004
int mp[26][26];

std::string str;
struct SAM {
	int cnt,c[maxn][27], fa[maxn], len[maxn],last;
	int sz[maxn],fir[maxn],to[maxn],nxt[maxn],e;
	int tag[maxn];
	int end[maxn];
	SAM(){cnt = last = 1, e = 0;}
	void ext(int ch,int L,int tg) {
		int p = last, np = last = ++cnt, q, nq;
		end[np] = L - 1;
		len[np] = L, sz[np] = 1;
		tag[np] = tg;
		for(;!c[p][ch];p = fa[p]) c[p][ch] = np;
		if (!p) {fa[np] = 1;return ;}
		q = c[p][ch];
		if (len[p] + 1 == len[q]) {
			fa[np] = q;return ;
		}
		nq = ++cnt;
		len[nq] = len[p] + 1;
		for(int i = 0; i < 26;i++) {
			c[nq][i] = c[q][i];
		}
		tag[nq] = tag[q];
		end[nq] = end[q];
		fa[nq] =fa[q], fa[q] = fa[np] = nq;
		for(;c[p][ch] == q;p = fa[p]) {
			c[p][ch] = nq;
		}
	}
	bool cmp(int A,int B) {
		return len[A] < len[B] || (len[A] == len[B] && A < B);
	}
	void pre() {
		int id[maxn];
		for(int i=1;i<=cnt;i++) {
			id[i] = i;
		}
		std::sort(id + 1,id + 1 + cnt,[&](int A,int B) {
			return len[A] < len[B] || (len[A] == len[B] && A < B);
		});
		for(int i = cnt; i>=1;i--) {
			tag[fa[id[i]]] |= tag[id[i]];
		}
	} 
	long long f[maxn][27];
	long long tp() {
		int d[maxn];
		memset(d,0,sizeof d);
		long long ans = 0;
		
		for(int i=1;i<=cnt;i++) {
			for(int j = 0; j < 26;j++) if (c[i][j]) {
				printf("%d->%d(%c)\n",i,c[i][j],'a'+j);
				// d[c[i][j]]++;
			}
		}
		for(int i=1;i<=cnt;i++) {
			printf("%d",i);
			for(int j = 0; j < 26;j++) if (tag[i] & (1<<j)) {
				putchar('a' + j);
			}
			putchar('\n');
		}
		
		for(int i=1;i<=cnt;i++) {
			for(int j = 0; j < 26;j++) if (c[i][j]) {
				// printf("%d->%d(%c)\n",i,c[i][j],'a'+j);
				d[c[i][j]]++;
			}
		}
		std::queue<int> que;
		for(int i = 0 ; i < 26; i++) if (c[1][i]){
			f[c[1][i]][i] = 1;
			d[c[1][i]]--;
			if (d[c[1][i]] == 0) {
				que.push(c[1][i]);
			}
		}

		while(!que.empty()) {
			int now = que.front();
			que.pop();
			for(int i = 0; i < 26; i++) {
				if (tag[now] & (1 << i)) {
					ans = (ans + f[now][i]);
					printf("%d %c%d\n",now,'a'+i,f[now][i]);
				}
				else {
					if (i + 'a' == str[end[now] - len[fa[now]]]) {
						if (tag[fa[now]] & (1 << i)) {
							ans ++;
							printf("%d %c%d\n",now,'a'+i,1);
						}
					}
				}
				if (i + 'a' == str[end[now] - len[fa[now]]] && len[fa[now]] == 0 && (tag[fa[now]] & (1 << i))) {
					ans --;
				}
			}
			for(int i = 0; i < 26; i++) if (c[now][i]) {
				d[c[now][i]]--;
				for(int j = 0; j < 26; j++) {
					f[c[now][i]][j] = (f[c[now][i]][j] + f[now][j]);
				}
				if (d[c[now][i]] == 0) {
					que.push(c[now][i]);
				}
			}
		}
		return ans;
	}
}s;
int main() {
	// freopen("in.txt","r",stdin);
	std::cin >> str;
	str.push_back('a' + 26);
	for(int i = 0; i < str.length() - 1; i++) {
		// printf("%d\n",i);
		s.ext(str[i] - 'a', i + 1, 1 << (str[i + 1] - 'a'));
	}
	for(int i = 1; i < str.length(); i++) {
		mp[str[i - 1] - 'a'][str[i] - 'a'] ++;
	}
	str.pop_back();
	bool t[27];
	memset(t,0,sizeof t);
	long long  Ans = 0;
	for(auto i : str) {
		if (!t[i - 'a']) {
			Ans ++;
			t[i - 'a'] = 1;
		}
	}
	s.pre();
	Ans = (Ans + s.tp());
	std::cout << Ans << std::endl;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 16556kb

input:

abaac

output:

1->2(a)
1->3(b)
1->6(c)
2->5(a)
2->3(b)
2->6(c)
3->4(a)
4->5(a)
5->6(c)
1abc
2abc
3a
4a
5c
6
2 a1
2 b0
2 c0
3 a1
3 b1
4 a1
4 b1
5 a1
5 c0
6 c1
7

result:

wrong output format Expected integer, but "1->2(a)" found