Submission #1296456

#TimeUsernameProblemLanguageResultExecution timeMemory
1296456herominhsteveIce Hockey World Championship (CEOI15_bobek)C++20
100 / 100
400 ms16852 KiB
#include <bits/stdc++.h> #define el '\n' #define FNAME "NAME" #define allof(x) x.begin(),x.end() #define allof1(x) x.begin()+1,x.end() #define mset(x,n) memset(x,(n),sizeof(x)) using namespace std; const long long MOD = (long long) 1e9 + 7; template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;} template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;} void setup(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if (fopen(FNAME".inp","r")){ freopen(FNAME".inp","r",stdin); freopen(FNAME".out","w",stdout); } } int n; long long S; vector<long long> a; int ls,rs; vector<long long> L,R; void init(){ cin>>n>>S; a.reserve(n); for (int i=0;i<n;i++){ long long x; cin>>x; if (x <= S) a.push_back(x); } n = a.size(); ls = n / 2; rs = n - ls; L.reserve(ls); for (int i=0;i<ls;i++) L.push_back(a[i]); R.reserve(rs); for (int i=ls;i<n;i++) R.push_back(a[i]); } vector<long long> build(const vector<long long> &a){ int n = a.size(); int MAXMASK = 1 << n; vector<long long> res; res.reserve(MAXMASK); for (int mask = 0; mask < MAXMASK; mask++){ long long sum = 0; bool check = 1; for (int i=0;i<n;i++){ if (mask & (1<<i)){ if (sum <= S - a[i]){ sum += a[i]; } else{ check = 0; break; } } } if (!check) continue; res.push_back(sum); } return res; } void sol(){ vector<long long> sumL = build(L); vector<long long> sumR = build(R); sort(allof(sumR)); long long res = 0; for (long long x : sumL){ vector<long long>::iterator it = upper_bound(allof(sumR),S - x); res += it - sumR.begin(); } cout<<res; } int main(){ setup(); init(); sol(); }

Compilation message (stderr)

bobek.cpp: In function 'void setup()':
bobek.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |                 freopen(FNAME".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 freopen(FNAME".out","w",stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...