Submission #791760

# Submission time Handle Problem Language Result Execution time Memory
791760 2023-07-24T09:40:04 Z 이성호(#10048) Netrpeljivost (COI23_netrpeljivost) C++17
27 / 100
123 ms 67200 KB
#include <iostream>
#include <string>
#include <algorithm>
#define int long long
using namespace std;
const int inf = 1e18;

int dp[256][128][128];
int V[128][128];
pair<int, int> lh[256];
int n;

pair<int, int> bounds(int x)
{
    string s;
    for (; x; x >>= 1) s += '0' + (x & 1);
    reverse(s.begin(), s.end());
    string st[2] = {s, s};
    for (int k = 0; k < 2; k++) {
        while (st[k].size() < n+1) st[k] += '0' + k;
    }
    pair<int, int> res = make_pair(0, 0);
    for (int i = 0; i <= n; i++) {
        res.first <<= 1; res.second <<= 1;
        res.first += st[0][i] - '0'; res.second += st[1][i] - '0';
    }
    res.first -= (1 << n); res.second -= (1 << n);
    return res;
}

signed main()
{
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> V[i][j];
        }
    }
    while (N != (1 << n)) n++;
    for (int i = 1; i < 2 * N; i++) lh[i] = bounds(i);
    fill(&dp[0][0][0], &dp[255][127][128], inf);
    for (int i = 2 * N - 1; i >= N; i--) {
        dp[i][i-N][i-N] = 0;
    }
    for (int i = N - 1; i >= 1; i--) {
        for (int p = lh[2*i].first; p <= lh[2*i].second; p++) {
            for (int q = lh[2*i].first; q <= lh[2*i].second; q++) {
                for (int r = lh[2*i+1].first; r <= lh[2*i+1].second; r++) {
                    for (int s = lh[2*i+1].first; s <= lh[2*i+1].second; s++) {
                        dp[i][p][s] = min(dp[i][p][s], dp[2*i][p][q] + dp[2*i+1][r][s] + V[q][r]);
                        dp[i][s][p] = min(dp[i][s][p], dp[2*i+1][s][r] + dp[2*i][q][p] + V[q][r]);
                    }
                }
            }
        }
    }
    int ans = inf;
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++) {
            ans = min(ans, dp[1][i][j]);
        }
    }
    cout << ans << '\n';
    return 0;
}

Compilation message

Main.cpp: In function 'std::pair<long long int, long long int> bounds(long long int)':
Main.cpp:20:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   20 |         while (st[k].size() < n+1) st[k] += '0' + k;
      |                ~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33080 KB Output is correct
2 Correct 15 ms 33084 KB Output is correct
3 Correct 18 ms 33088 KB Output is correct
4 Correct 15 ms 33088 KB Output is correct
5 Correct 13 ms 33064 KB Output is correct
6 Correct 14 ms 33104 KB Output is correct
7 Correct 14 ms 33112 KB Output is correct
8 Correct 15 ms 33104 KB Output is correct
9 Correct 14 ms 33116 KB Output is correct
10 Correct 17 ms 33052 KB Output is correct
11 Correct 14 ms 33136 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 15 ms 33108 KB Output is correct
14 Correct 15 ms 33032 KB Output is correct
15 Correct 15 ms 33124 KB Output is correct
16 Correct 17 ms 33128 KB Output is correct
17 Correct 15 ms 33108 KB Output is correct
18 Correct 16 ms 33136 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 15 ms 33032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33080 KB Output is correct
2 Correct 15 ms 33084 KB Output is correct
3 Correct 18 ms 33088 KB Output is correct
4 Correct 15 ms 33088 KB Output is correct
5 Correct 13 ms 33064 KB Output is correct
6 Correct 14 ms 33104 KB Output is correct
7 Correct 14 ms 33112 KB Output is correct
8 Correct 15 ms 33104 KB Output is correct
9 Correct 14 ms 33116 KB Output is correct
10 Correct 17 ms 33052 KB Output is correct
11 Correct 14 ms 33136 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 15 ms 33108 KB Output is correct
14 Correct 15 ms 33032 KB Output is correct
15 Correct 15 ms 33124 KB Output is correct
16 Correct 17 ms 33128 KB Output is correct
17 Correct 15 ms 33108 KB Output is correct
18 Correct 16 ms 33136 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 15 ms 33032 KB Output is correct
21 Correct 65 ms 33240 KB Output is correct
22 Correct 57 ms 33236 KB Output is correct
23 Correct 67 ms 33240 KB Output is correct
24 Correct 19 ms 33188 KB Output is correct
25 Correct 18 ms 33168 KB Output is correct
26 Correct 61 ms 33236 KB Output is correct
27 Correct 66 ms 33240 KB Output is correct
28 Correct 59 ms 33240 KB Output is correct
29 Correct 59 ms 33240 KB Output is correct
30 Correct 59 ms 33240 KB Output is correct
31 Correct 80 ms 33236 KB Output is correct
32 Correct 70 ms 33256 KB Output is correct
33 Correct 57 ms 33244 KB Output is correct
34 Correct 56 ms 33240 KB Output is correct
35 Correct 55 ms 33240 KB Output is correct
36 Correct 56 ms 33208 KB Output is correct
37 Correct 55 ms 33240 KB Output is correct
38 Correct 59 ms 33152 KB Output is correct
39 Correct 58 ms 33236 KB Output is correct
40 Correct 69 ms 33152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33080 KB Output is correct
2 Correct 15 ms 33084 KB Output is correct
3 Correct 18 ms 33088 KB Output is correct
4 Correct 15 ms 33088 KB Output is correct
5 Correct 13 ms 33064 KB Output is correct
6 Correct 14 ms 33104 KB Output is correct
7 Correct 14 ms 33112 KB Output is correct
8 Correct 15 ms 33104 KB Output is correct
9 Correct 14 ms 33116 KB Output is correct
10 Correct 17 ms 33052 KB Output is correct
11 Correct 14 ms 33136 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 15 ms 33108 KB Output is correct
14 Correct 15 ms 33032 KB Output is correct
15 Correct 15 ms 33124 KB Output is correct
16 Correct 17 ms 33128 KB Output is correct
17 Correct 15 ms 33108 KB Output is correct
18 Correct 16 ms 33136 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 15 ms 33032 KB Output is correct
21 Correct 65 ms 33240 KB Output is correct
22 Correct 57 ms 33236 KB Output is correct
23 Correct 67 ms 33240 KB Output is correct
24 Correct 19 ms 33188 KB Output is correct
25 Correct 18 ms 33168 KB Output is correct
26 Correct 61 ms 33236 KB Output is correct
27 Correct 66 ms 33240 KB Output is correct
28 Correct 59 ms 33240 KB Output is correct
29 Correct 59 ms 33240 KB Output is correct
30 Correct 59 ms 33240 KB Output is correct
31 Correct 80 ms 33236 KB Output is correct
32 Correct 70 ms 33256 KB Output is correct
33 Correct 57 ms 33244 KB Output is correct
34 Correct 56 ms 33240 KB Output is correct
35 Correct 55 ms 33240 KB Output is correct
36 Correct 56 ms 33208 KB Output is correct
37 Correct 55 ms 33240 KB Output is correct
38 Correct 59 ms 33152 KB Output is correct
39 Correct 58 ms 33236 KB Output is correct
40 Correct 69 ms 33152 KB Output is correct
41 Runtime error 123 ms 67200 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 33080 KB Output is correct
2 Correct 15 ms 33084 KB Output is correct
3 Correct 18 ms 33088 KB Output is correct
4 Correct 15 ms 33088 KB Output is correct
5 Correct 13 ms 33064 KB Output is correct
6 Correct 14 ms 33104 KB Output is correct
7 Correct 14 ms 33112 KB Output is correct
8 Correct 15 ms 33104 KB Output is correct
9 Correct 14 ms 33116 KB Output is correct
10 Correct 17 ms 33052 KB Output is correct
11 Correct 14 ms 33136 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 15 ms 33108 KB Output is correct
14 Correct 15 ms 33032 KB Output is correct
15 Correct 15 ms 33124 KB Output is correct
16 Correct 17 ms 33128 KB Output is correct
17 Correct 15 ms 33108 KB Output is correct
18 Correct 16 ms 33136 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 15 ms 33032 KB Output is correct
21 Correct 65 ms 33240 KB Output is correct
22 Correct 57 ms 33236 KB Output is correct
23 Correct 67 ms 33240 KB Output is correct
24 Correct 19 ms 33188 KB Output is correct
25 Correct 18 ms 33168 KB Output is correct
26 Correct 61 ms 33236 KB Output is correct
27 Correct 66 ms 33240 KB Output is correct
28 Correct 59 ms 33240 KB Output is correct
29 Correct 59 ms 33240 KB Output is correct
30 Correct 59 ms 33240 KB Output is correct
31 Correct 80 ms 33236 KB Output is correct
32 Correct 70 ms 33256 KB Output is correct
33 Correct 57 ms 33244 KB Output is correct
34 Correct 56 ms 33240 KB Output is correct
35 Correct 55 ms 33240 KB Output is correct
36 Correct 56 ms 33208 KB Output is correct
37 Correct 55 ms 33240 KB Output is correct
38 Correct 59 ms 33152 KB Output is correct
39 Correct 58 ms 33236 KB Output is correct
40 Correct 69 ms 33152 KB Output is correct
41 Runtime error 123 ms 67200 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -