QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#562767#8940. Piggy SortyyyyxhWA 0ms3808kbC++231.7kb2024-09-13 20:41:432024-09-13 20:41:43

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 20:41:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-09-13 20:41:43]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>
#define ALL(vc) (vc).begin(),(vc).end()
using namespace std;
int read(){
	char c=getchar();int x=0;bool f=0;
	while(c<48||c>57) f|=(c=='-'),c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	if(f) return -x;
	return x;
}
const int N=503;
typedef long long ll;
typedef vector<int> vi;
int n,m;
vi a[N],b;
ll s[N];
vi::iterator ps[N];
struct node{
	int a;ll b;int x;
	friend bool operator<(const node u,const node v){
		ll dlt=u.a*v.b-u.b*v.a;
		if(dlt<0) return 1;
		if(dlt>0) return 0;
		return u.x<v.x;
	}
}w[N];
int res[N];
void solve(){
	n=read();m=read();
	for(int i=0;i<m;++i){
		a[i].resize(n);
		for(int j=0;j<n;++j) a[i][j]=read();
	}
	sort(a,a+m,[](vi u,vi v){return accumulate(ALL(u),0ll)<accumulate(ALL(v),0ll);});
	b=a[0];
	for(int i=0;i<m;++i) s[i]=accumulate(ALL(a[i]),0ll);
	for(int i=1;i<m;++i) s[i]-=s[0];
	s[0]=0;
	for(int i=1;i<m;++i)
		if(s[i]==s[i-1]){
			for(int x=1;x<=n;++x) printf("%d ",x);
			return;
		}
	for(int it=0;it<n;++it){
		for(int i=1;i<m;++i){
			bool fl=1;
			for(int x=0;x<m;++x){
				ll cur=(ll)(a[i].back()-a[i-1].back())*(s[x]-s[i]);
				if(cur%(s[i]-s[i-1])){fl=0;break;}
				cur=a[i].back()+cur/(s[i]-s[i-1]);
				ps[x]=lower_bound(ALL(a[x]),cur);
				if(ps[x]==a[x].end()||*ps[x]!=cur){fl=0;break;}
			}
			if(fl){
				w[it].a=a[i].back()-a[i-1].back();
				w[it].b=s[i]-s[i-1];
				w[it].x=lower_bound(ALL(b),*ps[0])-b.begin();
				for(int x=0;x<m;++x) a[x].erase(ps[x]);
				break;
			}
		}
	}
	sort(w,w+n);
	for(int i=0;i<n;++i) res[w[i].x]=i+1;
	for(int i=0;i<n;++i) printf("%d ",res[i]);
	putchar('\n');
}
int main(){
	int tc=read();
	while(tc--) solve();
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3808kb

input:

3
2 4
1 2
3 4
5 6
7 8
1 2
1
1
3 4
1 2 3
6 9 9
10 15 17
12 18 21

output:

1 2 
1 3 1 2 

result:

wrong answer 2nd lines differ - expected: '1', found: '1 3 1 2 '