QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#383418#6693. Fast and FatSusie_Rain#WA 60ms3632kbC++172.2kb2024-04-09 13:51:122024-04-09 13:51:13

Judging History

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

  • [2024-04-09 13:51:13]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:3632kb
  • [2024-04-09 13:51:12]
  • 提交

answer

#include <bits/stdc++.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
// gp_hash_table<int, bool> hs;
#define bit1(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define lowbit(i) ((i) & -(i))
#define ull unsigned long long
#define int long long
// #define ll long long
#define Genshin return
#define Impact 0
#define endl '\n'
using namespace std;
const int mod = 998244353;
const int N = 2e5 + 10;
int ksm(int base, int n)
{
    int res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = (res * base) % mod;
        base = (base * base) % mod;
        n >>= 1;
    }
    return res;
}
int n;
pair<int, int> a[100010];
bool cmp(pair<int, int> x, pair<int, int> y)
{
    if (x.first + x.second == y.first + y.second)
        return x.first < y.first;
    return x.first + x.second < y.first + y.second;
}
bool check(int k)
{
    vector<bool> b(n + 1);
    vector<pair<int, int>> c;
    for (int i = 1; i <= n; i++)
    {
        if (a[i].second < k)
        {
            b[i] = 1;
        }
        else
        {
            c.push_back(a[i]);
        }
    }
    sort(all(c), cmp);
    int j = n, i = c.size() - 1;
    while (i >= 0 && j > 0)
    {
        while (j > 0 && b[j] == 0)
        {
            j--;
        }
        if (j <= 0)
            break;
        while (i >= 0 && (c[i].second - max(0LL, a[j].first - c[i].first)) < k)
        {
            i--;
        }
        if (i < 0)
            break;
        j--;
        i--;
    }
    if (j <= 0)
        return 1;
    return 0;
}
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].second >> a[i].first;
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = 1e9;
    int ans = 1;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (check(mid))
        {
            ans = mid;
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    cout << ans << endl;
    return;
}
signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int tt = 1;
    cin >> tt;
    while (tt--)
    {
        solve();
    }
    Genshin Impact;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3628kb

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: 60ms
memory: 3632kb

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:

280251502
785434740
470297536
280572174
704877362
960871619
691253609
525403368
136979645
399988835
610497257
576427565
636500913
315900406
370430730
526259135
781258283
631916852
300930080
419999540
431930706
479323438
530080165
391912906
613609546
467782812
457987604
389750718
447390353
696516804
...

result:

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