結果
問題 | No.134 走れ!サブロー君 |
ユーザー |
![]() |
提出日時 | 2019-01-29 16:43:38 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 66 ms / 5,000 ms |
コード長 | 3,900 bytes |
コンパイル時間 | 395 ms |
コンパイル使用メモリ | 33,024 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-10 11:28:03 |
合計ジャッジ時間 | 1,321 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <float.h>#include <limits.h>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>// 内部定数#define D_POINT_MAX 15 // 最大地点数#define D_PTN_MAX 10000 // 最大配達済パターン数// 内部構造体 - 地点情報typedef struct Point {int miX, miY; // 位置double mdWeight; // 重さ} Point;// 内部変数static FILE *szpFpI; // 入力static Point sz1Point[D_POINT_MAX]; // 地点 [0]:酒屋 [>0]:配達先static int siDCnt; // 配達先の数static double sd2Time[D_PTN_MAX][D_POINT_MAX]; // 最短時間[配達済][現在地]// 内部変数 - テスト用#ifdef D_TESTstatic int siRes;static FILE *szpFpA;#endif// 合計時間 - 取得doublefGetSum(int piNow // <I> 現在地, int piTo // <I> 行き先, int piDel // <I> 配達済, double pdWeight // <I> 重さ, double pdTime // <I> 時間){// 距離int liLen = abs(sz1Point[piNow].miX - sz1Point[piTo].miX);liLen += abs(sz1Point[piNow].miY - sz1Point[piTo].miY);// 合計時間double ldSum = pdTime + (double)liLen * (pdWeight + 100.0) / 120.0 + sz1Point[piTo].mdWeight;// 最短時間if (sd2Time[piDel][piTo] <= ldSum) {return -1.0;}sd2Time[piDel][piTo] = ldSum;return ldSum;}// 最短時間 - セットintfSetMin(int piDCnt // <I> 配達数, int piDel // <I> 配達済, int piNow // <I> 現在地, double pdWeight // <I> 重さ, double pdTime // <I> 時間){int i;// 配達終了if (piDCnt == siDCnt) {fGetSum(piNow, 0, 0, pdWeight, pdTime); // 酒屋へ戻るreturn 0;}// 配達for (i = 1; i <= siDCnt; i++) {int liBit = 1 << (i - 1);// 配達済if ((piDel & liBit) > 0) {continue;}int liDel = piDel | liBit;// 合計時間double ldSum = fGetSum(piNow, i, liDel, pdWeight, pdTime);if (ldSum < 0.0) {continue;}// 下位へfSetMin(piDCnt + 1, liDel, i, pdWeight - sz1Point[i].mdWeight, ldSum);}return 0;}// 実行メインintfMain(int piTNo // <I> テスト番号 1~){int i, j;char lc1Buf[1024], lc1Out[1024];// 入力 - セット#ifdef D_TESTsprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);szpFpI = fopen(lc1Buf, "r");sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);szpFpA = fopen(lc1Buf, "r");siRes = 0;#elseszpFpI = stdin;#endif// 最短時間 - 初期化for (i = 0; i < D_PTN_MAX; i++) {for (j = 0; j < D_POINT_MAX; j++) {sd2Time[i][j] = DBL_MAX;}}// 酒屋の位置 - 取得fgets(lc1Buf, sizeof(lc1Buf), szpFpI);sscanf(lc1Buf, "%d%d", &sz1Point[0].miX, &sz1Point[0].miY);// 配達先の数 - 取得fgets(lc1Buf, sizeof(lc1Buf), szpFpI);sscanf(lc1Buf, "%d", &siDCnt);// 配達先 - 取得double ldSum = 0.0;for (i = 1; i <= siDCnt; i++) {fgets(lc1Buf, sizeof(lc1Buf), szpFpI);sscanf(lc1Buf, "%d%d%lf", &sz1Point[i].miX, &sz1Point[i].miY, &sz1Point[i].mdWeight);// 重さ合計 - セットldSum += sz1Point[i].mdWeight;}// 最短時間 - セットfSetMin(0, 0, 0, ldSum, 0.0);// 結果 - セットsprintf(lc1Out, "%.8lf\n", sd2Time[0][0]);// 結果 - 表示#ifdef D_TESTfgets(lc1Buf, sizeof(lc1Buf), szpFpA);if (strcmp(lc1Buf, lc1Out)) {siRes = -1;}#elseprintf("%s", lc1Out);#endif// 残データ有無#ifdef D_TESTlc1Buf[0] = '\0';fgets(lc1Buf, sizeof(lc1Buf), szpFpA);if (strcmp(lc1Buf, "")) {siRes = -1;}#endif// テストファイルクローズ#ifdef D_TESTfclose(szpFpI);fclose(szpFpA);#endif// テスト結果#ifdef D_TESTif (siRes == 0) {printf("OK %d\n", piTNo);}else {printf("NG %d\n", piTNo);}#endifreturn 0;}intmain(){#ifdef D_TESTint i;for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {fMain(i);}#elsefMain(0);#endifreturn 0;}