Submission #699835

# Submission time Handle Problem Language Result Execution time Memory
699835 2023-02-18T05:52:57 Z bdl Group Photo (JOI21_ho_t3) C++17
100 / 100
292 ms 98380 KB
#include <iostream>
using namespace std;

const int N = 5e3;

int main() {
  int n;
  scanf("%d", &n);
  static int o[N + 1];
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    o[a] = i;
  }
  static int s[N + 1][N + 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (i < j && o[i] > o[j]);
  auto inv = [&](int i1, int i2, int j1, int j2) {
    return s[i2][j2] - s[i1 - 1][j2] - s[i2][j1 - 1] + s[i1 - 1][j1 - 1];
  };
  auto ninv = [&](int i, int j) {
    return (j - i + 1) * (j - i) / 2 - inv(i, j, i, j);
  };
  static int f[N + 1];
  for (int i = 1; i <= n; i++) {
    f[i] = ninv(1, i);
    for (int j = 1; j < i; j++)
      f[i] = min(f[i], f[j] + inv(1, j, j + 1, i) + ninv(j + 1, i));
  }
  printf("%d\n", f[n]);
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d", &a);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 7 ms 5940 KB Output is correct
32 Correct 7 ms 5940 KB Output is correct
33 Correct 6 ms 5972 KB Output is correct
34 Correct 7 ms 6012 KB Output is correct
35 Correct 7 ms 5972 KB Output is correct
36 Correct 7 ms 5972 KB Output is correct
37 Correct 6 ms 5972 KB Output is correct
38 Correct 7 ms 5944 KB Output is correct
39 Correct 7 ms 6008 KB Output is correct
40 Correct 7 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 7 ms 5940 KB Output is correct
32 Correct 7 ms 5940 KB Output is correct
33 Correct 6 ms 5972 KB Output is correct
34 Correct 7 ms 6012 KB Output is correct
35 Correct 7 ms 5972 KB Output is correct
36 Correct 7 ms 5972 KB Output is correct
37 Correct 6 ms 5972 KB Output is correct
38 Correct 7 ms 5944 KB Output is correct
39 Correct 7 ms 6008 KB Output is correct
40 Correct 7 ms 5972 KB Output is correct
41 Correct 270 ms 98140 KB Output is correct
42 Correct 282 ms 98172 KB Output is correct
43 Correct 280 ms 98380 KB Output is correct
44 Correct 282 ms 98196 KB Output is correct
45 Correct 281 ms 98196 KB Output is correct
46 Correct 275 ms 98164 KB Output is correct
47 Correct 286 ms 98124 KB Output is correct
48 Correct 277 ms 98268 KB Output is correct
49 Correct 288 ms 98208 KB Output is correct
50 Correct 285 ms 98228 KB Output is correct
51 Correct 284 ms 98208 KB Output is correct
52 Correct 286 ms 98208 KB Output is correct
53 Correct 292 ms 98124 KB Output is correct
54 Correct 283 ms 98240 KB Output is correct
55 Correct 280 ms 98200 KB Output is correct