답안 #63267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63267 2018-08-01T07:49:57 Z 노영훈(#1832) Alternating Current (BOI18_alternating) C++11
32 / 100
69 ms 3640 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n, m;
struct line{
    int s, e, ans=-1, idx;
    void scan(){
        cin>>s>>e;
    }
    bool operator < (const line &l) const {
        return s<l.s || (s==l.s && e>l.e);
    }
} L[MX];

bool solve(){
    bool done[MX][2]={};


    priority_queue<pii> Q;
    for(int i=1, frt=0; i<=n; i++){
        while(frt<m && L[frt+1].s<=i) frt++, Q.push({L[frt].e, frt});
        for(int j=0; j<=1; j++){
            if(done[i][j]) continue;
            while(!Q.empty() && Q.top().first<i) Q.pop();
            if(Q.empty()) return false;
            int e,idx; tie(e,idx)=Q.top(); Q.pop();
            for(int x=i; x<=e; x++) done[x][j]=true;
            L[idx].ans=j;
        }
    }
    return true;
}

bool check(int s){
    bool fill[20][2]={};
    for(int i=1; i<=m; i++)
        for(int ii=L[i].s; ii<=(L[i].s<=L[i].e ? L[i].e : L[i].e+n); ii++){
            int t=!!(s&(1<<(i-1)));
            fill[(ii-1)%n+1][t]=true;
        }
    for(int i=1; i<=n; i++) if(!fill[i][0] || !fill[i][1]) return false;
    return true;
}

void solve1(){
    for(int i=0; i<(1<<m); i++){
        if(check(i)){
            for(int j=1; j<=m; j++) cout<<!!(i&(1<<(j-1)));
            exit(0);
        }
    }
    cout<<"impossible\n";
    exit(0);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=1; i<=m; i++) L[i].scan(), L[i].idx=i;
    if(n<=15 && m<=15) solve1();
    sort(L+1, L+m+1);
    if(!solve()){ cout<<"impossible\n"; return 0; }
    sort(L+1, L+m+1, [](line &a, line &b){ return a.idx<b.idx; });
    for(int i=1; i<=m; i++) cout<<max(L[i].ans, 0);
    cout<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1912 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1948 KB Output is correct
4 Correct 3 ms 2028 KB Output is correct
5 Correct 3 ms 2080 KB Output is correct
6 Correct 5 ms 2080 KB Output is correct
7 Correct 4 ms 2096 KB Output is correct
8 Correct 4 ms 2152 KB Output is correct
9 Correct 5 ms 2152 KB Output is correct
10 Correct 4 ms 2152 KB Output is correct
11 Correct 4 ms 2152 KB Output is correct
12 Correct 4 ms 2152 KB Output is correct
13 Correct 5 ms 2152 KB Output is correct
14 Correct 4 ms 2152 KB Output is correct
15 Correct 4 ms 2152 KB Output is correct
16 Correct 4 ms 2152 KB Output is correct
17 Correct 4 ms 2160 KB Output is correct
18 Correct 5 ms 2160 KB Output is correct
19 Correct 4 ms 2160 KB Output is correct
20 Correct 4 ms 2160 KB Output is correct
21 Correct 4 ms 2160 KB Output is correct
22 Correct 4 ms 2160 KB Output is correct
23 Correct 3 ms 2160 KB Output is correct
24 Correct 4 ms 2160 KB Output is correct
25 Correct 4 ms 2160 KB Output is correct
26 Correct 4 ms 2160 KB Output is correct
27 Correct 5 ms 2160 KB Output is correct
28 Correct 4 ms 2160 KB Output is correct
29 Correct 4 ms 2160 KB Output is correct
30 Correct 5 ms 2160 KB Output is correct
31 Correct 4 ms 2160 KB Output is correct
32 Correct 3 ms 2160 KB Output is correct
33 Correct 4 ms 2160 KB Output is correct
34 Correct 5 ms 2160 KB Output is correct
35 Correct 15 ms 2160 KB Output is correct
36 Correct 5 ms 2160 KB Output is correct
37 Correct 4 ms 2160 KB Output is correct
38 Correct 13 ms 2160 KB Output is correct
39 Correct 4 ms 2160 KB Output is correct
40 Correct 3 ms 2212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1912 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1948 KB Output is correct
4 Correct 3 ms 2028 KB Output is correct
5 Correct 3 ms 2080 KB Output is correct
6 Correct 5 ms 2080 KB Output is correct
7 Correct 4 ms 2096 KB Output is correct
8 Correct 4 ms 2152 KB Output is correct
9 Correct 5 ms 2152 KB Output is correct
10 Correct 4 ms 2152 KB Output is correct
11 Correct 4 ms 2152 KB Output is correct
12 Correct 4 ms 2152 KB Output is correct
13 Correct 5 ms 2152 KB Output is correct
14 Correct 4 ms 2152 KB Output is correct
15 Correct 4 ms 2152 KB Output is correct
16 Correct 4 ms 2152 KB Output is correct
17 Correct 4 ms 2160 KB Output is correct
18 Correct 5 ms 2160 KB Output is correct
19 Correct 4 ms 2160 KB Output is correct
20 Correct 4 ms 2160 KB Output is correct
21 Correct 4 ms 2160 KB Output is correct
22 Correct 4 ms 2160 KB Output is correct
23 Correct 3 ms 2160 KB Output is correct
24 Correct 4 ms 2160 KB Output is correct
25 Correct 4 ms 2160 KB Output is correct
26 Correct 4 ms 2160 KB Output is correct
27 Correct 5 ms 2160 KB Output is correct
28 Correct 4 ms 2160 KB Output is correct
29 Correct 4 ms 2160 KB Output is correct
30 Correct 5 ms 2160 KB Output is correct
31 Correct 4 ms 2160 KB Output is correct
32 Correct 3 ms 2160 KB Output is correct
33 Correct 4 ms 2160 KB Output is correct
34 Correct 5 ms 2160 KB Output is correct
35 Correct 15 ms 2160 KB Output is correct
36 Correct 5 ms 2160 KB Output is correct
37 Correct 4 ms 2160 KB Output is correct
38 Correct 13 ms 2160 KB Output is correct
39 Correct 4 ms 2160 KB Output is correct
40 Correct 3 ms 2212 KB Output is correct
41 Correct 4 ms 2284 KB Output is correct
42 Incorrect 4 ms 2284 KB 'impossible' claimed, but there is a solution
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1912 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1948 KB Output is correct
4 Correct 3 ms 2028 KB Output is correct
5 Correct 3 ms 2080 KB Output is correct
6 Correct 5 ms 2080 KB Output is correct
7 Correct 4 ms 2096 KB Output is correct
8 Correct 4 ms 2152 KB Output is correct
9 Correct 5 ms 2152 KB Output is correct
10 Correct 4 ms 2152 KB Output is correct
11 Correct 4 ms 2152 KB Output is correct
12 Correct 4 ms 2152 KB Output is correct
13 Correct 5 ms 2152 KB Output is correct
14 Correct 4 ms 2152 KB Output is correct
15 Correct 4 ms 2152 KB Output is correct
16 Correct 4 ms 2152 KB Output is correct
17 Correct 4 ms 2160 KB Output is correct
18 Correct 5 ms 2160 KB Output is correct
19 Correct 4 ms 2160 KB Output is correct
20 Correct 4 ms 2160 KB Output is correct
21 Correct 4 ms 2160 KB Output is correct
22 Correct 4 ms 2160 KB Output is correct
23 Correct 3 ms 2160 KB Output is correct
24 Correct 4 ms 2160 KB Output is correct
25 Correct 4 ms 2160 KB Output is correct
26 Correct 4 ms 2160 KB Output is correct
27 Correct 5 ms 2160 KB Output is correct
28 Correct 4 ms 2160 KB Output is correct
29 Correct 4 ms 2160 KB Output is correct
30 Correct 5 ms 2160 KB Output is correct
31 Correct 4 ms 2160 KB Output is correct
32 Correct 3 ms 2160 KB Output is correct
33 Correct 4 ms 2160 KB Output is correct
34 Correct 5 ms 2160 KB Output is correct
35 Correct 15 ms 2160 KB Output is correct
36 Correct 5 ms 2160 KB Output is correct
37 Correct 4 ms 2160 KB Output is correct
38 Correct 13 ms 2160 KB Output is correct
39 Correct 4 ms 2160 KB Output is correct
40 Correct 3 ms 2212 KB Output is correct
41 Correct 4 ms 2284 KB Output is correct
42 Incorrect 4 ms 2284 KB 'impossible' claimed, but there is a solution
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 3432 KB Output is correct
2 Correct 4 ms 3432 KB Output is correct
3 Correct 18 ms 3432 KB Output is correct
4 Correct 26 ms 3432 KB Output is correct
5 Correct 53 ms 3432 KB Output is correct
6 Correct 40 ms 3432 KB Output is correct
7 Correct 50 ms 3432 KB Output is correct
8 Correct 6 ms 3432 KB Output is correct
9 Correct 6 ms 3432 KB Output is correct
10 Correct 67 ms 3432 KB Output is correct
11 Correct 43 ms 3432 KB Output is correct
12 Correct 43 ms 3432 KB Output is correct
13 Correct 5 ms 3432 KB Output is correct
14 Correct 5 ms 3432 KB Output is correct
15 Correct 65 ms 3588 KB Output is correct
16 Correct 25 ms 3588 KB Output is correct
17 Correct 69 ms 3588 KB Output is correct
18 Correct 62 ms 3640 KB Output is correct
19 Correct 8 ms 3640 KB Output is correct
20 Correct 52 ms 3640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1912 KB Output is correct
2 Correct 3 ms 1912 KB Output is correct
3 Correct 3 ms 1948 KB Output is correct
4 Correct 3 ms 2028 KB Output is correct
5 Correct 3 ms 2080 KB Output is correct
6 Correct 5 ms 2080 KB Output is correct
7 Correct 4 ms 2096 KB Output is correct
8 Correct 4 ms 2152 KB Output is correct
9 Correct 5 ms 2152 KB Output is correct
10 Correct 4 ms 2152 KB Output is correct
11 Correct 4 ms 2152 KB Output is correct
12 Correct 4 ms 2152 KB Output is correct
13 Correct 5 ms 2152 KB Output is correct
14 Correct 4 ms 2152 KB Output is correct
15 Correct 4 ms 2152 KB Output is correct
16 Correct 4 ms 2152 KB Output is correct
17 Correct 4 ms 2160 KB Output is correct
18 Correct 5 ms 2160 KB Output is correct
19 Correct 4 ms 2160 KB Output is correct
20 Correct 4 ms 2160 KB Output is correct
21 Correct 4 ms 2160 KB Output is correct
22 Correct 4 ms 2160 KB Output is correct
23 Correct 3 ms 2160 KB Output is correct
24 Correct 4 ms 2160 KB Output is correct
25 Correct 4 ms 2160 KB Output is correct
26 Correct 4 ms 2160 KB Output is correct
27 Correct 5 ms 2160 KB Output is correct
28 Correct 4 ms 2160 KB Output is correct
29 Correct 4 ms 2160 KB Output is correct
30 Correct 5 ms 2160 KB Output is correct
31 Correct 4 ms 2160 KB Output is correct
32 Correct 3 ms 2160 KB Output is correct
33 Correct 4 ms 2160 KB Output is correct
34 Correct 5 ms 2160 KB Output is correct
35 Correct 15 ms 2160 KB Output is correct
36 Correct 5 ms 2160 KB Output is correct
37 Correct 4 ms 2160 KB Output is correct
38 Correct 13 ms 2160 KB Output is correct
39 Correct 4 ms 2160 KB Output is correct
40 Correct 3 ms 2212 KB Output is correct
41 Correct 4 ms 2284 KB Output is correct
42 Incorrect 4 ms 2284 KB 'impossible' claimed, but there is a solution
43 Halted 0 ms 0 KB -