답안 #273072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
273072 2020-08-19T03:46:10 Z T0p_ 지구 온난화 (NOI13_gw) C++14
6 / 40
1000 ms 17012 KB
#include<bits/stdc++.h>
using namespace std;

int n;
long long h[1001000];
vector<long long> v;

int solve(long long x)
{
	bool ch = x < h[1];
	int ret = 0;
	for(int i=2 ; i<=n ; i++)
	{
		if(x < h[i]) ch = true;
		else
		{
			if(ch)
			{
				ch = false;
				ret++;
			}
		}
	}
	if(ch) ret++;
	return ret;
}

int main()
{
	scanf(" %d",&n);
	for(int i=1 ; i<=n ; i++)
	{
		scanf(" %lld",&h[i]);
		v.push_back(h[i]);
	}
	sort(v.begin(), v.end());
	int l = 0, r = n-1;
	while(l != r)
	{
		int mid = (l+r+1)>>1;
		int ll = 0, rr = mid;
		while(ll != rr)
		{
			int mm = (ll+rr+1)>>1;
			(solve(v[mm]) != solve(v[mid])) ? ll = mm : rr = mm-1;
		}
		(solve(v[ll]) <= solve(v[mid])) ? l = mid : r = mid-1;
	}
	printf("%d\n",solve(v[l]));
	return 0;
}

Compilation message

gw.cpp: In function 'int main()':
gw.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  scanf(" %d",&n);
      |  ~~~~~^~~~~~~~~~
gw.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   scanf(" %lld",&h[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 347 ms 2296 KB Output is correct
2 Correct 318 ms 2296 KB Output is correct
3 Correct 334 ms 2296 KB Output is correct
4 Correct 344 ms 2296 KB Output is correct
5 Correct 341 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 287 ms 2944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 17012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 16976 KB Time limit exceeded
2 Halted 0 ms 0 KB -