답안 #1085635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085635 2024-09-08T13:56:54 Z Sunbae 지구 온난화 (NOI13_gw) C++17
19 / 40
1000 ms 65536 KB
#include <bits/stdc++.h>
#define z exit(0)
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int N = 1e6 + 5, inf = 1e9;
int cp[N], a[N], m;
set<pii> s;
vector<int> to_remove[N];
int gw(int n, int H[]){
	for(int i = m = 0; i<n; ++i) cp[m++] = H[i];
	cp[m++] = 0;
	for(int i = 0; i<m; ++i) to_remove[i].clear(); s.clear();
	sort(cp, cp+m); m = unique(cp, cp+m) - cp;
	for(int i = 0; i<n; ++i) to_remove[a[i] = lower_bound(cp, cp+m, H[i]) - cp].push_back(i);
	for(int i = 0, j = 0; i<n; ){
		for(; j+1<n && H[j+1] > 0; ++j){}
		s.emplace(i, j);
		i = j+2; j = i;
	}
	int mx = (int)s.size();
	for(int t = 1; t<m; ++t){
		for(int j : to_remove[t]){
			set<pii>::iterator itr = (--s.upper_bound(mp(j, inf)));
			if(itr == s.end()) continue;
			int l = itr->F, r = itr->S;
			s.erase(itr);
			if(l <= j-1) s.emplace(l, j-1);
			if(j+1 <= r) s.emplace(j+1, r);
		}
		mx = max(mx, (int)s.size());
	}
	return mx;
}
signed main(){
	int n; scanf("%d", &n);
	int H[n];
	for(int i = 0; i<n; ++i) scanf("%d", H+i);
	printf("%d", gw(n, H));
}	

Compilation message

gw.cpp: In function 'int gw(int, int*)':
gw.cpp:15:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   15 |  for(int i = 0; i<m; ++i) to_remove[i].clear(); s.clear();
      |  ^~~
gw.cpp:15:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   15 |  for(int i = 0; i<m; ++i) to_remove[i].clear(); s.clear();
      |                                                 ^
gw.cpp: In function 'int main()':
gw.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
gw.cpp:40:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  for(int i = 0; i<n; ++i) scanf("%d", H+i);
      |                           ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 24152 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 10 ms 23812 KB Output is correct
4 Correct 10 ms 23900 KB Output is correct
5 Correct 11 ms 23988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 26708 KB Output is correct
2 Correct 37 ms 26704 KB Output is correct
3 Correct 38 ms 26716 KB Output is correct
4 Correct 43 ms 26716 KB Output is correct
5 Correct 55 ms 26776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 29264 KB Output is correct
2 Correct 45 ms 30544 KB Output is correct
3 Correct 72 ms 30116 KB Output is correct
4 Correct 81 ms 30292 KB Output is correct
5 Correct 76 ms 30296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 475 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 65536 KB Time limit exceeded
2 Halted 0 ms 0 KB -