QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#543424 | #9176. Non-Interactive Nim | Ashbourne | WA | 0ms | 21292kb | C++14 | 1.7kb | 2024-09-01 16:47:47 | 2024-09-01 16:47:47 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
vector<int> vec[300005];
const int MAXN=2e6;
const int INF = 1e9 + 7;
int a[300005],b[300005];
int ff[300005];
vector<pii> change[300005];
int head = 0;
const int M=11;
const int G=512;
void fz(int now,int las,int dep)
{
if(dep<=M)
{
a[now]=(1<<dep)*512;
if(dep==M) return;
}
for(int i=0;i<vec[now].size();i++)
{
int to=vec[now][i];
if(to==las)continue;
fz(to,now,dep+1);
}
}
int ans[300005];
void calc(int now,int las,int dep)
{
if(dep<=M)
{
if(b[now]%G==0 && b[now]/G<(1<<(dep+1))) ans[now]=1;
else ans[now]=0;
}
else
{
++head;
for(int i = 0; i <= 512; ++ i){
if(ff[i] > ff[((i - a[now]) + 512) % 512] + a[now])
change[head].push_back({i, ff[i]}), ff[i] = ff[((i - a[now]) + 512) % 512] + a[now];
}
if(ff[b[now] % 512] <= b[now]) ans[now] = 1;
}
for(int i=0;i<vec[now].size();i++)
{
int to=vec[now][i];
if(to==las)continue;
calc(to,now,dep+1);
}
if(dep <= M){
for(int i = 0; i < change[head].size(); ++ i){
int x = change[head][i].first, y = change[head][i].second;
ff[x] = y;
}
change[head].clear();
head--;
}
}
inline void solve()
{
int n;
cin>>n;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
vec[u].push_back(v);
vec[v].push_back(u);
}
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
fz(1,0,0);
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
ff[0] = 1;
calc(1,0,0);
for(int i=1;i<=n;i++) cout<<ans[i];
cout<<endl;
}
signed main()
{
// freopen("K.in","r",stdin);
// freopen("K.out","w",stdout);
int T;
cin.tie(0)->sync_with_stdio(0);
T=1;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 21292kb
input:
2 4 4 2 7 1 4 1 1 1 1
output:
512 7 00
result:
wrong answer Integer parameter [name=k] equals to 512, violates the range [-1, 100] (test case 1)