답안 #204464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204464 2020-02-25T19:58:17 Z 14kg 줄서기 (KOI17_line) C++11
100 / 100
287 ms 22648 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <functional>
#define N 100001

using namespace std;
int n, m, tm, ind[N], out[N];
int nn, tree[N*4];
vector<int> r[N];
priority_queue<int,vector<int>,greater<int> > Q;

int get(int lev, int l, int r, int x, int y){
    int mid=(l+r)/2;

    if(r<x || y<l) return 0;
    if(x<=l && r<=y) return tree[lev];
    return get(lev*2,l,mid,x,y)+get(lev*2+1,mid+1,r,x,y);
}
void update(int lev){
    tree[lev]++;
    if(lev>1) update(lev/2);
}
int main(){
    int m, x, y;

    scanf("%d %d",&n,&m);
    for(int i=1; i<=m; i++) {
        scanf("%d %d",&x,&y);
        r[y].push_back(x), ind[x]++;
    }

    for(int i=1; i<=n; i++)
        if(ind[i]==0) Q.push(i);

    for(int i=1; i<=n; i++){
        if(Q.empty()){ printf("-1"); return 0; }
        x=Q.top(), Q.pop();

        out[x]=i;
        for(vector<int>::iterator it=r[x].begin(); it!=r[x].end(); it++){
            ind[*it]--;
            if(ind[*it]==0) Q.push(*it);
        }
    }

    for(nn=1; nn<n; nn*=2);
    for(int i=n; i>=1; i--){
        tm+=get(1,1,nn,1,out[i]);
        update(nn+out[i]-1);
    }
    if(tm!=m){ printf("-1"); return 0; }
    for(int i=1; i<=n; i++) printf("%d ",out[i]);
}

Compilation message

line.cpp: In function 'int main()':
line.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
line.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 6 ms 2684 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 7 ms 2680 KB Output is correct
16 Correct 6 ms 2680 KB Output is correct
17 Correct 7 ms 2680 KB Output is correct
18 Correct 7 ms 2808 KB Output is correct
19 Correct 7 ms 2680 KB Output is correct
20 Correct 7 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 6 ms 2684 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 7 ms 2680 KB Output is correct
16 Correct 6 ms 2680 KB Output is correct
17 Correct 7 ms 2680 KB Output is correct
18 Correct 7 ms 2808 KB Output is correct
19 Correct 7 ms 2680 KB Output is correct
20 Correct 7 ms 2808 KB Output is correct
21 Correct 9 ms 2808 KB Output is correct
22 Correct 11 ms 2940 KB Output is correct
23 Correct 16 ms 3320 KB Output is correct
24 Correct 25 ms 3960 KB Output is correct
25 Correct 103 ms 9084 KB Output is correct
26 Correct 29 ms 4216 KB Output is correct
27 Correct 78 ms 7544 KB Output is correct
28 Correct 82 ms 8056 KB Output is correct
29 Correct 145 ms 12536 KB Output is correct
30 Correct 200 ms 16760 KB Output is correct
31 Correct 102 ms 8952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2680 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Correct 6 ms 2680 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 6 ms 2680 KB Output is correct
10 Correct 6 ms 2680 KB Output is correct
11 Correct 6 ms 2680 KB Output is correct
12 Correct 6 ms 2680 KB Output is correct
13 Correct 6 ms 2684 KB Output is correct
14 Correct 6 ms 2680 KB Output is correct
15 Correct 7 ms 2680 KB Output is correct
16 Correct 6 ms 2680 KB Output is correct
17 Correct 7 ms 2680 KB Output is correct
18 Correct 7 ms 2808 KB Output is correct
19 Correct 7 ms 2680 KB Output is correct
20 Correct 7 ms 2808 KB Output is correct
21 Correct 9 ms 2808 KB Output is correct
22 Correct 11 ms 2940 KB Output is correct
23 Correct 16 ms 3320 KB Output is correct
24 Correct 25 ms 3960 KB Output is correct
25 Correct 103 ms 9084 KB Output is correct
26 Correct 29 ms 4216 KB Output is correct
27 Correct 78 ms 7544 KB Output is correct
28 Correct 82 ms 8056 KB Output is correct
29 Correct 145 ms 12536 KB Output is correct
30 Correct 200 ms 16760 KB Output is correct
31 Correct 102 ms 8952 KB Output is correct
32 Correct 108 ms 9824 KB Output is correct
33 Correct 139 ms 11896 KB Output is correct
34 Correct 208 ms 16760 KB Output is correct
35 Correct 193 ms 15480 KB Output is correct
36 Correct 213 ms 17020 KB Output is correct
37 Correct 255 ms 20220 KB Output is correct
38 Correct 256 ms 20476 KB Output is correct
39 Correct 286 ms 22648 KB Output is correct
40 Correct 287 ms 22392 KB Output is correct