제출 #1079582

#제출 시각아이디문제언어결과실행 시간메모리
1079582ALeonidouPaint By Numbers (IOI16_paint)C++17
80 / 100
10 ms604 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; } vi v; string s; #define N 101 ll dp[N+1][N+1][2]; bool solve(ll n, ll k, bool prevBlack){ if (n >= sz(s)){ return (k == sz(v)); } if (dp[n][k][prevBlack] != -1) return dp[n][k][prevBlack]; if (s[n] == '_') return dp[n][k][prevBlack] = solve(n+1, k, false); bool canBeBlack = true; if (prevBlack || k >= sz(v) || n + v[k] > sz(s)) canBeBlack = false; for (ll i = 1; i < v[k] && canBeBlack; i++){ if (s[i+n] == '_'){ canBeBlack = false; } } if (s[n] == 'X'){ return dp[n][k][prevBlack] = (canBeBlack && solve(n+v[k], k+1, true)); } return dp[n][k][prevBlack] = (solve(n+1, k, false) || (canBeBlack && solve(n+v[k], k+1, true))); } bool checkPos(ll i, char c){ for (ll i =0; i<=N; i++){ for (ll j =0; j<=N; j++){ dp[i][j][0] = -1; dp[i][j][1] = -1; } } s[i] = c; bool x = solve(0, 0, false); s[i] = '.'; return x; } string solve_puzzle(string st, vi arr) { v = arr; s = st; ll n = sz(s); ll k = sz(v); string ans; ans.resize(n); for (ll i =0; i<n; i++){ if (s[i] == '_' || s[i] == 'X'){ ans[i] = s[i]; continue; } bool w = checkPos(i,'_'); bool b = checkPos(i,'X'); if (w && b) ans[i] = '?'; else if (w) ans[i] = '_'; else ans[i] = 'X'; // cout<<endl<<endl; } return ans; } /* .......... 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:39:49: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   39 |     if (s[n] == '_') return dp[n][k][prevBlack] = solve(n+1, k, false);
      |                             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
paint.cpp:50:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   50 |         return dp[n][k][prevBlack] = (canBeBlack && solve(n+v[k], k+1, true));
      |                ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:53:32: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   53 |     return dp[n][k][prevBlack] = (solve(n+1, k, false) || (canBeBlack && solve(n+v[k], k+1, true)));
      |            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paint.cpp: In function 'std::string solve_puzzle(std::string, vi)':
paint.cpp:73:8: warning: unused variable 'k' [-Wunused-variable]
   73 |     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...