QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244583#7764. 世界沉睡童话zhoukangyang#0 22ms39496kbC++111.8kb2023-11-09 12:27:572024-07-04 02:51:09

Judging History

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

  • [2024-07-04 02:51:09]
  • 评测
  • 测评结果:0
  • 用时:22ms
  • 内存:39496kb
  • [2023-11-09 12:27:57]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long 
#define i128 __int128
using namespace std;
const int N = 1 << 20, mod = 1019260817, G = 19491001;
int n, rt;
vi son[N];

int s[N], fa[N], top;
int a[N], p[N];
void dfs(int x) {
	s[++top] = x;
	for(auto&v : son[x]) {
		fa[v] = x;
		dfs(v);
	}
}

int pw[N], SUM[N];
void chck_slv(int x) {
	SUM[x] = (pw[a[x]] + mod - pw[p[x]]) % mod;
	for(auto&v : son[x]) {
		chck_slv(v);
		(SUM[x] += SUM[v]) %= mod;
	}
}

bool chck() {
	vi np(n + 1);
	L(i, 1, n) 
		np[i] = a[i];
	chck_slv(rt);
	L(i, 2, n) {
		if(SUM[s[i]]) {
			swap(np[s[i]], np[fa[s[i]]]);
		}
	}
	L(i, 1, n) 
		if(np[i] != p[i]) 
			return 0;
	return 1;
}
int main () {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> rt;
	L(i, 1, n) {
		cin >> a[i];
	}
	L(i, 1, n) {
		int k;
		cin >> k;
		while(k--) {
			int x;
			cin >> x;
			son[i].emplace_back(x);
		}
	}
	dfs(rt);
	L(i, 1, n) {
		cin >> p[i];
	}
	pw[0] = 1;
	L(i, 1, n) {
		pw[i] = (ll) pw[i - 1] * G % mod;
	}
	if(chck()) cout << "YES\n";
	else cout << "NO\n";
	cout << -1 << '\n';
	if(n <= 10) {
		int ans = 0;
		L(sub, 0, (1 << (n - 1)) - 1) {
			vi np(n + 1);
			L(i, 1, n) 
				np[i] = a[i];
			L(i, 2, n) {
				if(sub >> (i - 2) & 1) {
					swap(np[s[i]], np[fa[s[i]]]);
				}	
			}
			int win = 0;
			L(i, 1, n) {
				if(p[i] != np[i]) {
					win = np[i] < p[i];
					break;
				}
			}
			ans += win;
		}
		cout << ans << '\n';
	} else {
		cout << -1 << '\n';
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

20 10
20 6 18 12 8 14 15 5 1 17 11 10 19 13 7 16 2 9 3 4
3 13 16 20
1 4
1 17
0
1 19
0
0
0
3 5 8 11
3 1 3 18
0
0
2 15 12
3 6 9 2
1 14
0
0
0
1 7
0
19 6 17 12 3 14 13 5 8 9 11 7 10 1 20 16 2 18 15 4

output:

YES
-1
-1

result:

wrong answer Integer -1 violates the range [0, 998244352]

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 22ms
memory: 39496kb

input:

80000 1
77649 27240 19178 10270 1981 6216 42189 63630 66779 68852 46110 27187 4598 75779 69930 43632 68065 13395 33234 17719 76420 65825 3003 67410 18637 3380 32923 66692 9430 1915 118 62287 69323 9735 72936 30221 46487 33367 59048 61582 55572 10657 61645 68649 23643 39197 38086 66512 58864 51881 69...

output:

YES
-1
-1

result:

wrong answer Integer -1 violates the range [0, 998244352]

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #8:

0%

Subtask #10:

score: 0
Skipped

Dependency #9:

0%