답안 #44902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44902 2018-04-09T08:10:25 Z PowerOfNinjaGo Candies (JOI18_candies) C++17
100 / 100
589 ms 71472 KB
#include <cstdio>
#include <map>
#include <queue>
#include <utility>
using namespace std;
typedef pair<long long,int> pi;
typedef map<int,bool> mp;

priority_queue<pi > pq;
mp viable;

int n,k;
long long a[200005];

int main(){
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    for (int i=n-1; i>= 0; i--) {
        pq.push(pi(a[i],i));
        viable[i] = 1;
    }
    long long res = 0;
    for (int i=0; i<(n+1)/2; i++)
    {
        int p = pq.top().second; pq.pop();
        if(viable.count(p) == 0){
            i--;
            continue;
        }
        res += a[p];
        printf("%lld\n", res);
        viable.erase(viable.find(p));
        mp::iterator it = viable.upper_bound(p);
        long long x = 0; int cont = 0;
        if(it != viable.end()){
            x += a[(*it).first];
            viable.erase((*it).first);
        }
        else cont = 1;
        it = viable.upper_bound(p);
        if(it != viable.begin()){
            it--;
            x += a[(*it).first];
            viable.erase((*it).first);
        }
        else cont = 1;
        if(cont) continue;
        viable[p] = 1;
        a[p] = x - a[p];
        pq.push(pi(a[p],p));
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:18:25: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
         scanf("%d",&a[i]);
                    ~~~~~^
candies.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
candies.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 484 KB Output is correct
3 Correct 4 ms 576 KB Output is correct
4 Correct 4 ms 592 KB Output is correct
5 Correct 4 ms 668 KB Output is correct
6 Correct 4 ms 756 KB Output is correct
7 Correct 4 ms 808 KB Output is correct
8 Correct 4 ms 808 KB Output is correct
9 Correct 3 ms 828 KB Output is correct
10 Correct 3 ms 828 KB Output is correct
11 Correct 4 ms 832 KB Output is correct
12 Correct 4 ms 832 KB Output is correct
13 Correct 4 ms 832 KB Output is correct
14 Correct 4 ms 832 KB Output is correct
15 Correct 4 ms 832 KB Output is correct
16 Correct 5 ms 832 KB Output is correct
17 Correct 4 ms 832 KB Output is correct
18 Correct 4 ms 832 KB Output is correct
19 Correct 3 ms 832 KB Output is correct
20 Correct 4 ms 832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 484 KB Output is correct
3 Correct 4 ms 576 KB Output is correct
4 Correct 4 ms 592 KB Output is correct
5 Correct 4 ms 668 KB Output is correct
6 Correct 4 ms 756 KB Output is correct
7 Correct 4 ms 808 KB Output is correct
8 Correct 4 ms 808 KB Output is correct
9 Correct 3 ms 828 KB Output is correct
10 Correct 3 ms 828 KB Output is correct
11 Correct 4 ms 832 KB Output is correct
12 Correct 4 ms 832 KB Output is correct
13 Correct 4 ms 832 KB Output is correct
14 Correct 4 ms 832 KB Output is correct
15 Correct 4 ms 832 KB Output is correct
16 Correct 5 ms 832 KB Output is correct
17 Correct 4 ms 832 KB Output is correct
18 Correct 4 ms 832 KB Output is correct
19 Correct 3 ms 832 KB Output is correct
20 Correct 4 ms 832 KB Output is correct
21 Correct 569 ms 17092 KB Output is correct
22 Correct 552 ms 18872 KB Output is correct
23 Correct 589 ms 21088 KB Output is correct
24 Correct 325 ms 22760 KB Output is correct
25 Correct 303 ms 24540 KB Output is correct
26 Correct 304 ms 26192 KB Output is correct
27 Correct 339 ms 28200 KB Output is correct
28 Correct 326 ms 30056 KB Output is correct
29 Correct 337 ms 32232 KB Output is correct
30 Correct 342 ms 34012 KB Output is correct
31 Correct 343 ms 36024 KB Output is correct
32 Correct 345 ms 37936 KB Output is correct
33 Correct 415 ms 39772 KB Output is correct
34 Correct 401 ms 41524 KB Output is correct
35 Correct 399 ms 43344 KB Output is correct
36 Correct 517 ms 45240 KB Output is correct
37 Correct 555 ms 47280 KB Output is correct
38 Correct 522 ms 49052 KB Output is correct
39 Correct 301 ms 50836 KB Output is correct
40 Correct 298 ms 52820 KB Output is correct
41 Correct 294 ms 54500 KB Output is correct
42 Correct 401 ms 56524 KB Output is correct
43 Correct 340 ms 58392 KB Output is correct
44 Correct 308 ms 60252 KB Output is correct
45 Correct 331 ms 62376 KB Output is correct
46 Correct 331 ms 64164 KB Output is correct
47 Correct 331 ms 66364 KB Output is correct
48 Correct 412 ms 67980 KB Output is correct
49 Correct 396 ms 69748 KB Output is correct
50 Correct 437 ms 71472 KB Output is correct