Submission #1114132

# Submission time Handle Problem Language Result Execution time Memory
1114132 2024-11-18T08:30:41 Z SalihSahin Netrpeljivost (COI23_netrpeljivost) C++14
59 / 100
373 ms 98740 KB
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
 
const int inf = 1e15 + 10;
const int N = 2048 + 10;
 
vector<vector<int> > c(N, vector<int>(N));
vector<vector<int> > dp[N];

int ans;
 
void f(int node, int l, int r){
   if(l == r){
      dp[node].resize(1);
      dp[node][0].resize(1);
      dp[node][0][0] = 0;
      return;
   }
 
   int m = (l + r)/2;
   f(node * 2, l, m);
   f(node * 2 + 1, m+1, r);
   int sz = (r - l + 1);

   if(node == 1){
      vector<int> ldp(sz/2, inf), rdp(sz/2, inf);
      for(int i = 0; i < sz/2; i++){
         for(int j = 0; j < sz/2; j++){
            ldp[j] = min(ldp[j], dp[node*2][i][j]);
         }
      }
      for(int i = 0; i < sz/2; i++){
         for(int j = 0; j < sz/2; j++){
            rdp[i] = min(rdp[i], dp[node*2+1][i][j]);
         }
      }

      ans = inf;
      for(int i = 0; i < sz/2; i++){
         for(int j = 0; j < sz/2; j++){
            ans = min(ans, ldp[j] + c[j + l][i + l + sz/2] + rdp[i]);
         }
      }
      return;
   }
 
   dp[node].resize(sz);
   for(int i = 0; i < sz; i++){
      dp[node][i].resize(sz);
   }
 
   for(int i = 0; i < sz; i++){
      for(int j = 0; j < sz; j++){
         dp[node][i][j] = inf;
      }
   }

   vector<vector<int> > dp2(sz/2, vector<int>(sz/2, inf));
   for(int l1 = 0; l1 < sz/2; l1++){
      for(int r1 = 0; r1 < sz/2; r1++){
         for(int l2 = 0; l2 < sz/2; l2++){
            dp2[l1][l2] = min(dp2[l1][l2], dp[node*2][l1][r1] + c[r1 + l][l2 + l + sz/2]); 
         }
      }
   }

   for(int l1 = 0; l1 < sz/2; l1++){
      for(int r2 = 0; r2 < sz/2; r2++){
         for(int l2 = 0; l2 < sz/2; l2++){
            dp[node][l1][r2 + sz/2] = min(dp[node][l1][r2 + sz/2], dp2[l1][l2] + dp[node*2+1][l2][r2]);
         }
      }
   }

   for(int i = 0; i < sz/2; i++){
      for(int j = 0; j < sz/2; j++){
         dp2[i][j] = inf;
      }
   }

   for(int l2 = 0; l2 < sz/2; l2++){
      for(int r2 = 0; r2 < sz/2; r2++){
         for(int l1 = 0; l1 < sz/2; l1++){
            dp2[l2][l1] = min(dp2[l2][l1], dp[node*2 + 1][l2][r2] + c[r2 + l + sz/2][l1 + l]); 
         }
      }
   }

   for(int l2 = 0; l2 < sz/2; l2++){
      for(int r1 = 0; r1 < sz/2; r1++){
         for(int l1 = 0; l1 < sz/2; l1++){
            dp[node][l2 + sz/2][r1] = min(dp[node][l2 + sz/2][r1], dp2[l2][l1] + dp[node*2][l1][r1]);
         }
      }
   }
}
 
int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);
   int n;
   cin>>n;
   for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
         cin>>c[i][j];
      }
   }
   f(1, 0, n-1);
   cout<<ans<<endl;
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 33648 KB Output is correct
2 Correct 36 ms 33732 KB Output is correct
3 Correct 33 ms 33612 KB Output is correct
4 Correct 29 ms 33608 KB Output is correct
5 Correct 32 ms 33616 KB Output is correct
6 Correct 27 ms 33608 KB Output is correct
7 Correct 25 ms 33528 KB Output is correct
8 Correct 24 ms 33632 KB Output is correct
9 Correct 27 ms 33872 KB Output is correct
10 Correct 23 ms 33616 KB Output is correct
11 Correct 29 ms 33616 KB Output is correct
12 Correct 29 ms 33628 KB Output is correct
13 Correct 29 ms 33608 KB Output is correct
14 Correct 31 ms 33608 KB Output is correct
15 Correct 26 ms 33608 KB Output is correct
16 Correct 25 ms 33608 KB Output is correct
17 Correct 24 ms 33616 KB Output is correct
18 Correct 24 ms 33616 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 33648 KB Output is correct
2 Correct 36 ms 33732 KB Output is correct
3 Correct 33 ms 33612 KB Output is correct
4 Correct 29 ms 33608 KB Output is correct
5 Correct 32 ms 33616 KB Output is correct
6 Correct 27 ms 33608 KB Output is correct
7 Correct 25 ms 33528 KB Output is correct
8 Correct 24 ms 33632 KB Output is correct
9 Correct 27 ms 33872 KB Output is correct
10 Correct 23 ms 33616 KB Output is correct
11 Correct 29 ms 33616 KB Output is correct
12 Correct 29 ms 33628 KB Output is correct
13 Correct 29 ms 33608 KB Output is correct
14 Correct 31 ms 33608 KB Output is correct
15 Correct 26 ms 33608 KB Output is correct
16 Correct 25 ms 33608 KB Output is correct
17 Correct 24 ms 33616 KB Output is correct
18 Correct 24 ms 33616 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33608 KB Output is correct
21 Correct 24 ms 33872 KB Output is correct
22 Correct 24 ms 33844 KB Output is correct
23 Correct 26 ms 33700 KB Output is correct
24 Correct 25 ms 33808 KB Output is correct
25 Correct 26 ms 33780 KB Output is correct
26 Correct 26 ms 33872 KB Output is correct
27 Correct 25 ms 33864 KB Output is correct
28 Correct 24 ms 33872 KB Output is correct
29 Correct 24 ms 33872 KB Output is correct
30 Correct 24 ms 33872 KB Output is correct
31 Correct 24 ms 33872 KB Output is correct
32 Correct 24 ms 33872 KB Output is correct
33 Correct 24 ms 33864 KB Output is correct
34 Correct 24 ms 33864 KB Output is correct
35 Correct 24 ms 33868 KB Output is correct
36 Correct 24 ms 33912 KB Output is correct
37 Correct 23 ms 33852 KB Output is correct
38 Correct 24 ms 33872 KB Output is correct
39 Correct 24 ms 33872 KB Output is correct
40 Correct 24 ms 33864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 33648 KB Output is correct
2 Correct 36 ms 33732 KB Output is correct
3 Correct 33 ms 33612 KB Output is correct
4 Correct 29 ms 33608 KB Output is correct
5 Correct 32 ms 33616 KB Output is correct
6 Correct 27 ms 33608 KB Output is correct
7 Correct 25 ms 33528 KB Output is correct
8 Correct 24 ms 33632 KB Output is correct
9 Correct 27 ms 33872 KB Output is correct
10 Correct 23 ms 33616 KB Output is correct
11 Correct 29 ms 33616 KB Output is correct
12 Correct 29 ms 33628 KB Output is correct
13 Correct 29 ms 33608 KB Output is correct
14 Correct 31 ms 33608 KB Output is correct
15 Correct 26 ms 33608 KB Output is correct
16 Correct 25 ms 33608 KB Output is correct
17 Correct 24 ms 33616 KB Output is correct
18 Correct 24 ms 33616 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33608 KB Output is correct
21 Correct 24 ms 33872 KB Output is correct
22 Correct 24 ms 33844 KB Output is correct
23 Correct 26 ms 33700 KB Output is correct
24 Correct 25 ms 33808 KB Output is correct
25 Correct 26 ms 33780 KB Output is correct
26 Correct 26 ms 33872 KB Output is correct
27 Correct 25 ms 33864 KB Output is correct
28 Correct 24 ms 33872 KB Output is correct
29 Correct 24 ms 33872 KB Output is correct
30 Correct 24 ms 33872 KB Output is correct
31 Correct 24 ms 33872 KB Output is correct
32 Correct 24 ms 33872 KB Output is correct
33 Correct 24 ms 33864 KB Output is correct
34 Correct 24 ms 33864 KB Output is correct
35 Correct 24 ms 33868 KB Output is correct
36 Correct 24 ms 33912 KB Output is correct
37 Correct 23 ms 33852 KB Output is correct
38 Correct 24 ms 33872 KB Output is correct
39 Correct 24 ms 33872 KB Output is correct
40 Correct 24 ms 33864 KB Output is correct
41 Correct 62 ms 38560 KB Output is correct
42 Correct 58 ms 37448 KB Output is correct
43 Correct 57 ms 35912 KB Output is correct
44 Correct 60 ms 37428 KB Output is correct
45 Correct 61 ms 38252 KB Output is correct
46 Correct 61 ms 38332 KB Output is correct
47 Correct 64 ms 37464 KB Output is correct
48 Correct 57 ms 36044 KB Output is correct
49 Correct 59 ms 37624 KB Output is correct
50 Correct 59 ms 36100 KB Output is correct
51 Correct 59 ms 37448 KB Output is correct
52 Correct 71 ms 37704 KB Output is correct
53 Correct 59 ms 36048 KB Output is correct
54 Correct 62 ms 37448 KB Output is correct
55 Correct 66 ms 37576 KB Output is correct
56 Correct 58 ms 36044 KB Output is correct
57 Correct 62 ms 37428 KB Output is correct
58 Correct 66 ms 37448 KB Output is correct
59 Correct 66 ms 37420 KB Output is correct
60 Correct 65 ms 38328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 33648 KB Output is correct
2 Correct 36 ms 33732 KB Output is correct
3 Correct 33 ms 33612 KB Output is correct
4 Correct 29 ms 33608 KB Output is correct
5 Correct 32 ms 33616 KB Output is correct
6 Correct 27 ms 33608 KB Output is correct
7 Correct 25 ms 33528 KB Output is correct
8 Correct 24 ms 33632 KB Output is correct
9 Correct 27 ms 33872 KB Output is correct
10 Correct 23 ms 33616 KB Output is correct
11 Correct 29 ms 33616 KB Output is correct
12 Correct 29 ms 33628 KB Output is correct
13 Correct 29 ms 33608 KB Output is correct
14 Correct 31 ms 33608 KB Output is correct
15 Correct 26 ms 33608 KB Output is correct
16 Correct 25 ms 33608 KB Output is correct
17 Correct 24 ms 33616 KB Output is correct
18 Correct 24 ms 33616 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33608 KB Output is correct
21 Correct 24 ms 33872 KB Output is correct
22 Correct 24 ms 33844 KB Output is correct
23 Correct 26 ms 33700 KB Output is correct
24 Correct 25 ms 33808 KB Output is correct
25 Correct 26 ms 33780 KB Output is correct
26 Correct 26 ms 33872 KB Output is correct
27 Correct 25 ms 33864 KB Output is correct
28 Correct 24 ms 33872 KB Output is correct
29 Correct 24 ms 33872 KB Output is correct
30 Correct 24 ms 33872 KB Output is correct
31 Correct 24 ms 33872 KB Output is correct
32 Correct 24 ms 33872 KB Output is correct
33 Correct 24 ms 33864 KB Output is correct
34 Correct 24 ms 33864 KB Output is correct
35 Correct 24 ms 33868 KB Output is correct
36 Correct 24 ms 33912 KB Output is correct
37 Correct 23 ms 33852 KB Output is correct
38 Correct 24 ms 33872 KB Output is correct
39 Correct 24 ms 33872 KB Output is correct
40 Correct 24 ms 33864 KB Output is correct
41 Correct 62 ms 38560 KB Output is correct
42 Correct 58 ms 37448 KB Output is correct
43 Correct 57 ms 35912 KB Output is correct
44 Correct 60 ms 37428 KB Output is correct
45 Correct 61 ms 38252 KB Output is correct
46 Correct 61 ms 38332 KB Output is correct
47 Correct 64 ms 37464 KB Output is correct
48 Correct 57 ms 36044 KB Output is correct
49 Correct 59 ms 37624 KB Output is correct
50 Correct 59 ms 36100 KB Output is correct
51 Correct 59 ms 37448 KB Output is correct
52 Correct 71 ms 37704 KB Output is correct
53 Correct 59 ms 36048 KB Output is correct
54 Correct 62 ms 37448 KB Output is correct
55 Correct 66 ms 37576 KB Output is correct
56 Correct 58 ms 36044 KB Output is correct
57 Correct 62 ms 37428 KB Output is correct
58 Correct 66 ms 37448 KB Output is correct
59 Correct 66 ms 37420 KB Output is correct
60 Correct 65 ms 38328 KB Output is correct
61 Runtime error 373 ms 98740 KB Execution killed with signal 6
62 Halted 0 ms 0 KB -