Submission #169157

# Submission time Handle Problem Language Result Execution time Memory
169157 2019-12-18T18:06:11 Z itgl Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
#include<bits/stdc++.h>
#define pb push_back

using namespace std;
int a[1000005];
vector<int> mn,vec,mrgvec;

int mergesort(int ans){
  int i=0,j=0;
  int s1=mn.size();
  int s2=vec.size();
  int k=0;
  while(i<s1&&j<s2){
    if(mn[i]<=vec[i]){
      mrgvec.pb(mn[i]);
      i++;
      if(k!=1) ans++;
      k=1;
    }else{
      mrgvec.pb(vec[j]);
      j++;
      if(k!=2) ans++;
      k=2;
    }
  }
  while(i<s1){
    mrgvec.pb(mn[i]);
    i++;
    if(k!=1){
      ans++;
      k=1;
    }

  }
  while(j<s2){
    mrgvec.pb(vec[j]);
    j++;
    if(k!=2){
      ans++;
      k=2;
    }
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  a[n+1]=1e6+7;
  int pos;
  for(int i=1;i<=n;i++){
    if(a[i+1]>a[i]) mn.pb(a[i]);
    else{
      pos=i+1;
      mn.pb(a[i]);
      break;
    }
  }
  int ans=0;
  for(int i=pos;i<=n;i++){
    if(a[i+1]>a[i]){
      vec.pb(a[i]);
    }else{
      vec.pb(a[i]);
      ans = mergesort(ans);
      vec.clear();
      mn.clear();
      mn=mrgvec;
      mrgvec.clear();
    }
  }
  cout << ans << '\n';
  return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:51:7: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int pos;
       ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -