Submission #592107

#TimeUsernameProblemLanguageResultExecution timeMemory
592107yutabiPaint By Numbers (IOI16_paint)C++14
59 / 100
101 ms28528 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; #define pb push_back std::string solve_puzzle(std::string s, std::vector<int> c) { s='_'+s+'_'; vector <vector <bool> > DP_l(100007,vector <bool> (107,0)); vector <vector <bool> > DP_r(100007,vector <bool> (107,0)); vector <vector <bool> > DP3(100007,vector <bool> (107,0)); vector <vector <bool> > DP4(100007,vector <bool> (107,0)); vector <int> next_l; vector <int> next_r; int curr; for(int i=s.size()-1;i>=0;i--) { if(s[i]=='_') { curr=i; } next_l.pb(curr); } reverse(next_l.begin(),next_l.end()); for(int i=0;i<s.size();i++) { if(s[i]=='_') { curr=s.size()-i-1; } next_r.pb(curr); } DP_l[0][0]=1; for(int i=0;i<s.size();i++) { for(int j=0;j<=c.size();j++) { if(j!=c.size()) { if(DP_l[i][j] && i+c[j]<=next_l[i] && s[i+c[j]]!='X') { DP_l[i+c[j]+1][j+1]=1; DP3[i][j]=1; } } if(DP_l[i][j] && s[i]!='X') { DP_l[i+1][j]=1; } //printf("%d ",(int)DP_l[i][j]); } //printf("\n"); } //printf("\n"); reverse(s.begin(),s.end()); reverse(c.begin(),c.end()); reverse(next_r.begin(),next_r.end()); DP_r[0][0]=1; for(int i=0;i<s.size();i++) { for(int j=0;j<=c.size();j++) { if(j!=c.size()) { if(DP_r[i][j] && i+c[j]<=next_r[i] && s[i+c[j]]!='X') { //printf("%d %d\n",i,c[j]); DP_r[i+c[j]+1][j+1]=1; DP4[i][j]=1; } } if(DP_r[i][j] && s[i]!='X') { DP_r[i+1][j]=1; } //printf("%d ",(int)DP_r[i][j]); } //printf("\n"); } //printf("\n"); reverse(s.begin(),s.end()); reverse(c.begin(),c.end()); reverse(next_r.begin(),next_r.end()); curr=10000000; for(int i=s.size()-1;i>=0;i--) { for(int j=0;j<=c.size();j++) { if(j!=c.size()) { if(DP3[i][j] && DP4[s.size()-(i+c[j])][c.size()-(j+1)]) { for(int k=i;k<min(i+c[j],curr);k++) { if(s[k]=='_' || s[k]=='?') { s[k]='?'; } else { s[k]='X'; } } curr=i; if(s[i-1]=='X' || s[i-1]=='?') { s[i-1]='?'; } else { s[i-1]='_'; } if(s[i+c[j]]=='X' || s[i+c[j]]=='?') { s[i+c[j]]='?'; } else { s[i+c[j]]='_'; } } } if(DP_l[i][j] && DP_l[i+1][j] && DP_r[s.size()-(i)][c.size()-(j)] && DP_r[s.size()-(i+1)][c.size()-(j)]) { if(s[i]=='X' || s[i]=='?') { s[i]='?'; } else { s[i]='_'; } } } } string nw=""; for(int i=1;i<s.size()-1;i++) { nw+=s[i]; } return nw; }

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
paint.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
paint.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int j=0;j<=c.size();j++)
      |                     ~^~~~~~~~~~
paint.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             if(j!=c.size())
      |                ~^~~~~~~~~~
paint.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
paint.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |         for(int j=0;j<=c.size();j++)
      |                     ~^~~~~~~~~~
paint.cpp:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             if(j!=c.size())
      |                ~^~~~~~~~~~
paint.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for(int j=0;j<=c.size();j++)
      |                     ~^~~~~~~~~~
paint.cpp:119:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |             if(j!=c.size())
      |                ~^~~~~~~~~~
paint.cpp:177:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |     for(int i=1;i<s.size()-1;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...