Submission #864144

#TimeUsernameProblemLanguageResultExecution timeMemory
864144wiiIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
423 ms10700 KiB
#include <bits/stdc++.h> using namespace std; typedef double db; typedef long long ll; typedef long double ld; #define int ll typedef pair<int, int> pii; #define X first #define Y second #define gcd __gcd #define pb push_back #define all(x) (x).begin(), (x).end() #define bit(i, mask) ((mask) >> (i) & 1) #define reset(x, val) memset(x, val, sizeof(x)) #define foru(i,a,b) for(int i = (a); i <= (b); ++i) #define ford(i,a,b) for(int i = (a); i >= (b); --i) #define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); template<typename T> bool maximize(T &res, const T &val) { if (res < val) { res = val; return true; } return false; } template<typename T> bool minimize(T &res, const T &val) { if (val < res) { res = val; return true; } return false; } const ll Linf = 0x3f3f3f3f3f3f3f3f; const int Inf = 0x3f3f3f3f; const ll Mod = 1e9 + 7; const ll Mod2 = ll(1e9) + 9; const int Lim = 1e6 + 5; const int inv6 = 166666668; /// ====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*==== const int base = 3; const int N = 40 + 2; const int K = log2(N); const int dx[] = {+1, -1, 0, 0}; const int dy[] = {0, 0, +1, -1}; const int block_size = sqrt(2e9) + 2; int n, m; int a[N]; vector<int> lf; void solve() { cin >> n >> m; foru(i, 1, n) cin >> a[i]; int mid = (n >> 1) + (n & 1); for (int mask = 0; mask < (1LL << mid); ++mask) { int sum = 0; foru(i, 1, mid) if (mask >> i - 1 & 1) sum += a[i]; lf.pb(sum); } sort(all(lf)); int ans = 0; for (int mask = 0; mask < (1LL << n - mid); ++mask) { int sum = 0; foru(i, mid + 1, n) if (mask >> i - mid - 1 & 1) sum += a[i]; ans += upper_bound(all(lf), m - sum) - lf.begin(); } cout << ans; } signed main() { FastIO; #define task "test" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int ntest = 1; // cin >> ntest; while (ntest--) { //cout << "Case " << q << ": " << "\n"; solve(); cout << "\n"; } return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/

Compilation message (stderr)

bobek.cpp: In function 'void solve()':
bobek.cpp:52:39: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   52 |         foru(i, 1, mid) if (mask >> i - 1 & 1) sum += a[i];
      |                                     ~~^~~
bobek.cpp:58:41: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   58 |     for (int mask = 0; mask < (1LL << n - mid); ++mask) {
      |                                       ~~^~~~~
bobek.cpp:60:49: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   60 |         foru(i, mid + 1, n) if (mask >> i - mid - 1 & 1) sum += a[i];
      |                                         ~~~~~~~~^~~
bobek.cpp: In function 'int main()':
bobek.cpp:73:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:74:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   freopen(task".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...