QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#763540#9730. Elevator IIKonggeeWA 47ms3940kbC++202.3kb2024-11-19 20:53:032024-11-19 20:53:04

Judging History

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

  • [2024-11-19 20:53:04]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:3940kb
  • [2024-11-19 20:53:03]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <array>
#include <tuple>
#include <cassert>
#include <random>
#include <chrono>
#define int long long

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
using PII = std::pair<int, int>;

//std::mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()};
constexpr int N = 2e5 + 10;

void solve() {
    int n, f;
    std::cin >> n >> f;

    using tii = std::tuple<int, int, int>;
    std::vector<tii> a(n + 1);
    int res = 0;
    for (int i = 1; i <= n; i ++) {
        int l, r;
        std::cin >> l >> r;
        a[i] = {l, r, i};
        res += r - l;
    }
    std::sort(a.begin() + 1, a.end(), [](const auto& x, const auto& y) {
        if (std::get<1>(x) == std::get<1>(y)) {
            return std::get<0>(x) < std::get<0>(y);
        }
        return std::get<1>(x) > std::get<1>(y);
    });

    std::priority_queue<tii, std::vector<tii>, std::greater<tii>> q;

    std::vector<int> ans;
    std::vector<bool> st(n + 1);
    
    for (int i = 1; i <= n; i ++) {
        auto [l, r, id] = a[i];

        if (l <= f && f <= r) {
            f = r;
            ans.push_back(id);
            st[i] = 1;
            break;
        } else if (l <= f && f > r) {
            break;
        } else {
            q.push({l, r, i});
        }
    }

    while (!q.empty()) {
        auto [l, r, i] = q.top();
        int id = get<2>(a[i]);
        q.pop();

        if (l <= f) {
            f = r;
            ans.push_back(id);
            st[i] = 1;
        } else {
            res += l - f;
            f = r;
            ans.push_back(id);
            st[i] = 1;
        }
    }
    for (int i = 1; i <= n; i ++) {
        if (!st[i]) {
            ans.push_back(get<2>(a[i]));
        }
    }
    std::cout << res << "\n";
    for (auto x : ans) {
        std::cout << x << " ";
    }
    std::cout << "\n";
    return;
}
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int T = 1;
    std::cin >> T;
    while (T --) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:

11
3 1 4 2 
5
2 1 

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 47ms
memory: 3940kb

input:

6100
19 52
51 98
2 83
40 58
96 99
39 55
72 94
15 17
4 15
48 99
2 99
77 78
35 77
44 62
79 81
30 31
1 48
48 76
68 99
60 66
6 19
44 53
64 92
17 28
67 98
9 99
40 65
16 27
99 100
15 56
4 6
24 97
84 96
47 49
37 38
77 79
13 40
13 92
71 100
47 93
90 91
72 81
15 48
32 71
19 17
95 99
10 23
18 100
90 93
52 92
...

output:

524
10 9 18 4 1 6 2 14 11 12 17 19 13 3 5 16 15 7 8 
194
5 4 2 6 1 3 
397
4 11 1 5 12 10 13 14 8 16 2 6 15 9 7 3 
735
7 11 3 6 13 10 5 16 8 17 4 1 15 12 18 14 9 19 2 
247
3 10 14 5 6 4 2 12 8 11 9 1 15 13 7 
422
18 1 6 11 2 10 7 13 9 12 4 20 14 5 15 19 8 16 3 17 
104
4 1 3 2 
187
4 3 8 1 2 6 7 5 9 1...

result:

wrong answer Participant's cost is 735, which is worse than jury's cost 733 (test case 4)