QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#943183#2697. Exhausting ErrandsHashbinWA 0ms3584kbC++232.3kb2025-03-19 18:22:202025-03-19 18:22:28

Judging History

This is the latest submission verdict.

  • [2025-03-19 18:22:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-03-19 18:22:20]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node
{
    int l, r;
};
int cmp(node a, node b)
{
    if (a.r < b.r)
        return 1;
    if (a.r > b.r)
        return 0;
    if (a.l > b.l)
        return 1;
    if (a.l < b.l)
        return 0;
    return 0;
}
int cmp2(node a, node b)
{
    if (a.r > b.r)
        return 1;
    if (a.r < b.r)
        return 0;
    if (a.l > b.l)
        return 1;
    if (a.l < b.l)
        return 0;
    return 0;
}
void solve()
{
    int m, n;
    cin >> m >> n;
    vector<node> a, b;
    int l1 = 1e9, r1 = 0;
    int l2 = 1e9, r2 = 0;
    int flag1 = 0,flag2 = 0; 
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x < y)
        {
            l1 = min(x, l1);
            r1 = max(r1, y);
            a.push_back({x, y});
            l2 = min(x, l2);
            flag1=1;
        }
        else
            b.push_back({x, y}), r1 = max(r1, x), l2 = min(y, l2), r2 = max(r2, x),flag2=1;
    }
    if(!flag1)
    {
        int x=1e9,y=0;
        for(auto &c : b)
        {
            x = min(x,c.r);
            y = max(y,c.l);
        }
        cout << y - x << '\n';
        return ;
    }
    if(!flag2)
    {
        int x=1e9,y=0;
        for(auto &c : a)
        {
            x = min(x,c.l);
            y = max(y,c.r);
        }
       // cout << x << ' '<< y << '\n';
        cout << y - x << '\n';
        return ;
    }
    l1 = min(l1, r1);
    l2 = min(l2, r2);
    //cout << l1 << r1 << l2 << r2 << '\n';
    sort(b.begin(), b.end(), cmp);
    sort(a.begin(), a.end(), cmp2);
    int ans = 1e18;
    int sum = 0;
    for (auto &c : b)
    {
        ans = min(ans, sum + r1 - c.r);
        sum += 2 * (c.l - c.r);
        ans = min(ans, sum + r1 - c.r);
    }
    int cnt = ans + r1 - l1;
    sum = 0;
    ans = 1e18;
    for (auto &c : a)
    {
        ans = min(ans, sum + c.r - l2);
        sum += 2 * (c.r - c.l);
        ans = min(ans, sum + c.r - l2);
    }
    cnt = min(cnt, ans + r2 - l2);
    cout << cnt << '\n';
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}
/*
10 6
1 4
3 5
6 7
2 1
9 4
8 5
*/
/*
100 3
11 50
50 49
36 35
*/

詳細信息

Test #1:

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

input:

100 2
1 100
100 1

output:

198

result:

ok single line: '198'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3584kb

input:

100 6
10 6
20 15
50 54
100 98
92 87
90 89

output:

81

result:

wrong answer 1st lines differ - expected: '102', found: '81'