제출 #96906

#제출 시각아이디문제언어결과실행 시간메모리
96906liwiPaint By Numbers (IOI16_paint)C++11
59 / 100
18 ms768 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; #define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0) char _; #define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end()) #define all(a) a.begin(),a.end() #define println printf("\n"); #define readln(x) getline(cin,x); #define pb push_back #define endl "\n" #define INT_INF 0x3f3f3f3f #define LL_INF 0x3f3f3f3f3f3f3f3f #define MOD 1000000007 #define mp make_pair #define fastio cin.tie(0); cin.sync_with_stdio(0); #define MAXN 200005 #define MAXK 101 typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unordered_map<int,int> umii; typedef pair<int,int> pii; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef pair<int,pii> triple; typedef int8_t byte; mt19937 g1; int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);} ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);} ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);} ll lcm(ll a, ll b){return a*b/gcd(a,b);} ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;} ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;} int len,psa[MAXN],test[MAXK]={3},need[MAXN]; string res; bool forw[MAXN][MAXK],backw[MAXN][MAXK],white[MAXN],eforr[MAXN][MAXK]; bitset<MAXN> blocks[MAXK],possible; inline void print(bitset<MAXN> &possible){ for(int i=1; i<=len; i++) printf("%d",possible[i]?1:0); println; } string solve_puzzle(string s, vector<int> c){ int K = c.size(); res = ""; // possible.reset(); // memset(forw,0,sizeof forw); // memset(backw,0,sizeof backw); // memset(white,0,sizeof white); len = (int)s.size(); for(int i=1; i<=s.size(); i++){ psa[i] = psa[i-1]+(s[i-1]=='X'||s[i-1]=='.'); need[i] = need[i-1]+(s[i-1]=='X'); } for(int i=1; i<=K; i++){ // blocks[i].reset(); for(int k=1; k<=c[i-1]; k++) blocks[i][k] = true; // print(blocks[i]); } forw[0][0] = backw[s.size()+1][0] = true; for(int i=1; i<=s.size(); i++){ forw[i][0] = need[i]==0; if(i == 9){ // printf("\n"); } for(int k=1; k<=K; k++){ if(!(i == c[k-1] && k == 1) && i-c[k-1]-1 < 0) continue; forw[i][k] = forw[i-1][k]; int cur_len = c[k-1], valid = (psa[i]-psa[i-cur_len])==cur_len; if(valid && ((k == 1 && need[i-cur_len] == 0) || (k != 1 && i > cur_len && s[i-cur_len-1] != 'X' && forw[i-cur_len-1][k-1]))){ forw[i][k] = eforr[i][k] = true; // possible|=(blocks[k]<<(i-cur_len)); // print(blocks[k]); // print(possible); } } } for(int i=(int)s.size(); i>=1; i--){ backw[i][0] = need[len]-need[i-1]==0; if(i == 7){ // printf("\n"); } for(int k=1; k<=K; k++){ if(!(i+c[K-k]-1 <= s.size() && k == 1) && i+c[K-k]+1 > s.size()) continue; backw[i][k] = backw[i+1][k]; int idx = K-k+1, cur_len = c[idx-1], valid = (psa[i+cur_len-1]-psa[i-1])==cur_len; if(valid && ((k == 1 && (i+cur_len > len || need[len]-need[i+cur_len-1] == 0)) || (k != 1 && s.size()-i+1 > cur_len && s[i+cur_len-1] != 'X' && backw[i+cur_len+1][k-1]))){ backw[i][k] = true; if(i >= 2 && s[i-2] != 'X' && forw[i-2][K-k]){ if(i == 4){ // printf("\n"); } // print(blocks[idx]); possible|=(blocks[idx]<<(i-1)); // print(possible); if(possible[4]){ // printf("\n"); } } } } } for(int i=(int)s.size(); i>=1; i--) for(int k=1; k<=K; k++) backw[i][k]|=backw[i+1][k]; for(int i=1; i<=s.size(); i++){ for(int k=1; k<=K;k ++){ if(eforr[i][k] && ((i==s.size() && k == K) || (s[i] != 'X' && backw[i+2][K-k]))){ possible|=(blocks[k]<<(i-c[k-1])); // print(possible); if(possible[9]){ // printf("\n"); } } } } for(int i=1; i<=s.size(); i++) for(int k=1; k<=K; k++) forw[i][k]|=forw[i-1][k]; for(int i=1; i<=s.size(); i++){ if(i == 5){ // printf("\n"); } for(int k=0; k<=K; k++){ bool can_white = s[i-1]!='X'&&forw[i-1][k]&&backw[i+1][K-k]; // if(k == 0) can_white = s[i-1]!='X'&&(need[i-1]==0)&&backw[i+1][K-k]; // else if(k == K) can_white = s[i-1]!='X'&&forw[i-1][k]&&(need[len]-need[i]==0); if(can_white){ white[i] = true; break; } } } for(int i=1; i<=s.size(); i++){ if(possible[i] && white[i]) res+="?"; else if(possible[i]) res+="X"; else res+="_"; } return res; }

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

paint.cpp: In function 'std::__cxx11::string solve_puzzle(std::__cxx11::string, std::vector<int>)':
paint.cpp:65:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=s.size(); i++){
                  ~^~~~~~~~~~
paint.cpp:76:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=s.size(); i++){
                  ~^~~~~~~~~~
paint.cpp:99:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(!(i+c[K-k]-1 <= s.size() && k == 1) && i+c[K-k]+1 > s.size()) continue;
                  ~~~~~~~~~~~^~~~~~~~~~~
paint.cpp:99:66: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(!(i+c[K-k]-1 <= s.size() && k == 1) && i+c[K-k]+1 > s.size()) continue;
                                                       ~~~~~~~~~~~^~~~~~~~~~
paint.cpp:102:119: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(valid && ((k == 1 && (i+cur_len > len || need[len]-need[i+cur_len-1] == 0)) || (k != 1 && s.size()-i+1 > cur_len && s[i+cur_len-1] != 'X' && backw[i+cur_len+1][k-1]))){
                                                                                                          ~~~~~~~~~~~~~^~~~~~~~~
paint.cpp:121:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=s.size(); i++){
                  ~^~~~~~~~~~
paint.cpp:123:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(eforr[i][k] && ((i==s.size() && k == K) || (s[i] != 'X' && backw[i+2][K-k]))){
                                 ~^~~~~~~~~~
paint.cpp:132:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=s.size(); i++)
                  ~^~~~~~~~~~
paint.cpp:135:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=s.size(); i++){
                  ~^~~~~~~~~~
paint.cpp:149:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<=s.size(); i++){
                  ~^~~~~~~~~~
#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...