Submission #282809

# Submission time Handle Problem Language Result Execution time Memory
282809 2020-08-25T01:07:41 Z Benq Happiness (Balkan15_HAPPINESS) C++14
100 / 100
624 ms 16376 KB
#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 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 8 ms 1056 KB Output is correct
9 Correct 8 ms 1152 KB Output is correct
10 Correct 7 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 234 ms 9084 KB Output is correct
7 Correct 228 ms 9080 KB Output is correct
8 Correct 229 ms 9080 KB Output is correct
9 Correct 385 ms 10488 KB Output is correct
10 Correct 624 ms 13052 KB Output is correct
11 Correct 190 ms 13712 KB Output is correct
12 Correct 198 ms 13816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 8 ms 1056 KB Output is correct
9 Correct 8 ms 1152 KB Output is correct
10 Correct 7 ms 1024 KB Output is correct
11 Correct 234 ms 9084 KB Output is correct
12 Correct 228 ms 9080 KB Output is correct
13 Correct 229 ms 9080 KB Output is correct
14 Correct 385 ms 10488 KB Output is correct
15 Correct 624 ms 13052 KB Output is correct
16 Correct 190 ms 13712 KB Output is correct
17 Correct 198 ms 13816 KB Output is correct
18 Correct 307 ms 11440 KB Output is correct
19 Correct 286 ms 11512 KB Output is correct
20 Correct 551 ms 14584 KB Output is correct
21 Correct 300 ms 11000 KB Output is correct
22 Correct 215 ms 15864 KB Output is correct
23 Correct 220 ms 16376 KB Output is correct
24 Correct 271 ms 11384 KB Output is correct