QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708608 | #8064. Gas Station | jerry2423 | WA | 0ms | 3820kb | C++14 | 2.7kb | 2024-11-04 00:31:32 | 2024-11-04 00:31:37 |
Judging History
answer
#include <iostream>
#include <string>
#include <numeric>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>
#include <cstdint>
#include <map>
#include <list>
using namespace std;
int main()
{
int n, p;
cin >> p >> n;
std::vector<list<pair<int, char>>> l(p);
std::vector<list<pair<int, char>>> r(p);
for (int i = 0; i < n; i++)
{
int t, f;
char s;
cin >> t >> f >> s;
for (int i = 0; i < p; i++)
{
for (auto it = l[i].begin(); it != l[i].end();)
{
if (it->first <= t)
it = l[i].erase(it);
else
++it;
}
for (auto it = r[i].begin(); it != r[i].end();)
{
if (it->first <= t)
it = r[i].erase(it);
else
++it;
}
}
if (s == 'L')
{
bool added = false;
for (int i = 0; i < p; i++)
{
if (l[i].size() < 2)
{
l[i].emplace_back(t + f, (l[i].empty() ? 'A' : 'B'));
cout << t + f << endl;
added = true;
break;
}
}
if (!added)
{
int min_idx = 0;
for (int i = 1; i < p; i++)
{
if (l[i].size() < l[min_idx].size())
min_idx = i;
}
// cout << l[min_idx].back() + f << endl;
// l[min_idx].push_back(l[min_idx].back() + f);
auto p = std::prev(l[min_idx].end());
auto pp = std::prev(p);
if (p->second == 'A') {
l[min_idx].emplace_back(pp->first+f, 'B');
} else {
if (pp->second == 'B') {
l[min_idx].emplace_back(p->first+f, 'B');
} else {
if (p->first >= pp->first) {
l[min_idx].emplace_back(p->first+f, 'A');
} else {
l[min_idx].emplace_back(p->first+f, 'B');
}
}
}
cout << (l[min_idx].back()).first << endl;
}
}
else
{
bool added = false;
for (int i = 0; i < p; i++)
{
if (r[i].size() < 2)
{
r[i].emplace_back(t + f, (r[i].empty() ? 'A' : 'B'));
cout << t + f << endl;
added = true;
break;
}
}
if (!added)
{
int min_idx = 0;
for (int i = 1; i < p; i++)
{
if (r[i].size() < r[min_idx].size())
min_idx = i;
}
// cout << l[min_idx].back() + f << endl;
// l[min_idx].push_back(l[min_idx].back() + f);
auto p = std::prev(r[min_idx].end());
auto pp = std::prev(p);
if (p->second == 'A') {
r[min_idx].emplace_back(pp->first+f, 'B');
} else {
if (pp->second == 'B') {
r[min_idx].emplace_back(p->first+f, 'B');
} else {
if (p->first >= pp->first) {
r[min_idx].emplace_back(p->first+f, 'A');
} else {
r[min_idx].emplace_back(p->first+f, 'B');
}
}
}
cout << (r[min_idx].back()).first << endl;
}
}
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
1 4 1 9 L 2 5 L 3 10 L 4 10 L
output:
10 7 17 27
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 4 1 9 L 2 9 L 3 10 L 4 10 L
output:
10 11 21 21
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1 2 8 11 R 9 10 L
output:
19 19
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 10 1 10 R 2 3 R 3 10 R 4 12 R 5 1 R 6 5 R 7 10 R 10 2 R 11 7 R 13 4 R
output:
11 5 13 16 6 11 21 18 18 22
result:
ok 10 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 8 3 9 R 5 6 R 6 2 L 8 2 L 9 6 R 10 10 R 12 3 R 14 3 L
output:
12 11 8 10 15 20 15 17
result:
ok 8 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 10 1 1 L 2 7 L 3 6 L 4 10 L 5 7 L 6 1 L 7 6 L 8 1 L 9 4 L 10 1 L
output:
2 9 9 14 12 10 18 10 14 11
result:
ok 10 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
2 9 1 10 R 2 9 R 3 10 R 4 6 R 5 5 R 6 8 R 7 1 L 8 5 L 9 1 R
output:
11 11 13 10 16 18 8 13 12
result:
ok 9 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 9 2 2 R 6 6 R 10 4 L 12 2 R 13 5 L 17 5 R 21 3 L 23 9 R 27 9 R
output:
4 12 14 14 18 22 24 32 36
result:
ok 9 lines
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3820kb
input:
1 10 2 6 R 3 5 L 5 5 R 8 10 L 10 1 L 12 3 L 15 4 R 16 4 L 18 9 L 20 1 L
output:
8 8 10 18 11 15 19 20 27 21
result:
wrong answer 9th lines differ - expected: '29', found: '27'