QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#828177 | #8948. 报复社会 | chenxinyang2006 | 20 | 434ms | 12156kb | C++23 | 1.6kb | 2024-12-23 14:17:01 | 2024-12-23 14:17:01 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int T,n;
int fa[21],a[21];
inline int chk(int S,int p){
return (S >> p) & 1;
}
int dp[1 << 21];//[0] Alice,[1] Bob
void solve(){
scanf("%d",&n);
rep(u,1,n - 1){
scanf("%d",&fa[u]);
fa[u]--;
}
rep(u,0,n - 1) scanf("%d",&a[u]);
rep(S,1,(1 << n) - 1){
if(popcnt(S) == 1){
dp[S] = a[ctz(S)];
continue;
}
int op = (__builtin_parity(S) == n % 2);
if(op) dp[S] = 1;
else dp[S] = 0;
rep(i,0,n - 1){
if(!chk(S,i) || (i && chk(S,fa[i]))) continue;
if(op) chkmin(dp[S],dp[S - (1 << i)]);
else chkmax(dp[S],dp[S - (1 << i)]);
}
}
if(dp[(1 << n) - 1]) printf("Bob\n");
else printf("Alice\n");
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 46ms
memory: 6384kb
input:
1 19 1 2 3 3 2 6 7 7 6 6 6 2 2 2 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 0 0
output:
Bob
result:
ok "Bob"
Test #2:
score: 20
Accepted
time: 98ms
memory: 8592kb
input:
1 20 1 1 3 2 4 1 4 4 1 7 1 6 3 12 6 12 8 5 7 1 0 1 1 1 0 0 1 1 0 0 1 0 1 0 1 0 0 0 1
output:
Alice
result:
ok "Alice"
Test #3:
score: 20
Accepted
time: 42ms
memory: 6976kb
input:
1 19 1 2 3 4 5 1 1 8 8 3 7 3 13 3 15 10 2 17 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0
output:
Alice
result:
ok "Alice"
Test #4:
score: 20
Accepted
time: 45ms
memory: 7820kb
input:
1 19 1 2 3 4 5 1 1 8 8 3 7 3 13 3 15 10 2 17 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0
output:
Alice
result:
ok "Alice"
Test #5:
score: 20
Accepted
time: 43ms
memory: 7124kb
input:
1 19 1 1 1 1 1 3 4 7 3 2 8 6 2 10 10 4 7 14 0 0 1 0 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1
output:
Bob
result:
ok "Bob"
Test #6:
score: 20
Accepted
time: 94ms
memory: 8328kb
input:
1 20 1 2 3 4 5 3 7 3 3 3 2 2 2 1 15 16 16 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1
output:
Alice
result:
ok "Alice"
Test #7:
score: 20
Accepted
time: 43ms
memory: 7296kb
input:
1 19 1 2 3 4 2 2 2 1 9 10 11 11 10 10 10 9 17 9 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 1 1
output:
Alice
result:
ok "Alice"
Test #8:
score: 20
Accepted
time: 86ms
memory: 9828kb
input:
1 20 1 2 3 4 4 3 3 2 9 10 9 9 9 9 9 2 2 2 2 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 1 1
output:
Alice
result:
ok "Alice"
Test #9:
score: 20
Accepted
time: 46ms
memory: 6860kb
input:
1 19 1 2 3 4 5 6 6 5 9 5 5 5 2 2 2 2 2 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 1
output:
Alice
result:
ok "Alice"
Test #10:
score: 20
Accepted
time: 100ms
memory: 8048kb
input:
1 20 1 2 2 2 3 1 6 4 3 2 8 2 5 7 3 3 10 10 15 0 1 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 0 0
output:
Alice
result:
ok "Alice"
Test #11:
score: 20
Accepted
time: 48ms
memory: 7088kb
input:
1 19 1 2 3 1 4 6 2 8 6 4 3 6 10 7 6 3 5 2 1 0 1 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0
output:
Alice
result:
ok "Alice"
Test #12:
score: 20
Accepted
time: 98ms
memory: 9544kb
input:
1 20 1 1 3 2 2 4 4 6 5 1 5 2 2 10 13 11 6 5 11 1 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1 0 0 0
output:
Alice
result:
ok "Alice"
Test #13:
score: 20
Accepted
time: 48ms
memory: 6056kb
input:
1 19 1 2 3 1 4 6 6 1 4 10 5 3 7 11 4 4 4 4 1 0 1 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0
output:
Alice
result:
ok "Alice"
Test #14:
score: 20
Accepted
time: 92ms
memory: 8964kb
input:
1 20 1 2 3 4 5 5 3 8 3 3 3 3 2 14 15 2 2 2 2 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 1 0 1
output:
Alice
result:
ok "Alice"
Test #15:
score: 20
Accepted
time: 88ms
memory: 8072kb
input:
1 20 1 2 3 4 5 5 3 8 3 3 3 3 2 14 15 2 2 2 2 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 1 1 0 1
output:
Alice
result:
ok "Alice"
Test #16:
score: 20
Accepted
time: 41ms
memory: 7696kb
input:
1 19 1 2 3 4 5 3 3 3 3 2 1 12 13 12 15 15 15 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 1 1
output:
Bob
result:
ok "Bob"
Test #17:
score: 20
Accepted
time: 42ms
memory: 7816kb
input:
1 19 1 2 3 3 1 6 6 6 6 6 6 6 6 6 6 1 1 1 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 0 0
output:
Bob
result:
ok "Bob"
Test #18:
score: 20
Accepted
time: 91ms
memory: 8532kb
input:
1 20 1 2 3 4 5 5 5 4 4 4 4 4 3 3 2 2 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0
output:
Bob
result:
ok "Bob"
Test #19:
score: 20
Accepted
time: 47ms
memory: 6864kb
input:
1 19 1 2 3 1 5 1 6 1 6 6 1 4 7 13 2 14 10 2 0 0 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 1 0
output:
Alice
result:
ok "Alice"
Test #20:
score: 20
Accepted
time: 93ms
memory: 8500kb
input:
1 20 1 1 3 1 2 5 7 6 8 3 8 4 9 4 12 7 17 7 16 0 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 1 1
output:
Bob
result:
ok "Bob"
Test #21:
score: 20
Accepted
time: 45ms
memory: 7104kb
input:
1 19 1 1 1 1 3 6 1 5 2 4 2 8 2 1 9 14 10 8 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0
output:
Bob
result:
ok "Bob"
Test #22:
score: 20
Accepted
time: 83ms
memory: 8892kb
input:
1 20 1 2 3 4 4 4 3 8 8 8 8 3 3 3 3 3 2 2 2 0 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1
output:
Bob
result:
ok "Bob"
Test #23:
score: 20
Accepted
time: 41ms
memory: 7192kb
input:
1 19 1 1 2 3 4 2 1 1 1 6 7 6 3 5 5 16 15 12 0 1 0 1 0 0 0 1 0 1 1 1 1 1 1 0 0 1 0
output:
Bob
result:
ok "Bob"
Test #24:
score: 20
Accepted
time: 95ms
memory: 9800kb
input:
1 20 1 2 3 4 4 4 4 3 9 9 3 3 2 2 2 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 1 0 1
output:
Alice
result:
ok "Alice"
Test #25:
score: 20
Accepted
time: 48ms
memory: 6460kb
input:
1 19 1 1 2 3 2 6 6 4 3 8 10 2 11 9 5 1 10 5 1 1 0 1 0 1 0 1 1 0 1 1 1 1 1 0 0 0 0
output:
Bob
result:
ok "Bob"
Test #26:
score: 20
Accepted
time: 91ms
memory: 9596kb
input:
1 20 1 2 2 4 4 4 1 6 4 10 9 6 2 2 4 5 9 12 8 0 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 0 1 0 1
output:
Alice
result:
ok "Alice"
Test #27:
score: 20
Accepted
time: 46ms
memory: 7360kb
input:
1 19 1 1 1 3 5 2 3 2 1 7 6 11 12 9 13 7 16 15 0 0 1 0 1 1 1 0 0 0 1 0 1 0 1 0 0 0 1
output:
Alice
result:
ok "Alice"
Test #28:
score: 20
Accepted
time: 100ms
memory: 9652kb
input:
1 20 1 2 3 2 4 4 2 7 2 5 8 8 1 9 1 3 3 9 5 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 0
output:
Alice
result:
ok "Alice"
Test #29:
score: 20
Accepted
time: 45ms
memory: 7928kb
input:
1 19 1 2 3 4 5 6 2 8 2 2 2 2 1 14 15 16 15 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1
output:
Alice
result:
ok "Alice"
Test #30:
score: 20
Accepted
time: 41ms
memory: 7496kb
input:
1 19 1 2 3 4 5 6 2 8 2 2 2 2 1 14 15 16 15 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1
output:
Alice
result:
ok "Alice"
Test #31:
score: 20
Accepted
time: 33ms
memory: 7436kb
input:
1 19 1 2 2 2 1 6 7 8 8 8 8 8 6 6 1 1 1 1 0 0 1 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0
output:
Alice
result:
ok "Alice"
Test #32:
score: 20
Accepted
time: 94ms
memory: 9768kb
input:
1 20 1 2 3 4 5 6 5 3 9 9 9 3 2 2 2 2 2 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 1
output:
Alice
result:
ok "Alice"
Test #33:
score: 20
Accepted
time: 44ms
memory: 7076kb
input:
1 19 1 2 2 2 2 1 7 8 9 8 8 7 13 7 7 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 1 0 1
output:
Bob
result:
ok "Bob"
Test #34:
score: 20
Accepted
time: 88ms
memory: 10004kb
input:
1 20 1 2 1 4 5 6 5 4 9 10 10 9 9 9 9 9 4 1 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 1 1
output:
Alice
result:
ok "Alice"
Test #35:
score: 20
Accepted
time: 40ms
memory: 6724kb
input:
1 19 1 2 2 4 2 1 5 6 1 5 4 12 9 2 9 9 12 4 1 0 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 1
output:
Bob
result:
ok "Bob"
Test #36:
score: 20
Accepted
time: 89ms
memory: 8780kb
input:
1 20 1 2 3 4 5 4 3 3 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1
output:
Alice
result:
ok "Alice"
Test #37:
score: 20
Accepted
time: 45ms
memory: 6320kb
input:
1 19 1 2 3 4 2 6 7 6 6 2 2 1 13 14 14 13 13 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 1
output:
Alice
result:
ok "Alice"
Test #38:
score: 20
Accepted
time: 87ms
memory: 9032kb
input:
1 20 1 2 3 4 1 3 7 6 5 8 8 5 11 12 9 9 8 14 6 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0
output:
Bob
result:
ok "Bob"
Test #39:
score: 20
Accepted
time: 47ms
memory: 7212kb
input:
1 19 1 2 3 4 4 4 4 3 3 3 3 2 2 2 2 1 1 1 0 0 0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 1
output:
Bob
result:
ok "Bob"
Test #40:
score: 20
Accepted
time: 91ms
memory: 8900kb
input:
1 20 1 2 3 4 3 6 7 3 2 10 2 2 2 2 2 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0
output:
Bob
result:
ok "Bob"
Test #41:
score: 20
Accepted
time: 41ms
memory: 6956kb
input:
1 19 1 2 3 3 3 3 3 3 3 3 3 2 13 2 2 1 17 1 0 0 0 0 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1
output:
Alice
result:
ok "Alice"
Test #42:
score: 20
Accepted
time: 97ms
memory: 8412kb
input:
1 20 1 2 3 2 1 6 6 6 4 7 4 2 9 13 2 11 5 14 4 0 1 0 0 0 1 1 1 1 0 0 1 0 1 0 1 1 1 1 0
output:
Bob
result:
ok "Bob"
Test #43:
score: 20
Accepted
time: 48ms
memory: 6968kb
input:
1 19 1 1 3 3 3 4 1 5 5 2 5 11 4 4 4 6 17 17 1 0 1 0 0 1 0 0 1 1 0 1 1 0 0 1 0 0 1
output:
Bob
result:
ok "Bob"
Test #44:
score: 20
Accepted
time: 91ms
memory: 9176kb
input:
1 20 1 2 3 4 5 5 5 4 3 3 3 2 13 13 2 1 1 1 1 0 0 0 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1
output:
Alice
result:
ok "Alice"
Test #45:
score: 20
Accepted
time: 48ms
memory: 7612kb
input:
1 19 1 1 2 1 5 1 6 5 7 5 1 8 9 4 4 8 7 17 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1
output:
Bob
result:
ok "Bob"
Test #46:
score: 20
Accepted
time: 97ms
memory: 9364kb
input:
1 20 1 2 1 2 4 2 7 4 5 6 8 6 5 3 2 1 13 10 8 0 0 0 1 0 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0
output:
Alice
result:
ok "Alice"
Test #47:
score: 20
Accepted
time: 48ms
memory: 6816kb
input:
1 19 1 2 2 4 4 4 3 3 6 4 4 4 10 3 6 7 17 4 0 0 1 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 0
output:
Alice
result:
ok "Alice"
Test #48:
score: 20
Accepted
time: 92ms
memory: 8248kb
input:
1 20 1 2 3 4 4 4 4 3 9 9 9 3 3 3 3 1 1 1 1 0 0 0 0 0 1 0 1 0 1 0 1 1 1 1 1 0 0 0 0
output:
Bob
result:
ok "Bob"
Test #49:
score: 20
Accepted
time: 47ms
memory: 7208kb
input:
1 19 1 2 3 4 5 4 4 4 3 3 3 3 2 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 0 1 0 1
output:
Alice
result:
ok "Alice"
Subtask #2:
score: 0
Wrong Answer
Test #50:
score: 0
Wrong Answer
time: 394ms
memory: 11912kb
input:
10000 49 1 2 2 1 5 5 5 5 5 5 1 12 12 12 12 12 12 1 19 19 19 19 19 19 19 1 27 27 1 1 31 1 33 33 33 33 33 33 33 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 50 1 2 2 2 2 2 1 8 8 8 1 12 1 1 15 15 15 15 1 1 21 21 21 21 1 26 1 1 29 29...
output:
Bob Bob Bob Bob Bob Alice Alice Alice Alice Bob Bob Bob Bob Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Bob Alice Alice Alice Alice Alice Bob Bob Bob Bob Bob Bob Alice Bob Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Bob Bob Alice Alice Alice Al...
result:
wrong answer 2nd words differ - expected: 'Alice', found: 'Bob'
Subtask #3:
score: 0
Wrong Answer
Test #73:
score: 0
Wrong Answer
time: 434ms
memory: 12156kb
input:
10000 50 1 2 1 4 5 6 5 4 9 4 11 4 1 14 15 16 16 16 15 14 21 21 21 14 14 14 14 14 1 30 30 30 30 30 1 36 37 37 37 36 41 41 41 36 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 50 1 2 3 4 5 4 7 8 7 4 11 12 11 14 11 16 11 18 11 4 21 4 4 4 3 ...
output:
Bob Alice Alice Alice Alice Alice Bob Alice Bob Bob Bob Bob Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Bob Alice Alice Bob Bob Bob Bob Bob Bob Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Bob Bob Alice Alice Alice Alice Alice ...
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%