結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
ゆるく
|
| 提出日時 | 2015-02-21 02:21:08 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 2,160 bytes |
| コンパイル時間 | 486 ms |
| コンパイル使用メモリ | 24,704 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 01:19:56 |
| 合計ジャッジ時間 | 1,104 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:33:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
main.c:34:13: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | rep(i, n) scanf("%d", &t[i]);
| ^~~~~~~~~~~~~~~~~~
main.c:35:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%d", &m);
| ^~~~~~~~~~~~~~~
main.c:38:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%d %d %d", &a, &b, &c);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
typedef long long ll;
#define MAX_N 112233
#define REP(i, x, n) for(i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 0x7FFFFFF
#define ALLOCA(type, n) ((type*)alloca(sizeof(type) * (n)))
#define MALLOC(type, n) ((type*)malloc(sizeof(type) * (n)))
#define CALLOC(type, n) ((type*)calloc((n), sizeof(type)))
#define REALLOC(type, n, p) ((type*)realloc((p), sizeof(type) * (n)))
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
typedef struct heap_queue{long *data;long size;}hq;
void heappush(hq *q,int data){long i = q->size;q->size++;while(i > 0){long p = (i - 1) / 2;if (q->data[p]<=data){break;}q->data[i] = q->data[p];i=p;}q->data[i] = data;}
long heappop(hq *q){long ret = q->data[0];q->size--;long data = q->data[q->size];long i = 0;while(i * 2 + 1 < q->size) {long a = i * 2 + 1, b = i * 2 + 2;if (b < q->size && q->data[b] < q->data[a]) {a=b;}if (q->data[a] >= data) {break;}q->data[i] = q->data[a];i=a;}q->data[i]=data;return ret;}
#define SORT(h, n) qsort(h, n, sizeof(h[0]), ASC)
#define RSORT(h, n) qsort(h, n, sizeof(h[0]), DESC)
int ASC(const void *c1,const void *c2){int tmp1=*(int *)c1;int tmp2=*(int *)c2;if(tmp1<tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1>tmp2){return 1;}}
int DESC(const void *c1,const void *c2){int tmp1 = *(int *)c1;int tmp2=*(int *)c2;if(tmp1>tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1<tmp2){return 1;}}
void Reverse(char *a, char *b, unsigned int n) {unsigned int i = 0;unsigned int d = n;while(d--) {b[d] = a[i++];}b[n] = '\0';}
int n, m, t[51], l[51][51] = {INF};
int main(void)
{
int i,j,k;
int a,b,c;
int min;
scanf("%d", &n);
rep(i, n) scanf("%d", &t[i]);
scanf("%d", &m);
rep(i, 51) rep(j, 51) l[i][j] = INF;
rep(i, m) {
scanf("%d %d %d", &a, &b, &c);
l[a][b] = c;
l[b][a] = c;
}
rep(k, n) {
rep(i, n) {
rep(j, n) {
l[i][j] = MIN(l[i][j], l[i][k] + l[k][j]);
}
}
}
min = INF;
REP(i, 1, n - 1) {
REP(j, 1, n - 1) {
if(i != j) min = MIN(min, t[i] + t[j] + l[0][i] + l[i][j] + l[j][n - 1]);
}
}
printf("%d\n", min);
return 0;
}
ゆるく