結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー tnakao0123tnakao0123
提出日時 2016-11-21 15:08:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,366 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 88,208 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-05-05 12:14:57
合計ジャッジ時間 3,704 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
5,504 KB
testcase_02 AC 3 ms
5,632 KB
testcase_03 AC 2 ms
5,632 KB
testcase_04 AC 3 ms
5,760 KB
testcase_05 AC 3 ms
5,632 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 2 ms
5,632 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,504 KB
testcase_10 AC 2 ms
5,632 KB
testcase_11 AC 2 ms
5,632 KB
testcase_12 WA -
testcase_13 AC 13 ms
6,400 KB
testcase_14 AC 15 ms
6,656 KB
testcase_15 AC 37 ms
7,808 KB
testcase_16 WA -
testcase_17 AC 59 ms
9,600 KB
testcase_18 AC 11 ms
6,400 KB
testcase_19 WA -
testcase_20 AC 30 ms
7,424 KB
testcase_21 AC 78 ms
10,624 KB
testcase_22 AC 30 ms
7,296 KB
testcase_23 AC 81 ms
10,496 KB
testcase_24 WA -
testcase_25 AC 81 ms
10,624 KB
testcase_26 WA -
testcase_27 AC 60 ms
9,344 KB
testcase_28 WA -
testcase_29 AC 32 ms
7,552 KB
testcase_30 WA -
testcase_31 AC 14 ms
6,272 KB
testcase_32 AC 15 ms
6,656 KB
testcase_33 WA -
testcase_34 AC 86 ms
11,008 KB
testcase_35 WA -
testcase_36 AC 83 ms
11,084 KB
testcase_37 WA -
testcase_38 AC 87 ms
11,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:86:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   86 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:91:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   91 |     scanf("%d%d", &ts[i], &ds[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 448.cc: No.448 ゆきこーだーの雨と雪 (3) - 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_E2 = 1 << 19; // = 524288
const int INF = 2100000000;

/* typedef */

typedef long long ll;

template <typename T, const int MAX_E2>
struct SegTreeMax {
  int n, e2;
  T nodes[MAX_E2];
  SegTreeMax() {}

  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1);
    memset(nodes, 0, sizeof(nodes));
  }

  T get(int i) { return nodes[e2 - 1 + i]; }

  void set_all() {
    for (int i = e2 - 2; i >= 0; i--)
      nodes[i] = max(nodes[i * 2 + 1], nodes[i * 2 + 2]);
  }

  T max_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return 0;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = max_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = max_range(r0, r1, k * 2 + 2, im, i1);

    return max(v0, v1);
  }

  T max_range(int r0, int r1) {
    return max_range(r0, r1, 0, 0, e2);
  }
};

/* global variables */

int ts[MAX_N + 1], ds[MAX_N + 1];
ll dsums[MAX_N + 1];
SegTreeMax<int,MAX_E2> stm;
int dp0[MAX_N + 1];
ll dp1[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  stm.init(n);
  dsums[0] = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ts[i], &ds[i]);
    stm.nodes[stm.e2 - 1 + i] = ds[i];
    dsums[i + 1] = dsums[i] + ds[i];
  }
  stm.set_all();
  ts[n] = INF, ds[n] = 0;

  for (int i = 0; i <= n; i++) dp0[i] = INF, dp1[i] = 0;
  dp0[0] = 0;

  for (int i = 0; i < n; i++) {
    int d0 = max(dp0[i], ds[i]);
    ll d1 = dp1[i] + ds[i];
    if (dp0[i + 1] > d0 || (dp0[i + 1] == d0 && dp1[i + 1] > d1))
      dp0[i + 1] = d0, dp1[i + 1] = d1;

    int j = lower_bound(ts + i, ts + n + 1, ts[i] + k) - ts;
    d0 = max(dp0[i], stm.max_range(i + 1, j));
    d1 = dp1[i] + dsums[j] - dsums[i + 1];
    if (dp0[j] > d0 || (dp0[j] == d0 && dp1[j] > d1))
      dp0[j] = d0, dp1[j] = d1;
  }

  printf("%d\n%lld\n", dp0[n], dp1[n]);
  return 0;
}
0