QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801633 | #8939. Permutation | Infinite_Loopers# | TL | 0ms | 0kb | C++20 | 1.7kb | 2024-12-07 04:24:36 | 2024-12-07 04:24:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define tsolve int t;cin >> t;while(t--)solve
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
using pl = pair<ll, ll>;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<ll>> pictures(m, vector<ll>(n));
for (auto &pic: pictures) for (auto &x: pic) cin >> x;
vector<ll> times(m);
for (int i = 0; i < m; i++) times[i] = accumulate(begin(pictures[i]), end(pictures[i]), 0ll);
for (int i = 1; i < m; i++) times[i] -= times[0];
times[0] = 0;
if (times[1] == 0) {
for (int i = 1; i <= n; i++) cout << i << " ";
cout << "\n";
return;
}
vector<set<ll>> avail(m);
for (int i = 0; i < m; i++) {
auto &mp = avail[i];
for (ll x: pictures[i]) mp.insert(x);
}
vector<ll> velocity(n);
for (int i = 0; i < n; i++) {
ll x0 = pictures[0][i];
for (int x1: pictures[1]) {
ll v = x1 - x0;
bool ok = 1;
for (int i = 2; i < m; i++) {
ll xi = v * times[i];
if (xi%times[1]) { ok = false; break; }
xi = x0 + xi / times[1];
if (!avail[i].contains(xi)) {
ok = false;
break;
}
}
if (ok) velocity[i] = v;
}
}
vector<int> ans(n);
iota(begin(ans), end(ans), 0);
ranges::stable_sort(ans, {}, [&](int i) { return velocity[i]; });
vector<int> real_ans(n);
for (int i = 0; i < n; i++) real_ans[ans[i]] = i;
for (int x: real_ans) cout << x+1 << " ";
cout << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
tsolve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 5