#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
multiset<lint>s[40];
lint sum[40];
void add(lint x, int b){
int p = 0;
while(1ll<<(p+1) <= x) p++;
if(b == 1) s[p].insert(x), sum[p] += x;
else s[p].erase(s[p].find(x)), sum[p] -= x;
}
bool ok(){
lint cnt = 0;
for(int i=0;i<40;i++){
if(s[i].empty()) continue;
lint x = *s[i].begin();
if(cnt + 1 < x) return 0;
if(s[i].size() > 1 && cnt + x + 1 < *next(s[i].begin())) return 0;
cnt += sum[i];
}
return 1;
}
bool init(int coinsCount, lint maxCoinSize, lint coins[]) {
for(int i=0;i<coinsCount;i++) add(coins[i], 1);
return ok();
}
bool is_happy(int event, int coinsCount, lint coins[]){
for(int i=0;i<coinsCount;i++){
if(event == -1) add(coins[i], -1);
else add(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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
956 KB |
Output is correct |
9 |
Correct |
6 ms |
936 KB |
Output is correct |
10 |
Correct |
6 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
170 ms |
8976 KB |
Output is correct |
7 |
Correct |
145 ms |
9036 KB |
Output is correct |
8 |
Correct |
170 ms |
8996 KB |
Output is correct |
9 |
Correct |
243 ms |
10388 KB |
Output is correct |
10 |
Correct |
401 ms |
13024 KB |
Output is correct |
11 |
Correct |
163 ms |
13572 KB |
Output is correct |
12 |
Correct |
180 ms |
13628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
956 KB |
Output is correct |
9 |
Correct |
6 ms |
936 KB |
Output is correct |
10 |
Correct |
6 ms |
980 KB |
Output is correct |
11 |
Correct |
170 ms |
8976 KB |
Output is correct |
12 |
Correct |
145 ms |
9036 KB |
Output is correct |
13 |
Correct |
170 ms |
8996 KB |
Output is correct |
14 |
Correct |
243 ms |
10388 KB |
Output is correct |
15 |
Correct |
401 ms |
13024 KB |
Output is correct |
16 |
Correct |
163 ms |
13572 KB |
Output is correct |
17 |
Correct |
180 ms |
13628 KB |
Output is correct |
18 |
Correct |
246 ms |
11508 KB |
Output is correct |
19 |
Correct |
227 ms |
11368 KB |
Output is correct |
20 |
Correct |
359 ms |
14320 KB |
Output is correct |
21 |
Correct |
230 ms |
10780 KB |
Output is correct |
22 |
Correct |
195 ms |
15668 KB |
Output is correct |
23 |
Correct |
195 ms |
16132 KB |
Output is correct |
24 |
Correct |
209 ms |
11260 KB |
Output is correct |