結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2016-09-03 22:09:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,727 bytes |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 24,448 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 19:22:54 |
| 合計ジャッジ時間 | 3,228 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 9 RE * 12 |
コンパイルメッセージ
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];
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) {
if(i != j && dp[n - 1][i][j] < min) { min = dp[n - 1][i][j]; }
}
}
printf("%d\n", min - 1); // -1
return 0;
}
FF256grhy