#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
multiset<ll> todo[40];
ll SUM[40];
void ad(ll x, int b) {
int p = 0; while ((1LL<<(p+1)) <= x) p ++;
if (b == 1) {
todo[p].insert(x), SUM[p] += x;
} else {
todo[p].erase(todo[p].find(x)), SUM[p] -= x;
}
}
bool ok() {
ll sum = 0;
for (int i = 0; i < 40; ++i) if (todo[i].size() > 0) {
ll x = *begin(todo[i]);
if (sum+1 < x) return 0;
if (todo[i].size() > 1 && sum+x+1 < *next(begin(todo[i]))) return 0;
sum += SUM[i];
}
return 1;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
for (int i = 0; i < coinsCount; ++i) ad(coins[i],1);
return ok();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for (int i = 0; i < coinsCount; ++i) {
if (event == -1) ad(coins[i],-1);
else ad(coins[i],1);
}
return ok();
}
Compilation message
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 |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
7 ms |
1004 KB |
Output is correct |
9 |
Correct |
7 ms |
1004 KB |
Output is correct |
10 |
Correct |
6 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
203 ms |
5996 KB |
Output is correct |
7 |
Correct |
203 ms |
5988 KB |
Output is correct |
8 |
Correct |
199 ms |
5996 KB |
Output is correct |
9 |
Correct |
326 ms |
6124 KB |
Output is correct |
10 |
Correct |
522 ms |
8556 KB |
Output is correct |
11 |
Correct |
179 ms |
9964 KB |
Output is correct |
12 |
Correct |
195 ms |
9964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
7 ms |
1004 KB |
Output is correct |
9 |
Correct |
7 ms |
1004 KB |
Output is correct |
10 |
Correct |
6 ms |
1004 KB |
Output is correct |
11 |
Correct |
203 ms |
5996 KB |
Output is correct |
12 |
Correct |
203 ms |
5988 KB |
Output is correct |
13 |
Correct |
199 ms |
5996 KB |
Output is correct |
14 |
Correct |
326 ms |
6124 KB |
Output is correct |
15 |
Correct |
522 ms |
8556 KB |
Output is correct |
16 |
Correct |
179 ms |
9964 KB |
Output is correct |
17 |
Correct |
195 ms |
9964 KB |
Output is correct |
18 |
Correct |
276 ms |
11636 KB |
Output is correct |
19 |
Correct |
278 ms |
11628 KB |
Output is correct |
20 |
Correct |
443 ms |
14572 KB |
Output is correct |
21 |
Correct |
269 ms |
10860 KB |
Output is correct |
22 |
Correct |
207 ms |
15724 KB |
Output is correct |
23 |
Correct |
217 ms |
16236 KB |
Output is correct |
24 |
Correct |
251 ms |
11372 KB |
Output is correct |