結果
| 問題 |
No.614 壊れたキャンパス
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2017-12-17 23:25:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,700 bytes |
| コンパイル時間 | 1,089 ms |
| コンパイル使用メモリ | 88,740 KB |
| 実行使用メモリ | 22,356 KB |
| 最終ジャッジ日時 | 2024-12-15 23:07:54 |
| 合計ジャッジ時間 | 10,047 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d%d%d%d%d", &n, &m, &k, &st, &gl);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:58:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d%d%d", &ai, &bi, &ci);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 614.cc: No.614 壊れたキャンパス - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MAX_M = 200000;
typedef long long ll;
const ll LINF = 1LL << 60;
/* typedef */
typedef pair<int,int> pii;
typedef vector<pii> vpii;
/* global variables */
vpii nbrs[MAX_N];
ll dp[2][MAX_M];
/* subroutines */
inline ll absll(ll a) { return (a >= 0) ? a : -a; }
inline void setmin(ll &a, ll b) { if (a > b) a = b; }
/* main */
int main() {
int n, m, k, st, gl;
scanf("%d%d%d%d%d", &n, &m, &k, &st, &gl);
for (int i = 0; i < m; i++) {
int ai, bi, ci;
scanf("%d%d%d", &ai, &bi, &ci);
nbrs[ai].push_back(pii(bi, ci));
}
nbrs[0].push_back(pii(0, st));
dp[0][0] = 0;
int cur = 0, nxt = 1;
for (int i = 1; i < n; i++) {
vpii &nbr0 = nbrs[i - 1], &nbr1 = nbrs[i];
if (nbr1.empty()) {
puts("-1");
return 0;
}
int n0 = nbr0.size(), n1 = nbr1.size();
fill(dp[nxt], dp[nxt] + n1, LINF);
for (int j0 = 0; j0 < n0; j0++) {
int &f0 = nbr0[j0].second;
for (int j1 = 0; j1 < n1; j1++)
setmin(dp[nxt][j1], dp[cur][j0] + absll(nbr1[j1].first - f0));
}
cur ^= 1, nxt ^= 1;
}
ll mind = LINF;
for (int j = 0; j < nbrs[n - 1].size(); j++)
setmin(mind, dp[cur][j] + absll(gl - nbrs[n - 1][j].second));
printf("%lld\n", mind);
return 0;
}
tnakao0123