結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-12-26 00:02:21
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,058 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 52,088 KB
最終ジャッジ日時 2024-04-27 02:23:52
合計ジャッジ時間 1,898 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:10:1: error: ‘vector’ does not name a type
   10 | vector<vector<edge>> fG, rG;
      | ^~~~~~
main.cpp:11:1: error: ‘vector’ does not name a type
   11 | vector<i64> dp0, dp1;
      | ^~~~~~
main.cpp: In function ‘i64 rec0(int)’:
main.cpp:14:14: error: ‘dp0’ was not declared in this scope
   14 |   i64 &res = dp0[v];
      |              ^~~
main.cpp:17:17: error: ‘rG’ was not declared in this scope
   17 |   for(edge &e : rG[v]) {
      |                 ^~
main.cpp: In function ‘i64 rec1(int)’:
main.cpp:24:14: error: ‘dp1’ was not declared in this scope
   24 |   i64 &res = dp1[v];
      |              ^~~
main.cpp:27:17: error: ‘fG’ was not declared in this scope
   27 |   for(edge &e : fG[v]) {
      |                 ^~
main.cpp: In function ‘int main()’:
main.cpp:35:3: error: ‘fG’ was not declared in this scope
   35 |   fG.assign(n, vector<edge>());
      |   ^~
main.cpp:35:16: error: ‘vector’ was not declared in this scope
   35 |   fG.assign(n, vector<edge>());
      |                ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:35:27: error: expected primary-expression before ‘>’ token
   35 |   fG.assign(n, vector<edge>());
      |                           ^
main.cpp:35:29: error: expected primary-expression before ‘)’ token
   35 |   fG.assign(n, vector<edge>());
      |                             ^
main.cpp:36:3: error: ‘rG’ was not declared in this scope
   36 |   rG.assign(n, vector<edge>());
      |   ^~
main.cpp:36:27: error: expected primary-expression before ‘>’ token
   36 |   rG.assign(n, vector<edge>());
      |                           ^
main.cpp:36:29: error: expected primary-expression before ‘)’ token
   36 |   rG.assign(n, vector<edge>());
      |                             ^
main.cpp:42:3: err

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;

constexpr i64 inf = 987654321987654321LL;

struct edge { int to; i64 cost; };

vector<vector<edge>> fG, rG;
vector<i64> dp0, dp1;

i64 rec0(int v) {
  i64 &res = dp0[v];
  if(res != -1) { return res; }
  res = 0;
  for(edge &e : rG[v]) {
    res = max(res, rec0(e.to) + e.cost);
  }
  return res;
}

i64 rec1(int v) {
  i64 &res = dp1[v];
  if(res != -1) { return res; }
  res = inf;
  for(edge &e : fG[v]) {
    res = min(res, rec1(e.to) - e.cost);
  }
  return res;
}

int main(void) {
  int n, m; scanf("%d%d", &n, &m);
  fG.assign(n, vector<edge>());
  rG.assign(n, vector<edge>());
  for(int i=0; i<m; ++i) {
    int a, b; i64 c; scanf("%d%d%lld", &a, &b, &c);
    fG[a].push_back(edge({b, c}));
    rG[b].push_back(edge({a, c}));
  }
  dp0.assign(n, -1);
  rec0(n-1);
  dp1.assign(n, -1);
  i64 days = dp0[n-1];
  dp1[n-1] = days;
  rec1(0);

  int cnt = 0;
  for(int i=0; i<n; ++i) { cnt += dp0[i] != dp1[i]; }
  printf("%lld %d/%d\n", days, cnt, n);
  return 0;
}
0