Submission #117886


Source Code Expand

#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

int E[15][15];
int dp[1<<15][15];
void amin(int &x, int y) {
	if(x > y) x = y;
}
int main() {
	int N;
	cin >> N;
	rep(i, N-1) {
		reu(j, i+1, N) {
			int x;
			cin >> x;
			E[j][i] = E[i][j] = x;
		}
	}
	if(N == 2) {
		puts("0 0");
		return 0;
	}
	mset(dp, INF);
	dp[1][0] = 0;
	rep(mask, 1 << N) rep(i, N) {
		int x = dp[mask][i];
		if(x == INF) continue;
		assert(mask >> i & 1);
		rep(j, N) if(~mask >> j & 1)
			amin(dp[mask | 1 << j][j], x + E[i][j]);
	}
	int r = INF;
	rep(i, N) r = min(r, dp[(1 << N)-1][i] + E[i][0]);
	cout << N << " " << r << endl;
    return 0;
}

Submission Info

Submission Time
Task A - 特別作戦
User anta
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1826 Byte
Status AC
Exec Time 40 ms
Memory 2844 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 24
Set Name Test Cases
All 00-sample, 01-maximum, 02-minimum, 03-flat, 50-random-00, 50-random-01, 50-random-02, 50-random-03, 50-random-04, 50-random-05, 50-random-06, 50-random-07, 50-random-08, 50-random-09, 50-random-10, 50-random-11, 50-random-12, 50-random-13, 50-random-14, 50-random-15, 50-random-16, 50-random-17, 50-random-18, 50-random-19
Case Name Status Exec Time Memory
00-sample AC 25 ms 2720 KB
01-maximum AC 39 ms 2728 KB
02-minimum AC 22 ms 800 KB
03-flat AC 40 ms 2600 KB
50-random-00 AC 23 ms 2844 KB
50-random-01 AC 25 ms 2600 KB
50-random-02 AC 25 ms 2840 KB
50-random-03 AC 23 ms 2840 KB
50-random-04 AC 24 ms 2724 KB
50-random-05 AC 24 ms 2724 KB
50-random-06 AC 27 ms 2720 KB
50-random-07 AC 25 ms 2592 KB
50-random-08 AC 31 ms 2724 KB
50-random-09 AC 38 ms 2716 KB
50-random-10 AC 25 ms 2720 KB
50-random-11 AC 31 ms 2716 KB
50-random-12 AC 25 ms 2724 KB
50-random-13 AC 22 ms 932 KB
50-random-14 AC 28 ms 2592 KB
50-random-15 AC 26 ms 2600 KB
50-random-16 AC 25 ms 2604 KB
50-random-17 AC 28 ms 2720 KB
50-random-18 AC 32 ms 2672 KB
50-random-19 AC 25 ms 2716 KB