結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-24 02:41:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,334 bytes |
| コンパイル時間 | 480 ms |
| コンパイル使用メモリ | 45,900 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 04:37:39 |
| 合計ジャッジ時間 | 1,881 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:52:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | for(int i=0;i<N;i++)scanf("%d",&v[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#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));
}