제출 #1079628

#제출 시각아이디문제언어결과실행 시간메모리
1079628ALeonidouPaint By Numbers (IOI16_paint)C++17
59 / 100
95 ms160468 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; #define ll int #define F first #define S second #define sz(x) (ll)x.size() #define pb push_back typedef vector <ll> vi; typedef pair <ll,ll> ii; typedef vector <ii> vii; #define dbg(x) cout<<#x<<": "<<x<<endl; #define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl; #define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl; void printVct(vi &v){ for (ll i= 0; i<sz(v); i++){ cout<<v[i]<<" "; } cout<<endl; } #define N 200001 #define K 101 ll dp[N+1][K+1][2]; vi v,p; vi w,b; string s; ll getSum(ll l, ll r){ if (l == 0) return p[r]; return p[r] - p[l-1]; } bool solve(ll n, ll k, bool prevBlack){ //O(n * k) if (n >= sz(s)){ return (k == sz(v)); } if (dp[n][k][prevBlack] != -1) return dp[n][k][prevBlack]; if (s[n] == '_'){ w[n] |= solve(n+1, k, false); return dp[n][k][prevBlack] = w[n]; } bool canBeBlack = true; if (prevBlack || k >= sz(v) || n + v[k] > sz(s)) canBeBlack = false; if (canBeBlack) canBeBlack = (getSum(n, n+v[k]-1) == 0); if (s[n] == 'X'){ b[n] = max(b[n], (canBeBlack && solve(n+v[k], k+1, true)) * v[k]); return dp[n][k][prevBlack] = (b[n] > 0); } w[n] |= solve(n+1, k, false); b[n] = max(b[n], (canBeBlack && solve(n+v[k], k+1, true)) * v[k]); return dp[n][k][prevBlack] = (w[n] || b[n]); } string solve_puzzle(string st, vi arr) { v = arr; s = st; ll n = sz(s); ll k = sz(v); for (ll k =0; k<=N; k++){ for (ll j =0; j<=K; j++){ dp[k][j][0] = -1; dp[k][j][1] = -1; } } w.resize(n); b.resize(n); p.resize(sz(s)); p[0] = (s[0] == '_'); for (ll j =1; j<sz(s); j++){ p[j] = p[j-1] + (s[j] == '_'); } solve(0,0,false); // printVct(b); ll b_boost = 0; for (ll i =0; i<n; i++){ if (b[i] || b_boost){ b_boost = max(b[i], b_boost); b[i] = 1; } b_boost = max(b_boost-1, 0); } // printVct(b); for (ll i =0; i<n; i++){ if (s[i] == '.'){ if (w[i] && b[i]) s[i] = '?'; else if (w[i]) s[i] = '_'; else s[i] = 'X'; } } return s; } /* .......... 2 3 4 ..._._.... 1 3 .._._..................... 2 1 19 _........_ 3 2 2 2 ....._. 2 2 2 .......... 3 1 3 2 */

컴파일 시 표준 에러 (stderr) 메시지

paint.cpp: In function 'bool solve(int, int, bool)':
paint.cpp:50:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   50 |         return dp[n][k][prevBlack] = w[n];
paint.cpp:59:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   59 |         return dp[n][k][prevBlack] = (b[n] > 0);
      |                ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
paint.cpp:64:32: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   64 |     return dp[n][k][prevBlack] = (w[n] || b[n]);
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
paint.cpp: In function 'std::string solve_puzzle(std::string, vi)':
paint.cpp:71:8: warning: unused variable 'k' [-Wunused-variable]
   71 |     ll k = sz(v);
      |        ^
#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...