Submission #889175

#TimeUsernameProblemLanguageResultExecution timeMemory
889175AiperiiiPort Facility (JOI17_port_facility)C++14
10 / 100
6075 ms976 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; bool check(vector <vector <int> > v){ stack <int> st; for(auto x : v){ if(x[1]==0)st.push(x[2]); else{ if(st.size()!=0 && st.top()==x[2])st.pop(); else return false; } } return true; } signed main(){ ios_base::sync_with_stdio(); cin.tie(0); int n; cin>>n; vector <pair <int,int> > v(n); for(int i=0;i<n;i++){ cin>>v[i].ff>>v[i].ss; } int cnt=0; for(int i=0;i<(1<<n);i++){ vector <vector <int> > gr1,gr2; for(int j=0;j<n;j++){ if((i & (1<<j))!=0){ gr1.pb({v[j].ff,0,j}); gr1.pb({v[j].ss,1,j}); } else{ gr2.pb({v[j].ff,0,j}); gr2.pb({v[j].ss,1,j}); } } sort(all(gr1)); sort(all(gr2)); if(check(gr1) && check(gr2))cnt++; } cout<<cnt<<"\n"; } /* 0 2 1 0 4 2 0 6 3 1 5 1 1 7 3 1 8 2 0 2 1 1 5 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...