답안 #203818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203818 2020-02-22T09:31:28 Z ho94949 Candies (JOI18_candies) C++17
100 / 100
340 ms 16504 KB
#include<bits/stdc++.h>
using namespace std;

const long long INF = 1e18;
const int MAXN = 262144;
int N;
long long arr[MAXN];

int idx[2*MAXN];

void setv(int a, long long v)
{
    arr[a] = v;
    idx[a+MAXN] = a;
    a += MAXN;
    while((a=a/2))
    {
        if(arr[idx[2*a]] < arr[idx[2*a+1]])
            idx[a] = idx[2*a+1];
        else
            idx[a] = idx[2*a];
    }
}
int geti()
{
    return idx[1];
}

int main()
{
    int N; scanf("%d", &N);
    set<int> S;
    setv(0, -INF); S.insert(0);
    for(int i=1; i<=N; ++i)
    {
        long long t; scanf("%lld", &t);
        setv(i, t); S.insert(i);
    }
    setv(N+1, -INF); S.insert(N+1);


    auto query = [&]()
    {
        int idx = geti(); long long retv = arr[idx];


        auto it = S.find(idx);
        auto it2 = it; --it2; int pidx = *it2;
        auto it3 = it; ++it3; int nidx = *it3;

        S.erase(it2); S.erase(it3);
        long long newval = arr[pidx]+arr[nidx] - arr[idx];
        setv(pidx, -INF);
        setv(nidx, -INF);
        setv(idx, newval);

        return retv;
    };

    long long ans = 0;
    for(int i=0; i<(N+1)/2; ++i)
    {
        long long t; scanf("%lld", &t);
        ans += query();
        printf("%lld\n", ans);
    }
    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:31:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int N; scanf("%d", &N);
            ~~~~~^~~~~~~~~~
candies.cpp:36:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         long long t; scanf("%lld", &t);
                      ~~~~~^~~~~~~~~~~~
candies.cpp:63:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         long long t; scanf("%lld", &t);
                      ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 7 ms 504 KB Output is correct
3 Correct 7 ms 632 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 7 ms 632 KB Output is correct
8 Correct 8 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 8 ms 504 KB Output is correct
11 Correct 7 ms 504 KB Output is correct
12 Correct 7 ms 504 KB Output is correct
13 Correct 7 ms 508 KB Output is correct
14 Correct 7 ms 504 KB Output is correct
15 Correct 8 ms 632 KB Output is correct
16 Correct 7 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 8 ms 504 KB Output is correct
19 Correct 7 ms 504 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 7 ms 504 KB Output is correct
3 Correct 7 ms 632 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 7 ms 504 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 7 ms 632 KB Output is correct
8 Correct 8 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 8 ms 504 KB Output is correct
11 Correct 7 ms 504 KB Output is correct
12 Correct 7 ms 504 KB Output is correct
13 Correct 7 ms 508 KB Output is correct
14 Correct 7 ms 504 KB Output is correct
15 Correct 8 ms 632 KB Output is correct
16 Correct 7 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 8 ms 504 KB Output is correct
19 Correct 7 ms 504 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 333 ms 16504 KB Output is correct
22 Correct 324 ms 16376 KB Output is correct
23 Correct 340 ms 16376 KB Output is correct
24 Correct 232 ms 16232 KB Output is correct
25 Correct 226 ms 16120 KB Output is correct
26 Correct 243 ms 16248 KB Output is correct
27 Correct 225 ms 16324 KB Output is correct
28 Correct 223 ms 16376 KB Output is correct
29 Correct 228 ms 16308 KB Output is correct
30 Correct 243 ms 16408 KB Output is correct
31 Correct 235 ms 16376 KB Output is correct
32 Correct 233 ms 16376 KB Output is correct
33 Correct 260 ms 16120 KB Output is correct
34 Correct 271 ms 16208 KB Output is correct
35 Correct 267 ms 16124 KB Output is correct
36 Correct 328 ms 16504 KB Output is correct
37 Correct 317 ms 16376 KB Output is correct
38 Correct 325 ms 16376 KB Output is correct
39 Correct 226 ms 16120 KB Output is correct
40 Correct 229 ms 16248 KB Output is correct
41 Correct 234 ms 16224 KB Output is correct
42 Correct 228 ms 16504 KB Output is correct
43 Correct 226 ms 16376 KB Output is correct
44 Correct 229 ms 16376 KB Output is correct
45 Correct 240 ms 16376 KB Output is correct
46 Correct 228 ms 16376 KB Output is correct
47 Correct 239 ms 16376 KB Output is correct
48 Correct 272 ms 16124 KB Output is correct
49 Correct 262 ms 16120 KB Output is correct
50 Correct 270 ms 16120 KB Output is correct