Submission #485362

#TimeUsernameProblemLanguageResultExecution timeMemory
485362MilosMilutinovicHandcrafted Gift (IOI20_gift)C++14
100 / 100
150 ms22784 KiB
/** * author: m371 * created: 07.11.2021 10:35:40 **/ #include "gift.h" #include <bits/stdc++.h> using namespace std; class dsu { public: vector<int> p; int n; dsu(int _n) : n(_n) { p.resize(n); iota(p.begin(), p.end(), 0); } inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); } inline bool unite(int x, int y) { x = get(x); y = get(y); if (x != y) { p[x] = y; return true; } return false; } }; int construct(int n, int r, vector<int> a, vector<int> b, vector<int> x) { dsu d(n); for (int i = 0; i < r; i++) { if (x[i] == 1) { int j = d.get(a[i]); while (j <= b[i] && d.get(j) != d.get(b[i])) { d.unite(j, b[i]); j = d.get(j + 1); } } } for (int i = 0; i < r; i++) { if (x[i] == 2) { if (d.get(a[i]) == d.get(b[i])) { return 0; } } } string ans = "R"; for (int i = 1; i < n; i++) { if (d.get(i) != d.get(i - 1)) { ans += (ans.back() ^ 'R' ^ 'B'); } else { ans += ans.back(); } } craft(ans); 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...