Submission #349397

# Submission time Handle Problem Language Result Execution time Memory
349397 2021-01-17T14:12:14 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 = 30;
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 < L; 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;
      |            ^~~~~~~~
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 2093 ms 364 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 215 ms 6124 KB Output is correct
7 Correct 201 ms 5996 KB Output is correct
8 Correct 217 ms 5996 KB Output is correct
9 Correct 344 ms 6124 KB Output is correct
10 Correct 497 ms 8684 KB Output is correct
11 Correct 181 ms 9964 KB Output is correct
12 Correct 191 ms 9964 KB Output is correct
# Verdict Execution time Memory 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 2093 ms 364 KB Time limit exceeded
7 Halted 0 ms 0 KB -