제출 #643085

#제출 시각아이디문제언어결과실행 시간메모리
643085ddy888Paint By Numbers (IOI16_paint)C++17
32 / 100
0 ms212 KiB
// #include "paint.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops") using namespace std; using namespace __gnu_pbds; using ll = long long; #define pb push_back #define fi first #define si second #define ar array typedef pair<int,int> pi; typedef tuple<int,int,int> ti; template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} template<class key, class value = null_type, class cmp = less<key> > using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) const int MAXN = 200010; int n, m; int arr[MAXN], lo[MAXN], hi[MAXN]; // left endpoint vector<int> wc, bc; string solve_puzzle(std::string s, std::vector<int> c) { n = s.size(); m = c.size(); for (int i = 1; i <= m; ++i) arr[i] = c[i-1]; for (int i = 1; i <= n; ++i) { if (s[i-1] == 'X') bc.pb(i); else if (s[i-1] == '_') wc.pb(i); } vector<int> ori = wc; int ptr = 1; for (int i = 1; i <= m; ++i) { while (1) { auto near = lower_bound(wc.begin(), wc.end(), ptr); if (near != wc.end()) { if (*near <= ptr + arr[i] - 1) { ptr = *near + 1; } } lo[i] = ptr; break; } ptr += arr[i] + 1; } ptr = n - arr[m] + 1; for (int i = m; i >= 1; --i) { while (1) { auto near = lower_bound(wc.begin(), wc.end(), ptr); if (near != wc.end()) { if (*near <= ptr + arr[i] - 1) { ptr = *(--near); } } hi[i] = ptr; break; } ptr -= arr[i-1]; --ptr; } // for (int i = 1; i <= m; ++i) debug(lo[i], hi[i]); vector<pi> black, white; for (int i = 1; i <= m; ++i) { if (lo[i] == hi[i]) { black.pb({lo[i], lo[i]+arr[i]-1}); white.pb({lo[i]+arr[i], lo[i]+arr[i]}); } else { if (hi[i] <= lo[i] + arr[i] - 1) { black.pb({hi[i], lo[i] + arr[i] - 1}); } } } string ans = ""; for (int i = 0; i < n; ++i) ans += '?'; for (auto [l,r]: black) { for (int idx = l; idx <= r; ++ idx) if (idx <= n) ans[idx-1] = 'X'; } for (auto [l,r]: white) { for (int idx = l; idx <= r; ++ idx) if (idx <= n) ans[idx-1] = '_'; } for (int i = 0; i < n; ++i) if (ans[i] == '?' && s[i] != '.') ans[i] = s[i]; return ans; }
#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...