QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108115#6507. Recover the Stringwoyouxiangbaile#WA 113ms11444kbC++145.2kb2023-05-23 16:45:132023-05-23 16:45:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 16:45:16]
  • 评测
  • 测评结果:WA
  • 用时:113ms
  • 内存:11444kb
  • [2023-05-23 16:45:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
#define cep(n) while(n--)
#define gep(i, a) for(int i = firs[a]; i; i = neig[i])
int ured() {
	int re = 0;
	char ch;
	do {
		ch = getchar();
	} while('9' < ch || ch < '0');
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return re;
}
void uwit(int da) {
	int ch[21], cn = 0;
	do {
		ch[++cn] = da - da / 10 * 10;
	} while(da /= 10);
	do {
		putchar('0' ^ ch[cn]);
	} while(--cn);
}
mt19937 tran(time(0) * 1000 + clock());
int iran(int le, int ri) {
	uniform_int_distribution<int> re(le, ri);
	return re(tran);
}
const int _maxn = 1000011, _maxa = 1000000, _maxm = 2000011, _modf = 1000000007, _mods = 1000000009;
int qpow(int da, int up, int mo) {
	int re = 1;
	while(up) {
		if(up & 1) {
			re = 1ll * re * da % mo;
		}
		da = 1ll * da * da % mo, up >>= 1;
	}
	return re;
}
int fbas[_maxn], sbas[_maxn], finv, sinv;
struct mhas {
	int fh, sh, ln;
	mhas() {}
	mhas(int da) : fh(da), sh(da), ln(1) {}
	mhas(int fi, int se, int th) : fh(fi), sh(se), ln(th) {}
} zdat[_maxn], fdat[_maxn];
mhas operator+(mhas le, mhas ri) {
	return mhas((1ll * le . fh * fbas[ri . ln] + ri . fh) % _modf, (1ll * le . sh * sbas[ri . ln] + ri . sh) % _mods, le . ln + ri . ln);
}
mhas operator-(mhas le, int ri) {
	return mhas(1ll * (le . fh - ri + _modf) * finv % _modf, 1ll * (le . sh - ri + _mods) * sinv % _mods, le . ln - 1);
}
mhas operator-(int le, mhas ri) {
	return mhas((1ll * (_modf - fbas[ri . ln - 1]) * le + ri . fh) % _modf, (1ll * (_mods - sbas[ri . ln - 1]) * le + ri . sh) % _mods, ri . ln - 1);
}
bool operator==(mhas le, mhas ri) {
	return le . fh == ri . fh && le . sh == ri . sh && le . ln == ri . ln;
}
int t, n, m, u, v, lson[_maxn], rson[_maxn], indu[_maxn], firs[_maxn], neig[_maxm], arri[_maxm], queu[_maxn], head, tail;
int tdat[_maxn], edat[_maxn], cnts, atno, dans, rans[_maxn], cans[_maxn], toda[_maxn];
bool stat[_maxn][2], pdif;
int main() {
	t = ured(), fbas[0] = sbas[0] = 1, fbas[1] = iran(10000, 100000), sbas[1] = iran(200000, 300000);
	rep(i, 2, _maxa) {
		fbas[i] = 1ll * fbas[i - 1] * fbas[1] % _modf, sbas[i] = 1ll * sbas[i - 1] * sbas[1] % _mods;
	}
	finv = qpow(fbas[1], _modf - 2, _modf), sinv = qpow(sbas[1], _mods - 2, _mods);
	cep(t) {
		n = ured(), m = ured();
		rep(i, 1, n) {
			lson[i] = rson[i] = indu[i] = firs[i] = 0;
		}
		rep(i, 1, m) {
			u = ured(), v = ured(), neig[i] = firs[u], firs[u] = i, arri[i] = v;
			if(lson[v]) {
				rson[v] = u;
			} else {
				lson[v] = u;
			}
			++indu[v];
		}
		head = tail = cnts = 0;
		rep(i, 1, n) {
			if(!indu[i]) {
				queu[++tail] = i;
			}
		}
		while(head < tail) {
			atno = queu[++head];
			if(lson[atno] && rson[atno]) {
				if(tdat[lson[atno]] - zdat[lson[atno]] == zdat[rson[atno]] - edat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + edat[rson[atno]], fdat[atno] = fdat[rson[atno]] + tdat[lson[atno]];
					tdat[atno] = tdat[lson[atno]], edat[atno] = edat[rson[atno]], stat[atno][0] = 0, stat[atno][1] = 0;
				} else if(tdat[lson[atno]] - zdat[lson[atno]] == fdat[rson[atno]] - tdat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + tdat[rson[atno]], fdat[atno] = fdat[rson[atno]] + tdat[lson[atno]];
					tdat[atno] = tdat[lson[atno]], edat[atno] = tdat[rson[atno]], stat[atno][0] = 0, stat[atno][1] = 1;
				} else if(edat[lson[atno]] - fdat[lson[atno]] == zdat[rson[atno]] - edat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + edat[rson[atno]], fdat[atno] = fdat[rson[atno]] + edat[lson[atno]];
					tdat[atno] = edat[lson[atno]], edat[atno] = edat[rson[atno]], stat[atno][0] = 1, stat[atno][1] = 0;
				} else if(edat[lson[atno]] - fdat[lson[atno]] == fdat[rson[atno]] - tdat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + tdat[rson[atno]], fdat[atno] = fdat[rson[atno]] + edat[lson[atno]];
					tdat[atno] = edat[lson[atno]], edat[atno] = tdat[rson[atno]], stat[atno][0] = 1, stat[atno][1] = 1;
				}
			} else if(lson[atno]) {
				zdat[atno] = fdat[atno] = zdat[lson[atno]] + edat[lson[atno]], tdat[atno] = edat[atno] = tdat[lson[atno]];
			} else {
				zdat[atno] = fdat[atno] = mhas(tdat[atno] = edat[atno] = cnts++);
			}
			gep(i, atno) {
				if(!--indu[arri[i]]) {
					queu[++tail] = arri[i];
				}
			}
		}
		dans = 0;
		for(int i = 1, j = queu[tail], k = 0; j; ++i) {
			if(k) {
				rans[++dans] = tdat[j], k = stat[j][1], j = rson[j];
			} else {
				rans[++dans] = edat[j], k = stat[j][0], j = lson[j];
			}
		}
		rep(i, 0, cnts - 1) {
			toda[i] = -1;
		}
		cnts = 0;
		rep(i, 1, dans) {
			cans[dans - i + 1] = rans[i];
			if(toda[rans[i]] == -1) {
				toda[rans[i]] = cnts++;
			}
			rans[i] = toda[rans[i]];
		}
		rep(i, 0, cnts - 1) {
			toda[i] = -1;
		}
		cnts = 0;
		rep(i, 1, dans) {
			if(toda[cans[i]] == -1) {
				toda[cans[i]] = cnts++;
			}
			cans[i] = toda[cans[i]];
		}
		rep(i, 1, dans) {
			if(rans[i] != cans[i]) {
				pdif = rans[i] < cans[i];
				break;
			}
		}
		if(pdif) {
			rep(i, 1, dans) {
				putchar('a' + rans[i]);
			}
		} else {
			rep(i, 1, dans) {
				putchar('a' + cans[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 11444kb

input:

3
1 0
5 6
2 4
2 5
5 3
4 3
1 5
1 4
8 11
1 2
1 4
1 6
2 5
3 4
3 6
4 5
4 7
5 8
6 7
7 8

output:

a
aba
aaba

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 113ms
memory: 11388kb

input:

26837
1 0
2 1
2 1
3 2
1 3
2 3
3 2
3 1
1 2
5 5
4 3
5 1
1 2
3 2
5 3
5 6
2 4
2 5
5 3
4 3
1 5
1 4
5 5
1 5
2 1
2 4
4 5
3 4
6 6
1 4
5 3
2 4
4 6
3 6
2 3
4 3
1 3
3 4
2 1
7 8
2 5
1 3
7 1
3 5
7 6
1 2
4 6
6 3
8 11
2 6
2 7
3 7
8 1
6 4
4 5
7 4
7 1
3 8
2 8
1 5
8 10
8 1
4 5
7 8
3 5
3 1
7 3
1 2
5 2
6 4
6 3
9 11
5 2...

output:

a
aa
ab
aaa
aab
aba
aab
abc
aaaa
aaab
aaba
aabb
aabc
aaba
aaba
abac
aaba
abba
aabb
aabc
abac
abac
abcd
aaaaa
aabb
aaba
aabab
abaca
ababb
aaabb
abcab
aabba
aabb
aabbc
aabcc
aabcb
aabac
aaaaa
aaaba
aabaa
abaac
ababa
aabaa
aabac
aabcb
abbac
aabba
abcbd
aaabb
aabba
abbac
aaabb
aaaab
abbab
aabbc
ababb
aa...

result:

wrong answer 15th lines differ - expected: 'abab', found: 'aaba'