Submission #119224

#TimeUsernameProblemLanguageResultExecution timeMemory
119224patrikpavic2Paint By Numbers (IOI16_paint)C++17
100 / 100
1061 ms184512 KiB
#include "paint.h" #include <cstdlib> #include <cstdio> #include <iostream> #include <string> #include <cstring> #define PB push_back using namespace std; typedef vector < int > vi; const int N = 2e5 + 500; const int K = 105; int pref[N], n, can_W[N], can_B[N], dp[N][K][2]; string s; vi c; int dob(int i,int j){ if(j >= n) return 1; return pref[j] - (i ? pref[i - 1] : 0); } int f(int i,int j,int fl){ if(i == n) return (j == c.size()); if(dp[i][j][fl] != -1) return dp[i][j][fl]; //printf("%d %d\n", i, j); int ret = 0; if(s[i] == '_'){ can_W[i] = 1; return f(i + 1, j, 1); } if(s[i] != 'X'){ if(f(i + 1, j, 1)){ can_W[i] = 1; ret = 1; } } if(j < c.size() && !dob(i, i + c[j] - 1) && fl){ if(f(i + c[j], j + 1, 0)){ can_B[i]++; can_B[i + c[j]]--; ret = 1; } } return dp[i][j][fl] = ret; } string solve_puzzle(string ss, vi cc) { memset(dp, -1, sizeof(dp)); s = ss; c = cc; n = (int)s.size(); for(int i = 0;i < n;i++) pref[i] = (s[i] == '_') + (i ? pref[i - 1] : 0); f(0, 0, 1); for(int i = 1;i < n;i++) can_B[i] += can_B[i - 1]; string sol; for(int i = 0;i < n;i++){ if(can_W[i] && can_B[i]) sol.PB('?'); else if(can_W[i]) sol.PB('_'); else sol.PB('X'); } return sol; }

Compilation message (stderr)

paint.cpp: In function 'int f(int, int, int)':
paint.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(i == n) return (j == c.size());
                     ~~^~~~~~~~~~~
paint.cpp:43:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(j < c.size() && !dob(i, i + c[j] - 1) && fl){
     ~~^~~~~~~~~~
#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...