답안 #477868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477868 2021-10-04T09:45:49 Z sumit_kk10 지구 온난화 (NOI13_gw) C++17
19 / 40
532 ms 65540 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

void solve(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    vector<pair<long long, int> > comp;
    for(int i = 0; i < n; ++i)
        comp.push_back({a[i], i});
    sort(comp.begin(), comp.end());
    int ct = 1;
    a[comp[0].second] = ct;
    for(int i = 1; i < comp.size(); ++i){
        if(comp[i].first != comp[i - 1].first)
            ++ct;
        a[comp[i].second] = ct;
    }
    vector<int> pos[ct + 2];
    for(int i = 0; i < a.size(); ++i)
        pos[a[i]].push_back(i);
    int x = 0;
    for(int j = 0; j < n; ++j){
        int cur = j;
        while(a[cur] > 1 and cur < n)
            ++cur;
        if(cur != j){
            j = cur - 1;
            ++x;
        }
    }
    map<int, bool> mp;
    for(auto k : pos[1])
        mp[k] = true;
    int ans = x;
    for(int i = 2; i <= ct; ++i){
        for(auto k : pos[i]){
            if(mp[k - 1] and mp[k + 1]){
                --x;
                mp[k] = true;
                continue;
            }
            if(mp[k - 1]){
                if(k == n - 1) --x;
                mp[k] = true;
                continue;
            }
            if(mp[k + 1]){
                if(k == 0) --x;
                mp[k] = true;
                continue;
            }
            if(k != 0 and k != n - 1)
                x++;
            mp[k] = true;
        }
        ans = max(ans, x);
    }
    cout << ans << "\n";
}

int main(){
    fast;
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Compilation message

gw.cpp: In function 'void solve()':
gw.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i = 1; i < comp.size(); ++i){
      |                    ~~^~~~~~~~~~~~~
gw.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < a.size(); ++i)
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 7916 KB Output is correct
2 Correct 65 ms 7884 KB Output is correct
3 Correct 78 ms 7904 KB Output is correct
4 Correct 64 ms 7864 KB Output is correct
5 Correct 65 ms 7880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 12780 KB Output is correct
2 Correct 66 ms 13376 KB Output is correct
3 Correct 111 ms 13696 KB Output is correct
4 Correct 108 ms 13640 KB Output is correct
5 Correct 117 ms 13508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 349 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 532 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -