답안 #498347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498347 2021-12-25T04:37:09 Z vinnipuh01 Sure Bet (CEOI17_sure) C++17
60 / 100
2000 ms 6652 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define double long double
 
using namespace std;
 
const long long oo = 1000000000000000000;
 
long long int  sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
 
 
/*
    ViHHiPuh
 
   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))
 
 
    cout << fixed << setprecision(6) << x;
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    freopen ( "sum.in", "r", stdin )
*/
 
int n;
double a[ 100001 ], b[ 100001 ];
vector <double> v, vv;
 
double f( int mask, int o, double sum, double ans, double col ) {
	double mxx = min( sum - col, ans - col );
	for ( int i = o; i < n; i ++ ) {
		if ( !( mask & ( 1 << i ) ) ) {
			mask |= ( 1 << i );
			col ++;
			sum += a[ i ];
			mxx = max( mxx, f( mask, i + 1, sum, ans, col ) );
			sum -= a[ i ];
			ans += b[ i ];
			mxx = max( mxx, f( mask, i + 1, sum, ans, col ) );
			col --;
			ans -= b[ i ];
			col += 2;
			ans += b[ i ];
			sum += a[ i ];
			mxx = max( mxx, f( mask, i + 1, sum, ans, col ) );
			col -= 2;
			ans -= b[ i ];
			sum -= a[ i ];
			mask ^= ( 1 << i );
		}
	}
	return mxx;
}
 
int main () {
	cin >> n;
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ] >> b[ i ];
		v.push_back( a[ i ] );
		vv.push_back( b[ i ] );
	}
	sort( v.begin(), v.end() );
	sort( vv.begin(), vv.end() );
	reverse( v.begin(), v.end() );
	reverse( vv.begin(), vv.end() );
	double sum, num, ans, mx;
	sum = num = ans = mx = 0;
	for ( int i = 1; i <= v.size(); i ++ ) {
		sum += v[ i - 1 ];
		ans = i;
		mx = max( mx, min( sum - ans, -ans ) );
		for ( int j = 1; j <= vv.size(); j ++ ) {
			ans ++;
			num += vv[ j - 1 ];
			mx = max( mx, min( sum - ans, num - ans ) );
		}
		num = 0;
		
	}
	cout << fixed << setprecision(4) << mx;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:89:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for ( int i = 1; i <= v.size(); i ++ ) {
      |                   ~~^~~~~~~~~~~
sure.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for ( int j = 1; j <= vv.size(); j ++ ) {
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 6 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 5 ms 332 KB Output is correct
16 Correct 6 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 6 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 5 ms 332 KB Output is correct
16 Correct 6 ms 400 KB Output is correct
17 Execution timed out 2077 ms 6652 KB Time limit exceeded
18 Halted 0 ms 0 KB -