답안 #676555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676555 2022-12-31T08:50:54 Z tamthegod Candies (JOI18_candies) C++14
100 / 100
611 ms 24288 KB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n;
int a[maxN];
set<int> pos;
struct cmp
{
    bool operator () (int i, int j) const
    {
        return (a[i] > a[j] || (a[i] == a[j] && i < j));
    }
};
multiset<int, cmp> S;
void ReadInput()
{
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    a[0] = a[n + 1] = -oo;
    for(int i=0; i<=n+1; i++)
    {
        S.insert(i);
        pos.insert(i);
    }
}
void Solve()
{
    int res = 0;
    for(int i=1; i<=(n+1)/2; i++)
    {
        auto it = S.begin();
        res += a[*it];
        auto it1 = pos.find(*it);
        auto l = it1, r = it1;
        int val = -a[*it];
        if(l != pos.begin())
        {
            l--;
            val += a[*l];
            S.erase(*l);
            pos.erase(*l);
        }
        r++;
        if(r != pos.end())
        {
            val += a[*r];
            S.erase(*r);
            pos.erase(*r);
        }
        int tmp = *it;
        S.erase(tmp);
        a[tmp] = val;
        S.insert(tmp);
       cout << res << '\n';
    }
}
int32_t main()
{
    //freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
/*
49
98
143
187
225
252
262
267
269
269
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 488 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 3 ms 472 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 3 ms 488 KB Output is correct
18 Correct 2 ms 488 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 488 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 3 ms 472 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 3 ms 488 KB Output is correct
18 Correct 2 ms 488 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 554 ms 24100 KB Output is correct
22 Correct 547 ms 24052 KB Output is correct
23 Correct 556 ms 23980 KB Output is correct
24 Correct 240 ms 24020 KB Output is correct
25 Correct 218 ms 23884 KB Output is correct
26 Correct 238 ms 23948 KB Output is correct
27 Correct 229 ms 24072 KB Output is correct
28 Correct 254 ms 24048 KB Output is correct
29 Correct 240 ms 24288 KB Output is correct
30 Correct 241 ms 24060 KB Output is correct
31 Correct 239 ms 24036 KB Output is correct
32 Correct 282 ms 24012 KB Output is correct
33 Correct 348 ms 23832 KB Output is correct
34 Correct 374 ms 23896 KB Output is correct
35 Correct 353 ms 23984 KB Output is correct
36 Correct 611 ms 24100 KB Output is correct
37 Correct 541 ms 24116 KB Output is correct
38 Correct 541 ms 24004 KB Output is correct
39 Correct 225 ms 23884 KB Output is correct
40 Correct 232 ms 23904 KB Output is correct
41 Correct 219 ms 23856 KB Output is correct
42 Correct 231 ms 24180 KB Output is correct
43 Correct 249 ms 24212 KB Output is correct
44 Correct 222 ms 24036 KB Output is correct
45 Correct 237 ms 24012 KB Output is correct
46 Correct 255 ms 24136 KB Output is correct
47 Correct 241 ms 24048 KB Output is correct
48 Correct 375 ms 23824 KB Output is correct
49 Correct 333 ms 23816 KB Output is correct
50 Correct 374 ms 23936 KB Output is correct