답안 #349394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349394 2021-01-17T14:08:55 Z parsabahrami Happiness (Balkan15_HAPPINESS) C++17
40 / 100
2000 ms 13804 KB
#include "happiness.h"
#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 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 Execution timed out 2089 ms 364 KB Time limit exceeded
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 224 ms 9196 KB Output is correct
7 Correct 201 ms 9196 KB Output is correct
8 Correct 216 ms 9324 KB Output is correct
9 Correct 352 ms 10732 KB Output is correct
10 Correct 500 ms 13316 KB Output is correct
11 Correct 183 ms 13676 KB Output is correct
12 Correct 208 ms 13804 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 Execution timed out 2089 ms 364 KB Time limit exceeded
7 Halted 0 ms 0 KB -