답안 #427607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427607 2021-06-14T17:47:35 Z CSQ31 Happiness (Balkan15_HAPPINESS) C++14
40 / 100
679 ms 524292 KB
#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	ll lf,rg,sum;
	node *l,*r;
	node(ll _lf,ll _rg){
		l = nullptr;
		r = nullptr;
		sum = 0;
		lf = _lf;
		rg = _rg;
	}
	void upd(ll val,ll c){
		sum+=val*c;
		if(lf==rg)return;
		int tm = (lf+rg)/2;
		if(val<=tm){
			if(l == nullptr)l = new node(lf,tm);
			l->upd(val,c);
		}else{
			if(r == nullptr)r = new node(tm+1,rg);
			r->upd(val,c);
		}
	}
	long long query(long long a, long long b) {
		if (rg < a || lf > b) return 0;
		if (rg <= b && lf >= a) return sum;
		long long ret = 0;
		if (l) ret += l->query(a, b);
		if (r) ret += r->query(a, b);
		return ret;
	}
};
ll m;
node *root;
bool check(){
	ll cur = 1,mx = root->sum;
	while(cur<mx){
		ll t = root->query(1,cur);
		if(cur>t)return false;
		cur = t+1;
	}
	return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
	m = maxCoinSize;
    root = new node(1,m);	
	for(int i=0;i<coinsCount;i++)root->upd(coins[i],1);
	return check();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
	for(int i=0;i<coinsCount;i++)root->upd(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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Runtime error 465 ms 524292 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 442 ms 34512 KB Output is correct
7 Correct 434 ms 33948 KB Output is correct
8 Correct 466 ms 34452 KB Output is correct
9 Correct 671 ms 44268 KB Output is correct
10 Correct 679 ms 48132 KB Output is correct
11 Correct 170 ms 33268 KB Output is correct
12 Correct 170 ms 33220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Runtime error 465 ms 524292 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -