답안 #276346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
276346 2020-08-20T12:15:40 Z sjimed Happiness (Balkan15_HAPPINESS) C++14
60 / 100
2000 ms 499608 KB
#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

struct Node {
	ll v, lz;
	int l, r;

	Node() {
		v = INF;
		lz = 0;
		l = r = 0;
	}

	Node(ll e) {
		v = INF - e;
		lz = 0;
		l = r = 0;
	}
};

ll sz = 0;
ll n, m;
map<ll,int> chk;
Node tree[20202020];

void update(int node, ll s, ll e, ll l, ll r, ll x) {
	if(r < s || e < l) return;
	if(l <= s && e <= r) {
		tree[node].lz += x;
		
		return;
	}

	if(tree[node].l == 0) {
		tree[node].l = sz++;
		tree[tree[node].l].v = INF - (s+e)/2;
	}
	if(tree[node].r == 0) {
		tree[node].r = sz++;
		tree[tree[node].r].v = INF - e;
	}

	update(tree[node].l, s, (s+e)/2, l, r, x);
	update(tree[node].r, (s+e)/2+1, e, l, r, x);

	tree[node].v = min(tree[tree[node].l].v + tree[tree[node].l].lz, tree[tree[node].r].v + tree[tree[node].r].lz);
}

bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
	n = coinsCount;
	m = maxCoinSize + 1;

	tree[0].v = INF - m;
	sz++;

	for(int i=0; i<n; i++) {
		if(chk.find(coins[i]) == chk.end()) update(0, 0, m, coins[i], coins[i], -INF);
		
		update(0, 0, m, coins[i]+1, m, coins[i]);
		
		chk[coins[i]]++;
	}

	return tree[0].v + tree[0].lz >= -1;
}

bool is_happy(int event, int coinsCount, long long coins[]) {
	n = coinsCount;

	for(int i=0; i<n; i++) {
		if(chk.find(coins[i]) != chk.end() && chk[coins[i]] == 1 && event == -1) update(0, 0, m, coins[i], coins[i], INF);
		if((chk.find(coins[i]) == chk.end() || chk[coins[i]] == 0) && event == 1) update(0, 0, m, coins[i], coins[i], -INF);

		if(event == 1) update(0, 0, m, coins[i]+1, m, coins[i]);
		else update(0, 0, m, coins[i]+1, m, -coins[i]);

		chk[coins[i]] += event;
	}

	return tree[0].v + tree[0].lz >= -1;
}

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 264 ms 474736 KB Output is correct
2 Correct 268 ms 474616 KB Output is correct
3 Correct 268 ms 474744 KB Output is correct
4 Correct 262 ms 474744 KB Output is correct
5 Correct 265 ms 474772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 474736 KB Output is correct
2 Correct 268 ms 474616 KB Output is correct
3 Correct 268 ms 474744 KB Output is correct
4 Correct 262 ms 474744 KB Output is correct
5 Correct 265 ms 474772 KB Output is correct
6 Correct 275 ms 474844 KB Output is correct
7 Correct 270 ms 474872 KB Output is correct
8 Correct 307 ms 475644 KB Output is correct
9 Correct 304 ms 475512 KB Output is correct
10 Correct 326 ms 475640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 474736 KB Output is correct
2 Correct 268 ms 474616 KB Output is correct
3 Correct 268 ms 474744 KB Output is correct
4 Correct 262 ms 474744 KB Output is correct
5 Correct 265 ms 474772 KB Output is correct
6 Correct 1348 ms 487040 KB Output is correct
7 Correct 1213 ms 486900 KB Output is correct
8 Correct 1272 ms 487288 KB Output is correct
9 Correct 1932 ms 492780 KB Output is correct
10 Correct 1941 ms 495092 KB Output is correct
11 Correct 956 ms 496888 KB Output is correct
12 Correct 1004 ms 497016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 474736 KB Output is correct
2 Correct 268 ms 474616 KB Output is correct
3 Correct 268 ms 474744 KB Output is correct
4 Correct 262 ms 474744 KB Output is correct
5 Correct 265 ms 474772 KB Output is correct
6 Correct 275 ms 474844 KB Output is correct
7 Correct 270 ms 474872 KB Output is correct
8 Correct 307 ms 475644 KB Output is correct
9 Correct 304 ms 475512 KB Output is correct
10 Correct 326 ms 475640 KB Output is correct
11 Correct 1348 ms 487040 KB Output is correct
12 Correct 1213 ms 486900 KB Output is correct
13 Correct 1272 ms 487288 KB Output is correct
14 Correct 1932 ms 492780 KB Output is correct
15 Correct 1941 ms 495092 KB Output is correct
16 Correct 956 ms 496888 KB Output is correct
17 Correct 1004 ms 497016 KB Output is correct
18 Correct 1803 ms 492792 KB Output is correct
19 Correct 1810 ms 494456 KB Output is correct
20 Execution timed out 2120 ms 499608 KB Time limit exceeded
21 Halted 0 ms 0 KB -