結果

問題 No.771 しおり
ユーザー cielciel
提出日時 2019-01-05 01:44:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 67,956 KB
実行使用メモリ 47,988 KB
最終ジャッジ日時 2023-09-29 12:51:25
合計ジャッジ時間 4,519 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
47,936 KB
testcase_01 AC 22 ms
11,076 KB
testcase_02 AC 2 ms
4,932 KB
testcase_03 AC 2 ms
4,932 KB
testcase_04 AC 1 ms
4,944 KB
testcase_05 AC 1 ms
4,936 KB
testcase_06 AC 2 ms
4,984 KB
testcase_07 AC 2 ms
4,960 KB
testcase_08 AC 2 ms
5,028 KB
testcase_09 AC 2 ms
4,964 KB
testcase_10 AC 2 ms
4,900 KB
testcase_11 AC 2 ms
4,960 KB
testcase_12 AC 2 ms
4,952 KB
testcase_13 AC 2 ms
4,964 KB
testcase_14 AC 2 ms
5,088 KB
testcase_15 AC 2 ms
4,980 KB
testcase_16 AC 2 ms
4,992 KB
testcase_17 AC 2 ms
5,008 KB
testcase_18 AC 1 ms
4,960 KB
testcase_19 AC 1 ms
4,988 KB
testcase_20 AC 1 ms
4,956 KB
testcase_21 AC 2 ms
5,004 KB
testcase_22 AC 2 ms
4,944 KB
testcase_23 AC 2 ms
5,032 KB
testcase_24 AC 2 ms
5,004 KB
testcase_25 AC 98 ms
27,404 KB
testcase_26 AC 4 ms
5,284 KB
testcase_27 AC 23 ms
11,156 KB
testcase_28 AC 48 ms
15,116 KB
testcase_29 AC 23 ms
11,136 KB
testcase_30 AC 215 ms
47,960 KB
testcase_31 AC 218 ms
47,932 KB
testcase_32 AC 6 ms
5,528 KB
testcase_33 AC 216 ms
47,988 KB
testcase_34 AC 212 ms
47,976 KB
testcase_35 AC 6 ms
5,624 KB
testcase_36 AC 3 ms
5,092 KB
testcase_37 AC 3 ms
5,060 KB
testcase_38 AC 6 ms
5,524 KB
testcase_39 AC 3 ms
5,096 KB
testcase_40 AC 95 ms
27,472 KB
testcase_41 AC 212 ms
47,936 KB
testcase_42 AC 202 ms
47,896 KB
testcase_43 AC 23 ms
11,088 KB
testcase_44 AC 207 ms
47,932 KB
testcase_45 AC 207 ms
47,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 9999999
using namespace std;

typedef int Weight;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

const int M = 20;
Weight best[1<<M][M];
int    prev[1<<M][M];
void buildPath(int S, int i, vector<int> &path) {
  if (!S) return;
  buildPath(S^(1<<i), ::prev[S][i], path);
  path.push_back(i);
}
Weight shortestHamiltonPath(const Matrix &w, vector<int> &path) {
  int n=w.size();
  int N = 1 << n, K;
  REP(S,N) REP(i,n) best[S][i] = INF;
  REP(S,N) REP(i,n) if(S&1<<i) REP(j,n) if (!(S&(1<<j)))
    if (K=best[S][i]==INF ? w[i][j] : max(best[S][i],w[i][j]), best[S|(1<<j)][j] > K)
      best[S|(1<<j)][j] = K,
      ::prev[S|(1<<j)][j] = i;
  int t = min_element(best[N-1], best[N-1]+n) - best[N-1];
  //path.clear(); buildPath(N-1, t, path);
  return best[N-1][t];
}

int main(){
	int V,s,t,d;
	scanf("%d",&V);
	Matrix m(V,Array(V));
	{
		vector<pair<int,int> >v(V);
		for(int i=0;i<V;i++)scanf("%d%d",&v[i].first,&v[i].second);
		for(s=0;s<V;s++)for(t=0;t<V;t++)if(s!=t){
			m[s][t]=v[s].second-v[s].first+v[t].first;
		}
	}
	vector<int>path;
	printf("%d\n",shortestHamiltonPath(m,path));
}
0