답안 #278570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
278570 2020-08-21T14:36:42 Z arnold518 Happiness (Balkan15_HAPPINESS) C++14
10 / 100
2000 ms 488748 KB
#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MAXN = 1e18;

ll M;

unordered_map<ll, ll> tree;

void update(ll i, ll k) { for(; i<=MAXN; i+=(i&-i)) tree[i]+=k; }
ll query(ll i) { ll ret=0; for(; i>0; i-=(i&-i)) ret+=tree[i]; return ret; }

void push(ll x)
{
	update(x, x);
}

void pop(ll x)
{
	update(x, -x);
}

bool query()
{
	ll now=1;
	ll sum=query(M);
	for(ll i=1; i<=sum; i++) if(query(i)<i) return 0;
	/*
	while(now<sum)
	{
		if(query(now)<now) return 0;
		now=query(now)+1;
	}
	*/
	return 1;
}

bool init(int coinsCount, ll maxCoinSize, ll coins[])
{
	M=maxCoinSize;

	for(int i=0; i<coinsCount; i++) push(coins[i]);
	return query();
}

bool is_happy(int event, int coinsCount, ll coins[])
{
	if(event==-1) for(int i=0; i<coinsCount; i++) pop(coins[i]);
	else for(int i=0; i<coinsCount; i++) push(coins[i]);
	return query();
}

Compilation message

happiness.cpp: In function 'bool query()':
happiness.cpp:30:5: warning: unused variable 'now' [-Wunused-variable]
   30 |  ll now=1;
      |     ^~~
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 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 46 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 46 ms 888 KB Output is correct
6 Execution timed out 2108 ms 487312 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 46 ms 888 KB Output is correct
6 Execution timed out 2129 ms 488748 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 7 ms 512 KB Output is correct
5 Correct 46 ms 888 KB Output is correct
6 Execution timed out 2108 ms 487312 KB Time limit exceeded
7 Halted 0 ms 0 KB -