Submission #96294

#TimeUsernameProblemLanguageResultExecution timeMemory
96294figter001Paint By Numbers (IOI16_paint)C++14
90 / 100
2073 ms96916 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5+50; const int maxk = 110; int n; vector<int> c; string s; int dp[maxn][maxk]; bool can[maxn][2]; int calc(int idx,int at){ if(idx >= n)return (at == (int)c.size()); int &res = dp[idx][at]; if(res != -1)return res; res = 0; if(s[idx] == 'X'){ if(at == c.size()){ res = 0; return res; } int to = idx + c[at] - 1; if(to >= n){ res = 0; return res; } for(int i=idx;i<=to;i++)if(s[i] == '_')return res = 0; if(s[to + 1] == 'X')return res = 0; res = calc(to+2,at+1); if(res){ can[to+1][1] = 1; for(int i=idx;i<=to;i++)can[i][0] = 1; } } else if(s[idx] == '_'){ res = calc(idx+1,at); }else{ res = calc(idx+1,at); if(res)can[idx][1] = 1; if(at != c.size()){ int to = idx + c[at] - 1; if(to < n){ bool f = 1; for(int i=idx;i<=to;i++)if(s[i] == '_')f = 0; if(f){ if(s[to + 1] != 'X'){ res |= calc(to+2,at+1); if(calc(to+2,at+1)){ can[to+1][1] = 1; for(int i=idx;i<=to;i++)can[i][0] = 1; } } } } } } return res; } string solve_puzzle(string S, vector<int> C){ memset(dp,-1,sizeof(dp)); n = S.size(); c = C; s = S; calc(0,0); string ans; for(int i=0;i<n;i++){ if(s[i] == '.'){ if(can[i][0] && can[i][1])ans += '?'; else if(can[i][1])ans += '_'; else ans += 'X'; }else ans += s[i]; } return ans; }

Compilation message (stderr)

paint.cpp: In function 'int calc(int, int)':
paint.cpp:22:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(at == c.size()){
      ~~~^~~~~~~~~~~
paint.cpp:44:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(at != c.size()){
      ~~~^~~~~~~~~~~
#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...