Submission #466761

#TimeUsernameProblemLanguageResultExecution timeMemory
466761M4mouHandcrafted Gift (IOI20_gift)C++17
100 / 100
232 ms22816 KiB
#include <bits/stdc++.h> #include "gift.h" using namespace std; vector<int>parent; void init(int n) { parent.resize(n); for(int l=0;l<n;l++) parent[l]=l; } int findset(int n) { return (parent[n]==n)?n:(parent[n]=findset(parent[n])); } bool sameSet(int a, int b) { return findset(a)==findset(b); } void unionSet(int a, int b) { if(sameSet(a, b)) return; a=findset(a); b=findset(b); if(a < b) parent[a]=b; else parent[b] = a; } int construct(int n, int r, std::vector<int> a, std::vector<int> b, std::vector<int> x) { init(n+1); for(int i = 0; i < r; i++){ if(x[i] == 2) continue; int j = findset(a[i]); while(j <= b[i] && findset(j) != findset(b[i])){ unionSet(j,b[i]); j++; j = findset(j); } } for(int i=0;i<r;i++){ if(x[i]==1){ continue; } if(findset(a[i])==findset(b[i])){ return 0; } } string s ="R"; for(int i=1;i<n;i++) { if(findset(i) != findset(i-1)) if(s.back() == 'R')s += "B"; else s+= "R"; else s+= s.back(); } craft(s); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...