QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750579 | #9730. Elevator II | ytck# | WA | 180ms | 3872kb | C++20 | 2.8kb | 2024-11-15 15:03:27 | 2024-11-15 15:03:27 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int inf = 2e18;
int n, st;
struct node
{
int first, second;
int id;
};
bool cmp(const node &x, const node &y)
{
return x.first < y.first;
}
void solves()
{
cin >> n >> st;
map<int, int> ma;
map<int, int> mp;
int mx = -inf;
int sum = 0;
vector<node> vis;
for (int i = 1; i <= n; i++)
{
int l, r;
cin >> l >> r;
sum += r - l;
mx = max(mx, l);
vis.push_back({l, r, i});
}
sort(vis.begin(), vis.end(), cmp);
map<int, vector<int>> path;
for (int i = 0; i < n; i++)
{
int l = vis[i].first, r = vis[i].second;
int id = vis[i].id;
if (mp[l])
{
ma[mp[l]] = r;
mp[r] = mp[l];
path[mp[l]].push_back(id);
mp.erase(l);
path[l].clear();
}
else
{
if (r > ma[l])
{
ma[l] = r;
mp[r] = l;
path[l].clear();
path[l].push_back(id);
}
}
}
// for (auto item : ma)
// cout << item.first << ' ' << item.second << endl;
int label = 0;
for (auto item : ma)
{
if (item.first <= st and item.second >= mx)
{
cout << sum << endl;
label = item.first;
break;
}
}
if (label)
{
map<int, int> flag;
for (auto item : path[label])
{
cout << item << ' ';
flag[item] = true;
}
for (int i = n - 1; i >= 0; i--)
{
int id = vis[i].id;
if (flag[id])
continue;
cout << id << ' ';
}
cout << endl;
}
else
{
for (auto item : ma)
{
if (item.second >= mx)
{
cout << sum + abs(item.first - st) << endl;
map<int, int> flag;
for (int i = 0; i < path[item.first].size(); i++)
{
cout << path[item.first][i] << ' ';
flag[path[item.first][i]] = true;
}
for (int i = n - 1; i >= 0; i--)
{
int id = vis[i].id;
if (flag[id])
continue;
cout << id << ' ';
}
cout << endl;
}
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solves();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
11 2 1 4 3 5 2 1
result:
ok ok 2 cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 180ms
memory: 3872kb
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 16 9 4 14 11 6 18 19 1 17 13 3 5 12 15 7 8 10 2 194 5 4 2 1 6 3 402 16 11 1 13 5 8 14 12 6 7 4 15 2 10 9 3 469 1 13 5 8 14 11 12 6 7 16 4 15 2 10 9 3 734 3 1 4 17 8 16 5 12 10 19 13 14 6 11 7 18 9 15 2 736 6 1 4 17 8 16 5 12 10 19 13 14 11 3 7 18 9 15 2 766 10 1 4 17 8 16 5 12 19 13 14 6 1...
result:
wrong answer Participant's cost is 402, which is worse than jury's cost 397 (test case 3)