# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
275345 | 2020-08-20T05:36:20 Z | 문홍윤(#5111) | Happiness (Balkan15_HAPPINESS) | C++17 | 2000 ms | 255992 KB |
#include "happiness.h" #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL INF=1e12; LL sum; struct SEGMENT_TREE{ struct NODE{ LL b; NODE *l, *r; NODE(){b=0; l=r=0;} }*rt; SEGMENT_TREE(){rt=new NODE();} void update(NODE* nd, LL s, LL e, LL num, LL val){ if(s==e){ nd->b+=val; return; } if(num<=(s+e)/2){ if(!nd->l)nd->l=new NODE(); update(nd->l, s, (s+e)/2, num, val); } else{ if(!nd->r)nd->r=new NODE(); update(nd->r, (s+e)/2+1, e, num, val); } nd->b=0; if(nd->l)nd->b+=nd->l->b; if(nd->r)nd->b+=nd->r->b; } void update(LL num, LL val){update(rt, 1ll, INF, num, val);} LL query(NODE* nd, LL s, LL e, LL a, LL b){ if(e<a||s>b)return 0ll; if(a<=s&&e<=b)return nd->b; LL ret=0; if(nd->l)ret+=query(nd->l, s, (s+e)/2, a, b); if(nd->r)ret+=query(nd->r, (s+e)/2+1, e, a, b); return ret; } LL query(LL a, LL b){return query(rt, 1ll, INF, a, b);} }seg; bool query(){ LL pos=0; while(1){ if(pos==sum)return true; LL tmp=seg.query(1ll, pos+1); if(tmp==pos)return false; pos=tmp; } } bool init(int coinsCount, LL maxCoinSize, LL coins[]) { for(int i=0; i<coinsCount; i++){ seg.update(coins[i], coins[i]); sum+=coins[i]; } return query(); } bool is_happy(int event, int coinsCount, LL coins[]) { for(int i=0; i<coinsCount; i++){ seg.update(coins[i], coins[i]*(LL)event); sum+=coins[i]*(LL)event; } return query(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 288 KB | Output is correct |
6 | Correct | 5 ms | 1408 KB | Output is correct |
7 | Correct | 5 ms | 1408 KB | Output is correct |
8 | Correct | 48 ms | 9476 KB | Output is correct |
9 | Correct | 48 ms | 9548 KB | Output is correct |
10 | Correct | 45 ms | 9216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 288 KB | Output is correct |
6 | Correct | 1002 ms | 25652 KB | Output is correct |
7 | Correct | 811 ms | 26232 KB | Output is correct |
8 | Correct | 895 ms | 26748 KB | Output is correct |
9 | Correct | 1187 ms | 34460 KB | Output is correct |
10 | Correct | 1288 ms | 37168 KB | Output is correct |
11 | Correct | 473 ms | 26228 KB | Output is correct |
12 | Correct | 412 ms | 26272 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 288 KB | Output is correct |
6 | Correct | 5 ms | 1408 KB | Output is correct |
7 | Correct | 5 ms | 1408 KB | Output is correct |
8 | Correct | 48 ms | 9476 KB | Output is correct |
9 | Correct | 48 ms | 9548 KB | Output is correct |
10 | Correct | 45 ms | 9216 KB | Output is correct |
11 | Correct | 1002 ms | 25652 KB | Output is correct |
12 | Correct | 811 ms | 26232 KB | Output is correct |
13 | Correct | 895 ms | 26748 KB | Output is correct |
14 | Correct | 1187 ms | 34460 KB | Output is correct |
15 | Correct | 1288 ms | 37168 KB | Output is correct |
16 | Correct | 473 ms | 26228 KB | Output is correct |
17 | Correct | 412 ms | 26272 KB | Output is correct |
18 | Correct | 1494 ms | 152824 KB | Output is correct |
19 | Correct | 1778 ms | 158728 KB | Output is correct |
20 | Execution timed out | 2107 ms | 255992 KB | Time limit exceeded |
21 | Halted | 0 ms | 0 KB | - |