Submission #961303

#TimeUsernameProblemLanguageResultExecution timeMemory
961303Ahmed57Paint By Numbers (IOI16_paint)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; string solve_puzzle(string s, vector<int> c){ int n = s.size() , k = c.size(); int pref[n+2][k+1]; int suf[n+3][k+1]; memset(pref,0,sizeof pref); memset(suf,0,sizeof suf); pref[0][0] = 1; suf[n+1][k] = 1; suf[n+2][k] = 1; s = '0'+s; int wi[n+1] = {0},bl[n+1] = {0}; int nah[n+1] = {0},part[n+2] = {0}; for(int i = 1;i<=s.size();i++){ wi[i] = wi[i-1]; bl[i] = bl[i-1]; if(s[i]=='_'){ wi[i] = wi[i-1]+1; }else if(s[i]=='X'){ bl[i] = bl[i-1]+1; } } for(int i = 1;i<=n;i++){ for(int j = 0;j<=k;j++){ if(s[i]=='.'||s[i]=='_'){ pref[i][j] |= pref[i-1][j]; }if(j>=1&&c[j-1]<=i&&wi[i]-wi[i-c[j-1]]==0&&(i-c[j-1]<=0||s[i-c[j-1]]!='X')){ cout<<i<<"hhh "<<j<<endl; if(i-c[j-1]==0){ if(j==1)pref[i][j] |= 1; } else pref[i][j] |= pref[i-c[j-1]-1][j-1]; } } } for(int i = n;i>=1;i--){ for(int j = 0;j<=k;j++){ if(s[i]=='.'||s[i]=='_'){ suf[i][j] |= suf[i+1][j]; }if(j<k&&c[j]<=(n-i+1)&&wi[i+c[j]-1]-wi[i-1]==0&&(i+c[j]>n||s[i+c[j]]!='X')){ if(i+c[j]==n+1){ if(j==k-1)suf[i][j] = 1; } else suf[i][j] |= suf[i+c[j]+1][j+1]; } } } cout<<pref[3][1]<<endl; for(int i = 1;i<=n;i++){ bool ss = 0; for(int j = 0;j<=k;j++){ if(pref[i-1][j]&&suf[i+1][j]&&s[i]!='X'){ ss = 1; } } if(ss)nah[i]|=1; } for(int i = 1;i<=n;i++){ for(int j = 0;j<k;j++){ if(pref[i-1][j]&&i+c[j]-1<=n&&suf[i+c[j]+1][j+1]&&wi[i+c[j]-1]-wi[i-1]==0&&(i+c[j]>n||s[i+c[j]]!='X')){ if(i+c[j]>n){ if(j+1==k){ part[i]++; part[i+c[j]]--; } }else{ part[i]++; part[i+c[j]]--; } } } } for(int i = 1;i<=n;i++){ part[i]+=part[i-1]; if(part[i])nah[i]|=2; } string ans; for(int i = 1;i<=n;i++){ cout<<nah[i]<<" "; if(nah[i]==3)ans+='?'; if(nah[i]==1)ans+='_'; if(nah[i]==2)ans+='X'; } return ans; } /* int main(){ cout<<solve_puzzle("..._._....", {3}) <<endl; }*/

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 1;i<=s.size();i++){
      |                   ~^~~~~~~~~~
#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...