이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 200005, inf = 1e18;
ll n, a[N], par[N];
set<pll> val, idx;
ll Find (ll X) {
if(par[X] == X) return X;
return par[X] = Find(par[X]);
}
int main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++) {
scanf("%lld",&a[i]);
par[i] = i;
val.insert({-a[i], i});
idx.insert({i, -a[i]});
}
ll R = 0;
for(ll i=1;i<=(n+1)/2;i++) {
ll A, B, C, D;
tie(A, B) = *val.begin();
val.erase(pll(A, B));
idx.erase(pll(B, A));
R -= A;
A *= -1;
if(B != 1) {
tie(C, D) = *idx.lower_bound(pll(Find(B-1), -inf));
idx.erase(pll(C, D));
val.erase(pll(D, C));
A += D;
par[B] = B-1;
}
if(B != n) {
tie(C, D) = *idx.lower_bound(pll(B+1, -inf));
idx.erase(pll(C, D));
val.erase(pll(D, C));
A += D;
par[B+1] = B;
}
B = Find(B);
val.insert(pll(A, B));
idx.insert(pll(B, A));
printf("%lld\n",R);
}
}
컴파일 시 표준 에러 (stderr) 메시지
candies.cpp: In function 'int main()':
candies.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
candies.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[i]);
~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |