Submission #371220

#TimeUsernameProblemLanguageResultExecution timeMemory
371220pure_memHappiness (Balkan15_HAPPINESS)C++14
100 / 100
523 ms16236 KiB
#include "happiness.h" #include <set> #define ll long long #define X first #define Y second #define MP make_pair using namespace std; multiset<ll> st[42]; ll pr_sum[42]; void add(ll val, int tp){ int mx = 0; while((1ll << (mx + 1ll)) <= val) mx++; if(tp == 1){ st[mx].insert(val), pr_sum[mx] += val; } else{ st[mx].erase(st[mx].find(val)), pr_sum[mx] -= val; } } bool solve(){ ll sums = 0; for(int i = 0;i < 41;i++){ if(st[i].empty()) continue; ll x = *st[i].begin(); if(1 + sums < x) return 0; if(st[i].size() > 1 && 1 + sums + x < *next(st[i].begin())) return 0; sums += pr_sum[i]; } return 1; } bool init(int coinsCount, long long maxCoinSize, long long coins[]) { for(int i = 0;i < coinsCount;i++) add(coins[i], 1); return solve(); } bool is_happy(int event, int coinsCount, long long coins[]) { for(int i = 0;i < coinsCount;i++) add(coins[i], event); return solve(); }

Compilation message (stderr)

grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...