답안 #1114181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114181 2024-11-18T09:30:21 Z SalihSahin Netrpeljivost (COI23_netrpeljivost) C++14
100 / 100
1496 ms 98212 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(r - l == 1){
      dp[node].resize(2);
      dp[node][0].resize(2);
      dp[node][1].resize(2);

      dp[node][0][1] = dp[node][1][0] = c[l][r];
      dp[node][0][0] = dp[node][1][1] = inf;
      return;
   }
 
   int m = (l + r)/2;
   f(node * 2, l, m);
   f(node * 2 + 1, m+1, r);
   int sz = (r - l + 1)/2;

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

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

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

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


   dp[node*2].clear();
   dp[node*2+1].clear();
}
 
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++){
         //c[i][j] = 1;
         cin>>c[i][j];
      }
   }

   if(n == 1){
      cout<<0<<endl;
      return 0;
   }
   f(1, 0, n-1);
   cout<<ans<<endl;
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 33616 KB Output is correct
2 Correct 26 ms 33616 KB Output is correct
3 Correct 30 ms 33628 KB Output is correct
4 Correct 27 ms 33628 KB Output is correct
5 Correct 26 ms 33616 KB Output is correct
6 Correct 26 ms 33532 KB Output is correct
7 Correct 25 ms 33616 KB Output is correct
8 Correct 30 ms 33604 KB Output is correct
9 Correct 32 ms 33536 KB Output is correct
10 Correct 26 ms 33608 KB Output is correct
11 Correct 27 ms 33616 KB Output is correct
12 Correct 26 ms 33616 KB Output is correct
13 Correct 26 ms 33612 KB Output is correct
14 Correct 25 ms 33608 KB Output is correct
15 Correct 26 ms 33612 KB Output is correct
16 Correct 26 ms 33700 KB Output is correct
17 Correct 26 ms 33608 KB Output is correct
18 Correct 25 ms 33584 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 33616 KB Output is correct
2 Correct 26 ms 33616 KB Output is correct
3 Correct 30 ms 33628 KB Output is correct
4 Correct 27 ms 33628 KB Output is correct
5 Correct 26 ms 33616 KB Output is correct
6 Correct 26 ms 33532 KB Output is correct
7 Correct 25 ms 33616 KB Output is correct
8 Correct 30 ms 33604 KB Output is correct
9 Correct 32 ms 33536 KB Output is correct
10 Correct 26 ms 33608 KB Output is correct
11 Correct 27 ms 33616 KB Output is correct
12 Correct 26 ms 33616 KB Output is correct
13 Correct 26 ms 33612 KB Output is correct
14 Correct 25 ms 33608 KB Output is correct
15 Correct 26 ms 33612 KB Output is correct
16 Correct 26 ms 33700 KB Output is correct
17 Correct 26 ms 33608 KB Output is correct
18 Correct 25 ms 33584 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33632 KB Output is correct
21 Correct 29 ms 33872 KB Output is correct
22 Correct 28 ms 33616 KB Output is correct
23 Correct 27 ms 33832 KB Output is correct
24 Correct 25 ms 33752 KB Output is correct
25 Correct 23 ms 33616 KB Output is correct
26 Correct 24 ms 33616 KB Output is correct
27 Correct 24 ms 33616 KB Output is correct
28 Correct 25 ms 33616 KB Output is correct
29 Correct 24 ms 33696 KB Output is correct
30 Correct 24 ms 33872 KB Output is correct
31 Correct 24 ms 33676 KB Output is correct
32 Correct 24 ms 33616 KB Output is correct
33 Correct 25 ms 33736 KB Output is correct
34 Correct 24 ms 33608 KB Output is correct
35 Correct 24 ms 33616 KB Output is correct
36 Correct 24 ms 33616 KB Output is correct
37 Correct 24 ms 33632 KB Output is correct
38 Correct 24 ms 33616 KB Output is correct
39 Correct 24 ms 33712 KB Output is correct
40 Correct 24 ms 33616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 33616 KB Output is correct
2 Correct 26 ms 33616 KB Output is correct
3 Correct 30 ms 33628 KB Output is correct
4 Correct 27 ms 33628 KB Output is correct
5 Correct 26 ms 33616 KB Output is correct
6 Correct 26 ms 33532 KB Output is correct
7 Correct 25 ms 33616 KB Output is correct
8 Correct 30 ms 33604 KB Output is correct
9 Correct 32 ms 33536 KB Output is correct
10 Correct 26 ms 33608 KB Output is correct
11 Correct 27 ms 33616 KB Output is correct
12 Correct 26 ms 33616 KB Output is correct
13 Correct 26 ms 33612 KB Output is correct
14 Correct 25 ms 33608 KB Output is correct
15 Correct 26 ms 33612 KB Output is correct
16 Correct 26 ms 33700 KB Output is correct
17 Correct 26 ms 33608 KB Output is correct
18 Correct 25 ms 33584 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33632 KB Output is correct
21 Correct 29 ms 33872 KB Output is correct
22 Correct 28 ms 33616 KB Output is correct
23 Correct 27 ms 33832 KB Output is correct
24 Correct 25 ms 33752 KB Output is correct
25 Correct 23 ms 33616 KB Output is correct
26 Correct 24 ms 33616 KB Output is correct
27 Correct 24 ms 33616 KB Output is correct
28 Correct 25 ms 33616 KB Output is correct
29 Correct 24 ms 33696 KB Output is correct
30 Correct 24 ms 33872 KB Output is correct
31 Correct 24 ms 33676 KB Output is correct
32 Correct 24 ms 33616 KB Output is correct
33 Correct 25 ms 33736 KB Output is correct
34 Correct 24 ms 33608 KB Output is correct
35 Correct 24 ms 33616 KB Output is correct
36 Correct 24 ms 33616 KB Output is correct
37 Correct 24 ms 33632 KB Output is correct
38 Correct 24 ms 33616 KB Output is correct
39 Correct 24 ms 33712 KB Output is correct
40 Correct 24 ms 33616 KB Output is correct
41 Correct 53 ms 35144 KB Output is correct
42 Correct 52 ms 35188 KB Output is correct
43 Correct 52 ms 35148 KB Output is correct
44 Correct 53 ms 35152 KB Output is correct
45 Correct 52 ms 35268 KB Output is correct
46 Correct 53 ms 35260 KB Output is correct
47 Correct 57 ms 35144 KB Output is correct
48 Correct 52 ms 35152 KB Output is correct
49 Correct 53 ms 35272 KB Output is correct
50 Correct 53 ms 35104 KB Output is correct
51 Correct 53 ms 35144 KB Output is correct
52 Correct 58 ms 35144 KB Output is correct
53 Correct 56 ms 35276 KB Output is correct
54 Correct 53 ms 35216 KB Output is correct
55 Correct 61 ms 35148 KB Output is correct
56 Correct 64 ms 35056 KB Output is correct
57 Correct 60 ms 35144 KB Output is correct
58 Correct 56 ms 35192 KB Output is correct
59 Correct 65 ms 35144 KB Output is correct
60 Correct 59 ms 35144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 33616 KB Output is correct
2 Correct 26 ms 33616 KB Output is correct
3 Correct 30 ms 33628 KB Output is correct
4 Correct 27 ms 33628 KB Output is correct
5 Correct 26 ms 33616 KB Output is correct
6 Correct 26 ms 33532 KB Output is correct
7 Correct 25 ms 33616 KB Output is correct
8 Correct 30 ms 33604 KB Output is correct
9 Correct 32 ms 33536 KB Output is correct
10 Correct 26 ms 33608 KB Output is correct
11 Correct 27 ms 33616 KB Output is correct
12 Correct 26 ms 33616 KB Output is correct
13 Correct 26 ms 33612 KB Output is correct
14 Correct 25 ms 33608 KB Output is correct
15 Correct 26 ms 33612 KB Output is correct
16 Correct 26 ms 33700 KB Output is correct
17 Correct 26 ms 33608 KB Output is correct
18 Correct 25 ms 33584 KB Output is correct
19 Correct 26 ms 33616 KB Output is correct
20 Correct 26 ms 33632 KB Output is correct
21 Correct 29 ms 33872 KB Output is correct
22 Correct 28 ms 33616 KB Output is correct
23 Correct 27 ms 33832 KB Output is correct
24 Correct 25 ms 33752 KB Output is correct
25 Correct 23 ms 33616 KB Output is correct
26 Correct 24 ms 33616 KB Output is correct
27 Correct 24 ms 33616 KB Output is correct
28 Correct 25 ms 33616 KB Output is correct
29 Correct 24 ms 33696 KB Output is correct
30 Correct 24 ms 33872 KB Output is correct
31 Correct 24 ms 33676 KB Output is correct
32 Correct 24 ms 33616 KB Output is correct
33 Correct 25 ms 33736 KB Output is correct
34 Correct 24 ms 33608 KB Output is correct
35 Correct 24 ms 33616 KB Output is correct
36 Correct 24 ms 33616 KB Output is correct
37 Correct 24 ms 33632 KB Output is correct
38 Correct 24 ms 33616 KB Output is correct
39 Correct 24 ms 33712 KB Output is correct
40 Correct 24 ms 33616 KB Output is correct
41 Correct 53 ms 35144 KB Output is correct
42 Correct 52 ms 35188 KB Output is correct
43 Correct 52 ms 35148 KB Output is correct
44 Correct 53 ms 35152 KB Output is correct
45 Correct 52 ms 35268 KB Output is correct
46 Correct 53 ms 35260 KB Output is correct
47 Correct 57 ms 35144 KB Output is correct
48 Correct 52 ms 35152 KB Output is correct
49 Correct 53 ms 35272 KB Output is correct
50 Correct 53 ms 35104 KB Output is correct
51 Correct 53 ms 35144 KB Output is correct
52 Correct 58 ms 35144 KB Output is correct
53 Correct 56 ms 35276 KB Output is correct
54 Correct 53 ms 35216 KB Output is correct
55 Correct 61 ms 35148 KB Output is correct
56 Correct 64 ms 35056 KB Output is correct
57 Correct 60 ms 35144 KB Output is correct
58 Correct 56 ms 35192 KB Output is correct
59 Correct 65 ms 35144 KB Output is correct
60 Correct 59 ms 35144 KB Output is correct
61 Correct 1417 ms 56948 KB Output is correct
62 Correct 1463 ms 97320 KB Output is correct
63 Correct 1442 ms 97320 KB Output is correct
64 Correct 1385 ms 97260 KB Output is correct
65 Correct 1304 ms 97344 KB Output is correct
66 Correct 1365 ms 97320 KB Output is correct
67 Correct 1412 ms 97320 KB Output is correct
68 Correct 1371 ms 97552 KB Output is correct
69 Correct 1399 ms 97320 KB Output is correct
70 Correct 1390 ms 97352 KB Output is correct
71 Correct 1295 ms 97976 KB Output is correct
72 Correct 1349 ms 97988 KB Output is correct
73 Correct 1445 ms 97832 KB Output is correct
74 Correct 1427 ms 97820 KB Output is correct
75 Correct 1455 ms 97996 KB Output is correct
76 Correct 1474 ms 97832 KB Output is correct
77 Correct 1496 ms 97672 KB Output is correct
78 Correct 1358 ms 98212 KB Output is correct
79 Correct 1296 ms 97996 KB Output is correct
80 Correct 1393 ms 97972 KB Output is correct