Submission #120612

# Submission time Handle Problem Language Result Execution time Memory
120612 2019-06-25T05:24:10 Z Mercenary Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
343 ms 16848 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,int> lli;
const int maxn = 1e6 + 6;
const ld inf = 1e9 + 5;

int n;
ll a[maxn];
ll can;
vector<ll> val , val1;
void enter(){
    cin >> n >> can;
//    n = 40;can = 1e18;
    for(int i = 0 ; i < n / 2 ; ++i){
        cin >> a[i];
//        a[i] = 1;
    }
    val.reserve((1 << (n / 2)));
    for(int j = 0 ; j < (1 << (n / 2)) ; ++j){
        ll sum = 0;
        for(int i = 0 ; i < n / 2 ; ++i){
            if((j >> i) & 1)sum += a[i];
            if(sum > can)break;
        }
        if(sum <= can)val.pb(sum);
    }
    n -= (n / 2);
    for(int i = 0 ; i < n ; ++i){
        cin >> a[i];
//        a[i] = 1;
    }
    val1.reserve((1 << n));
    for(int j = 0 ; j < (1 << n) ; ++j){
        ll sum = 0;
        for(int i = 0 ; i < n ; ++i){
            if((j >> i) & 1)sum += a[i];
            if(sum > can)break;
        }
        if(sum <= can)val1.pb(sum);
    }
    sort(val.begin(),val.end());
    sort(val1.begin(),val1.end());
    int j = val.size() - 1;
    ll res = 0;
    for(ll c : val1){
        while(j >= 0 && val[j] > can - c)--j;
        res += j + 1;
//        cout << " " << c << " " << j << endl;
    }
//    cout << val1.size() << " " <<  val.size() << endl;
    cout << res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    enter();
}

Compilation message

bobek.cpp: In function 'int main()':
bobek.cpp:69:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:70:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1916 KB Output is correct
2 Correct 79 ms 4472 KB Output is correct
3 Correct 339 ms 16836 KB Output is correct
4 Correct 81 ms 4480 KB Output is correct
5 Correct 16 ms 1408 KB Output is correct
6 Correct 10 ms 896 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2432 KB Output is correct
2 Correct 30 ms 1920 KB Output is correct
3 Correct 142 ms 8568 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 8 ms 1024 KB Output is correct
6 Correct 20 ms 1408 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 3448 KB Output is correct
2 Correct 121 ms 6560 KB Output is correct
3 Correct 120 ms 6520 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 91 ms 6520 KB Output is correct
6 Correct 312 ms 16700 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 257 ms 12712 KB Output is correct
2 Correct 36 ms 1920 KB Output is correct
3 Correct 12 ms 952 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 9 ms 896 KB Output is correct
6 Correct 252 ms 12776 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1920 KB Output is correct
2 Correct 78 ms 4472 KB Output is correct
3 Correct 10 ms 896 KB Output is correct
4 Correct 10 ms 896 KB Output is correct
5 Correct 92 ms 6652 KB Output is correct
6 Correct 29 ms 1920 KB Output is correct
7 Correct 11 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 16848 KB Output is correct
2 Correct 29 ms 1920 KB Output is correct
3 Correct 11 ms 896 KB Output is correct
4 Correct 343 ms 16772 KB Output is correct
5 Correct 123 ms 8632 KB Output is correct
6 Correct 20 ms 1408 KB Output is correct
7 Correct 4 ms 384 KB Output is correct