제출 #1079561

#제출 시각아이디문제언어결과실행 시간메모리
1079561ALeonidouPaint By Numbers (IOI16_paint)C++17
59 / 100
1 ms600 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 c; ll fill_in(ll k, ll init_x, ll s, ll e, ll u = -1){ // dbg3(k, s, e); ll p = s; //posisition of last black ll x = init_x; //block index if (u == -1){ //just fill in while (x < k && p + c[x] + 1 < e){ p += c[x] + 1; x++; } } else{ //include black u // dbg(u); while (x < k-1 && p + 1 + c[x] < u-1){ p += c[x] + 1; x++; } // dbg(p); p = max(p + c[x] + 1, u); // dbg(p); if (p >= e){ if (x == init_x) return x; p = u; } else{ x++; } while (x < k && p + c[x] + 1 < e){ p += c[x] + 1; x++; } } return x; } bool checkWhite(ll n, ll k, ll i, vi &whitePoints){ ll x = 0; bool done_i = false; ll prev = -1; for (ll j =0; j<sz(whitePoints); j++){ if (!done_i && i < whitePoints[j]){ x = fill_in(k, x, prev-1, i); prev = i; done_i = true; } x = fill_in(k, x, prev-1, whitePoints[j]); prev = whitePoints[j]; } return (x >= k); } bool checkBlack(ll n, ll k, ll i, vi &whitePoints){ for (ll w = 0; w<k; w++){ ll x = 0; bool done_i = false; ll prev = -1; bool ok = true; for (ll j =0; j<sz(whitePoints); j++){ // dbg(j); if (!done_i && i < whitePoints[j]){ ll prevX = x; x = fill_in(k, x, prev-1, whitePoints[j], i); if (x == prevX){ ok = false; break; } done_i = true; } else{ if (!done_i){ x = fill_in(w, x, prev-1, whitePoints[j]); } else{ x = fill_in(k, x, prev-1, whitePoints[j]); } } prev = whitePoints[j]; } if (x >= k && ok) return true; } return false; } string solve_puzzle(string s, vi v) { c = v; ll n = sz(s); ll k = sz(c); vi whitePoints; for (ll i =0; i<n; i++){ if (s[i] == '_') whitePoints.pb(i); } whitePoints.pb(n); string ans; ans.resize(n); for (ll i =0; i<n; i++){ if (s[i] == '_'){ ans[i] = '_'; continue; } bool w = checkWhite(n,k,i,whitePoints); bool b = checkBlack(n,k,i,whitePoints); if (w && b) ans[i] = '?'; else if (w) ans[i] = '_'; else ans[i] = 'X'; // cout<<endl<<endl; } return ans; } /* ..._._.... 1 3 .._._..................... 2 1 19 ..........._._......................._...._........_._.___..........._.................. 2 1 19 _........_ 3 2 2 2 ....._. 2 2 2 .......... 3 1 3 2 */
#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...