Submission #119902

#TimeUsernameProblemLanguageResultExecution timeMemory
119902tutisTrapezi (COI17_trapezi)C++17
63 / 100
1069 ms92944 KiB
/*input 5 00000000000 0000000000000 0000000.0000000 000..0000.0000000 00.0.00000.00000000 00.0000000000000000 00000000000000000 0000000.0000000 0000000000000 00000000000 */ #pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; struct grupe { int x, y, z; bool reikia = false; }; vector<grupe>xx; vector<char>col; bitset<150>x; bitset<150>prad; int timer = 0; vector<int>jj[150]; bitset<390>xxxxx; unordered_map<bitset<150>, bitset<390>>M; unordered_set<bitset<150>>buvau[150]; void ieskom(int i) { if (buvau[i].count(x) || i > timer / 2) return; buvau[i].insert(x); M[x] = xxxxx; if (x[i] == false) return ieskom(i + 1); for (int j : jj[i]) { if (x[xx[j].x] && x[xx[j].y] && x[xx[j].z]) { x[xx[j].x] = false; x[xx[j].y] = false; x[xx[j].z] = false; xxxxx[j] = true; ieskom(i + 1); xxxxx[j] = false; x[xx[j].x] = true; x[xx[j].y] = true; x[xx[j].z] = true; } } } int n; bool ieskom1(int i) { bitset<150>y = (~x)&prad; if (M.count(y)) { auto xxx = M[y]; for (int i = 0; i < (int)xx.size(); i++) if (xxx[i]) xx[i].reikia = true; return true; } if (i < timer / 2 + 2 * n - 1) return false; if (x[i] == false) return ieskom1(i - 1); for (int j : jj[i]) { if (x[xx[j].x] && x[xx[j].y] && x[xx[j].z]) { x[xx[j].x] = false; x[xx[j].y] = false; x[xx[j].z] = false; xx[j].reikia = true; if (ieskom1(i - 1)) return true; xx[j].reikia = false; x[xx[j].x] = true; x[xx[j].y] = true; x[xx[j].z] = true; } } return false; } int main() { ios_base::sync_with_stdio(false); cin >> n; string s[2 * n]; for (int i = 0; i < 2 * n; i++) cin >> s[i]; int kiek = 0; vector<int>id[2 * n]; for (int i = 0; i < 2 * n; i++) for (char c : s[i]) { id[i].push_back(timer++); col.push_back(c); if (c == '0') kiek++; } vector<int>adj[timer]; for (int i = 0; i < 2 * n; i++) { for (int t = 0; t + 1 < (int)id[i].size(); t++) { int x = id[i][t]; int y = id[i][t + 1]; adj[x].push_back(y); adj[y].push_back(x); } } for (int i = 0; i <= n - 2; i++) { for (int t = 0; t < (int)id[i].size(); t += 2) { int x = id[i][t]; int y = id[i + 1][t + 1]; adj[x].push_back(y); adj[y].push_back(x); } } for (int t = 0; t < (int)id[n - 1].size(); t += 2) { int x = id[n - 1][t]; int y = id[n][t]; adj[x].push_back(y); adj[y].push_back(x); } for (int i = n + 1; i < 2 * n; i++) { for (int t = 0; t < (int)id[i].size(); t += 2) { int x = id[i][t]; int y = id[i - 1][t + 1]; adj[x].push_back(y); adj[y].push_back(x); } } for (int i = 0; i < timer; i++) { for (int j : adj[i]) { for (int k : adj[i]) { if (j < k) { grupe a; a.x = i; a.y = j; a.z = k; xx.push_back(a); } } } } random_shuffle(xx.begin(), xx.end()); for (int i = 0; i < (int)xx.size(); i++) { jj[xx[i].x].push_back(i); jj[xx[i].y].push_back(i); jj[xx[i].z].push_back(i); } for (int i = 0; i < 2 * n; i++) { for (int t = 0; t < (int)id[i].size(); t++) { if (s[i][t] == '0') x[id[i][t]] = true; } } prad = x; ieskom(0); if (ieskom1(timer - 1)) { for (grupe a : xx) { if (a.reikia == false) continue; set<int>aplink; for (int i : {a.x, a.y, a.z}) for (int j : adj[i]) aplink.insert(j); for (int i : {a.x, a.y, a.z}) aplink.erase(i); set<char>cols; for (int i : aplink) cols.insert(col[i]); for (char x = '1'; x <= '6'; x++) if (cols.count(x) == 0) { col[a.x] = x; col[a.y] = x; col[a.z] = x; } } for (int i = 0; i < 2 * n; i++) { for (int t = 0; t < (int)id[i].size(); t++) { cout << col[id[i][t]]; } cout << '\n'; } } else cout << "nemoguce\n"; }
#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...