fork download
  1. #include "paint.h"
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. string solve_puzzle(string s, vector<int> c) {
  6. int K =c.size(), N =s.length();
  7.  
  8. vector<int> maxl(N,0),maxr(N,0);
  9. for(int i =0; i < N; i++) {
  10. if(s[i] == '_') continue;
  11. if(i == 0) maxl[i] =1;
  12. else maxl[i] =maxl[i-1]+1;}
  13. for(int i =N-1; i >= 0; i--) {
  14. if(s[i] == '_') continue;
  15. if(i == N-1) maxr[i] =1;
  16. else maxr[i] =maxr[i+1]+1;}
  17.  
  18. vector< vector<int> > lft(K+1,vector<int>(N+1,0)),rt(K+1,vector<int>(N+1,0));
  19. lft[0][0] =rt[0][N] =1;
  20. for(int i =0; i <= K; i++) for(int j =0; j < N; j++) {
  21. if(s[j] != 'X' && lft[i][j]) lft[i][j+1] =1;
  22. if(i == K || maxl[j] < c[i]) continue;
  23. if(j == N-1) {
  24. if(lft[i][j+1-c[i]]) lft[i+1][j+1] =1;
  25. }
  26. else {
  27. if(s[j+1] == 'X') continue;
  28. if(lft[i][j+1-c[i]]) lft[i+1][j+2] =1;}
  29. }
  30. for(int i =0; i <= K; i++) for(int j =N-1; j >= 0; j--) {
  31. if(s[j] != 'X' && rt[i][j+1]) rt[i][j] =1;
  32. if(i == K || maxr[j] < c[K-1-i]) continue;
  33. if(j == 0) {
  34. if(rt[i][j+c[K-1-i]]) rt[i+1][j] =1;
  35. }
  36. else {
  37. if(s[j-1] == 'X') continue;
  38. if(rt[i][j+c[K-1-i]]) rt[i+1][j-1] =1;}
  39. }
  40.  
  41. string ans =s;
  42. vector<int> isw(N,0),isb(N,0);
  43. // can be white?
  44. for(int i =1; i < N-1; i++) if(s[i] == '.')
  45. for(int j =0; j <= K; j++) if(lft[j][i+1] && rt[K-j][i]) isw[i] =1;
  46. if(rt[K][1] || (N > 1 && maxr[1] >= c[0] && rt[K-1][c[0]+1])) isw[0] =1;
  47. if(lft[K][N-1] || (N > 1 && maxl[N-2] >= c[K-1] && lft[K-1][N-1-c[K-1]])) isw[N-1] =1;
  48.  
  49. // can be black?
  50. vector<int> maxbr(N,0);
  51. for(int i =0; i < N; i++) for(int j =0; j < K; j++) if(maxr[i] >= c[j])
  52. if(lft[j][i] && rt[K-j-1][i+c[j]]) maxbr[i] =max(maxbr[i],c[j]);
  53. for(int i =0; i < N-1; i++) if(maxbr[i] > 0) maxbr[i+1] =max(maxbr[i+1],maxbr[i]-1);
  54. for(int i =0; i < N; i++) if(s[i] == '.' && maxbr[i] > 0) isb[i] =1;
  55.  
  56. for(int i =0; i < N; i++) if(s[i] == '.') {
  57. if(isw[i] == 0) ans[i] ='X';
  58. else if(isb[i] == 0) ans[i] ='_';
  59. if(ans[i] == '.') ans[i] ='?';}
  60. return ans;}
  61.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:19: fatal error: paint.h: No such file or directory
compilation terminated.
stdout
Standard output is empty