QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836569#9730. Elevator IIyylxTL 0ms3576kbC++141.6kb2024-12-29 00:46:522024-12-29 00:46:53

Judging History

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

  • [2024-12-29 00:46:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3576kb
  • [2024-12-29 00:46:52]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Person {
    int id;
    int l;
    int r;
};

int main() {
    int T;
    cin >> T;

    while (T--) {
        int n, f;
        cin >> n >> f;

        vector<Person> people(n);
        for (int i = 0; i < n; ++i) {
            people[i].id = i + 1;
            cin >> people[i].l >> people[i].r;
        }

        long long min_cost = -1;
        vector<int> min_permutation;

        vector<int> permutation(n);
        for (int i = 0; i < n; ++i) {
            permutation[i] = i;
        }

        do {
            long long current_cost = 0;
            int current_floor = f;
            vector<int> current_permutation;

            for (int i = 0; i < n; ++i) {
                int person_index = permutation[i];
                current_cost += max(0, people[person_index].l - current_floor);
                current_floor = people[person_index].l;
                current_cost += people[person_index].r - people[person_index].l;
                current_floor = people[person_index].r;
                current_permutation.push_back(people[person_index].id);
            }

            if (min_cost == -1 || current_cost < min_cost) {
                min_cost = current_cost;
                min_permutation = current_permutation;
            }
        } while (next_permutation(permutation.begin(), permutation.end()));

        cout << min_cost << endl;
        for (int i = 0; i < n; ++i) {
            cout << min_permutation[i] << (i == n - 1 ? "" : " ");
        }
        cout << endl;
    }

    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

11
2 1 3 4
5
2 1

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

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:


result: