QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#542879 | #8940. Piggy Sort | ucup-team3695# | RE | 1ms | 3580kb | C++14 | 2.7kb | 2024-09-01 06:46:57 | 2024-09-01 06:47:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define MAXN 510
int a[MAXN][MAXN];
bool taken[MAXN][MAXN];
float times[MAXN];
float velocity[MAXN];
map<int, vi> posmap[MAXN];
pair<pair<float, int>, int> dataa[MAXN];
int out[MAXN];
const float eps = 1e-8;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
srand(130481);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
rep(i, 0, n) velocity[i] = -1;
rep(i, 0, m) posmap[i].clear();
rep(i, 0, m) rep(j, 0, n) {
cin >> a[i][j];
posmap[i][a[i][j]].pb(j);
taken[i][j] = false;
}
ll basedisplacement = 0;
rep(j, 0, n) basedisplacement += a[1][j] - a[0][j];
//cout << basedisplacement << endl;
if (basedisplacement == 0) {
rep(i, 0, n) cout << i+1 << ' ';
cout << '\n';
continue;
}
times[0] = 0;
times[1] = 1;
rep(i, 2, m) {
ll displacement = 0;
rep(j, 0, n) displacement += a[i][j] - a[0][j];
times[i] = displacement / float(basedisplacement);
}
//rep(_, 0, n) {
rep(pig, 0, n) {
if (taken[0][pig]) continue;
vector<float> speeds;
rep(j, 0, n) {
float cand = a[1][j] - a[0][pig];
//cerr << "candidate " << cand << endl;
int kills = 1;
bool ok = true;
rep(i, 1, m) {
float neededpos = a[0][pig] + cand*times[i];
int need = round(neededpos);
if (fabs(need-neededpos) > eps) ok = false;
//cerr << "needed pos " << need << endl;
for (int x : posmap[i][need]) {
//cerr << "look at " << x << endl;
if (!taken[i][x]) {
kills++;
break;
}
}
}
if (kills != m) ok = false;
if (ok) speeds.pb(cand);
}
if (speeds.empty()) {
cerr << "bad" << endl;
return 1;
}
bool last = true;
rep(i, pig+1, n) if (velocity[i] != -1) last = false;
if (true) {
// lock in
taken[0][pig] = true;
float cand = speeds[0];
velocity[pig] = cand;
rep(i, 1, m) {
float neededpos = a[0][pig] + cand*times[i];
int need = round(neededpos);
for (int x : posmap[i][need]) {
if (!taken[i][x]) {
taken[i][x] = true;
break;
}
}
}
//break;
}
}
//}
rep(i, 0, n) dataa[i] = mp(mp(velocity[i], a[0][i]), i);
sort(dataa, dataa+n);
rep(i, 0, n) out[dataa[i].second] = i+1;
rep(i, 0, n) cout << out[i] << ' ';
cout << '\n';
//cout << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
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
Runtime Error
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