This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define SZ(x) (int) x.size()
#define F first
#define S second
const int L = 40;
ll S[L]; multiset<ll> M[L];
void add(ll x, int b) {
int g = 0; while ((1 << (g + 1)) <= x) g++;
S[g] += b * x;
if (~b) M[g].insert(x);
else M[g].erase(M[g].find(x));
}
int check() {
ll sum = 0;
for (int i = 0; i < 40; i++) {
if (!SZ(M[i])) continue;
ll x = *M[i].begin();
if (sum + 1 < x) return 0;
if (SZ(M[i]) > 1 && *next(M[i].begin()) > sum + 1 + x) return 0;
sum += S[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 check();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for (int i = 0; i < coinsCount; i++) {
add(coins[i], event);
}
return check();
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |