結果

問題 No.1 道のショートカット
ユーザー moyashi_senpai
提出日時 2016-08-17 15:29:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,523 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 04:29:51
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d %d %d", &n, &c, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:29:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |                 scanf("%d", &s);
      |                 ~~~~~^~~~~~~~~~
main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |                 scanf("%d", &s);
      |                 ~~~~~^~~~~~~~~~
main.cpp:39:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |                 scanf("%d", &s);
      |                 ~~~~~^~~~~~~~~~
main.cpp:44:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |                 scanf("%d", &s);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

int main() {
	int n,c,v;
	array<array<pii, 50>, 50> graph = {};
	scanf("%d %d %d", &n, &c, &v);
	vector<pii> roads(v, {0,0});
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		roads[i].first = s-1;
	}
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		roads[i].second = s-1;
	}
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		graph[roads[i].first][roads[i].second].first = s;
	}
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		graph[roads[i].first][roads[i].second].second = s;
	}

	array<array<int, 301>, 51> dp;
	for (auto itr = dp.begin(); itr != dp.end(); itr++) {
		fill(itr->begin(), itr->end(), INT_MAX);
	}
	dp[0][c] = 0;
	for (int i = 0; n-1 > i; i++) {
		for (int j = 0; c >= j; j++) {
			if (dp[i][j] != INT_MAX) {
				for (int k = i + 1; n > k; k++) {
					if (graph[i][k].first && j - graph[i][k].first >= 0) {
						dp[k][j - graph[i][k].first] = min(dp[k][j - graph[i][k].first], dp[i][j] + graph[i][k].second);
					}
				}
			}
		}
	}
	int ans = *min_element(dp[n - 1].begin(), dp[n - 1].end());
	if (ans == INT_MAX)
		ans = -1;
	printf("%d\n", ans);
	return 0;
}
0