QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#836569 | #9730. Elevator II | yylx | TL | 0ms | 3576kb | C++14 | 1.6kb | 2024-12-29 00:46:52 | 2024-12-29 00:46:53 |
Judging History
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 ...