//https://usaco.guide/solutions/balkan-15-happiness?lang=cpp
#include "happiness.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "no-stack-protector", "unroll-loops")
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define V vector
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << ") -> " << #x << " is " << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 1e9 + 7;
const ll oo = 1e18;
ll sum[40];
multiset<ll> s[40];
void add(ll x, int type) {
int bucket = __lg(x);
if(type == 1) {
s[bucket].insert(x);
sum[bucket] += x;
} else {
s[bucket].erase(s[bucket].find(x));
sum[bucket] -= x;
}
}
bool happy() {
ll SUM = 0;
for(int i = 0; i < 40; i++) if(s[i].size()) {
ll x = *s[i].begin();
if(SUM + 1 < x) return false;
if(s[i].size() > 1) {
ll y = *next(s[i].begin());
if(SUM + x + 1 < y) return false;
}
SUM += sum[i];
}
return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
for(int i = 0; i < 40; i++) {
s[i].clear();
sum[i] = 0;
}
for(int i = 0; i < coinsCount; i++)
add(coins[i], 1);
return happy();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for(int i = 0; i < coinsCount; i++)
add(coins[i], event);
return happy();
}
Compilation message
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
1036 KB |
Output is correct |
10 |
Correct |
6 ms |
1004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
206 ms |
6048 KB |
Output is correct |
7 |
Correct |
205 ms |
5996 KB |
Output is correct |
8 |
Correct |
242 ms |
5996 KB |
Output is correct |
9 |
Correct |
395 ms |
6148 KB |
Output is correct |
10 |
Correct |
542 ms |
8648 KB |
Output is correct |
11 |
Correct |
190 ms |
9972 KB |
Output is correct |
12 |
Correct |
185 ms |
9964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1036 KB |
Output is correct |
10 |
Correct |
6 ms |
1004 KB |
Output is correct |
11 |
Correct |
206 ms |
6048 KB |
Output is correct |
12 |
Correct |
205 ms |
5996 KB |
Output is correct |
13 |
Correct |
242 ms |
5996 KB |
Output is correct |
14 |
Correct |
395 ms |
6148 KB |
Output is correct |
15 |
Correct |
542 ms |
8648 KB |
Output is correct |
16 |
Correct |
190 ms |
9972 KB |
Output is correct |
17 |
Correct |
185 ms |
9964 KB |
Output is correct |
18 |
Correct |
265 ms |
10612 KB |
Output is correct |
19 |
Correct |
286 ms |
8044 KB |
Output is correct |
20 |
Correct |
743 ms |
14444 KB |
Output is correct |
21 |
Correct |
295 ms |
10884 KB |
Output is correct |
22 |
Correct |
204 ms |
15852 KB |
Output is correct |
23 |
Correct |
216 ms |
16236 KB |
Output is correct |
24 |
Correct |
273 ms |
11500 KB |
Output is correct |