제출 #1129968

#제출 시각아이디문제언어결과실행 시간메모리
1129968LudisseyAlternating Current (BOI18_alternating)C++20
13 / 100
875 ms1114112 KiB
#include <bits/stdc++.h> #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; vector<pair<pair<int,int>,int>> edge; vector<vector<vector<vector<int>>>> memo; vector<vector<vector<vector<int>>>> place; int l=0; int n,m; bool dp(int i, int r, int l2, int r2){ if(memo[i][r][l2][r2]>-1) return memo[i][r][l2][r2]; if(i==m){ if(r-l>=n-1&&r2-l2>=n-1) return (memo[i][r][l2][r2]=1); return (memo[i][r][l2][r2]=0); } bool tk=false; bool ntk=false; if(edge[i].first.first-1<=r){ tk=dp(i+1,max(edge[i].first.second,r),l2,r2); } if(edge[i].first.first-1<=r2){ ntk=dp(i+1,r,l2,max(edge[i].first.second,r2)); } if(tk) place[i][r][l2][r2]=0; else if(ntk) place[i][r][l2][r2]=1; return max(tk,ntk); } vector<int> out; void prnt(int i, int r, int l2, int r2){ if(i>=m) return; out[edge[i].second]=place[i][r][l2][r2]; if(place[i][r][l2][r2]==0){ prnt(i+1,max(edge[i].first.second,r),l2,r2); }else{ prnt(i+1,r,l2,max(edge[i].first.second,r2)); } return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; edge.resize(m); out.resize(m); memo.resize(m+1,vector<vector<vector<int>>>(n*2,vector<vector<int>>(n*2,vector<int>(n*2,-1)))); place.resize(m+1,vector<vector<vector<int>>>(n*2,vector<vector<int>>(n*2,vector<int>(n*2,-1)))); for (int i = 0; i < m; i++) { int a,b; cin >> a >> b; a--; b--; if(b<a) b+=n; edge[i]={{a,b},i}; } sort(all(edge)); l=edge[0].first.first; int r=edge[0].first.second; for (int i = 1; i < m; i++) { if(edge[i-1].first.first-1<=r) r=max(edge[i-1].first.second,r); if(dp(i+1,r,edge[i].first.first,edge[i].first.second)){ for (int j = 0; j < i; j++) out[edge[j].second]=0; out[edge[i].second]=1; prnt(i+1,r,edge[i].first.first,edge[i].first.second); for (int j = 0; j < m; j++) cout << out[j]; cout << "\n"; return 0; } } cout << "impossible\n"; return 0; }
#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...