QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#879726 | #8940. Piggy Sort | fryan | WA | 1ms | 3712kb | C++20 | 1.9kb | 2025-02-02 11:44:59 | 2025-02-02 11:45:05 |
Judging History
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: 100
Accepted
time: 0ms
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:
1 2 1 3 1 2
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3712kb
input:
41 1 2 -19 9531 2 3 11 13 3175 4759 2211 3313 10 19 -54 -25 -19 -18 -1 3 61 63 85 88 -54 753 863 2397 3111 4649 4671 4756 5507 7762 -54 369 479 1245 1575 2345 2367 2452 2819 3922 -54 553 663 1797 2311 3449 3471 3556 4107 5762 -54 87 197 399 447 653 675 760 845 1102 -54 320 430 1098 1379 2051 2073 21...
output:
1 1 2 1 2 0 0 0 0 0 0 0 0 3 2 1 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 3 2 1 4 0 0 0 0 2 1 1 4 0 0 0 0 0 0 2 3 1 4 3 2 4 1 0 0 0 0 0 1 2 4 1 0 0 0 0 0 5 4 2 3 1 0 0 0 0 1 4 2 3 1 0 0 0 0 0 2 1 2 3 1 0 0 0 0 0 1 1 2 3 1 0 0 0 0 4 1 2 3 1 0 0 0 0 2 1 2 3 1 0 0 0 0 0 3 2 1...
result:
wrong answer 3rd lines differ - expected: '1 2 6 10 5 7 9 4 3 8', found: '1 2 0 0 0 0 0 0 0 0 '