Submission #944130

#TimeUsernameProblemLanguageResultExecution timeMemory
944130Nika533Paint By Numbers (IOI16_paint)C++14
32 / 100
1 ms600 KiB
#pragma GCC diagnostic warning "-std=c++11" #include <bits/stdc++.h> #include "paint.h" #define pb push_back #define MOD 1000000007 #define flush fflush(stdout) #define all(x) (x).begin(),(x).end() #define allr(x) (x).rbegin(), (x).rend() #define pii pair<int,int> using namespace std; const int N=105,K=105; bool dpPref[N][K],dpSuf[N][K]; int lastBlackPref[N],lastBlackSuf[N]; string solve_puzzle(string s, vector<int> c) { int n=s.size(); int k=c.size(); // build lastBlackPref; if (s[0]=='X') lastBlackPref[0]=0; else lastBlackPref[0]=-1e9; for (int i=1; i<n; i++) { lastBlackPref[i]=lastBlackPref[i-1]; if (s[i]=='X') lastBlackPref[i]=i; } // build lastBlackSuf; if (s[n-1]=='X') lastBlackSuf[n-1]=n-1; else lastBlackSuf[n-1]=1e9; for (int i=n-2; i>=0; i--) { lastBlackSuf[i]=lastBlackSuf[i+1]; if (s[i]=='X') lastBlackSuf[i]=i; } // build dpPref int firstBlack=lastBlackSuf[0]; int lastWhite=-1e9; for (int i=c[0]-1; i<=min(n-1,firstBlack+c[0]-1); i++) { if (s[i]=='_') lastWhite=i; if (i-c[0]+1>lastWhite) dpPref[i][0]=1; } for (int ind=1; ind<k; ind++) { lastWhite=-1e9; for (int i=0; i<n; i++) { if (s[i]=='_') lastWhite=i; if (i-c[ind]+1<=lastWhite) continue; if ((i-c[ind])-1<0) continue; if (s[i-c[ind]]=='X') continue; for (int j=max(0,lastBlackPref[(i-c[ind])-1]); j<=(i-c[ind])-1; j++) { if (dpPref[j][ind-1]==1) dpPref[i][ind]=1; } } } // build dpSuf int lastBlack=lastBlackPref[n-1]; lastWhite=1e9; for (int i=n-c[k-1]; i>=max(0,lastBlack-c[k-1]+1); i--) { if (s[i]=='_') lastWhite=i; if (i+c[k-1]-1<lastWhite) dpSuf[i][k-1]=1; } for (int ind=k-2; ind>=0; ind--) { lastWhite=1e9; for (int i=n-1; i>=0; i--) { if (s[i]=='_') lastWhite=i; if (i+c[ind]-1>=lastWhite) continue; if ((i+c[ind])+1>n-1) continue; if (s[(i+c[ind])]=='X') continue; for (int j=min(n-1,lastBlackSuf[(i+c[ind])+1]); j>=(i+c[ind])+1; j--) { if (dpSuf[j][ind+1]==1) dpSuf[i][ind]=1; } } } // build answer string ans=s; for (int i=0; i<n; i++) { if (s[i]!='.') continue; bool canBeWhite=0,canBeBlack=0; // can be '_' for (int j=i+1; j<=min(n-1,lastBlackSuf[i+1]); j++) { if (dpSuf[j][0]==1 && lastBlackPref[i]<0) canBeWhite=1; } for (int ind=0; ind<k-1; ind++) { bool B1=0,B2=0; for (int j=i-1; j>=max(0,lastBlackPref[i-1]); j--) { if (dpPref[j][ind]==1) B1=1; } for (int j=i+1; j<=min(n-1,lastBlackSuf[i+1]); j++) { if (dpSuf[j][ind+1]==1) B2=1; } if (B1 && B2) canBeWhite=1; } for (int j=i-1; j>=max(0,lastBlackPref[i]); j--) { if (dpPref[j][k-1]==1 && lastBlackSuf[i]>n-1) canBeWhite=1; } // can be 'X' int lb=-1,rb=n; for (int j=i; j>=0; j--) { if (s[j]=='_') { lb=j; break; } } for (int j=i; j<n; j++) { if (s[j]=='_') { rb=j; break; } } for (int ind=0; ind<k; ind++) { for (int o=0; o<c[ind]; o++) { int l=(i-o),r=(i+c[ind]-o-1); if (l<0 || r>n-1) continue; if (dpPref[r][ind]==1 && dpSuf[l][ind]==1) canBeBlack=1; } } if (canBeBlack==1 && canBeWhite==1) ans[i]='?'; else if (canBeBlack==1) ans[i]='X'; else ans[i]='_'; } return ans; }

Compilation message (stderr)

paint.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:91:7: warning: variable 'lb' set but not used [-Wunused-but-set-variable]
   91 |   int lb=-1,rb=n;
      |       ^~
paint.cpp:91:13: warning: variable 'rb' set but not used [-Wunused-but-set-variable]
   91 |   int lb=-1,rb=n;
      |             ^~
#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...