답안 #311268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311268 2020-10-09T19:47:02 Z kimbj0709 지구 온난화 (NOI13_gw) C++14
40 / 40
265 ms 25952 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int n;
  int input;
  cin >> n;
  vector<int> h = {-1};
  vector<int> vect1 = {-1};
  for(int i=0;i<n;i++){
    cin >> input;
    vect1.push_back(input);
  }
  for(int i=1;i<vect1.size();i++){
    if(vect1[i]!=vect1[i-1]){
      h.push_back(vect1[i]);
    }
  }
  h.push_back(-1);
  vector<pair<int,int> > sorted;
  for(int i=1;i<h.size()-1;i++){
    sorted.push_back({h[i],i});
  }
  sort(sorted.begin(),sorted.end());
  reverse(sorted.begin(),sorted.end());
  int curr = 0;
  int ans = 1;
  for(int i=0;i<sorted.size();){
    int current = sorted[i].f;
    while(i<sorted.size()&&sorted[i].f==current){
      int pos = sorted[i].s;
      if(h[pos-1]>current&&h[pos+1]>current){
        curr--;
      }
      else if(h[pos-1]<current&&h[pos+1]<current){
        curr++;
      }
      i++;
    }
    //cout << curr << "--\n";
    ans = max(ans,curr);
  }
  cout << ans;

}

Compilation message

gw.cpp: In function 'int32_t main()':
gw.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for(int i=1;i<vect1.size();i++){
      |               ~^~~~~~~~~~~~~
gw.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i=1;i<h.size()-1;i++){
      |               ~^~~~~~~~~~~
gw.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i=0;i<sorted.size();){
      |               ~^~~~~~~~~~~~~~
gw.cpp:33:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     while(i<sorted.size()&&sorted[i].f==current){
      |           ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2556 KB Output is correct
2 Correct 21 ms 2556 KB Output is correct
3 Correct 20 ms 2556 KB Output is correct
4 Correct 20 ms 2556 KB Output is correct
5 Correct 20 ms 2556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3196 KB Output is correct
2 Correct 17 ms 2940 KB Output is correct
3 Correct 24 ms 3196 KB Output is correct
4 Correct 23 ms 3068 KB Output is correct
5 Correct 22 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 25856 KB Output is correct
2 Correct 259 ms 25828 KB Output is correct
3 Correct 255 ms 25952 KB Output is correct
4 Correct 261 ms 25824 KB Output is correct
5 Correct 248 ms 25184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 25232 KB Output is correct
2 Correct 265 ms 25348 KB Output is correct
3 Correct 259 ms 25188 KB Output is correct
4 Correct 223 ms 19296 KB Output is correct
5 Correct 231 ms 19464 KB Output is correct