QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244141#7689. Flipping Cardsycccc319#WA 0ms3592kbC++171.5kb2023-11-08 21:31:542023-11-08 21:31:56

Judging History

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

  • [2023-11-08 21:31:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2023-11-08 21:31:54]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    set<int> s;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        s.insert(a[i]);
        s.insert(b[i]);
    }
    //test
    int tmp[n+1][4];
    int L = 0, R = 1e9+10, as = 0;
    while (L + 1 < R) {
        int x = (R - L >> 1) + L;
        for (int i = 1; i <= n; i++) {
            if (a[i] < x) tmp[i][1] = 0;
            else tmp[i][1] = 1;
        }
        for (int i = 1; i <= n; i++) {
            if (b[i] < x) tmp[i][2] = 0;
            else tmp[i][2] = 1;
        }
        for (int i = 1; i <= n; i++) {
            tmp[i][3] = tmp[i][2] - tmp[i][1];
        }
        int sum[n + 1];
        sum[1] = tmp[1][3];
        int id = 1;
        int mx{}, l = 1, r = 1;
        for (int i = 2; i <= n; i++) {
            sum[i] = sum[i - 1] + tmp[i][3];
            if (sum[i] < sum[id])id = i;
            if (mx < sum[i] - sum[id])l = id, r = i, mx = sum[i] - sum[id];
        }
        int ans[n + 1];
        for (int i = 1; i <= l - 1; i++)ans[i] = tmp[i][1];
        for (int i = l; i <= r; i++) ans[i] = tmp[i][1] + tmp[i][3];
        for (int i = r + 1; i <= n; i++) ans[i] = tmp[i][1];
        ll o = 0;
        for (int i = 1; i <= n; i++) if (ans[i] >= 1) o++;




        if (o >= (n + 1) / 2)L = x;
        else R = x - 1;
    }
    cout<<R;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
3 6
5 2
4 7
6 4
2 8

output:

6

result:

ok 1 number(s): "6"

Test #2:

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

input:

1
2 1

output:

1

result:

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