Submission #47828446


Source Code Expand

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
#define int long long
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
bool chkmin(int &a, int b) {return (b < a ? a = b, true : false);}
const int N = 110;
const int INF = 1e18;
int n, k;
int c[N], pos[N], f[N][N][N];
signed main() {
  n = read(); k = read();
  for(int i = 1; i <= k; i++)c[i] = read();
  for(int i = 1; i <= n; i++)pos[read()] = i;
  for(int i = 0; i <= k; i++) {
    for(int l = 1; l <= n; l++) {
      for(int r = l; r <= n; r++) {
        f[i][l][r] = INF;
      }
    }
  }
  for(int l = 1; l <= n; l++) {
    for(int r = l; r <= n; r++) {
      f[k][l][r] = 0;
      if(r == n || pos[r] > pos[r + 1])break;
    }
  }
  for(int i = k; i; i--) {
    for(int l = 1; l <= n; l++) {
      for(int r = l; r <= n; r++) {
        chkmin(f[i - 1][l][r], f[i][l][r]);
        for(int x = l; x < r; x++) {
          chkmin(f[i - 1][l][r], f[i][l][x] + f[i][x + 1][r] + c[i] * (r - x));
        }
      }
    }
  }
  printf("%lld\n", (f[0][1][n] == INF ? -1 : f[0][1][n]));
  return 0;
}

Submission Info

Submission Time
Task B - Split and Insert
User thebighead
Language C++ 20 (gcc 12.2)
Score 700
Code Size 1440 Byte
Status AC
Exec Time 21 ms
Memory 12992 KiB

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 1 ms 3712 KiB
00_sample_02.txt AC 1 ms 3720 KiB
00_sample_03.txt AC 1 ms 4076 KiB
01_rand_01.txt AC 10 ms 7680 KiB
01_rand_02.txt AC 7 ms 6244 KiB
01_rand_03.txt AC 6 ms 5952 KiB
01_rand_04.txt AC 12 ms 9060 KiB
01_rand_05.txt AC 15 ms 10528 KiB
01_rand_06.txt AC 15 ms 10556 KiB
01_rand_07.txt AC 8 ms 7252 KiB
01_rand_08.txt AC 19 ms 12232 KiB
01_rand_09.txt AC 14 ms 9640 KiB
01_rand_10.txt AC 7 ms 6300 KiB
01_rand_11.txt AC 21 ms 12900 KiB
01_rand_12.txt AC 21 ms 12700 KiB
01_rand_13.txt AC 20 ms 12780 KiB
01_rand_14.txt AC 19 ms 12992 KiB
01_rand_15.txt AC 20 ms 12772 KiB
01_rand_16.txt AC 18 ms 12828 KiB
01_rand_17.txt AC 19 ms 12696 KiB
01_rand_18.txt AC 20 ms 12804 KiB
01_rand_19.txt AC 20 ms 12924 KiB
01_rand_20.txt AC 18 ms 12984 KiB
01_rand_21.txt AC 19 ms 12916 KiB
01_rand_22.txt AC 18 ms 12864 KiB
01_rand_23.txt AC 20 ms 12780 KiB
01_rand_24.txt AC 20 ms 12916 KiB
01_rand_25.txt AC 18 ms 12984 KiB
02_worst_01.txt AC 18 ms 12992 KiB
02_worst_02.txt AC 19 ms 12864 KiB
02_worst_03.txt AC 18 ms 12868 KiB
02_worst_04.txt AC 18 ms 12808 KiB
02_worst_05.txt AC 18 ms 12720 KiB
02_worst_06.txt AC 18 ms 12848 KiB
02_worst_07.txt AC 18 ms 12800 KiB
02_worst_08.txt AC 19 ms 12884 KiB
02_worst_09.txt AC 18 ms 12988 KiB
02_worst_10.txt AC 18 ms 12800 KiB
03_impossible_01.txt AC 2 ms 3952 KiB
03_impossible_02.txt AC 2 ms 3980 KiB
03_impossible_03.txt AC 2 ms 4116 KiB
03_impossible_04.txt AC 2 ms 4184 KiB
03_impossible_05.txt AC 3 ms 4308 KiB
04_handmade_01.txt AC 1 ms 3636 KiB
04_handmade_02.txt AC 2 ms 4508 KiB
04_handmade_03.txt AC 2 ms 4536 KiB
04_handmade_04.txt AC 18 ms 12864 KiB
04_handmade_05.txt AC 18 ms 12896 KiB