QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#541815 | #8940. Piggy Sort | ucup-team3734# | WA | 0ms | 3616kb | C++23 | 2.0kb | 2024-08-31 20:59:49 | 2024-08-31 20:59:50 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(), (x).end()
const int M = 505;
const ld eps = 1e-9;
int n, m;
vector<int> x[M];
ll s[M];
void read() {
cin >> n >> m;
for (int i = 0; i < m; ++i) {
x[i].resize(n);
for (int j = 0; j < n; ++j) {
cin >> x[i][j];
}
}
fill(s, s + m, 0);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j)
s[i] += x[i][j];
}
}
bool check(ll x0, ll x1, int k) {
ll t0 = s[0];
ll t1 = s[1];
ll tk = s[k];
ll pos = (x1 - x0) * (tk - t0);
if (pos % (t1 - t0) != 0)
return false;
pos /= t1 - t0;
pos += x0;
// ld v = ld(x1 - x0) / ld(t1 - t0);
// ld pos = x0 + v * (tk - t0);
for (int j = 0; j < n; ++j)
// if (fabs(x[k][j] - pos) < eps)
if (x[k][j] == eps)
return true;
return false;
}
void solve() {
vector<int> ans(n, -1);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
bool ok = true;
for (int k = 2; k < m; ++k) {
ok &= check(x[0][i], x[1][j], k);
if (!ok)
break;
}
if (ok)
ans[i] = j;
}
// if (ans[i] == -1)
// cerr << "HUI\n";
}
// for (int i = 0; i < n; ++i)
// cerr << ans[i] << " ";
// cerr << "\n";
vector<ld> vs(n);
for (int i = 0; i < n; ++i) {
vs[i] = ld(x[1][ans[i]] - x[0][i]) / ld(s[1] - s[0]);
}
vector<int> perm(n);
iota(all(perm), 0);
sort(all(perm), [&](int i, int j) -> bool {
return make_pair(vs[i], x[0][i]) < make_pair(vs[j], x[0][j]);
});
vector<int> q(n);
for (int i = 0; i < n; ++i)
q[perm[i]] = i;
for (int i = 0; i < n; ++i)
cout << q[i] + 1 << " ";
cout << "\n";
}
int main() {
#ifndef ONLINE_JUDGE
freopen("i.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
read();
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
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 2 1
result:
wrong answer 1st lines differ - expected: '1 2', found: '2 1 '