結果

問題 No.286 Modulo Discount Store
ユーザー cielciel
提出日時 2015-10-24 02:41:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,334 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 48,732 KB
実行使用メモリ 5,188 KB
最終ジャッジ日時 2023-10-11 05:20:34
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,996 KB
testcase_01 AC 2 ms
5,012 KB
testcase_02 AC 3 ms
5,020 KB
testcase_03 AC 2 ms
4,976 KB
testcase_04 AC 2 ms
5,048 KB
testcase_05 AC 2 ms
5,000 KB
testcase_06 AC 4 ms
5,076 KB
testcase_07 AC 2 ms
5,004 KB
testcase_08 AC 2 ms
4,988 KB
testcase_09 AC 2 ms
5,068 KB
testcase_10 AC 3 ms
5,040 KB
testcase_11 AC 2 ms
5,020 KB
testcase_12 AC 2 ms
5,040 KB
testcase_13 AC 3 ms
5,008 KB
testcase_14 AC 2 ms
5,040 KB
testcase_15 AC 2 ms
4,988 KB
testcase_16 AC 2 ms
5,004 KB
testcase_17 AC 5 ms
5,188 KB
testcase_18 AC 2 ms
5,040 KB
testcase_19 AC 2 ms
4,988 KB
testcase_20 AC 2 ms
4,984 KB
testcase_21 AC 2 ms
4,972 KB
testcase_22 AC 2 ms
5,020 KB
testcase_23 AC 3 ms
5,044 KB
testcase_24 AC 2 ms
4,972 KB
testcase_25 AC 2 ms
4,972 KB
testcase_26 AC 2 ms
5,080 KB
testcase_27 AC 2 ms
4,980 KB
testcase_28 AC 4 ms
5,104 KB
testcase_29 AC 2 ms
4,992 KB
testcase_30 AC 2 ms
4,988 KB
testcase_31 AC 2 ms
4,972 KB
testcase_32 AC 2 ms
4,976 KB
testcase_33 AC 2 ms
5,016 KB
testcase_34 AC 2 ms
5,024 KB
testcase_35 AC 2 ms
4,972 KB
testcase_36 AC 2 ms
5,020 KB
testcase_37 AC 2 ms
4,968 KB
testcase_38 AC 2 ms
5,000 KB
testcase_39 AC 3 ms
5,064 KB
testcase_40 AC 2 ms
5,000 KB
testcase_41 AC 2 ms
5,012 KB
testcase_42 AC 2 ms
5,008 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 99999999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

const int M = 20;
Weight best[1<<M];
Weight total[1<<M];
Weight shortestHamiltonCycle(const Array &w) {
	int n=w.size();
	int N = 1 << n;
	REP(S,N) best[S] = total[S] = INF;
	best[0] = total[0] = 0;
	REP(S,N) REP(j,n) if (!(S&(1<<j))) {
		Weight discount=total[S]%1000;
		Weight discounted=max(0,w[j]-discount);
		if (best[S|(1<<j)] > best[S] + discounted) {
			best[S|(1<<j)] = best[S] + discounted;
			total[S|(1<<j)] = total[S] + w[j];
		}
	}
	return best[N-1];
}

int main(){
	int N;
	scanf("%d",&N);
	Array v(N);
	for(int i=0;i<N;i++)scanf("%d",&v[i]);
	printf("%d\n",shortestHamiltonCycle(v));
}
0