답안 #202511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202511 2020-02-16T17:08:55 Z stefdasca Candies (JOI18_candies) C++14
100 / 100
127 ms 10520 KB
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

// #define fisier 1

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand_seed()
{
    long long a = rng();
    return a;
}

priority_queue<pair<ll, int> >q;

int n, st[200002], dr[200002];

ll ans, v[200002];

bool pus[200002];

int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        st[i] = i-1;
        dr[i] = i+1;
        q.push({v[i], i});
    }
    v[0] = v[n+1] = -(1LL<<60);
    for(int i = 1; i <= (n+1) / 2; ++i)
    {
        while(!q.empty() && pus[q.top().se])
            q.pop();
        pair<ll, int> tp = q.top();
        q.pop();
        ans += tp.fi;
        cout << ans << '\n';
        pus[st[tp.se]] = 1, pus[dr[tp.se]] = 1;
        v[tp.se] = v[st[tp.se]] + v[dr[tp.se]] - v[tp.se];
        q.push({v[tp.se], tp.se});
        st[tp.se] = st[st[tp.se]]; dr[st[tp.se]] = tp.se;
        dr[tp.se] = dr[dr[tp.se]]; st[dr[tp.se]] = tp.se;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 508 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 508 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 508 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 508 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 127 ms 10460 KB Output is correct
22 Correct 122 ms 10336 KB Output is correct
23 Correct 121 ms 10336 KB Output is correct
24 Correct 106 ms 10240 KB Output is correct
25 Correct 98 ms 10208 KB Output is correct
26 Correct 101 ms 10208 KB Output is correct
27 Correct 114 ms 10464 KB Output is correct
28 Correct 108 ms 10336 KB Output is correct
29 Correct 106 ms 10520 KB Output is correct
30 Correct 109 ms 10336 KB Output is correct
31 Correct 107 ms 10336 KB Output is correct
32 Correct 103 ms 10464 KB Output is correct
33 Correct 113 ms 10208 KB Output is correct
34 Correct 110 ms 10208 KB Output is correct
35 Correct 111 ms 10208 KB Output is correct
36 Correct 125 ms 10464 KB Output is correct
37 Correct 127 ms 10340 KB Output is correct
38 Correct 123 ms 10336 KB Output is correct
39 Correct 100 ms 10336 KB Output is correct
40 Correct 98 ms 10208 KB Output is correct
41 Correct 93 ms 10208 KB Output is correct
42 Correct 105 ms 10372 KB Output is correct
43 Correct 107 ms 10340 KB Output is correct
44 Correct 110 ms 10464 KB Output is correct
45 Correct 108 ms 10336 KB Output is correct
46 Correct 108 ms 10336 KB Output is correct
47 Correct 106 ms 10336 KB Output is correct
48 Correct 117 ms 10208 KB Output is correct
49 Correct 123 ms 10208 KB Output is correct
50 Correct 117 ms 10212 KB Output is correct