답안 #1086717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086717 2024-09-11T10:14:41 Z LOLOLO Happiness (Balkan15_HAPPINESS) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#include <happiness.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 = sum[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 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -