Submission #333275

#TimeUsernameProblemLanguageResultExecution timeMemory
333275MarcoMeijerPaint By Numbers (IOI16_paint)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second

const int MX=2e5+10;

int n, k;
vi c;
int sm[MX][200];
int possible[MX][200];
int smX[MX], sm_[MX];
bool visited[MX][200];

inline int getSum(int x, int y, char c) {
    return sm[min(n,y+1)][c]-sm[x][c];
}
inline void addX(int x, int y) {
    smX[y+1]--;
    smX[x]++;
}
inline void add_(int x, int y) {
    sm_[y+1]--;
    sm_[x]++;
}
inline bool isPossible(int x, int y) {
    if(x >= n) return y == k;
    return possible[x][y];
}
void visit(int x, int y) {
    if(x >= n) return;
    if(visited[x][y])
        return;
    visited[x][y] = 1;
    if(!possible[x][y])
        return;
    
    if(y == k) {
        add_(x,x);
        visit(x+1,y);
    } else {
        if(x+c[y] <= n && getSum(x,x+c[y]-1,'_') == 0 && getSum(x+c[y],x+c[y],'X') == 0) {
            if(possible[x+c[y]+1][y+1]) {
                addX(x,x+c[y]-1);
                add_(x+c[y],x+c[y]);
                visit(x+c[y]+1,y+1);
            }
        }
        if(getSum(x,x,'X') == 0 && possible[x+1][y]) {
            add_(x,x);
            visit(x+1,y);
        }
    }
}

string solve_puzzle(string s, vi C) {
    c=C;
    n = s.size(); k = c.size();
    RE(i,MX) RE(j,200) sm[i][j] = 0;
    RE(i,n) sm[i+1]['_'] = sm[i]['_']+(s[i]=='_'?1:0);
    RE(i,n) sm[i+1]['X'] = sm[i]['X']+(s[i]=='X'?1:0);
    RE(i,n) sm[i+1]['.'] = sm[i]['.']+(s[i]=='.'?1:0);
    RE(i,MX) smX[i]=sm_[i]=0;
    RE(i,MX) RE(j,200) visited[i][j] = 0;

    REV(x,n) RE(y,k) {
        possible[x][y] = 0;
        if(getSum(x,x,'X') == 0)
            if(isPossible(x+1,y))
                possible[x][y] = 1;

        if(y != k)
            if(x+c[y] <= n && getSum(x,x+c[y]-1,'_') == 0 && getSum(x+c[y],x+c[y],'X') == 0)
                if(isPossible(x+c[y]+1,y+1))
                    possible[x][y] = 1;
    }

    visit(0,0);
    REP(i,1,MX) smX[i]+=smX[i-1];
    REP(i,1,MX) sm_[i]+=sm_[i-1];
    string ans; ans.resize(n);
    RE(i,n) {
        if(smX[i] && sm_[i]) {
            ans[i] = '?';
        } else if(smX[i]) {
            ans[i] = 'X';
        } else {
            ans[i] = '_';
        }
    }
    return ans;
}

Compilation message (stderr)

paint.cpp:85:12: error: macro "REV" requires 3 arguments, but only 2 given
   85 |     REV(x,n) RE(y,k) {
      |            ^
paint.cpp:19: note: macro "REV" defined here
   19 | #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
      | 
paint.cpp: In function 'int getSum(int, int, char)':
paint.cpp:35:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   35 |     return sm[min(n,y+1)][c]-sm[x][c];
      |                           ^
paint.cpp:35:36: warning: array subscript has type 'char' [-Wchar-subscripts]
   35 |     return sm[min(n,y+1)][c]-sm[x][c];
      |                                    ^
paint.cpp: In function 'std::string solve_puzzle(std::string, vi)':
paint.cpp:85:5: error: 'REV' was not declared in this scope
   85 |     REV(x,n) RE(y,k) {
      |     ^~~
paint.cpp:85:17: error: 'y' was not declared in this scope
   85 |     REV(x,n) RE(y,k) {
      |                 ^
paint.cpp:15:38: note: in definition of macro 'REP'
   15 | #define REP(a,b,c) for(int a=int(b); a<int(c); a++)
      |                                      ^
paint.cpp:85:14: note: in expansion of macro 'RE'
   85 |     REV(x,n) RE(y,k) {
      |              ^~