답안 #349396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349396 2021-01-17T14:11:05 Z parsabahrami Happiness (Balkan15_HAPPINESS) C++11
40 / 100
2000 ms 9964 KB
#include "happiness.h"
#pragma GCC optimize("O2")
#include <bits/stdc++.h> 

using namespace std;

typedef long long int ll;

#define SZ(x)               (int) x.size()
#define F                   first
#define S                   second

const int L = 40;
ll S[L]; multiset<ll> M[L];

void add(ll x, int b) {
    int g = 0; while ((1 << (g + 1)) <= x) g++;
    S[g] += b * x;
    if (~b) M[g].insert(x);
    else M[g].erase(M[g].find(x));
}

int check() {
    ll sum = 0;
    for (int i = 0; i < 40; i++) {
        if (!SZ(M[i])) continue;
        ll x = *M[i].begin();
        if (sum + 1 < x) return 0;
        if (SZ(M[i]) > 1 && *next(M[i].begin()) > sum + 1 + x) return 0;
        sum += S[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 check();
}

bool is_happy(int event, int coinsCount, long long coins[]) {
    for (int i = 0; i < coinsCount; i++) {
       add(coins[i], event);
    }
    return check();
}

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 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 0 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 Execution timed out 2071 ms 364 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 223 ms 6124 KB Output is correct
7 Correct 201 ms 6124 KB Output is correct
8 Correct 214 ms 5996 KB Output is correct
9 Correct 337 ms 5996 KB Output is correct
10 Correct 534 ms 8556 KB Output is correct
11 Correct 183 ms 9964 KB Output is correct
12 Correct 193 ms 9928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Execution timed out 2071 ms 364 KB Time limit exceeded
7 Halted 0 ms 0 KB -