Submission #204464

#TimeUsernameProblemLanguageResultExecution timeMemory
20446414kg줄서기 (KOI17_line)C++11
100 / 100
287 ms22648 KiB
#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 (stderr)

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);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...