# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
494806 | blue | Discharging (NOI20_discharging) | C++17 | 444 ms | 10012 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
#define sz(x) int(x.size())
const ll INF = 1'000'000'000'000'000'000LL;
int main()
{
int N;
cin >> N;
int TS = N;
vector<pll> T;
ll t1;
cin >> t1;
T.push_back({t1, 1});
for(int i = 2; i <= N; i++)
{
ll t;
cin >> t;
if(t <= T.back().first)
T.back().second++;
else
T.push_back({t, 1});
}
// for(auto t:T) cerr << t.first << "/" << t.second << " ";
// cerr << '\n';
int ct = 0;
vector<pll> S;
for(auto t:T)
{
// cerr << "turn = " << ++ct << '\n';
S.push_back(t);
while(sz(S) >= 2)
{
auto x = S[sz(S)-2];
auto y = S[sz(S)-1];
// cerr << x.first << ' ' << x.second << " + " << y.first << ' ' << y.second << '\n';
// cerr << y.first * x.second << ' ' << x.first * (x.second + y.second) << '\n';
if(!(y.first * x.second <= x.first * (x.second + y.second))) break;
// cerr <<
pll newT{S[sz(S)-1].first, S[sz(S)-1].second + S[sz(S)-2].second};
S.pop_back();
S.pop_back();
S.push_back(newT);
}
}
// for(auto t:T) cerr << t.first << "/" << t.second << " ";
// cerr << '\n';
ll ans = 0;
reverse(S.begin(), S.end());
ll suff = 0;
for(auto t:S)
{
suff += t.second;
ans += suff*t.first;
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |