제출 #1129044

#제출 시각아이디문제언어결과실행 시간메모리
1129044LudisseyAlternating Current (BOI18_alternating)C++20
0 / 100
36 ms9144 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;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n,m; cin >> n >> m;
    vector<pair<pair<int,int>,int>> edge1(m);
    vector<pair<int,int>> edge(m);
    vector<bool> c(m);
    vector<pair<int,int>> furthest(n+1, {-1,-1});
    for (int i = 0; i < m; i++)
    {
        int a,b; cin >> a >> b;
        edge1[i]={{a,b},i};
    }
    sort(all(edge1));
    for (int i = 0; i < m; i++)
    {
        edge[i]={edge1[i].first.first,edge1[i].first.second};
    }
    priority_queue<pair<pair<int,int>,int>> pq;
    int j=0;
    for (int i = 0; i <= n; i++)
    {
        while(j<sz(edge)&&edge[j].first-1<=i){
            pq.push({{edge[j].first,edge[j].second},j});
            j++;
        }
        while(!pq.empty()&&pq.top().first.second<=i){
            pq.pop();
        }
        if(!pq.empty()) furthest[i]={pq.top().first.second, pq.top().second};
    }
    int e=0;
    while(e!=n){
        if(furthest[e].first==-1) break;
        c[edge1[furthest[e].second].second]=1;
        e=furthest[e].first;
    }
    bool b=(e==n);
    e=0;
    for (int i = 0; i < m; i++)
    {
        if(c[edge1[i].second]==1) continue;
        if(e>=edge[i].first-1) e=edge[i].second;
    }
    b=(e==n);
    if(b==false) cout << "impossible\n";
    else{
        for (int i = 0; i < m; i++)
        {
            cout << c[i];
        }
        cout << "\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...