# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926563 | 2024-02-13T09:45:42 Z | Aiperiii | Rabbit Carrot (LMIO19_triusis) | C++14 | 1000 ms | 196248 KB |
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define all(x) x.begin(),x.end() #define pb push_back using namespace std; const int N=5e3+5; int dp[N][N]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,m; cin>>n>>m; vector <int> a(n); for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<=5000;i++){ if(i!=a[0])dp[0][i]=1; } for(int i=0;i<=5000;i++){ if(i>m)dp[0][i]+=1e9; } for(int i=1;i<n;i++){ multiset <int> ms; int ind=0; for(int j=0;j<=5000;j++){ int mn=1e9; if(ms.size()!=0)mn=*ms.begin(); if(j!=a[i])dp[i][j]=mn+1; else dp[i][j]=mn; ms.insert(dp[i-1][j]); if(ms.size()>m){ ms.erase(ms.find(dp[i-1][ind])); ind++; } } int mn=1e9; for(int j=5000;j>=0;j--){ mn=min(mn,dp[i-1][j]); if(j!=a[i])dp[i][j]=min(dp[i][j],mn+1); else dp[i][j]=min(dp[i][j],mn); } } int ans=1e9; for(int i=0;i<=5000;i++){ ans=min(ans,dp[n-1][i]); } cout<<ans<<"\n"; } /* 5 400 300 700 200 1000 500 3 300 700 1000 1300 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 2 ms | 2672 KB | Output is correct |
5 | Correct | 2 ms | 2652 KB | Output is correct |
6 | Correct | 2 ms | 2652 KB | Output is correct |
7 | Correct | 2 ms | 2652 KB | Output is correct |
8 | Correct | 2 ms | 2652 KB | Output is correct |
9 | Correct | 4 ms | 2652 KB | Output is correct |
10 | Correct | 3 ms | 2648 KB | Output is correct |
11 | Correct | 3 ms | 2652 KB | Output is correct |
12 | Correct | 2 ms | 2652 KB | Output is correct |
13 | Correct | 2 ms | 2652 KB | Output is correct |
14 | Correct | 2 ms | 2664 KB | Output is correct |
15 | Correct | 2 ms | 2652 KB | Output is correct |
16 | Correct | 2 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 2 ms | 2672 KB | Output is correct |
5 | Correct | 2 ms | 2652 KB | Output is correct |
6 | Correct | 2 ms | 2652 KB | Output is correct |
7 | Correct | 2 ms | 2652 KB | Output is correct |
8 | Correct | 2 ms | 2652 KB | Output is correct |
9 | Correct | 4 ms | 2652 KB | Output is correct |
10 | Correct | 3 ms | 2648 KB | Output is correct |
11 | Correct | 3 ms | 2652 KB | Output is correct |
12 | Correct | 2 ms | 2652 KB | Output is correct |
13 | Correct | 2 ms | 2652 KB | Output is correct |
14 | Correct | 2 ms | 2664 KB | Output is correct |
15 | Correct | 2 ms | 2652 KB | Output is correct |
16 | Correct | 2 ms | 2652 KB | Output is correct |
17 | Correct | 2 ms | 2652 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 782 ms | 160732 KB | Output is correct |
21 | Execution timed out | 1044 ms | 196248 KB | Time limit exceeded |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2652 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 782 ms | 160732 KB | Output is correct |
5 | Execution timed out | 1044 ms | 196248 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2652 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 782 ms | 160732 KB | Output is correct |
5 | Execution timed out | 1044 ms | 196248 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |