답안 #791758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791758 2023-07-24T09:39:17 Z 이성호(#10048) Netrpeljivost (COI23_netrpeljivost) C++17
10 / 100
58 ms 33180 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[128];
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;
      |                ~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33108 KB Output is correct
2 Correct 14 ms 33028 KB Output is correct
3 Correct 13 ms 33124 KB Output is correct
4 Correct 14 ms 33108 KB Output is correct
5 Correct 13 ms 33040 KB Output is correct
6 Correct 14 ms 33108 KB Output is correct
7 Correct 13 ms 33036 KB Output is correct
8 Correct 14 ms 33152 KB Output is correct
9 Correct 13 ms 33068 KB Output is correct
10 Correct 13 ms 33108 KB Output is correct
11 Correct 13 ms 33040 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 16 ms 33048 KB Output is correct
14 Correct 18 ms 33120 KB Output is correct
15 Correct 14 ms 33076 KB Output is correct
16 Correct 13 ms 33160 KB Output is correct
17 Correct 13 ms 33036 KB Output is correct
18 Correct 13 ms 33108 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 13 ms 33088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33108 KB Output is correct
2 Correct 14 ms 33028 KB Output is correct
3 Correct 13 ms 33124 KB Output is correct
4 Correct 14 ms 33108 KB Output is correct
5 Correct 13 ms 33040 KB Output is correct
6 Correct 14 ms 33108 KB Output is correct
7 Correct 13 ms 33036 KB Output is correct
8 Correct 14 ms 33152 KB Output is correct
9 Correct 13 ms 33068 KB Output is correct
10 Correct 13 ms 33108 KB Output is correct
11 Correct 13 ms 33040 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 16 ms 33048 KB Output is correct
14 Correct 18 ms 33120 KB Output is correct
15 Correct 14 ms 33076 KB Output is correct
16 Correct 13 ms 33160 KB Output is correct
17 Correct 13 ms 33036 KB Output is correct
18 Correct 13 ms 33108 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 13 ms 33088 KB Output is correct
21 Incorrect 58 ms 33180 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33108 KB Output is correct
2 Correct 14 ms 33028 KB Output is correct
3 Correct 13 ms 33124 KB Output is correct
4 Correct 14 ms 33108 KB Output is correct
5 Correct 13 ms 33040 KB Output is correct
6 Correct 14 ms 33108 KB Output is correct
7 Correct 13 ms 33036 KB Output is correct
8 Correct 14 ms 33152 KB Output is correct
9 Correct 13 ms 33068 KB Output is correct
10 Correct 13 ms 33108 KB Output is correct
11 Correct 13 ms 33040 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 16 ms 33048 KB Output is correct
14 Correct 18 ms 33120 KB Output is correct
15 Correct 14 ms 33076 KB Output is correct
16 Correct 13 ms 33160 KB Output is correct
17 Correct 13 ms 33036 KB Output is correct
18 Correct 13 ms 33108 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 13 ms 33088 KB Output is correct
21 Incorrect 58 ms 33180 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33108 KB Output is correct
2 Correct 14 ms 33028 KB Output is correct
3 Correct 13 ms 33124 KB Output is correct
4 Correct 14 ms 33108 KB Output is correct
5 Correct 13 ms 33040 KB Output is correct
6 Correct 14 ms 33108 KB Output is correct
7 Correct 13 ms 33036 KB Output is correct
8 Correct 14 ms 33152 KB Output is correct
9 Correct 13 ms 33068 KB Output is correct
10 Correct 13 ms 33108 KB Output is correct
11 Correct 13 ms 33040 KB Output is correct
12 Correct 14 ms 33108 KB Output is correct
13 Correct 16 ms 33048 KB Output is correct
14 Correct 18 ms 33120 KB Output is correct
15 Correct 14 ms 33076 KB Output is correct
16 Correct 13 ms 33160 KB Output is correct
17 Correct 13 ms 33036 KB Output is correct
18 Correct 13 ms 33108 KB Output is correct
19 Correct 13 ms 33108 KB Output is correct
20 Correct 13 ms 33088 KB Output is correct
21 Incorrect 58 ms 33180 KB Output isn't correct
22 Halted 0 ms 0 KB -