#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define s second
#define f first
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6 + 10;
ll sum[40];
multiset <ll> save[40];
void add(ll x, int c) {
int p = 0;
while ((ll)1 << (p + 1) <= x) {
p++;
}
if (c == 1) {
sum[p] += x;
save[p].insert(x);
} else {
sum[p] -= x;
save[p].erase(save[p].find(x));
}
}
bool ok() {
ll cur = 0;
for (int i = 0; i < 40; i++) {
if (save[i].empty())
continue;
auto it = save[i].begin();
ll val = *it;
if (cur + 1 < val)
return 0;
if (sz(save[i]) >= 2) {
it = next(it);
if (cur + val + 1 < *it)
return 0;
}
cur += sum[i];
}
return 1;
}
bool init(int n, ll mx, ll coin[]) {
for (int i = 0; i < n; i++) {
add(coin[i], 1);
}
return ok();
}
bool is_happy(int c, int n, long long coin[]) {
for (int i = 0; i < n; ++i) {
add(coin[i], c);
}
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;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
1116 KB |
Output is correct |
9 |
Correct |
6 ms |
1028 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
113 ms |
9112 KB |
Output is correct |
7 |
Correct |
113 ms |
9048 KB |
Output is correct |
8 |
Correct |
123 ms |
8980 KB |
Output is correct |
9 |
Correct |
185 ms |
10580 KB |
Output is correct |
10 |
Correct |
219 ms |
12944 KB |
Output is correct |
11 |
Correct |
110 ms |
13636 KB |
Output is correct |
12 |
Correct |
125 ms |
13712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
1116 KB |
Output is correct |
9 |
Correct |
6 ms |
1028 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
11 |
Correct |
113 ms |
9112 KB |
Output is correct |
12 |
Correct |
113 ms |
9048 KB |
Output is correct |
13 |
Correct |
123 ms |
8980 KB |
Output is correct |
14 |
Correct |
185 ms |
10580 KB |
Output is correct |
15 |
Correct |
219 ms |
12944 KB |
Output is correct |
16 |
Correct |
110 ms |
13636 KB |
Output is correct |
17 |
Correct |
125 ms |
13712 KB |
Output is correct |
18 |
Correct |
152 ms |
11392 KB |
Output is correct |
19 |
Correct |
148 ms |
11344 KB |
Output is correct |
20 |
Correct |
242 ms |
14416 KB |
Output is correct |
21 |
Correct |
174 ms |
10836 KB |
Output is correct |
22 |
Correct |
132 ms |
15704 KB |
Output is correct |
23 |
Correct |
140 ms |
16208 KB |
Output is correct |
24 |
Correct |
139 ms |
11348 KB |
Output is correct |