Submission #371220

# Submission time Handle Problem Language Result Execution time Memory
371220 2021-02-26T06:35:30 Z pure_mem Happiness (Balkan15_HAPPINESS) C++14
100 / 100
523 ms 16236 KB
#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

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 220 ms 9068 KB Output is correct
7 Correct 210 ms 9072 KB Output is correct
8 Correct 210 ms 9216 KB Output is correct
9 Correct 392 ms 10732 KB Output is correct
10 Correct 523 ms 13292 KB Output is correct
11 Correct 190 ms 13804 KB Output is correct
12 Correct 195 ms 13804 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 220 ms 9068 KB Output is correct
12 Correct 210 ms 9072 KB Output is correct
13 Correct 210 ms 9216 KB Output is correct
14 Correct 392 ms 10732 KB Output is correct
15 Correct 523 ms 13292 KB Output is correct
16 Correct 190 ms 13804 KB Output is correct
17 Correct 195 ms 13804 KB Output is correct
18 Correct 301 ms 11504 KB Output is correct
19 Correct 285 ms 11500 KB Output is correct
20 Correct 489 ms 14828 KB Output is correct
21 Correct 290 ms 10908 KB Output is correct
22 Correct 211 ms 15724 KB Output is correct
23 Correct 218 ms 16236 KB Output is correct
24 Correct 258 ms 11372 KB Output is correct