Submission #850846

# Submission time Handle Problem Language Result Execution time Memory
850846 2023-09-17T14:24:53 Z tiago Kronican (COCI16_kronican) C++14
0 / 100
29 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define infinito 999999999
long long int n,k;
long long int v[22][22];
long long int dp[(1<<21)][22];
long long int fib(long long int bitmask, long long int kk){
    if(kk <= k){
        return 0;
    }
    else if(dp[bitmask][kk] != infinito){
        return dp[bitmask][kk];
    }
    for(int i = 0; i < n; i++){
        if((bitmask & (1<<i)) == 0){
            for(int y = 0; y < n; y++){
                if((bitmask & (1<<y)) == 0 && y != i ){
                    dp[bitmask][kk] = min(dp[bitmask][kk],  fib((bitmask | (1<<i)), kk-1) + v[i][y]);
                }
            }
        }
    }
    return dp[bitmask][kk];
}
int main(){
    for(int i = 0; i < (1<<21)-1; i++){
        for(int y = 0; y < 22; y++){
            dp[i][y] = infinito;
        }
    }
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        for(int y = 0; y < n; y++){
            cin >> v[i][y];
        }
    }
    cout << fib(0,n);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 65536 KB Execution killed with signal 9
2 Runtime error 18 ms 65536 KB Execution killed with signal 9
3 Runtime error 21 ms 65536 KB Execution killed with signal 9
4 Runtime error 19 ms 65536 KB Execution killed with signal 9
5 Runtime error 29 ms 65536 KB Execution killed with signal 9
6 Runtime error 21 ms 65536 KB Execution killed with signal 9
7 Runtime error 17 ms 65536 KB Execution killed with signal 9
8 Runtime error 20 ms 65536 KB Execution killed with signal 9
9 Runtime error 20 ms 65536 KB Execution killed with signal 9
10 Runtime error 17 ms 65536 KB Execution killed with signal 9