Submission #496165

#TimeUsernameProblemLanguageResultExecution timeMemory
496165asandikciSlagalica (COCI19_slagalica2)C++17
10 / 70
66 ms7740 KiB
#include"iostream" #include"vector" // #include"queue" // #include"deque" #include"set" // #include"map" #include"algorithm" // #include"iomanip" // #include"cstring" // #include"cmath" // #include"bitset" #define int long long using namespace std; const int INF=1e9; const int maxn=1e5; int sbmp=0,ebmp=0; set<int> st[7]; bool check(int a,int b,int c,int d){ if(a<0 || b<0 || c<0 || d<0){return 0;} if(a==0 && b==0 && c==0 && d==0){return 1;} // cout << a << " " << b << " " << c <<" " << d << "\n"; if(sbmp==1 && ebmp==0){ // cout << "asd?"; if(a==d){ if(a==0 && b!=0){ return 0; } else{ return 1; } } return 0; } if(sbmp==0 && ebmp==1){ if(a==d){ if(a==0 && c!=0){ return 0; } else{ return 1; } } return 0; } if(sbmp==1 && ebmp==1){ if(a==d-1){ return 1; } return 0; } if(sbmp==0 && ebmp==0){ // cout << a << " " << b << " " << c <<" " << d << "\n"; if(d==a-1){ return 1; } return 0; } cout << "wha?"; return 0; } void solve(){ int n,a,b; cin >> n; pair<int,int> start,end; for(int i=0;i<n;i++){ cin >> a >> b; if(a<=4) st[a].insert(b); else if(a<=6) start={a,b}; else if(a<=8) end={a,b}; } // for(int i=0;i<5;i++){ // cout << st[i].size() << "\n"; // } if(start.first==5){ sbmp=1; } if(end.first==7){ ebmp=1; } vector<int> ans; for(int i=1;i<n-1;i++){ int mini=1e9; int mininum=0; sbmp=1; if(check(st[1].size()-1,st[2].size(),st[3].size(),st[4].size())){ mini = min(mini,*(st[1].begin())); mininum=1; } sbmp=0; if(check(st[1].size(),st[2].size()-1,st[3].size(),st[4].size())){ mini = min(mini,*(st[2].begin())); mininum=2; } sbmp=1; if(check(st[1].size(),st[2].size(),st[3].size()-1,st[4].size())){ mini = min(mini,*(st[3].begin())); mininum=3; } sbmp=0; if(check(st[1].size(),st[2].size(),st[3].size(),st[4].size()-1)){ mini = min(mini,*(st[4].begin())); mininum=4; } ans.push_back(mini); if(mini==1e9){cout << "-1";return;} if(mininum==1 || mininum==3){sbmp=1;} if(mininum==2 || mininum==4){sbmp=0;} st[mininum].erase(*(st[mininum].begin())); // cout << "\n"; } cout << start.second << " "; for(auto it : ans){ cout << it << " "; } cout << end.second << " "; // for(int i=0;i<5;i++){ // cout << st[i].size() << "\n"; // } } signed main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("","r",stdin);freopen("","w",stdout); int t=1; // cin >> t; for(int i=1;i<=t;i++){ // cout << "Case " << i << ":\n"; solve(); // cout <<"\n\n"; } }
#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...
#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...