結果

問題 No.1104 オンライン点呼
ユーザー simansiman
提出日時 2023-09-13 05:41:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 106,800 KB
実行使用メモリ 6,700 KB
最終ジャッジ日時 2023-09-13 05:41:16
合計ジャッジ時間 3,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 86 ms
4,684 KB
testcase_02 AC 78 ms
4,688 KB
testcase_03 AC 57 ms
4,684 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 43 ms
6,700 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 36 ms
4,376 KB
testcase_13 AC 30 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 48 ms
4,380 KB
testcase_16 AC 56 ms
4,380 KB
testcase_17 AC 35 ms
4,376 KB
testcase_18 AC 45 ms
4,380 KB
testcase_19 AC 66 ms
4,476 KB
testcase_20 AC 89 ms
4,444 KB
testcase_21 AC 71 ms
4,448 KB
testcase_22 AC 59 ms
4,376 KB
testcase_23 AC 46 ms
4,376 KB
testcase_24 AC 20 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int id;
  ll t;

  Node(int id = -1, ll t = -1) {
    this->id = id;
    this->t = t;
  }

  bool operator>(const Node &n) const {
    return t > n.t;
  }
};

int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> A(N);
  vector<ll> B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  priority_queue <Node, vector<Node>, greater<Node>> pque;
  vector<bool> visited(N, false);
  ll ans = 0;
  pque.push(Node(0, 0));

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (visited[node.id]) continue;
    visited[node.id] = true;
    if(node.id >= N - 2) {
      ans = max(ans, node.t);
    }

    if (node.id + 1 < N) {
      pque.push(Node(node.id + 1, node.t + A[node.id] + B[node.id + 1]));
    }
    if (node.id + 2 < N) {
      pque.push(Node(node.id + 2, node.t + A[node.id] + B[node.id + 2] + K));
    }
  }

  cout << ans << endl;

  return 0;
}
0