Submission #1114262

# Submission time Handle Problem Language Result Execution time Memory
1114262 2024-11-18T13:15:15 Z epicci23 Netrpeljivost (COI23_netrpeljivost) C++17
59 / 100
411 ms 13392 KB
#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;

const int INF = 1e18;
const int N = 520;

int cost[N][N],dp[N][N],pre[N][N];

void f(int l,int r){
  
  if(l+1==r){
    dp[l][l]=dp[r][r]=0;
    dp[l][r]=dp[r][l]=cost[l][r];
    return;
  }

  int m=(l+r)/2;
  f(l,m),f(m+1,r);
   
  int col[N];
  for(int i=l;i<=r;i++){
    if(i<=m) col[i]=0;
    else col[i]=1;
  }

  for(int b=l;b<=r;b++)
    for(int c=l;c<=r;c++)
      for(int d=l;d<=r;d++){
      	if(col[b]==col[c]) continue;
        if(col[c]==col[d]) continue;
        if(col[b]!=col[d]) continue;
  	    if(d==c || d==b || b==c) continue;
      	pre[b][c]=min(pre[b][c], dp[d][b] + cost[c][d]);
      }

  for(int a=l;a<=r;a++){
  	for(int b=l;b<=r;b++){
  	  if(col[a]==col[b]) continue;
  	  for(int c=l;c<=r;c++){
  	  	if(c==a || c==b || a==b) continue;
  	  	if(col[a] != col[c]) continue;
  	  	dp[a][b] = min(dp[a][b], dp[a][c] + pre[b][c]);
  	  }
  	}
  }

  for(int a=l;a<=r;a++) 
    for(int b=l;b<=r;b++) 
      if(col[a]==col[b]){
       dp[b][a]=dp[a][b]=INF;
       pre[a][b]=pre[b][a]=INF;
      }
}

void _(){
  int n;
  cin >> n;
  
  for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) pre[i][j]=dp[i][j]=INF;
  	
  for(int i=1;i<=n;i++){
  	for(int j=1;j<=n;j++){
  	  cin >> cost[i][j];
  	}
  }
  
  f(1,n);
  int ans=INF;
  for(int i=1;i<=n;i++){
  	for(int j=1;j<=n;j++){
      if(i<=n/2 && j<=n/2) continue;
      if(i>n/2 && j>n/2) continue;
  	  ans=min(ans,dp[i][j]);
  	}
  }

  cout << ans << '\n';
}

int32_t main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 2 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 2 ms 6620 KB Output is correct
21 Correct 9 ms 6992 KB Output is correct
22 Correct 9 ms 6992 KB Output is correct
23 Correct 8 ms 6992 KB Output is correct
24 Correct 3 ms 6736 KB Output is correct
25 Correct 3 ms 6904 KB Output is correct
26 Correct 8 ms 6736 KB Output is correct
27 Correct 9 ms 6992 KB Output is correct
28 Correct 8 ms 6992 KB Output is correct
29 Correct 8 ms 6904 KB Output is correct
30 Correct 9 ms 6736 KB Output is correct
31 Correct 9 ms 6992 KB Output is correct
32 Correct 8 ms 6828 KB Output is correct
33 Correct 9 ms 6932 KB Output is correct
34 Correct 8 ms 6736 KB Output is correct
35 Correct 9 ms 6968 KB Output is correct
36 Correct 8 ms 6904 KB Output is correct
37 Correct 9 ms 6736 KB Output is correct
38 Correct 9 ms 6736 KB Output is correct
39 Correct 8 ms 6988 KB Output is correct
40 Correct 8 ms 7016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 2 ms 6620 KB Output is correct
21 Correct 9 ms 6992 KB Output is correct
22 Correct 9 ms 6992 KB Output is correct
23 Correct 8 ms 6992 KB Output is correct
24 Correct 3 ms 6736 KB Output is correct
25 Correct 3 ms 6904 KB Output is correct
26 Correct 8 ms 6736 KB Output is correct
27 Correct 9 ms 6992 KB Output is correct
28 Correct 8 ms 6992 KB Output is correct
29 Correct 8 ms 6904 KB Output is correct
30 Correct 9 ms 6736 KB Output is correct
31 Correct 9 ms 6992 KB Output is correct
32 Correct 8 ms 6828 KB Output is correct
33 Correct 9 ms 6932 KB Output is correct
34 Correct 8 ms 6736 KB Output is correct
35 Correct 9 ms 6968 KB Output is correct
36 Correct 8 ms 6904 KB Output is correct
37 Correct 9 ms 6736 KB Output is correct
38 Correct 9 ms 6736 KB Output is correct
39 Correct 8 ms 6988 KB Output is correct
40 Correct 8 ms 7016 KB Output is correct
41 Correct 356 ms 9296 KB Output is correct
42 Correct 365 ms 9288 KB Output is correct
43 Correct 383 ms 9344 KB Output is correct
44 Correct 361 ms 9296 KB Output is correct
45 Correct 363 ms 9544 KB Output is correct
46 Correct 358 ms 9340 KB Output is correct
47 Correct 352 ms 9296 KB Output is correct
48 Correct 353 ms 9032 KB Output is correct
49 Correct 411 ms 9288 KB Output is correct
50 Correct 371 ms 9176 KB Output is correct
51 Correct 362 ms 9384 KB Output is correct
52 Correct 368 ms 9340 KB Output is correct
53 Correct 362 ms 9564 KB Output is correct
54 Correct 365 ms 9296 KB Output is correct
55 Correct 358 ms 9228 KB Output is correct
56 Correct 368 ms 9288 KB Output is correct
57 Correct 360 ms 9236 KB Output is correct
58 Correct 389 ms 9344 KB Output is correct
59 Correct 367 ms 9296 KB Output is correct
60 Correct 385 ms 9544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 2 ms 6480 KB Output is correct
3 Correct 2 ms 6480 KB Output is correct
4 Correct 2 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 2 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 2 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 2 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 2 ms 6480 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 2 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6480 KB Output is correct
20 Correct 2 ms 6620 KB Output is correct
21 Correct 9 ms 6992 KB Output is correct
22 Correct 9 ms 6992 KB Output is correct
23 Correct 8 ms 6992 KB Output is correct
24 Correct 3 ms 6736 KB Output is correct
25 Correct 3 ms 6904 KB Output is correct
26 Correct 8 ms 6736 KB Output is correct
27 Correct 9 ms 6992 KB Output is correct
28 Correct 8 ms 6992 KB Output is correct
29 Correct 8 ms 6904 KB Output is correct
30 Correct 9 ms 6736 KB Output is correct
31 Correct 9 ms 6992 KB Output is correct
32 Correct 8 ms 6828 KB Output is correct
33 Correct 9 ms 6932 KB Output is correct
34 Correct 8 ms 6736 KB Output is correct
35 Correct 9 ms 6968 KB Output is correct
36 Correct 8 ms 6904 KB Output is correct
37 Correct 9 ms 6736 KB Output is correct
38 Correct 9 ms 6736 KB Output is correct
39 Correct 8 ms 6988 KB Output is correct
40 Correct 8 ms 7016 KB Output is correct
41 Correct 356 ms 9296 KB Output is correct
42 Correct 365 ms 9288 KB Output is correct
43 Correct 383 ms 9344 KB Output is correct
44 Correct 361 ms 9296 KB Output is correct
45 Correct 363 ms 9544 KB Output is correct
46 Correct 358 ms 9340 KB Output is correct
47 Correct 352 ms 9296 KB Output is correct
48 Correct 353 ms 9032 KB Output is correct
49 Correct 411 ms 9288 KB Output is correct
50 Correct 371 ms 9176 KB Output is correct
51 Correct 362 ms 9384 KB Output is correct
52 Correct 368 ms 9340 KB Output is correct
53 Correct 362 ms 9564 KB Output is correct
54 Correct 365 ms 9296 KB Output is correct
55 Correct 358 ms 9228 KB Output is correct
56 Correct 368 ms 9288 KB Output is correct
57 Correct 360 ms 9236 KB Output is correct
58 Correct 389 ms 9344 KB Output is correct
59 Correct 367 ms 9296 KB Output is correct
60 Correct 385 ms 9544 KB Output is correct
61 Runtime error 13 ms 13392 KB Execution killed with signal 11
62 Halted 0 ms 0 KB -