QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624817#8940. Piggy Sortucup-team1264WA 1ms3868kbC++202.7kb2024-10-09 16:40:092024-10-09 16:40:09

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 16:40:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-10-09 16:40:09]
  • 提交

answer

// https://www.youtube.com/watch?v=CrymicX875M
// Angel of mercy
// How did you move me
// Why am I on my feet again

#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;

// #define int i64
void solve() {
    int n, m; cin >> n >> m;
    vector a(m, vector<int>(n));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
        if (i) sort(a[i].begin(), a[i].end());
    }
    sort(a.begin() + 1, a.end(), [&](const auto& a, const auto& b) {
        return accumulate(a.begin(), a.end(), 0ll) < accumulate(b.begin(), b.end(), 0ll);
    });
    vector<i64> time(m);
    for (int i = 1; i < m; i++) {
        time[i] = accumulate(a[i].begin(), a[i].end(), 0ll) - accumulate(a[0].begin(), a[0].end(), 0ll);
        if (!time[i]) time[i] = i;
    }
    vector<int> speed(n);
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) v[i] = {a[0][i], i};
    sort(v.begin(), v.end());
    for (auto [x0, p]: v) {
        // O(n) speed to check
        vector<int> pnt(m);
        int n1 = a[1].size();
        for (int x1: a[1]) {
            if (x1 < x0) continue;
            bool feasible = true;
            for (int t = 2; t < m; t++) {
                // (x1 - x0) / t1 = (xt - x0) / tt
                // xt = tt / t1 * (x1 - x0) + x0
                if (time[t] * (x1 - x0) % time[1]) {
                    feasible = false;
                    break;
                } else {
                    int xt = time[t] * (x1 - x0) / time[1] + x0;
                    while (pnt[t] < n1 && a[t][pnt[t]] < xt) pnt[t]++;
                    if (pnt[t] == n1 || a[t][pnt[t]] != xt) {
                        feasible = false;
                        break;
                    }
                }
            }
            if (!feasible) continue;
            speed[p] = x1 - x0;
            debug(x0, p, speed[p]);
            a[1].erase(find(a[1].begin(), a[1].end(), x1));
            for (int t = 2; t < m; t++) {
                a[t].erase(a[t].begin() + pnt[t]);
            }
            break;
        }
    }
    vector<int> rank(n);
    iota(rank.begin(), rank.end(), 0);
    sort(rank.begin(), rank.end(), [&](int i, int j) {
        return speed[i] < speed[j];
    });
    for (int i: rank) {
        cout << i + 1 << " ";
    }
    cout << "\n";
}
#undef int

// Make bold hypotheses and verify carefully
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    };
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3868kb

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 
2 3 1 

result:

wrong answer 3rd lines differ - expected: '3 1 2', found: '2 3 1 '