Submission #319671

#TimeUsernameProblemLanguageResultExecution timeMemory
319671VROOM_VARUNPaint By Numbers (IOI16_paint)C++14
Compilation error
0 ms0 KiB
/*
ID: varunra2
LANG: C++
TASK: paint
*/

#include<bits/stdc++.h>
#include "paint.h"
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
const char black = 'X';
const char white = '_';
const int maxn = (int)2e5 + 3;
const int maxk = 103;

bool dp[maxn][maxk][2][2];

string solve_puzzle(string s, VI c) {
  int n = sz(s);
  int k = sz(c);
  s = '*' + s;
  c.insert(c.begin(), 69420); // padding

  MEM(dp, false);

  int lst = 0, fst = n + 1;

  dp[0][0][0][0] = true;
  dp[n + 1][k + 1][1][0] = true;

  for(int i = 1; i <= n; i++) {
    if(s[i] != black) {
      dp[i][0][0][0] = dp[i - 1][0][0][0];
      for(int j = 1; j <= k; j++) {
        dp[i][j][0][0] = dp[i - 1][j][0][0] or ((lst < i - c[j]) and dp[i - c[j] - 1][j - 1][0][0]);
      }
    }
    if(s[i] != white) {
      for(int j = 1; j <= k; j++) {
        dp[i][j][0][1] = (lst <= i - c[j]) and dp[i - c[j]][j - 1][0][0];
      }
    }
    if(s[i] == white) lst = i;
  }

  int fst = n + 1;
  for(int i = n; i; i--) {
    if(s[i] != black) {
      dp[i][k + 1][1][0] = dp[i + 1][k + 1][1][0];
      for(int j = 1; j <= k; j++) {
        dp[i][j][1][0] = dp[i + 1][j][1][0] or ((fst > i + c[j]) and dp[i + c[j] + 1][j + 1][0]);
      }
    }
    if(s[i] != white) {
      for(int j = 1; j <= k; j++) {
        dp[i][j][1][1] = (i + c[j] <= fst) and dp[i + c[j]][j + 1][1][0];
      }
    }
    if(s[i] == white) fst = i;
  }
  VI mkb(n), mkw(n);

  for(int i = 1; i <= n; i++) {
    mkb[i - 1] = mkw[i - 1] = 0;
    int mx = 0;
    for(int j = 1; j <= k; j++) {
      if(dp[i][j][0][0] and (dp[i][j + 1][1][0] or dp[i + 1][j + 1][1][1])) mkw[i - 1] = 1;
      if(dp[i][j][0][1] and dp[i + 1][j + 1][1][0]) mx = max(mx, c[j]);
    }
    if(dp[i][0][0][0] and (dp[i + 1][1][1][0] or dp[i + 1][1][1][1])) mkw[i - 1] = 1;
    for(int j = i; j > i - mx; j--) mkb[j - 1] = 1;
  }
  
  string ret = "";
  for(int i = 0; i < n; i++) {
    if(mkb[i] and mkw[i]) ret.append(1, '?');
    else if(mkw[i]) ret.append(1, white);
    else if(mkb[i]) ret.append(1, black);
  }
  return ret;
} 

// int main() {
// #ifndef ONLINE_JUDGE
//   freopen("paint.in", "r", stdin);
//   freopen("paint.out", "w", stdout);
// #endif
//   cin.sync_with_stdio(0); cin.tie(0);

//   int n, k;
//   cin >> n >> k;
//   string s;
//   cin >> s;
//   VI vals(k);
//   for(int i = 0; i < k; i++) {
//     cin >> vals[i];
//   }

//   cout << solve_puzzle(s, vals) << '\n';

//   return 0;
// }

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, VI)':
paint.cpp:90:7: error: redeclaration of 'int fst'
   90 |   int fst = n + 1;
      |       ^~~
paint.cpp:70:16: note: 'int fst' previously declared here
   70 |   int lst = 0, fst = n + 1;
      |                ^~~