답안 #897767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897767 2024-01-03T16:15:31 Z AI_2512 Money (IZhO17_money) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, res = 0;
    bool b = false;
    cin >> n;
    vector<int> vec(n);
    set<int> a;
    vector<pair<int, int>> mapp;
    for (int i = 0; i< n; i++) cin >> vec[i];

    int start = 0, end = 0, maxx = 0;
    int s,e;
    for (int i = 0; i< n-1;i++){
        if (vec[i] < vec[i+1]){
            b = true;
            start = i;
        }else{
            if (b){
                end = i;
                if (maxx < vec[end]-vec[start]){
                    maxx = vec[end]-vec[start];
                    s = start;
                    e = end;
                    if (res == 0) res++;
                }
            }
        }
    }
    for (int i = s; i<=e;i++){
        a.insert(vec[s]);
        vec.erase(vec.begin()+s);
    }
    for (int k = 0; k< vec.size(); k++){
        for (int i = 0; i< n-1;i++){
            if (vec[i] < vec[i+1]){
                b = true;
                start = i;
            }else{
                if (b){
                    end = i;
                    if (maxx < vec[end]-vec[start]){
                        maxx = vec[end]-vec[start];
                        s = start;
                        e = end;
                    }
                }
            }
        }
        for (int i = s; i<=e;i++){
            a.insert(vec[s]);
            mapp.push_back({vec[s], *a.find(vec[s])});
            vec.erase(vec.begin()+s);
        }
    }
    for (int i = 0; i< mapp.size(); i++){
        if (mapp[i].first > mapp[i+1].first || mapp[i+1].second-mapp[i].second != 1){
            res++;
        }
    }
    cout << res;
    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int k = 0; k< vec.size(); k++){
      |                     ~^~~~~~~~~~~~
money.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i< mapp.size(); i++){
      |                     ~^~~~~~~~~~~~~
money.cpp:32:22: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     for (int i = s; i<=e;i++){
      |                     ~^~~
money.cpp:33:23: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |         a.insert(vec[s]);
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -