답안 #381663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381663 2021-03-25T13:48:41 Z ntabc05101 Happiness (Balkan15_HAPPINESS) C++14
40 / 100
468 ms 9964 KB
#include "happiness.h";
#include<bits/stdc++.h>

#define LL long long

const int log_mx=40;

std::multiset<LL> m[log_mx];
LL sum[log_mx];

void update(int p, int event) {
        int log_p=0;
        while ((1LL<<log_p+1)<=p) log_p++;

        if (event==1) {
                m[log_p].insert(p);
                sum[log_p]+=p;
        }
        else {
                m[log_p].erase(m[log_p].find(p));
                sum[log_p]-=p;
        }
}

bool check() {
        LL current=0;
        for (int i=0; i<log_mx; i++) {
                if (!m[i].empty()) {
                        LL x=*m[i].begin();
                        if (current+1<x) return false;
                        if (m[i].size()>1 and current+x+1<*next(begin(m[i]))) return false;
                        current+=sum[i];
                }
        }

        return true;
}

bool init(int coinsCount, LL maxCoinSize, LL coins[]) {
        for (int i=0; i<coinsCount; i++) {
                update(coins[i], 1);
        }

        return check();
}

bool is_happy(int event, int coinsCount, LL coins[]) {
        for (int i=0; i<coinsCount; i++) {
                update(coins[i], event);
        }

        return check();
}

/*int main() {
        std::ios_base::sync_with_stdio(0); std::cin.tie(0);

        int n; LL m; std::cin>>n>>m;
        LL coins[n];
        for (int i=0; i<n; i++) std::cin>>coins[i];
        std::cout<<init(n, m, coins)<<"\n";

        int q; std::cin>>q;
        while (q--) {
                int e, k; std::cin>>e>>k;
                LL coins[k]; 
                for (int i=0; i<k; i++) std::cin>>coins[i];
                std::cout<<is_happy(e, k, coins)<<"\n";
        }

        return 0;
}*/

Compilation message

happiness.cpp:1:23: warning: extra tokens at end of #include directive
    1 | #include "happiness.h";
      |                       ^
happiness.cpp: In function 'void update(int, int)':
happiness.cpp:13:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   13 |         while ((1LL<<log_p+1)<=p) log_p++;
      |                      ~~~~~^~
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 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 219 ms 5996 KB Output is correct
7 Correct 202 ms 6124 KB Output is correct
8 Correct 204 ms 6048 KB Output is correct
9 Correct 330 ms 6124 KB Output is correct
10 Correct 468 ms 8684 KB Output is correct
11 Correct 181 ms 9932 KB Output is correct
12 Correct 193 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 Incorrect 1 ms 364 KB Output isn't correct
7 Halted 0 ms 0 KB -