답안 #169441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169441 2019-12-20T11:03:34 Z Ruxandra985 Sure Bet (CEOI17_sure) C++14
100 / 100
168 ms 5244 KB
/// pe langa faptul ca sunt inteligenta si nu stiu sa citesc enunturi
/// cateodata mai si uit sa trec pe standard input/output si iau 0 degeaba:)
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;
double v[DIMN],w[DIMN] , spv[DIMN] , spw[DIMN];
double check (int x , int y){
    return min(spv[x] - x - y , spw[y] - x - y);
}
int main()
{
    FILE *fin = stdin;
    int n , i , j , taken = 0 , st , dr , mid , nr;
    double sol = 0.0 ,x , y, z ,sx , sy;
    fscanf (fin,"%d",&n);
    for (i=1;i<=n;i++){
        fscanf (fin,"%lf%lf",&v[i],&w[i]);
    }
    sort (v+1 , v + n + 1);
    sort (w+1 , w + n + 1);

    for (i=1;i<=n-i+1;i++){
        swap(v[i] , v[n-i+1]);
        swap(w[i] , w[n-i+1]);
    }

    for (i=1;i<=n;i++){
        spv[i] = spv[i-1] + v[i];
        spw[i] = spw[i-1] + w[i];
    }
    spv[0] = spw[0] = -2000000000;
    spv[n+1] = spw[n+1] = -2000000000;
    for (i=1;i<=n;i++){
        /// avem spv[i]

        /// pot sa caut ternar sol pe w
        st = 1;
        dr = n;
        nr = 100;
        while (st <= dr && nr){
            mid = (st + dr)/2;
            x = check(i , mid-1);
            y = check(i , mid);
            z = check(i , mid+1);
            if (x <= y && y >= z){ /// solutie
                sol = max(sol , min(spv[i] - i - mid , spw[mid] - i - mid));
                st = mid;
            }
            else if (x <= y && y <= z)
                st = mid;
            else dr = mid;
            nr--;
        }
        sol = max(sol , min(spv[i] - i - st , spw[st] - i - st));
        sol = max(sol , min(spv[i] - i - dr , spw[dr] - i - dr));
    }

    /*sx = 0.0;
    for (i=1;i<=n;i++){
        sx += v[n-i+1];
        taken = 0;
        sy = 0.0;
        for (j=n;j;j--){
            sy += w[j];
            taken++;
            if (sol < min(sx - i - taken , sy - i - taken)){
                sol = min(sx - i - taken , sy - i - taken);
                printf ("%d %d\n" ,i , n-j+1);
            }
        }
    }*/

    cout << setprecision(4) << fixed << sol;
    return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:13:17: warning: unused variable 'j' [-Wunused-variable]
     int n , i , j , taken = 0 , st , dr , mid , nr;
                 ^
sure.cpp:13:21: warning: unused variable 'taken' [-Wunused-variable]
     int n , i , j , taken = 0 , st , dr , mid , nr;
                     ^~~~~
sure.cpp:14:33: warning: unused variable 'sx' [-Wunused-variable]
     double sol = 0.0 ,x , y, z ,sx , sy;
                                 ^~
sure.cpp:14:38: warning: unused variable 'sy' [-Wunused-variable]
     double sol = 0.0 ,x , y, z ,sx , sy;
                                      ^~
sure.cpp:15:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d",&n);
     ~~~~~~~^~~~~~~~~~~~~
sure.cpp:17:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%lf%lf",&v[i],&w[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 4 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 4 ms 636 KB Output is correct
17 Correct 161 ms 4924 KB Output is correct
18 Correct 161 ms 4856 KB Output is correct
19 Correct 162 ms 4880 KB Output is correct
20 Correct 160 ms 4860 KB Output is correct
21 Correct 166 ms 5224 KB Output is correct
22 Correct 161 ms 4856 KB Output is correct
23 Correct 161 ms 4856 KB Output is correct
24 Correct 161 ms 4856 KB Output is correct
25 Correct 161 ms 4856 KB Output is correct
26 Correct 168 ms 5244 KB Output is correct