답안 #285467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285467 2020-08-29T05:38:53 Z arnold518 Discharging (NOI20_discharging) C++14
0 / 100
157 ms 8256 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6;
const ll INF = 1e15;

int N;
ll dp[MAXN+10], A[MAXN+10];

struct Line { ll a, b; };
double cross(Line p, Line q) { return (double)(q.b-p.b)/(p.a-q.a); }

struct CHT
{
	int pos=0;
	vector<Line> S;
	void push(Line p)
	{
		while(S.size()>1 && cross(S[S.size()-1], S[S.size()-2])>=cross(S[S.size()-1], p)) S.pop_back();
		S.push_back(p);
	}
	ll query(ll x)
	{
		if(pos>=S.size()) pos=S.size()-1;
		else while(pos<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
		return S[pos].a*x+S[pos].b;
	}
}cht;

int main()
{
	scanf("%d", &N);
	for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
	reverse(A+1, A+N+1);
	
	A[0]=INF;

	vector<int> S;
	S.push_back(0);
	for(int i=1; i<=N; i++)
	{
		while(!S.empty() && A[S.back()]<=A[i]) S.pop_back();
		S.push_back(i);
	}

	for(int i=1; i<S.size(); i++) 
	{
		cht.push({A[S[i]], dp[i-1]});
		dp[i]=cht.query(S[i]);
	}
	printf("%lld\n", dp[S.size()-1]);
}

Compilation message

Discharging.cpp: In member function 'll CHT::query(ll)':
Discharging.cpp:28:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   if(pos>=S.size()) pos=S.size()-1;
      |      ~~~^~~~~~~~~~
Discharging.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   else while(pos<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
      |              ~~~^~~~~~~~~
Discharging.cpp: In function 'int main()':
Discharging.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i=1; i<S.size(); i++)
      |               ~^~~~~~~~~
Discharging.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Discharging.cpp:37:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  for(int i=1; i<=N; i++) scanf("%lld", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 157 ms 8256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -