답안 #870857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870857 2023-11-09T10:09:53 Z pcc Discharging (NOI20_discharging) C++14
20 / 100
79 ms 500 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


vector<pll> v;
vector<pll> st;
int n;
ll total = 0;
ll sum = 0;

inline bool check(pll a,pll b){
	ll ta = a.fs*(sum-b.sc)+b.fs*sum;
	ll tb = a.fs*sum;
	if(ta>tb)return true;
	else return false;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 0;i<n;i++){
		int k;
		cin>>k;
		if(v.empty()||v.back().fs < k)v.push_back({k,1});
		else v.back().sc++;
	}
	reverse(v.begin(),v.end());
	for(auto &i:v){
		sum += i.sc;
		while(!st.empty()&&check(st.back(),i)){
			total -= st.back().fs*(sum-i.sc);
			i.sc += st.back().sc;
			i.fs = st.back().fs;
			st.pop_back();
		}
		total += sum*i.fs;
		st.push_back(i);
	}
	//for(auto &i:st)cout<<i.fs<<' '<<i.sc<<endl;
	cout<<total;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 428 KB Output is correct
2 Correct 79 ms 344 KB Output is correct
3 Correct 75 ms 432 KB Output is correct
4 Correct 71 ms 348 KB Output is correct
5 Correct 70 ms 344 KB Output is correct
6 Correct 70 ms 344 KB Output is correct
7 Correct 69 ms 348 KB Output is correct
8 Correct 70 ms 432 KB Output is correct
9 Correct 71 ms 348 KB Output is correct
10 Correct 69 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 344 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 344 KB Output isn't correct
16 Halted 0 ms 0 KB -