Submission #639804

#TimeUsernameProblemLanguageResultExecution timeMemory
639804ghostwriterPaint By Numbers (IOI16_paint)C++14
100 / 100
349 ms44840 KiB
#include "paint.h" #include <cstdlib> #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ const int N = 2e5 + 5; const int K = 105; int n, k, a[N], f[N]; str s; vi c; bool d[N][K], d1[N][K], check[N][2]; std::string solve_puzzle(std::string s, std::vector<int> c) { n = sz(s); k = sz(c); s = "#" + s + "#"; vi c1; c1.pb(0); EACH(i, c) c1.pb(i); c1.pb(0); c = c1; ::s = s; ::c = c; FOR(i, 1, n) f[i] = f[i - 1] + (s[i] == '_'? 1 : 0); d[0][0] = 1; FOR(i, 1, n) FOR(j, 0, k) { if (s[i] == '_') { d[i][j] = d[i - 1][j]; continue; } if (s[i] == 'X') { if (!j) { d[i][j] = 0; continue; } if (c[j] > i || f[i] - f[i - c[j]] || s[i - c[j]] == 'X') { d[i][j] = 0; continue; } d[i][j] = (i - c[j] - 1 >= 0? d[i - c[j] - 1][j - 1] : j == 1? 1 : 0); continue; } d[i][j] = d[i - 1][j]; if (j && c[j] <= i && f[i] - f[i - c[j]] == 0 && s[i - c[j]] != 'X') d[i][j] = d[i][j] || (i - c[j] - 1 >= 0? d[i - c[j] - 1][j - 1] : j == 1? 1 : 0); } d1[n + 1][k + 1] = 1; FOS(i, n, 1) FOS(j, k + 1, 1) { if (s[i] == '_') { d1[i][j] = d1[i + 1][j]; continue; } if (s[i] == 'X') { if (j > k) { d1[i][j] = 0; continue; } if (c[j] > n - i + 1 || f[i + c[j] - 1] - f[i - 1] || s[i + c[j]] == 'X') { d1[i][j] = 0; continue; } d1[i][j] = (i + c[j] + 1 <= n + 1? d1[i + c[j] + 1][j + 1] : j == k? 1 : 0); continue; } d1[i][j] = d1[i + 1][j]; if (j <= k && c[j] <= n - i + 1 && f[i + c[j] - 1] - f[i - 1] == 0 && s[i + c[j]] != 'X') d1[i][j] = d1[i][j] || (i + c[j] + 1 <= n + 1? d1[i + c[j] + 1][j + 1] : j == k? 1 : 0); } FOR(i, 1, n) { if (s[i] != '.') { if (s[i] == '_') check[i][0] = 1; else check[i][1] = 1; continue; } bool ok = 0; FOR(j, 0, k) ok = ok || (d[i - 1][j] && d1[i + 1][j + 1]); check[i][0] = ok; } FOR(i, 1, k) FOR(j, 1, n - c[i] + 1) { if (f[j + c[i] - 1] - f[j - 1]) continue; if (s[j - 1] == 'X' || s[j + c[i]] == 'X') continue; bool ok = (j > 1? d[j - 2][i - 1] : i - 1 == 0? 1 : 0) && (j + 1 + c[i] <= n + 1? d1[j + 1 + c[i]][i + 1] : i == k? 1 : 0); if (ok) { ++a[j]; --a[j + c[i]]; } } FOR(i, 1, n) a[i] += a[i - 1]; FOR(i, 1, n) { if (s[i] != '.') continue; if (a[i]) check[i][1] = 1; } str ans; FOR(i, 1, n) if (check[i][0] && check[i][1]) ans.pb('?'); else if (check[i][0]) ans.pb('_'); else ans.pb('X'); return ans; } /* .X........ 1 3 */

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:29:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   29 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
paint.cpp:51:5: note: in expansion of macro 'EACH'
   51 |     EACH(i, c) c1.pb(i);
      |     ^~~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:56:5: note: in expansion of macro 'FOR'
   56 |     FOR(i, 1, n) f[i] = f[i - 1] + (s[i] == '_'? 1 : 0);
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:58:5: note: in expansion of macro 'FOR'
   58 |     FOR(i, 1, n)
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:59:5: note: in expansion of macro 'FOR'
   59 |     FOR(j, 0, k) {
      |     ^~~
paint.cpp:28:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   28 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
paint.cpp:81:5: note: in expansion of macro 'FOS'
   81 |     FOS(i, n, 1)
      |     ^~~
paint.cpp:28:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   28 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
paint.cpp:82:5: note: in expansion of macro 'FOS'
   82 |     FOS(j, k + 1, 1) {
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:103:5: note: in expansion of macro 'FOR'
  103 |     FOR(i, 1, n) {
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:110:9: note: in expansion of macro 'FOR'
  110 |         FOR(j, 0, k) ok = ok || (d[i - 1][j] && d1[i + 1][j + 1]);
      |         ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:113:5: note: in expansion of macro 'FOR'
  113 |     FOR(i, 1, k)
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:114:5: note: in expansion of macro 'FOR'
  114 |     FOR(j, 1, n - c[i] + 1) {
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:123:5: note: in expansion of macro 'FOR'
  123 |     FOR(i, 1, n) a[i] += a[i - 1];
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:124:5: note: in expansion of macro 'FOR'
  124 |     FOR(i, 1, n) {
      |     ^~~
paint.cpp:27:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   27 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
paint.cpp:129:5: note: in expansion of macro 'FOR'
  129 |     FOR(i, 1, 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...