Submission #963952

#TimeUsernameProblemLanguageResultExecution timeMemory
963952AiperiiiMoney (IZhO17_money)C++14
45 / 100
221 ms262144 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=1e3+5; int cnt[N][N]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n; cin>>n; vector <int> a(n+1); vector <int> sr; for(int i=1;i<=n;i++){ cin>>a[i]; } vector <int> v; vector <vector <int> > vec; vec.pb({}); for(int i=1;i<=n;i++){ v.pb(a[i]); vec.pb(v); } for(int i=0;i<vec.size();i++){ sort(all(vec[i])); } for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ cnt[i][j]=1e9; } } cnt[0][0]=0; for(int i=1;i<=n;i++){ for(int j=i;j<=n;j++){ int mn=1e9,ind=-1; for(int k=j;k>=i;k--){ bool ok=0; auto it=upper_bound(all(vec[k-1]),a[k]); if(it==vec[k-1].end() or *it>=a[j])ok=1; if(ok){ cnt[i][j]=min(cnt[i][j],cnt[i-1][k-1]+1); } if(k-1>=i && a[k]<a[k-1])break; } } } for(int i=1;i<=n;i++){ if(cnt[i][n]!=1e9){ cout<<i<<"\n";return 0; } } } /* 6 3 6 4 5 1 2 */

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:27:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0;i<vec.size();i++){
      |                 ~^~~~~~~~~~~
money.cpp:38:17: warning: unused variable 'mn' [-Wunused-variable]
   38 |             int mn=1e9,ind=-1;
      |                 ^~
money.cpp:38:24: warning: unused variable 'ind' [-Wunused-variable]
   38 |             int mn=1e9,ind=-1;
      |                        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...