Submission #4673491


Source Code Expand

Copy
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[5010], b[5010], c[5010];
ll mem[5010][5010], rt, lf, n;
ll dp(int  x, int y){
    if(x+1==y || x==n || y==1){
        return 0;
    }
    if(mem[x][y]!=-1)
        return  mem[x][y];
    ll res;
    int tmp=x+1;
    if(b[tmp]>=y){
        res=dp(x+1, y);
    }
    else{
        res=rt+dp(x+1, y);
    }
    tmp=y-1;
    if(c[tmp]<=x){
        res=min(res, dp(x, y-1));
    }
    else{
        res=min(res, lf+dp(x, y-1));
    }
    mem[x][y]=res;
    return res;
}
int main(){
    while(cin>>n>>lf>>rt){
        ll ans=0;
        int tmp;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
            tmp=n+1;
            for(int j=0; j<i; ++j){
                  if(a[j]>a[i])
                        tmp=min(tmp, a[j]);
            }
            b[a[i]]=tmp;
        }
        for(int i=0; i<n; ++i){
            tmp=0;
            for(int j=n-1; j>i; --j){
                if(a[j]<a[i]){
                    tmp=max(tmp, a[j]);
                }
            }
            c[a[i]]=tmp;
        }
        memset(mem, -1, sizeof mem);
        ans=dp(0,n+1);
        cout<<ans<<endl;
    }
  return 0;
}


Submission Info

Submission Time
Task D - Rotation Sort
User Zain
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1334 Byte
Status
Exec Time 251 ms
Memory 196608 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:39:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",a+i);
                            ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 0 / 1000 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt
Case Name Status Exec Time Memory
0_00.txt 49 ms 196352 KB
0_01.txt 49 ms 196352 KB
0_02.txt 49 ms 196352 KB
0_03.txt 49 ms 196352 KB
0_04.txt 49 ms 196352 KB
1_00.txt 49 ms 196352 KB
1_01.txt 166 ms 196608 KB
1_02.txt 188 ms 196608 KB
1_03.txt 251 ms 196608 KB
1_04.txt 166 ms 196608 KB
1_05.txt 167 ms 196608 KB
1_06.txt 167 ms 196608 KB
1_07.txt 166 ms 196608 KB
1_08.txt 245 ms 196608 KB
1_09.txt 246 ms 196608 KB
1_10.txt 243 ms 196608 KB
1_11.txt 243 ms 196608 KB
1_12.txt 235 ms 196608 KB
1_13.txt 249 ms 196608 KB
1_14.txt 245 ms 196608 KB
1_15.txt 248 ms 196608 KB
1_16.txt 248 ms 196608 KB
1_17.txt 249 ms 196608 KB
1_18.txt 246 ms 196608 KB
1_19.txt 246 ms 196608 KB
1_20.txt 244 ms 196608 KB
1_21.txt 249 ms 196608 KB
1_22.txt 247 ms 196608 KB
1_23.txt 247 ms 196608 KB
1_24.txt 246 ms 196608 KB
1_25.txt 248 ms 196608 KB
1_26.txt 238 ms 196608 KB
1_27.txt 246 ms 196608 KB
1_28.txt 246 ms 196608 KB
1_29.txt 247 ms 196608 KB
1_30.txt 244 ms 196608 KB
1_31.txt 240 ms 196608 KB
1_32.txt 248 ms 196608 KB
1_33.txt 249 ms 196608 KB
1_34.txt 239 ms 196608 KB
1_35.txt 245 ms 196608 KB
1_36.txt 235 ms 196608 KB
1_37.txt 245 ms 196608 KB
1_38.txt 250 ms 196608 KB
1_39.txt 249 ms 196608 KB