QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610737 | #8932. Bingo | UESTC_NLNS | RE | 0ms | 0kb | C++20 | 2.7kb | 2024-10-04 17:11:51 | 2024-10-04 17:11:55 |
answer
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ldb = long double;
const int inf = 0x3f3f3f3f;
struct point {
ll x, y;
point operator-(const point& o) const { return {x - o.x, y - o.y}; };
ll operator*(const point& o) const {
return x * o.y - o.x * y;
}
};
struct item {
ll v, x, id;
};
using i128 = __int128_t;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> a(m, vector<int>(n));
vector<item> val(n);
vector<ll> t(m);
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j) cin >> a[i][j], t[i] += a[i][j];
for (int i = 0; i < n; ++i) {
val[i].x = a[0][i];
val[i].id = i + 1;
}
vector<unordered_map<ll, int>> mp(m);
auto add = [&](int i, ll v) {
if (mp[i].find(v) == mp[i].end())
mp[i][v] = 1;
else
mp[i][v]++;
};
auto sub = [&](int i, ll v) { mp[i][v]--; };
auto in = [&](int i, ll v) { return mp[i].find(v) != mp[i].end() && mp[i][v] > 0; };
auto get = [&](const point& a1, const point& a2, int t) -> ll {
i128 p = i128(a1.x - a2.x) * (t - a1.y);
ll q = (a1.y - a2.y);
if (p % q != 0 || p / q > inf) return inf;
return a1.x + p / q;
};
for (int k = 2; k < m; ++k) {
for (const int u : a[k]) {
add(k, u);
}
}
vector<int> vis(n);
for (int i = 0; i < n; ++i) {
point p1 = {a[0][i], t[0]};
for (int j = 0; j < n; ++j) {
if (vis[j]) continue;
point p2 = {a[1][j], t[1]};
int ok = 1;
for (int k = 2; k < m; ++k) {
ll tmp = get(p1, p2, t[k]);
if (!in(k, tmp)) {
ok = 0;
break;
}
}
if (!ok) continue;
for (int k = 2; k < m; ++k) {
ll tmp = get(p1, p2, t[k]);
sub(k, tmp);
val[i].v = a[1][j] - a[0][i];
vis[j] = 1;
}
break;
}
}
sort(val.begin(), val.end(), [](const item& a, const item& b) {
if (a.v != b.v) return a.v < b.v;
return a.x < b.x;
});
vector<int> ans(n);
for (int i = 0; i < n; ++i) {
ans[val[i].id - 1] = i;
}
for (int i = 0; i < n; ++i) {
cout << ans[i] + 1 << " ";
}
cout << '\n';
}
int main() {
cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) solve();
}
/*
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
*/
詳細信息
Test #1:
score: 0
Runtime Error
input:
6 7 3 12 3 9 10 249 51 1369 37 2 1