제출 #462503

#제출 시각아이디문제언어결과실행 시간메모리
462503Killer2501Candies (JOI18_candies)C++14
100 / 100
639 ms32016 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "asd"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, a[N], b[N], s, u, v, d[N][4], dp[N][4];
vector<pll> adj[N];
vector<ll> kq;

ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
void dij(ll ui, ll id)
{
    for(int i = 1; i <= n; i ++)d[i][id] = mod;
    priority_queue< pll, vector<pll>, greater<pll> > pq;
    pq.push({0, ui});
    d[ui][id] = 0;
    while(!pq.empty())
    {
        pll u = pq.top();
        pq.pop();
        if(u.fi != d[u.se][id])continue;
        for(pll v : adj[u.se])
        {
            if(d[v.se][id] > u.fi + v.fi)
            {
                d[v.se][id] = u.fi + v.fi;
                pq.push({d[v.se][id], v.se});
            }
        }
    }
}
void sol()
{
    cin >> n;
    set<pll> st;
    set<ll> id;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        st.insert({a[i], i});
        id.insert(i);
    }
    a[0] = a[n+1] = -mod;
    id.insert(0);
    id.insert(n+1);
    for(int i = 1; i <= (n+1)/2; i ++)
    {
        pll x = (*st.rbegin());
        ans += x.fi;
        st.erase(x);
        id.erase(x.se);
        auto lf = id.lower_bound(x.se);
        auto rt = id.upper_bound(x.se);
        --lf;
        ll l = *lf, r = *rt;
        id.erase(r);
        st.erase({a[l], l});
        st.erase({a[r], r});
        a[l] += a[r] - x.fi;
        st.insert({a[l], l});
        cout << ans << '\n';
    }
}
int main()
{
    if(fopen(task".INP", "r"))
    {
       freopen(task".INP", "r", stdin);
       freopen(task".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
1 2
2 3
3 4
4 5
*/

컴파일 시 표준 에러 (stderr) 메시지

candies.cpp: In function 'int main()':
candies.cpp:85:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |        freopen(task".INP", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:86:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |        freopen(task".OUT", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...