Submission #41624682


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const ll MAXN=110,INF=1e18;
void tomin(ll& x,ll y){x=min(x,y);}

ll n,k,c[MAXN],p[MAXN],pos[MAXN];

ll a[MAXN],m;

ll dp[MAXN][MAXN][MAXN],s[MAXN];

int main(){
	cin>>n>>k;
	rep(i,1,k)cin>>c[i];

	rep(i,1,n)cin>>p[i],pos[p[i]] = i;
	for(int l=1,r;l<=n;l=r+1){
		r=l;
		while(r+1 <= n && pos[r] < pos[r+1])r++;
		a[++m] = r-l+1;
	}

	rep(i,1,k+1)rep(a,0,m+1)rep(b,0,m+1)if(a<b)dp[i][a][b] = INF;

	rep(i,1,m)s[i] = s[i-1] + a[i];

	per(cur,k,1){
		rep(len,2,m){
			rep(i,1,m-len+1){
				int j=i+len-1;
				rep(l,i,j+1){
					tomin(dp[cur][i][j],c[cur] * (s[j]-s[l-1]) + dp[cur+1][i][l-1] + dp[cur+1][l][j]);
				}
			}
		}
	}

	ll ret = dp[1][1][m];
	if(ret==INF){
		cout<<"-1\n";
	}else{
		cout<<ret<<"\n";
	}
    return 0;
}

Submission Info

Submission Time
Task B - Split and Insert
User Crying
Language C++ (GCC 9.2.1)
Score 700
Code Size 1167 Byte
Status AC
Exec Time 42 ms
Memory 12772 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 48
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_rand_01.txt, 01_rand_02.txt, 01_rand_03.txt, 01_rand_04.txt, 01_rand_05.txt, 01_rand_06.txt, 01_rand_07.txt, 01_rand_08.txt, 01_rand_09.txt, 01_rand_10.txt, 01_rand_11.txt, 01_rand_12.txt, 01_rand_13.txt, 01_rand_14.txt, 01_rand_15.txt, 01_rand_16.txt, 01_rand_17.txt, 01_rand_18.txt, 01_rand_19.txt, 01_rand_20.txt, 01_rand_21.txt, 01_rand_22.txt, 01_rand_23.txt, 01_rand_24.txt, 01_rand_25.txt, 02_worst_01.txt, 02_worst_02.txt, 02_worst_03.txt, 02_worst_04.txt, 02_worst_05.txt, 02_worst_06.txt, 02_worst_07.txt, 02_worst_08.txt, 02_worst_09.txt, 02_worst_10.txt, 03_impossible_01.txt, 03_impossible_02.txt, 03_impossible_03.txt, 03_impossible_04.txt, 03_impossible_05.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 7 ms 3588 KB
00_sample_02.txt AC 2 ms 3624 KB
00_sample_03.txt AC 2 ms 3680 KB
01_rand_01.txt AC 6 ms 5676 KB
01_rand_02.txt AC 6 ms 4760 KB
01_rand_03.txt AC 4 ms 4880 KB
01_rand_04.txt AC 8 ms 6224 KB
01_rand_05.txt AC 11 ms 7044 KB
01_rand_06.txt AC 11 ms 7192 KB
01_rand_07.txt AC 5 ms 5220 KB
01_rand_08.txt AC 15 ms 7992 KB
01_rand_09.txt AC 8 ms 6452 KB
01_rand_10.txt AC 5 ms 4936 KB
01_rand_11.txt AC 17 ms 8528 KB
01_rand_12.txt AC 12 ms 8556 KB
01_rand_13.txt AC 13 ms 8668 KB
01_rand_14.txt AC 10 ms 7764 KB
01_rand_15.txt AC 13 ms 8736 KB
01_rand_16.txt AC 2 ms 4268 KB
01_rand_17.txt AC 6 ms 4712 KB
01_rand_18.txt AC 6 ms 6612 KB
01_rand_19.txt AC 12 ms 8356 KB
01_rand_20.txt AC 2 ms 4032 KB
01_rand_21.txt AC 4 ms 4380 KB
01_rand_22.txt AC 3 ms 4716 KB
01_rand_23.txt AC 11 ms 6604 KB
01_rand_24.txt AC 13 ms 8220 KB
01_rand_25.txt AC 2 ms 4000 KB
02_worst_01.txt AC 42 ms 12600 KB
02_worst_02.txt AC 36 ms 12696 KB
02_worst_03.txt AC 35 ms 12584 KB
02_worst_04.txt AC 35 ms 12592 KB
02_worst_05.txt AC 35 ms 12740 KB
02_worst_06.txt AC 31 ms 12668 KB
02_worst_07.txt AC 30 ms 12740 KB
02_worst_08.txt AC 38 ms 12748 KB
02_worst_09.txt AC 36 ms 12592 KB
02_worst_10.txt AC 36 ms 12772 KB
03_impossible_01.txt AC 2 ms 3604 KB
03_impossible_02.txt AC 2 ms 3624 KB
03_impossible_03.txt AC 2 ms 3700 KB
03_impossible_04.txt AC 2 ms 3596 KB
03_impossible_05.txt AC 3 ms 4000 KB
04_handmade_01.txt AC 2 ms 3396 KB
04_handmade_02.txt AC 8 ms 4304 KB
04_handmade_03.txt AC 9 ms 4240 KB
04_handmade_04.txt AC 1 ms 4004 KB
04_handmade_05.txt AC 2 ms 3876 KB