結果
問題 |
No.107 モンスター
|
ユーザー |
|
提出日時 | 2015-10-24 05:27:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,157 bytes |
コンパイル時間 | 441 ms |
コンパイル使用メモリ | 46,336 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-18 01:59:16 |
合計ジャッジ時間 | 1,169 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:46:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d",&N); | ~~~~~^~~~~~~~~ main.cpp:48:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | 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; typedef vector<Weight> Array; typedef vector<Array> Matrix; const int M = 20; Weight best[1<<M]; Weight total[1<<M]; Weight shortestHamiltonPath(const Array &w) { int n=w.size(); int N = 1 << n; REP(S,N) best[S] = total[S] = 0; best[0] = total[0] = 100; REP(S,N) REP(j,n) if (!(S&(1<<j)) && best[S]>0) { if (w[j]>0) { Weight hp=min(best[S]+w[j],total[S]); if (best[S|(1<<j)] < hp) { best[S|(1<<j)] = hp; total[S|(1<<j)] = total[S]; } } else { Weight hp=best[S]+w[j]; if (hp<=0) continue; if (total[S|(1<<j)] < total[S]+100 || (total[S|(1<<j)] == total[S]+100 && best[S|(1<<j)] < hp)) { best[S|(1<<j)] = hp; total[S|(1<<j)] = total[S]+100; } } } 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",shortestHamiltonPath(v)); }