답안 #313343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313343 2020-10-15T19:56:21 Z mohamedsobhi777 Sure Bet (CEOI17_sure) C++14
100 / 100
111 ms 5484 KB
#include<bits/stdc++.h>


#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

#define I inline void 
#define S struct 
#define vi vector<int> 
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std ; 
using ll = long long ; 
using ld = long double ; 

const int N = 2e5 + 7 , mod = 1e9 + 7 ; 
const ll inf = 2e18 ; 

// How interesting!

int n ; 
vector<double> d[2], pd[2]; 
double ans ; 

void solve2(){
        double sum1 = 0.0 ; 
        for(int i = 0 ;i < n; ++ i){
                sum1 += d[0][i] ; 
                int k = lower_bound(pd[1].begin() , pd[1].end() , sum1 + i + 1 ) - pd[1].begin() ; 
                if(k != pd[1].size()){
                        ans = max(ans , sum1 - k - 1)  ; 
                }      
        }
}

int main(){
        ios_base::sync_with_stdio(0) ;
        cin.tie(0) ; 
        //freopen("in.in" , "r" , stdin) ; 
        cin >> n; 
        for(int i = 0 ;i < n; ++ i){
                double a , b; 
                cin >> a >> b ;
                a-=1.0 ; b-=1.0 ; 
                d[0].push_back(a) ; 
                d[1].push_back(b) ; 
        }
        for(int i = 0 ;i < 2 ; ++ i){
                sort(d[i].begin() , d[i].end(), greater<double>()) ; 
                pd[i].resize(n) ; 
        }

        pd[0][0] = d[0][0] +1.0; 
        pd[1][0] = d[1][0] +1.0; 
        for(int i = 0 ; i < 2 ; ++ i){

                for(int j = 1 ;j < n ; ++ j)
                        pd[i][j] = pd[i][j-1] + d[i][j] +1.0; 
        }
        solve2() ; 
        swap(d[0] , d[1]) ; 
        swap(pd[0] , pd[1]) ;
        solve2() ; 
        cout<< fixed <<setprecision(4) << ans ;
        return 0 ; 
}

/*
        - bounds sir (segtree = 4N, eulerTour = 2N, ...)
        - a variable defined twice?
        - will overflow?
        - is it a good complexity?
        - don't mess up indices (0-indexed vs 1-indexed)
        - reset everything between testcases. 
*/

Compilation message

sure.cpp: In function 'void solve2()':
sure.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |                 if(k != pd[1].size()){
      |                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 105 ms 3812 KB Output is correct
18 Correct 109 ms 5216 KB Output is correct
19 Correct 108 ms 5124 KB Output is correct
20 Correct 109 ms 5092 KB Output is correct
21 Correct 111 ms 5484 KB Output is correct
22 Correct 108 ms 5216 KB Output is correct
23 Correct 110 ms 5088 KB Output is correct
24 Correct 106 ms 5344 KB Output is correct
25 Correct 105 ms 5092 KB Output is correct
26 Correct 111 ms 5472 KB Output is correct