QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695633#6693. Fast and Fatiscreamc3WA 36ms3636kbC++171.7kb2024-10-31 20:29:222024-10-31 20:29:29

Judging History

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

  • [2024-10-31 20:29:29]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:3636kb
  • [2024-10-31 20:29:22]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;
#define Z cout << "\n"
#define lb lower_bound
#define ub upper_bound
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define unq(x) sort(x.begin(), x.end()), x.erase(unique(x.begin(), x.end()), x.end())
#define D(x) cerr << #x << ": " << (x) << "\n"
#define DV(v) cerr<< #v << ": "; for(int i=0;i <(v).size(); i++)cerr << ((v)[i]) << ",";cerr << "\n"
#if 0
#define int i64
#endif

struct node {
    int v, w, no;
    bool operator <(const node& o)const {
        return v + w <= o.v + o.w;
    }
    bool operator >(const node& o)const {
        return v + w > o.v + o.w;
    }
};

void solve() {
    int n;
    cin >> n;

    vector<node>a(n + 1);
    set<node, greater<node>>se;
    set<pair<int, int>>S;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].v >> a[i].w;
        a[i].no = i;
        se.insert(a[i]);
        S.insert({ a[i].v,i });
    }

    while (1) {
        if (se.empty())break;
        auto B = *S.begin();
        auto top = *se.begin();
        int yv = top.v;
        int v = top.w + top.v - a[B.second].w;
        v = min(v, yv);
        //D(v);
        se.erase(se.begin());
        if (v < 0)break;
        se.insert({ v,top.w,top.no });
        se.erase({ B.first,a[B.second].w,B.second });
        S.erase(S.begin());
        S.erase({ top.v,top.no });
        S.insert({ v, top.no });
    }
    cout << S.begin()->first << "\n";
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)solve();
    return 0;
}

详细

Test #1:

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

input:

2
5
10 5
1 102
10 100
7 4
9 50
2
1 100
10 1

output:

8
1

result:

ok 2 number(s): "8 1"

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 3636kb

input:

10000
4
280251502 664541723
375808746 641141991
95134537 898607509
455259328 944978891
2
798417052 547329847
785434740 991778535
6
623628702 857611223
275667427 453747403
292209526 283132767
330752033 988721243
470297536 608192332
477186035 325224271
3
280572174 994054447
306566740 923535026
3781360...

output:

455259328
353968364
492518682
236047319
719352030
960871619
852497327
635783477
136979645
740094681
630388477
402840544
895057091
315900406
642234951
711095784
753070871
460247234
355137761
867849295
812952251
585400914
657739840
635081456
595925967
739530850
745319288
480095087
798382479
413183426
...

result:

wrong answer 1st numbers differ - expected: '352409014', found: '455259328'