답안 #541007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541007 2022-03-22T06:21:25 Z Kiarat Money (IZhO17_money) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector <pair<ll,ll>> v;

int main(){
    ll n;
    cin >> n;

    ll a[n+1];

    for(int i=1;i<=n;i++)
    {
      cin >> a[i];
    }
    a[n+1] = -10;
    ll ans=0;
    ll sum=0;
    ll cnt=0,ss=100000;
    for(ll i=2;i<=n+1;i++){
      if(a[i-1] <= a[i]){
        ss = min(a[i-1],ss);
        cnt = max(a[i],cnt);
      }
      else{
        v.push_back({ss,cnt});
        cnt=0,ss=100000;
        sum++;
    }
}


 sort(v.begin(),v.end());

 for(int i=1;i<v.size();i++){
  if(v[i].first >= v[i-1].first && v[i].second <= v[i-1].second){
    continue;
  }
  else if(v[i].first >= v[i-1].first && v[i].first >= v[i-1].second ){
    continue;
  }
  else if(v[i-1].second <= v[i].first && v[i-1].second <= v[i].second){
    continue;
  }
  else{
    sum++;
  }
 } 

 if(sum == 1){
  cout << 0 ;
  }
  else
    cout << sum;

}

Compilation message

money.cpp: In function 'int main()':
money.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=1;i<v.size();i++){
      |              ~^~~~~~~~~
money.cpp:19:8: warning: unused variable 'ans' [-Wunused-variable]
   19 |     ll ans=0;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -