5370 | 2023-04-26 19:07:40 | kohumark | Különböző katicák | cpp17 | Time limit exceeded 0/100 | 600ms | 130744 KiB |
#include <iostream>
#include <vector>
#include <set>
using namespace std;
vector<vector<int>> con;
set<int> act; set<int> visited;
void actual(int i, int p[], int l){
visited.insert(i);
set<int> now;
for(auto it=con[i].begin(); it!=con[i].end(); it++){
if(p[*it]!=-1){
int a=-l;
while(a!=l){
if(p[*it]+a>=0) now.insert(p[*it]+a);
a+=2;
}
}
if(!visited.count(*it)) actual(*it, p, l+1);
}
//for(auto it=now.begin(); it!=now.end(); it++) cout << *it << '\n';
for(auto it=act.begin(); it!=act.end(); it++) if(!now.count(*it)){act.erase(*it); it=act.begin(); if(act.size()==0) break;}
}
int solve(int i, int p[]){
//cout << '\n' << i << '\n';
visited.insert(i);
for(auto it=con[i].begin(); it!=con[i].end(); it++){
if(p[*it]!=-1){act.insert(p[*it]+1); act.insert(abs(p[*it]-1));}
actual(*it, p, 2);
}
if(act.size()==0) return -1;
int x=*(act.begin()); act.clear(); visited.clear();
return x;
}
int main(){
bool ok=true;
int n; cin >> n;
int p[n]; //f[n];
con.assign(n, vector<int>());
for(int i=0; i<n; i++){
int x; cin >> x;
if(x!=0){con[i].push_back(x-1); con[x-1].push_back(i);}
}
for(int i=0; i<n; i++) cin >> p[i];
for(int i=0; i<n; i++){
if(p[i]==-1) p[i]=solve(i, p);
if(p[i]==-1){ok=false; break;}
}
if(ok){
cout << "IGEN\n";
for(int i=0; i<n; i++){
cout << p[i] << ' ';
}
}
else cout << "NEM";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
3 | Time limit exceeded | 600ms | 13568 KiB | ||||
subtask2 | 0/10 | ||||||
4 | Wrong answer | 100ms | 18848 KiB | ||||
5 | Wrong answer | 112ms | 20700 KiB | ||||
6 | Wrong answer | 122ms | 22212 KiB | ||||
7 | Wrong answer | 140ms | 24372 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Runtime error | 237ms | 130744 KiB | ||||
9 | Runtime error | 230ms | 130504 KiB | ||||
10 | Runtime error | 240ms | 130272 KiB | ||||
11 | Runtime error | 234ms | 130192 KiB | ||||
12 | Runtime error | 238ms | 129996 KiB | ||||
13 | Runtime error | 232ms | 129780 KiB | ||||
14 | Wrong answer | 128ms | 51532 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Wrong answer | 4ms | 4356 KiB | ||||
16 | Accepted | 4ms | 4508 KiB | ||||
17 | Accepted | 3ms | 4344 KiB | ||||
18 | Wrong answer | 3ms | 4472 KiB | ||||
19 | Wrong answer | 4ms | 4784 KiB | ||||
20 | Wrong answer | 3ms | 4552 KiB | ||||
21 | Wrong answer | 4ms | 4704 KiB | ||||
22 | Wrong answer | 4ms | 4720 KiB | ||||
subtask5 | 0/40 | ||||||
23 | Wrong answer | 123ms | 23704 KiB | ||||
24 | Time limit exceeded | 558ms | 16512 KiB | ||||
25 | Accepted | 305ms | 27500 KiB | ||||
26 | Wrong answer | 134ms | 24400 KiB | ||||
27 | Wrong answer | 370ms | 26116 KiB | ||||
28 | Time limit exceeded | 560ms | 16456 KiB | ||||
29 | Wrong answer | 112ms | 25644 KiB | ||||
30 | Wrong answer | 133ms | 25192 KiB | ||||
31 | Time limit exceeded | 565ms | 18160 KiB | ||||
32 | Time limit exceeded | 550ms | 17680 KiB | ||||
33 | Time limit exceeded | 577ms | 15588 KiB |