Submission #428280

#TimeUsernameProblemLanguageResultExecution timeMemory
428280AzimjonPaint By Numbers (IOI16_paint)C++17
7 / 100
1 ms304 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; string solve(string s, vector<int> c) { int lst = 0; for (int k = 0; k < (int)c.size(); k++) { bool flag; int x = c[k]; do { flag = true; for (int i = lst; i < lst + x; i++) { // cerr << i << " " << endl; flag &= (s[i] == '.'); } if (flag) { for (int i = lst; i < lst + x; i++) { s[i] = 'X'; } lst += x; } else { lst++; } } while (!flag); lst++; } return s; } std::string solve_puzzle(std::string s, std::vector<int> c) { int n = s.size(); string a, b; reverse(s.begin(), s.end()); reverse(c.begin(), c.end()); a = solve(s, c); reverse(a.begin(), a.end()); reverse(s.begin(), s.end()); reverse(c.begin(), c.end()); b = solve(s, c); swap(a, b); // cerr << a << endl; // cerr << b << endl; int i, j; i = j = 0; while (i < n && a[i] != 'X') i++; while (j < n && b[j] != 'X') j++; vector<int> aa, bb; aa = bb = vector<int>(n, -1); for (int q = 0; q < (int)c.size(); q++) { while (i < n && a[i] == 'X') { aa[i] = q; i++; } while (j < n && b[j] == 'X') { bb[j] = q; j++; } i++; j++; } vector<int> q(n, -1); for (int i = 0; i < n; i++) { q[i] = (aa[i] == -1 ? bb[i] : aa[i]); if (s[i] == '_') continue; if (aa[i] == bb[i] && a[i] == 'X') { s[i] = 'X'; } } string t = s; for (int i = 0; i < n; i++) { if (s[i] != '.') continue; if (a[i] == 'X' || b[i] == 'X') { t[i] = '?'; continue; } int l, r; l = r = i; if (s[i] == '.') { while (l >= 0 && aa[l] == -1) { if (s[l] != '.') break; l--; } while (r < n && bb[r] == -1) { if (s[r] != '.') break; r++; } } if (q[l] == q[r] && q[l] != -1) { t[i] = '?'; } } // for (int i = 0; i < n; i++) // cout << aa[i] << " "; // cout << endl; // for (int i = 0; i < n; i++) // cout << bb[i] << " "; // cout << endl; // for (int i : q) // cout << i << " "; // cout << endl; return t; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...