結果

問題 No.614 壊れたキャンパス
ユーザー hiroakiehiroakie
提出日時 2017-12-18 14:54:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,190 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 71,556 KB
実行使用メモリ 18,884 KB
最終ジャッジ日時 2024-05-09 11:21:34
合計ジャッジ時間 5,814 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,568 KB
testcase_01 AC 4 ms
8,064 KB
testcase_02 AC 5 ms
8,088 KB
testcase_03 AC 5 ms
8,064 KB
testcase_04 AC 5 ms
8,208 KB
testcase_05 AC 5 ms
8,192 KB
testcase_06 AC 5 ms
8,064 KB
testcase_07 AC 4 ms
8,192 KB
testcase_08 AC 87 ms
10,804 KB
testcase_09 AC 76 ms
12,756 KB
testcase_10 AC 112 ms
11,136 KB
testcase_11 AC 128 ms
10,360 KB
testcase_12 AC 141 ms
10,496 KB
testcase_13 AC 127 ms
10,400 KB
testcase_14 AC 91 ms
10,796 KB
testcase_15 AC 85 ms
11,008 KB
testcase_16 AC 85 ms
11,584 KB
testcase_17 AC 87 ms
14,228 KB
testcase_18 TLE -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |                 scanf("%d%d%d", &a, &b, &c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
typedef pair<int, int> str;
typedef long long int ll;
const int N = 200000;
vector<str> G[N - 1];
vector<ll> dp[2];
int n, m, k, s, t;

ll mn(ll a, ll b) {
	if (a == -1)return b; if (b == -1)return a;
	return min(a, b);
}

int main() {
	cin >> n >> m >> k >> s >> t;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		G[a - 1].push_back(make_pair(b, c));
	}
	for (int i = 0; i < G[0].size(); i++) { dp[0].push_back(abs(G[0][i].first - s)); }
	for (int i = 0; i < n - 2; i++) {
		for (int j = 0; j < G[i+1].size(); j++)dp[(i + 1) % 2].push_back(-1);
		for (int j = 0; j < G[i].size(); j++) {
			ll cp = G[i][j].second,cv=dp[i%2][j];
			for (int k = 0; k < G[i + 1].size(); k++) {
				dp[(i + 1) % 2][k] = mn(dp[(i + 1) % 2][k], cv + abs(cp - G[i + 1][k].first));
			}
		}
		dp[i % 2].clear();
	}

	if (n == 1) { cout << abs(t - s) << endl; }
	else {
		ll ans = -1;
		for (int j = 0; j < dp[(n - 2) % 2].size(); j++) {
			ans = mn(ans, dp[(n - 2) % 2][j] + abs(t - G[n - 2][j].second));
		}
		cout << ans << endl;
	}

	return 0;
}
0