답안 #1071114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071114 2024-08-23T04:55:24 Z phong Candies (JOI18_candies) C++17
0 / 100
3 ms 5208 KB
#include<bits/stdc++.h>

#define ll long long
const int nmax = 2e5 + 5, N = 1e5;
const ll oo = 1e18 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;

int n, a[nmax];
ll ans[nmax];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    multiset<pii> one, two;
    a[0] = -oo;
    a[n + 1] = -oo;
    for(int i = 0; i <= n + 1; ++i){
        one.insert({a[i], i});
        two.insert({i, a[i]});
    }
    for(int i = 1; i <= (n + 1) / 2; ++i){
        auto x = *one.rbegin();
        ans[i] = ans[i - 1] + x.fi;
        cout << ans[i] << endl;
        auto it = two.lower_bound({x.se, -oo});
        --it;
        auto s1 = it;
        one.erase({it->se, it->fi});
        two.erase(it++);
        auto s2 = it;
        one.erase({it->se, it->fi});
        two.erase(it++);
        auto s3 = it;
        one.erase({it->se, it->fi});
        two.erase(it++);
        one.insert({s1->se + s3->se - s2->se, s2->fi});
        two.insert({s2->fi, s1->se + s3->se - s2->se});


    }

}
/*
1
13 1
3 0
4 4
0 2
0 5
3 1
3 2
3 4
0 5
4 4
0 7
4 6
3 2
4 2



*/

Compilation message

candies.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~
candies.cpp: In function 'int main()':
candies.cpp:26:12: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow]
   26 |     a[0] = -oo;
      |            ^~~
candies.cpp:27:16: warning: overflow in conversion from 'long long int' to 'int' changes value from '-1000000000000000000' to '1486618624' [-Woverflow]
   27 |     a[n + 1] = -oo;
      |                ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5208 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5208 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -