Submission #992451

#TimeUsernameProblemLanguageResultExecution timeMemory
992451LOLOLOSan (COCI17_san)C++14
24 / 120
45 ms6668 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (ll)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 40 + 100; ll h[N], g[N], ans = 0, n, k; vector <ll> lst[N]; vector <int> ed[N]; void dfs(int cur, int st, ll sum) { lst[st].pb(sum); if (sum >= k) { ans++; } for (auto x : ed[cur]) { dfs(x, st, sum + g[x]); } } ll cal(int a, int b) { ll ans = 0; for (auto x : lst[a]) { ll t = lower_bound(all(lst[b]), k - x) - lst[b].begin(); ans += (sz(lst[b]) - t); } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> h[i] >> g[i]; } int m = n / 2; for (int i = 1; i <= m; i++) { for (int j = i + 1; j <= m; j++) { if (h[j] >= h[i]) { ed[j].pb(i); } } } for (int i = m + 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (h[j] >= h[i]) { ed[i].pb(j); } } } for (int i = 1; i <= n; i++) { dfs(i, i, g[i]); } for (int i = 1; i <= m; i++) { for (int j = m + 1; j <= n; j++) { if (h[j] >= h[i]) { ans += cal(i, j); } } } cout << ans << '\n'; return 0; }
#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...