結果

問題 No.844 split game
ユーザー akakimidoriakakimidori
提出日時 2019-07-06 09:46:35
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,161 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 19:22:27
合計ジャッジ時間 5,391 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,348 KB
testcase_01 AC 17 ms
4,372 KB
testcase_02 AC 47 ms
4,372 KB
testcase_03 AC 32 ms
4,372 KB
testcase_04 AC 16 ms
4,372 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 53 ms
4,372 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 52 ms
4,372 KB
testcase_19 AC 52 ms
4,372 KB
testcase_20 AC 52 ms
4,372 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,372 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,372 KB
testcase_29 AC 4 ms
4,372 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1 ms
4,372 KB
testcase_33 AC 6 ms
4,372 KB
testcase_34 AC 4 ms
4,372 KB
testcase_35 AC 7 ms
4,372 KB
testcase_36 AC 4 ms
4,372 KB
testcase_37 AC 10 ms
4,372 KB
testcase_38 AC 18 ms
4,372 KB
testcase_39 AC 37 ms
4,372 KB
testcase_40 AC 11 ms
4,372 KB
testcase_41 AC 1 ms
4,372 KB
testcase_42 AC 1 ms
4,372 KB
testcase_43 AC 1 ms
4,372 KB
testcase_44 AC 1 ms
4,372 KB
testcase_45 AC 1 ms
4,372 KB
testcase_46 AC 1 ms
4,372 KB
testcase_47 AC 1 ms
4,372 KB
testcase_48 WA -
testcase_49 AC 1 ms
4,372 KB
testcase_50 AC 1 ms
4,372 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 1 ms
4,372 KB
testcase_54 AC 1 ms
4,372 KB
testcase_55 AC 1 ms
4,372 KB
testcase_56 AC 1 ms
4,372 KB
testcase_57 AC 1 ms
4,372 KB
testcase_58 AC 1 ms
4,372 KB
testcase_59 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

typedef struct range {
  i32 l, r, p;
} range;

int cmp_range (const void *a, const void *b) {
  i32 d = ((range *)a)->r - ((range *)b)->r;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, m, a;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &m, &a);
  range *q = ALLOC (m, range);
  for (i32 i = 0; i < m; ++i) {
    i32 l, r, p;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &p);
    l--;
    q[i] = (range) {l, r, p};
  }
  SORT (q, m, cmp_range);
  i64 *dp = ALLOC (n + 1, i64);
  for (i32 i = 0, j = 0; i <= n; ++i) {
    i64 cost = 0 < i && i < n ? -a : 0;
    i64 max = cost;
    for (; j < m && q[j].r == i; ++j) {
      max = MAX (max, cost + q[j].p + dp[q[j].l]);
    }
    dp[i] = max;
  }
  i64 ans = 0;
  for (i32 i = 0; i <= n; ++i) {
    ans = MAX (ans, dp[i]);
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}
0