QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398009#3756. 字典序xlwangAC ✓89ms35256kbC++141.9kb2024-04-24 21:07:072024-04-24 21:07:07

Judging History

This is the latest submission verdict.

  • [2024-04-24 21:07:07]
  • Judged
  • Verdict: AC
  • Time: 89ms
  • Memory: 35256kb
  • [2024-04-24 21:07:07]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
int n,m;
const int Maxn=2e3+10;
int a[Maxn][Maxn];
vector<int> vc[Maxn];
int vis[Maxn];
int d[Maxn];
priority_queue<int,vector<int> ,greater<int> > q;
vector<int> ans;
inline void work(){
    vector<int> ().swap(ans);
    while(!q.empty()) q.pop();
    fr(i,1,n) fr(j,1,m) a[i][j]=read();
    fr(i,1,n) vc[i].clear();
    fr(i,1,m) d[i]=0;
    fr(i,2,n) vis[i]=0;
    fr(j,1,m) fr(i,2,n) if(a[i][j]<a[i-1][j]) ++d[j],vc[i].push_back(j);
    fr(i,1,m) if(!d[i]) q.push(i);
    while(!q.empty()){
        int x=q.top();q.pop();ans.push_back(x);
        fr(i,2,n) if(a[i][x]>a[i-1][x] && !vis[i]){
            vis[i]=1;
            for(auto y:vc[i]){
                --d[y];if(d[y]==0) q.push(y);
            }
        }
    }
    if(ans.size()!=m){
        writeln(-1);
        return;
    }
    for(auto x:ans) writepl(x);puts("");
}
inline void init(){
    while(cin>>n>>m) work();
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 89ms
memory: 35256kb

input:

8 3
6 1 2
3 2 2
7 2 2
7 2 2
7 2 2
9 2 2
10 2 2
4 10 2
6 2
3 1
3 4
3 4
3 7
3 7
3 8
7 7
1 3 3 2 6 3 3
1 3 3 2 6 3 3
1 3 3 2 6 3 3
6 3 3 2 1 4 3
6 3 3 2 4 4 3
7 2 4 2 4 10 6
7 3 4 10 4 3 3
4 3
2 3 9
2 4 9
2 4 9
2 4 9
8 10
9 6 6 3 6 10 1 8 2 5
9 6 6 3 6 10 1 9 2 5
5 3 8 6 7 2 1 7 2 10
5 10 8 7 4 7 1 4 8...

output:

2 1 3 
1 2 
1 2 3 4 5 6 7 
1 2 3 
7 3 1 2 4 5 6 8 9 10 
3 2 1 4 5 
1 3 2 4 5 6 7 8 9 
1 2 3 4 5 6 
1 2 3 4 5 6 
2 1 3 4 5 6 
6 4 3 5 1 2 7 8 9 10 
1 
2 1 
2 4 6 7 1 3 5 8 
1 2 
2 1 
1 2 3 
1 
9 4 3 5 1 2 6 7 8 10 
1 2 3 
1 
3 4 2 1 5 6 
1 3 4 5 6 7 2 8 9 
2 1 3 4 
1 2 3 4 6 5 
5 1 2 4 3 6 7 8 9 
1 2...

result:

ok 110618 tokens