QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#401266#7689. Flipping CardsBlobo2_Blobo2WA 1ms3712kbC++231.6kb2024-04-28 11:34:172024-04-28 11:34:18

Judging History

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

  • [2024-04-28 11:34:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2024-04-28 11:34:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define SZ(s) (int)(s.size())
#define gen(arr,n)  generate(arr,arr+n,nxt)
#define all(v) v.begin(),v.end()
#define Blobo2 ios_base::sync_with_stdio(false);cin.tie(NULL);

const int mod = 1e9+7;
int32_t nxt(){int32_t x;cin>>x;return x;}

void testCase(){
   int n=nxt();
   int a[n],b[n];
   for(int i=0;i<n;i++)
        a[i] = nxt(), b[i] = nxt();
    int s=1,e=1e9;
    while(s<=e){
        int mid = (s+e)/2;
        int ok[n];
        for(int i=0;i<n;i++){
            if(a[i] >= mid && b[i] < mid)
                ok[i] = -1;
            else if(a[i] < mid && b[i] < mid)
                ok[i] = 0;
            else ok[i] = 1;
        }
        int mx = 0, sum = 0, start = 0, end = 0, S = 0;
        for(int i=0;i<n;i++){
            sum += ok[i];
            if(mx < sum){
                mx = sum;
                start = S;
                end = i;
            }
            if(sum < 0){
                sum = 0;
                S = i + 1;
            }
        }
        if(!mx) start = end = n;
        int cnt = 0;
        for(int i=0;i<start;i++)
            cnt += (a[i] >= mid);
        for(int i=end+1;i<n;i++)
            cnt += (a[i] >= mid);
        cnt += mx;
        if(cnt >= n/2+1)
            s = mid + 1;
        else e = mid - 1;
    }
    cout<<e<<endl;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen("in1.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    Blobo2
    int qu=1;
    for(int i=0;i<qu;i++){
        testCase();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
3 6
5 2
4 7
6 4
2 8

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

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

input:

99
749159996 323524232
125448341 365892333
481980673 143665393
394405973 44741918
687549448 513811513
287088118 385131171
11865696 666468353
449920567 373650719
671547289 116780561
41003675 671513243
351534153 507850962
374160874 985661954
222519431 600582098
987220654 704142246
856147059 37783620
1...

output:

279496529

result:

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