Submission #591285

#TimeUsernameProblemLanguageResultExecution timeMemory
591285Loki_NguyenSan (COCI17_san)C++14
72 / 120
13 ms2008 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, int> #define pii pair<int, int> #define fi first #define se second #define pb push_back const int N = 3e1 + 3; const int M = 1 << 20; const int mod = 1e9 + 7; const int base = 300; const ll inf = 1e12; int pw(int k, int n) { int total = 1; for (; n; n >>= 1) { if (n & 1) total = total * k % mod; k = k * k % mod; } return total; } int m, n, t, a[N], b[N], c[N], d[N]; vector<int> adj[N], vi; vector<pll> L, R; ll ans, tong, k; struct BIT { int n; vector<int> fe; BIT(int _n) { n = _n; fe.resize(n + 1, 0); } void add(int id) { for (; id <= n; id += id & -id) fe[id] += 1; } int get(int id) { int res = 0; for (; id; id -= id & -id) res += fe[id]; return res; } }; int lwr(int x) { return lower_bound(vi.begin(), vi.end(), x) - vi.begin() + 1; } void sol() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; vi.pb(a[i]); } BIT bit(n); sort(vi.begin(), vi.end()); vi.erase(unique(vi.begin(), vi.end()), vi.end()); for (int mask = 1; mask < (1 << (n / 2)); mask++) { tong = 0; int lst = 0; for (int i = 0; i < n / 2; i++) { if (mask >> i & 1) { if (lst > a[i]) { tong = -1; break; } lst = a[i]; tong += b[i]; } } if (tong == -1) continue; L.pb({tong, lwr(lst)}); if (tong >= k) ++ans; } for (int mask = 1; mask < (1 << (n - n / 2)); mask++) { tong = 0; int lst = mod; for (int i = n - n / 2 - 1; i >= 0; i--) { if (mask >> i & 1) { if (lst < a[i + n / 2]) { tong = -1; break; } lst = a[i + n / 2]; tong += b[i + n / 2]; } } if (tong == -1) continue; R.pb({tong, lwr(lst)}); if (tong >= k) ++ans; } sort(L.begin(), L.end()); sort(R.begin(), R.end()); for (pll x : R) { while (!L.empty() && x.fi + L.back().fi >= k) { bit.add(L.back().se); L.pop_back(); } ans += bit.get(x.se); } cout << ans; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "tests" if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } int ntest = 1; // cin >> ntest; while (ntest-- > 0) sol(); } /* 10 10 259008492 685257993 684081919 849336162 185724174 230558609 147159919 225162936 734023603 130213023 2 1 4 2 4 7 2 2 8 2 4 10 2 5 8 2 5 6 2 1 10 2 3 8 2 1 8 2 2 4 2 1 6 */

Compilation message (stderr)

san.cpp: In function 'int main()':
san.cpp:134:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
san.cpp:135:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |         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...