답안 #427581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427581 2021-06-14T17:25:25 Z CSQ31 Happiness (Balkan15_HAPPINESS) C++14
40 / 100
686 ms 524292 KB
#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e9+1)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
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);
		}
	}
	ll query(int L,int R){
		if(lf == L && R == rg)return sum;
		int tm = (lf+rg)/2;
		if(R<=tm){
			if(l==nullptr)l = new node(lf,tm);
			return l->query(L,R);
		}
		else if(L>tm){
			if(r==nullptr)r = new node(tm+1,rg);
			return r->query(L,R);
		}else{
			if(l==nullptr)l = new node(lf,tm);
			if(r==nullptr)r = new node(tm+1,rg);
			return l->query(L,tm) + r->query(tm+1,R);
			
		}
	}
};
node *root;
ll m;
bool check(){
	ll cur = 1,mx = root->sum;
	while(cur<mx){
		ll t = root->query(1,min(m,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 511 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 431 ms 34928 KB Output is correct
7 Correct 431 ms 34976 KB Output is correct
8 Correct 463 ms 34936 KB Output is correct
9 Correct 686 ms 44324 KB Output is correct
10 Correct 642 ms 48236 KB Output is correct
11 Correct 218 ms 33268 KB Output is correct
12 Correct 206 ms 33356 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 511 ms 524292 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -