답안 #895134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895134 2023-12-29T13:08:00 Z d4xn Rabbit Carrot (LMIO19_triusis) C++17
35 / 100
1000 ms 22156 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

const int N = 5e3+1, inf = INT_MAX;

int n, m, mx, a[N];
vector<int> suf, dp[2];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  a[0] = 0;
  mx = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }

  dp[0].clear();
  dp[0].resize(1);
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int x = min(mx+1, m*(i-1) + 1);
    suf.clear();
    suf.resize(x);
    for (int j = x-1; j >= 0; j--) {
      suf[j] = min(dp[(i-1)%2][j], (j+1 < x ? suf[j+1] : inf));
    }

    int y = min(mx+1, m*i + 1);
    dp[i%2].clear();
    dp[i%2].resize(y);
    for (int j = 0; j < y; j++) {
      dp[i%2][j] = suf[max(0, j-m)] + (j != a[i]);
    }
  }

  int ans = inf;
  for (int i = 0; i <= min(mx, n*m); i++) {
    ans = min(ans, dp[n%2][i]);
  }
  cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 96 ms 528 KB Output is correct
24 Correct 96 ms 344 KB Output is correct
25 Correct 39 ms 348 KB Output is correct
26 Correct 96 ms 348 KB Output is correct
27 Correct 49 ms 668 KB Output is correct
28 Correct 49 ms 676 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 18 ms 348 KB Output is correct
31 Correct 49 ms 600 KB Output is correct
32 Correct 96 ms 544 KB Output is correct
33 Correct 96 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 96 ms 528 KB Output is correct
8 Correct 96 ms 344 KB Output is correct
9 Correct 39 ms 348 KB Output is correct
10 Correct 96 ms 348 KB Output is correct
11 Correct 49 ms 668 KB Output is correct
12 Correct 49 ms 676 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 18 ms 348 KB Output is correct
15 Correct 49 ms 600 KB Output is correct
16 Correct 96 ms 544 KB Output is correct
17 Correct 96 ms 548 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Execution timed out 1086 ms 22156 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 1086 ms 22156 KB Time limit exceeded
3 Halted 0 ms 0 KB -