Submission #69187091


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

/////////////////// メイン ///////////////////

int main () {
  
  //////////////////// 入力 ////////////////////

  int n, m;
  cin >> n >> m;

  vector<long long> w(n);
  for (int i=0; i<n; i++) {
    cin >> w.at(i);
  }

  // 隣接リストに受け取る
  vector<int> u(m), v(m);
  vector<set<int>> graph(n);
  for (int i=0; i<m; i++) {
    cin >> u.at(i) >> v.at(i);
    u.at(i)--;
    v.at(i)--;
    graph.at(u.at(i)).emplace(v.at(i));
    graph.at(v.at(i)).emplace(u.at(i));
  }

  //////////////// 出力変数定義 ////////////////

  vector<long long> result;

  //////////////////// 処理 ////////////////////

  // DPテーブル
  // dp.at(i).at(j) は、n回中i回移動して頂点jに到達したときの消費燃料
  // ただし、nターンになるまで何も食べずに移動し続けるコスト分も加算している
  vector<vector<long long>> dp(n+1,vector<long long>(n,1e18));

  // テーブル更新
  for (int i=0; i<n; i++) {

    // スタートするターンを遅らせる場合を考慮する
    dp.at(i).at(0) = 0;

    // 頂点ごとに離接頂点に情報を配っていく
    for (int j=0; j<n; j++) {

      // まず食事をする
      dp.at(i).at(j) += w.at(j)*(n-i);

      // 配る
      for (int next : graph.at(j)) {
        dp.at(i+1).at(next) = min(dp.at(i+1).at(next),dp.at(i).at(j));
      }

    }

  }

  // スタート地点はコスト0でいい
  dp.at(n).at(0) = 0;

  // n回移動を終えた後のデータが答え
  result = dp.at(n);

  //////////////////// 出力 ////////////////////

  for (int i=0; i<n; i++) {
    cout << result.at(i) << endl;
  }

  //////////////////// 終了 ////////////////////

  return 0;

}

Submission Info

Submission Time
Task F - Eat and Ride
User wightou
Language C++ 23 (gcc 12.2)
Score 500
Code Size 1829 Byte
Status AC
Exec Time 459 ms
Memory 199776 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 51
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3500 KiB
00_sample_01.txt AC 1 ms 3516 KiB
00_sample_02.txt AC 1 ms 3504 KiB
01_random_03.txt AC 97 ms 37100 KiB
01_random_04.txt AC 87 ms 47648 KiB
01_random_05.txt AC 50 ms 10072 KiB
01_random_06.txt AC 67 ms 40796 KiB
01_random_07.txt AC 47 ms 29440 KiB
01_random_08.txt AC 122 ms 29612 KiB
01_random_09.txt AC 28 ms 5008 KiB
01_random_10.txt AC 15 ms 11340 KiB
01_random_11.txt AC 440 ms 199632 KiB
01_random_12.txt AC 454 ms 199608 KiB
01_random_13.txt AC 441 ms 199588 KiB
01_random_14.txt AC 453 ms 199540 KiB
01_random_15.txt AC 444 ms 199580 KiB
01_random_16.txt AC 410 ms 199776 KiB
01_random_17.txt AC 426 ms 199708 KiB
01_random_18.txt AC 459 ms 199548 KiB
01_random_19.txt AC 416 ms 199652 KiB
01_random_20.txt AC 421 ms 199632 KiB
01_random_21.txt AC 411 ms 199640 KiB
01_random_22.txt AC 419 ms 199580 KiB
01_random_23.txt AC 456 ms 199552 KiB
01_random_24.txt AC 419 ms 199584 KiB
01_random_25.txt AC 417 ms 199648 KiB
01_random_26.txt AC 413 ms 199568 KiB
01_random_27.txt AC 429 ms 199584 KiB
01_random_28.txt AC 454 ms 199616 KiB
01_random_29.txt AC 417 ms 199632 KiB
01_random_30.txt AC 418 ms 199524 KiB
01_random_31.txt AC 91 ms 17632 KiB
01_random_32.txt AC 166 ms 54156 KiB
01_random_33.txt AC 59 ms 8464 KiB
01_random_34.txt AC 193 ms 70688 KiB
01_random_35.txt AC 60 ms 9268 KiB
01_random_36.txt AC 160 ms 46112 KiB
01_random_37.txt AC 369 ms 155268 KiB
01_random_38.txt AC 159 ms 46456 KiB
01_random_39.txt AC 79 ms 13952 KiB
01_random_40.txt AC 43 ms 6116 KiB
01_random_41.txt AC 313 ms 126484 KiB
01_random_42.txt AC 303 ms 117108 KiB
01_random_43.txt AC 293 ms 115672 KiB
01_random_44.txt AC 293 ms 115060 KiB
01_random_45.txt AC 308 ms 125852 KiB
01_random_46.txt AC 154 ms 53124 KiB
01_random_47.txt AC 154 ms 53060 KiB
01_random_48.txt AC 422 ms 199700 KiB
01_random_49.txt AC 417 ms 199528 KiB
01_random_50.txt AC 420 ms 199612 KiB