# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888360 | 2023-12-17T05:02:38 Z | 1075508020060209tc | Alternating Current (BOI18_alternating) | C++14 | 38 ms | 4564 KB |
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; int n;int m; pair<pair<int,int>,int>ar[500005]; int freq[500005]; int freq2[500005]; int ans[500005]; void chk(){ for(int i=1;i<=m;i++){ if(ans[ar[i].second]){ freq[ar[i].first.first]++; freq[ar[i].first.second+1]--; }else{ freq2[ar[i].first.first]++; freq2[ar[i].first.second+1]--; } } for(int i=1;i<=n;i++){ freq[i]+=freq[i-1]; freq2[i]+=freq2[i-1]; if(freq[i]==0||freq2[i]==0){ cout<<"impossible\n";exit(0); } } } signed main(){ cin>>n>>m; for(int i=1;i<=m;i++){ cin>>ar[i].first.first; cin>>ar[i].first.second; ar[i].second=i; } sort(ar+1,ar+m+1); int stx=0;int sty=0;int xrr=1; priority_queue<pair<int,int>>pq; for(int i=1;i<=m;i++){ if(ar[i].first.first<=stx+1&&ar[i].first.second<=sty){ stx=max(stx,ar[i].first.second); continue; } if(ar[i].first.second<=sty){continue;} if(ar[i].first.first>stx+1){ ans[ar[i].second]=1; sty=ar[i].first.second; continue; } pq.push({ar[i].first.second,ar[i].second}); if(pq.size()==2){ int r1=pq.top().first;int id1=pq.top().second; int r2=pq.top().first;int id2=pq.top().second; if(r1>sty){ sty=r1; stx=r2; ans[id2]=1; }else{ stx=r1; sty=r2; ans[id1]=1; } pq.pop(); pq.pop(); } } for(int i=1;i<=m;i++){ cout<<ans[i]; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 0 ms | 2396 KB | no wires in direction 0 between segments 12 and 12 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 0 ms | 2396 KB | no wires in direction 0 between segments 12 and 12 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 0 ms | 2396 KB | no wires in direction 0 between segments 12 and 12 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 4564 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 22 ms | 4544 KB | no wires in direction 1 between segments 1 and 1 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Incorrect | 0 ms | 2396 KB | no wires in direction 0 between segments 12 and 12 |
4 | Halted | 0 ms | 0 KB | - |