QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#879723#8940. Piggy SortfryanWA 1ms3712kbC++201.9kb2025-02-02 11:43:062025-02-02 11:43:08

Judging History

This is the latest submission verdict.

  • [2025-02-02 11:43:08]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3712kb
  • [2025-02-02 11:43:06]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define int long long

const int mxn = 505;

int n,m;
vector<vector<int>> x;
vector<int> su;
vector<pair<long double,int>> pt;
int pos[mxn];

void solve() {
	cin>>n>>m; x.resize(m); su.resize(m);
	for (int i=0; i<m; i++) {
		x[i].resize(n);
		su[i] = 0;
		for (int j=0; j<n; j++) {
			cin>>x[i][j];
			su[i] += x[i][j];
		}
		sort(all(x[i]));
	}
	
	int tr = 1;
	for (int i=1; i<m; i++) {
		for (int j=0; j<n; j++) {
			if (x[i-1][j] != x[i][j]) {
		//		cout<<x[i-1][j]<<" "<<x[i][j]<<"  ";
		//		cout<<i<<" "<<j<<"\n";
				tr = 0;
			}
		}
	}
	if (tr) {
		for (int i=1; i<=n; i++) {
			cout<<i<<" ";
		}
		cout<<"\n";
		return;
	}

	
	for (int i=0; i<n; i++) {
		int cx = x[0][0];
		int cy = su[0];
			
		int te = -69420;
		
		for (int nx : x[1]) {
			int ny = su[1];
			int ok=1;
//			cout<<cx<<" "<<cy<<"  "<<nx<<" "<<ny<<endl;
			for (int j=2; j<m; j++) {
				int y = su[j];
				int vv = (nx-cx)*(y-cy);
//				cout<<vv<<endl;
				if (vv%(ny-cy)==0) {
					vv/=(ny-cy);
					vv+=cx;
				} else {
					ok = 0;
					break;
				}
				if (binary_search(all(x[j]),vv)) {
					continue;
				} else {
					ok = 0;
				}
			}
			if (ok) {
				x[0].erase(find(all(x[0]),cx));
				te = nx;
				
				for (int j=2; j<m; j++) {
					int y = su[j];
					int vv = (nx-cx)*(y-cy)/(ny-cy);
					x[j].erase(lower_bound(all(x[j]),vv));
				}
				
				pt.push_back({(ny-cy)/1.0/(nx-cx),i});
				break;
			}
		}
	//	cout<<cx<<endl;
	//	cout<<te<<endl;
		x[1].erase(find(all(x[1]),te));
	}
	sort(all(pt));
	reverse(all(pt));
	for (int i=0; i<sz(pt); i++) {
		pos[pt[i].second] = i+1;
	}
	pt.clear();
	for (int i=0; i<n; i++) {
		cout<<pos[i]<<" ";
	}
	cout<<"\n";
	
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int t; cin>>t;
	while (t--) {
		solve();
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

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:

2 1 
1 
3 1 2 

result:

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