結果
問題 |
No.17 2つの地点に泊まりたい
|
ユーザー |
![]() |
提出日時 | 2016-09-03 22:25:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,386 ms / 5,000 ms |
コード長 | 1,757 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 24,576 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-10-15 01:37:02 |
合計ジャッジ時間 | 7,646 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 21 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:22:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | INC0(i, n) { scanf("%d", &s[i]); } | ~~~~~^~~~~~~~~~~~~ main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%d", &m); | ~~~~~^~~~~~~~~~ main.cpp:24:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | INC0(i, m) { scanf("%d%d%d", &a[i], &b[i], &c[i]); } | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #define FOR(i, l, r) for(int i = (l) ; i < (r); i++) #define REV(i, l, r) for(int i = (r) - 1; i >= (l); i--) #define INC0(i, n) FOR(i, 0, n) #define INC1(i, n) FOR(i, 1, (n) + 1) #define DEC0(i, n) REV(i, 0, n) #define DEC1(i, n) REV(i, 1, (n) + 1) typedef long long signed int LL; typedef long long unsigned int LU; int n, s[50], m, a[1225], b[1225], c[1225]; struct DP { int v, s1, s2; }; DP queue[50 * 50 * 50 * 50]; // テキトー int get, set; int dp[50][50][50]; int main() { scanf("%d", &n); INC0(i, n) { scanf("%d", &s[i]); } scanf("%d", &m); INC0(i, m) { scanf("%d%d%d", &a[i], &b[i], &c[i]); } dp[0][0][0] = 1; // +1 DP temp = {0, 0, 0}; queue[set++] = temp; while(get < set) { DP q = queue[get++]; int v = q.v; INC0(i, m) { if(a[i] == v || b[i] == v) { int w; if(a[i] == v) { w = b[i]; } else { w = a[i]; } int x = dp[v][q.s1][q.s2] + c[i]; int& y = dp[w][q.s1][q.s2]; if(y == 0 || x < y) { y = x; DP temp = {w, q.s1, q.s2}; queue[set++] = temp; } if(v != 0 && v != n - 1 && q.s1 == 0) { int x = dp[v][0][0] + s[v] + c[i]; int& y = dp[w][v][0]; if(y == 0 || x < y) { y = x; DP temp = {w, v, 0}; queue[set++] = temp; } } if(v != 0 && v != n - 1 && v != q.s1 && q.s1 != 0 && q.s2 == 0) { int x = dp[v][q.s1][0] + s[v] + c[i]; int& y = dp[w][q.s1][v]; if(y == 0 || x < y) { y = x; DP temp = {w, q.s1, v}; queue[set++] = temp; } } } } } int min = 6000000; FOR(i, 1, n - 1) { FOR(j, 1, n - 1) { int x = dp[n - 1][i][j]; if(i != j && x != 0 && x < min) { min = x; } } } printf("%d\n", min - 1); // -1 return 0; }