답안 #878002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878002 2023-11-24T02:01:15 Z phong Sure Bet (CEOI17_sure) C++17
100 / 100
383 ms 2132 KB
#include <bits/stdc++.h>


using ll = long long;
const int nmax = 1e5 + 5;
const int lg = 20;
const int mod = 1e9 + 7;
const ll oo = 1e18;
#define fi first
#define se second
#define pii pair<int, int>
using namespace std;

int n, q, t;

double a[nmax], b[nmax];

bool check(double k){
    for(int i = 0; i <= n; ++i){
        int l = 0, r = n, it1 = -1;
        while(l <= r){
            int mid = r + l >> 1;
            if(a[i] - i - mid >= k){
                it1 = mid;
                l = mid + 1;
            }
            else r = mid - 1;
        }
        if(it1 != -1){
            if(a[i] - i - it1 >= k && b[it1] - it1 - i >= k) return 1;
        }
    }
    return 0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    sort(a + 1, a + 1 + n, greater<double> ());
    sort(b + 1, b + 1 + n, greater<double> ());
    for(int i = 1; i <= n; ++i){
        a[i] += a[i - 1];
        b[i] += b[i - 1];
    }
    double l = 0, r = 2e8, kq = 0;
    for(int t = 1; t <= 100; ++t){
        double mid = (r + l) / 2;
        if(check(mid)){
            kq = mid;
            l = mid;
        }
        else r = mid;
    }
    cout << fixed << setprecision(4) << kq;
}
/*
10
4.0530 1.2670
4.3790 2.1420
1.9230 2.1920
3.3740 1.0850
0.9690 3.4510
1.5270 0.5160
4.3860 1.3360
4.5560 1.5050
4.9650 1.8120
0.6250 0.4820

*/

Compilation message

sure.cpp: In function 'bool check(double)':
sure.cpp:22:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |             int mid = r + l >> 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 332 ms 2000 KB Output is correct
18 Correct 367 ms 2000 KB Output is correct
19 Correct 383 ms 2000 KB Output is correct
20 Correct 374 ms 1908 KB Output is correct
21 Correct 227 ms 1896 KB Output is correct
22 Correct 313 ms 2000 KB Output is correct
23 Correct 376 ms 2132 KB Output is correct
24 Correct 383 ms 2000 KB Output is correct
25 Correct 380 ms 2000 KB Output is correct
26 Correct 205 ms 1868 KB Output is correct