QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#565036 | #8948. 报复社会 | Kevin5307# | 20 | 89ms | 7952kb | C++23 | 1.4kb | 2024-09-15 19:58:38 | 2024-09-15 19:58:41 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int p[22],c[22],dp[1<<20];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=2;i<=n;i++)
cin>>p[i];
for(int i=1;i<=n;i++)
cin>>c[i];
for(int i=0;i<(1<<n);i++)
{
if(!i) continue;
if(__builtin_popcount(i)==1)
{
dp[i]=c[__lg(i)+1];
continue;
}
if((n-__builtin_popcount(i))&1)
{
dp[i]=0;
for(int j=0;j<n;j++)
if(i>>j&1)
if(j==0||!(i>>(p[j+1]-1)&1))
dp[i]=max(dp[i],dp[i^(1<<j)]);
}
else
{
dp[i]=1;
for(int j=0;j<n;j++)
if(i>>j&1)
if(j==0||!(i>>(p[j+1]-1)&1))
dp[i]=min(dp[i],dp[i^(1<<j)]);
}
}
cout<<(dp[(1<<n)-1]?"Bob":"Alice")<<'\n';
}
return 0;
}
詳細信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 40ms
memory: 5764kb
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: 82ms
memory: 7604kb
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: 36ms
memory: 6604kb
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: 41ms
memory: 7092kb
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: 42ms
memory: 6368kb
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: 82ms
memory: 7648kb
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: 38ms
memory: 7120kb
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: 70ms
memory: 7944kb
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: 37ms
memory: 6004kb
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: 89ms
memory: 7712kb
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: 39ms
memory: 6268kb
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: 81ms
memory: 7872kb
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: 42ms
memory: 6852kb
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: 82ms
memory: 7772kb
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: 78ms
memory: 7952kb
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: 38ms
memory: 6416kb
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: 37ms
memory: 6568kb
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: 85ms
memory: 7644kb
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: 42ms
memory: 6936kb
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: 81ms
memory: 7720kb
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: 39ms
memory: 7692kb
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: 77ms
memory: 7872kb
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: 42ms
memory: 7180kb
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: 79ms
memory: 7752kb
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: 42ms
memory: 6564kb
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: 87ms
memory: 7648kb
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: 36ms
memory: 6844kb
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: 83ms
memory: 7940kb
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: 35ms
memory: 6216kb
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: 39ms
memory: 7040kb
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: 31ms
memory: 6644kb
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: 82ms
memory: 7708kb
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: 38ms
memory: 6096kb
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: 76ms
memory: 7708kb
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: 38ms
memory: 6424kb
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: 78ms
memory: 7712kb
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: 40ms
memory: 7380kb
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: 78ms
memory: 7744kb
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: 41ms
memory: 7544kb
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: 81ms
memory: 7908kb
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: 7752kb
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: 85ms
memory: 7704kb
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: 43ms
memory: 6284kb
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: 83ms
memory: 7648kb
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: 41ms
memory: 6660kb
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: 84ms
memory: 7704kb
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: 39ms
memory: 6220kb
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: 80ms
memory: 7752kb
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: 37ms
memory: 6116kb
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
Time Limit Exceeded
Test #50:
score: 0
Time Limit Exceeded
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:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #73:
score: 0
Time Limit Exceeded
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:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%