QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785817#9730. Elevator IIProaesWA 53ms3680kbC++172.3kb2024-11-26 19:19:582024-11-26 19:19:59

Judging History

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

  • [2024-11-26 19:19:59]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:3680kb
  • [2024-11-26 19:19:58]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve()
{
    ll n, f, ans = 0;
    cin >> n >> f;
    multiset<int> s;
    vector<array<int, 3>> seg(n);
    vector<int> path, vis(n + 1, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> seg[i][0] >> seg[i][1];
        seg[i][2] = i;
    }
    sort(seg.begin(), seg.end(), [&](array<int, 3> u, array<int, 3> v)
         { return u[1] < v[1]; });

    int st = -1;
    for (int i = 0; i < n; i++)
        if (seg[i][0] <= f && f <= seg[i][1])
        {
            st = seg[i][2];
            break;
        }

    if (st == -1)
    {
        for (int i = 0; i < n; i++)
            if (f <= seg[i][1])
                s.insert(i);
        if (s.size())
        {
            st = *s.begin();
            s.erase(st);
            ans += seg[st][0] - f;
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
            if (i != st && seg[st][1] <= seg[i][1])
                s.insert(seg[i][2]);
    }
    if (st != -1)
    {
        vis[st] = 1;
        path.push_back(st);
        ans += seg[st][1] - seg[st][0];
    }
    // cout << st << endl;
    while (s.size())
    {
        while (s.size() && seg[*s.begin()][1] < seg[st][1])
            s.erase(s.begin());
        if (s.size())
        {
            if (seg[*s.begin()][0] > seg[st][1])
                ans += seg[*s.begin()][0] - seg[st][1];
            st = *s.begin();
            vis[st] = 1;
            path.push_back(st);
            ans += seg[st][1] - seg[st][0];
            s.erase(st);
        }
    }

    vector<int> a;
    for (int i = 0; i < n; i++)
        if (!vis[i])
            a.push_back(i);
    sort(a.begin(), a.end(), [&](int u, int v)
         { return seg[u][0] > seg[v][0]; });

    for (auto &i : a)
    {
        path.push_back(i);
        ans += seg[i][1] - seg[i][0];
    }
    cout << ans << endl;
    for (auto &i : path)
        cout << i + 1 << " ";
    cout << endl;
}

int main()
{
#ifdef x3ea
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    for (; _; _--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

11
2 3 4 1 
5
2 1 

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 53ms
memory: 3680kb

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:

525
5 6 9 10 11 12 13 14 17 18 19 8 15 7 3 2 1 16 4 
194
3 4 5 2 1 6 
406
9 10 11 12 13 15 8 16 5 2 7 14 4 6 3 1 
733
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 
250
3 3 4 5 6 8 9 10 11 12 14 15 13 7 2 1 
422
17 18 16 14 15 13 9 10 5 7 6 12 3 8 19 4 2 11 20 1 
104
3 4 2 1 
187
6 8 10 9 7 3 5 2 ...

result:

wrong answer Participant declares the cost to be 525, but the plan actually costs 644 (test case 1)