답안 #25139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25139 2017-06-20T08:05:09 Z zoomswk 지구 온난화 (NOI13_gw) C++14
0 / 40
0 ms 1012 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

pair<int, int> h[1000005];
vector<int> vt[1000005];
int par[1000005];

int findpar(int x){
    if(par[x] != x) par[x] = findpar(par[x]);
    return par[x];
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &h[i].first);
        h[i].second = i;
    }
    sort(h, h+n);
    int ptr = 0;
    for(int i=0; i<n; i++){
        if(i != 0 && h[i].first != h[i-1].first) ptr++;
        vt[ptr].push_back(h[i].second);
    }
    int res = 0, cur = 0;
    for(int i=0; i<=n; i++) par[i] = n;
    for(int i=ptr-1; i>=0; i--){
        cur += vt[i].size();
        for(int j=0; j<vt[i].size(); j++){
            par[vt[i][j]] = vt[i][j];
        }
        for(int j=0; j<vt[i].size(); j++){
            int pos = vt[i][j];
            int u = findpar(pos);
            if(pos != n-1){
                int v = findpar(pos+1);
                if(v != n && u != v) par[v] = u, cur--;
            }
            if(pos != 0){
                int v = findpar(pos-1);
                if(v != n && u != v) par[v] = u, cur--;
            }
        }
        if(cur > res) res = cur;
    }
    printf("%d", res);
    return 0;
}

Compilation message

gw.cpp: In function 'int main()':
gw.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<vt[i].size(); j++){
                       ^
gw.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<vt[i].size(); j++){
                       ^
gw.cpp:18:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
gw.cpp:20:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &h[i].first);
                                 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 1012 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -