QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796419#8313. Nim Cheatereggegg185WA 17ms6564kbC++141.3kb2024-12-01 18:21:142024-12-01 18:21:14

Judging History

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

  • [2024-12-01 18:21:14]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:6564kb
  • [2024-12-01 18:21:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
short head[20010],to[20010],nxt[20010],cnt = 0; short a[20010],b[20010],req[40010],ans[20010],siz[20010],son[20010],sum,fa[20005];
void add(int u,int v) {
	cnt++; to[cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
}
void D(int now) {
	siz[now] = 1; for(int i = head[now]; i; i = nxt[i]) {
		int v = to[i]; D(v); siz[now] += siz[v];
		if(!son[now] || siz[son[now]]<siz[v]) son[now] = v;
	}
}
long long dp[18][17005],tmp[17005]; //sigh
void dfs(int now,int dep) {
	if(dep >= 18) exit(0);
	sum ^= a[now]; ans[now] = dp[dep][sum];
	for(int i = head[now]; i; i = nxt[i]) {
		int v = to[i]; if(v == son[now]) continue;
		for(int i = 0; i < 16384; i++) dp[dep+1][i] = min(dp[dep][i],dp[dep][i^a[v]]+b[v]);
		dfs(v,dep+1);
	} if(son[now]) {
		for(int i = 0; i < 16384; i++) tmp[i] = dp[dep][i];
		for(int i = 0; i < 16384; i++) dp[dep][i] = min(tmp[i],tmp[i^a[son[now]]]+b[son[now]]);
		dfs(son[now],dep);
	} sum ^= a[now];
}
char s[10];
signed main() {
	int n,cnt = 0,cur = 0; scanf("%d",&n); for(int i = 1; i <= n; i++) {
		scanf("%s",s+1);
		if(s[1] == 'A') {cnt++; scanf("%d%d",&a[cnt],&b[cnt]); add(fa[cnt] = cur,cnt); cur = cnt;}
		else cur = fa[cur]; req[i] = cur;
	} D(0); memset(dp,0x3f,sizeof(dp)); dp[0][0] = 0; dfs(0,0); for(int i = 1; i <= n; i++) printf("%d\n",ans[req[i]]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6536kb

input:

7
ADD 3 10
ADD 2 4
ADD 1 5
ADD 2 1
DEL
DEL
ADD 3 5

output:

10
14
0
1
0
14
4

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 6564kb

input:

1964
ADD 3004 35344
ADD 6315 69182
ADD 59 78550
ADD 13842 11063
ADD 6255 35962
DEL
ADD 13953 33214
ADD 5693 55297
ADD 1056 32685
ADD 13524 45844
ADD 5495 63087
ADD 2963 5957
ADD 7390 51487
ADD 9194 77728
DEL
ADD 1958 85909
DEL
ADD 6060 26702
ADD 13745 1556
ADD 6128 21684
ADD 9177 98957
ADD 670 35242...

output:

-30192
-26546
-13532
-2469
-32043
-2469
30745
20506
-12345
-32037
31050
-28529
22958
-30386
22958
-22205
22958
-15876
-14320
-14303
19118
-11176
8060
-11731
8060
-11176
19118
-4529
19118
-14303
-10993
-14303
14287
23250
-9429
-4711
-15125
16214
27895
-4282
6464
24827
-110
-27327
13071
27968
13071
-2...

result:

wrong answer 1st lines differ - expected: '35344', found: '-30192'