結果

問題 No.2603 Tone Correction
ユーザー 👑 chro_96chro_96
提出日時 2024-01-13 16:30:54
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,187 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 30,080 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-13 16:31:00
合計ジャッジ時間 4,815 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 3 ms
6,676 KB
testcase_34 AC 57 ms
6,676 KB
testcase_35 AC 56 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int a[200000] = {};
  int b = 0;
  
  int res = 0;
  
  long long ans = 0LL;
  long long dp[200000][2] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
  }
  for (int i = 0; i < n; i++) {
    res = scanf("%d", &b);
    a[i] = (b-a[i]+m)%m;
  }
  
  dp[0][0] = (long long)a[0];
  dp[0][1] = (long long)(m-a[0]);
  for (int i = 1; i < n; i++) {
    if (a[i-1] < a[i]) {
      dp[i][0] = dp[i-1][0]+((long long)(a[i]-a[i-1]));
      dp[i][1] = dp[i-1][1]+((long long)(a[i]-a[i-1]));
    } else {
      dp[i][0] = dp[i-1][0]-((long long)(a[i]-a[i-1]));
      dp[i][1] = dp[i-1][1]-((long long)(a[i]-a[i-1]));
    }
    if (dp[i][0] > dp[i-1][1]+((long long)(a[i]+m-a[i-1]))) {
      dp[i][0] = dp[i-1][1]+((long long)(a[i]+m-a[i-1]));
    }
    if (dp[i][1] > dp[i-1][0]+((long long)(a[i-1]+m-a[i]))) {
      dp[i][1] = dp[i-1][0]+((long long)(a[i-1]+m-a[i]));
    }
  }
  
  ans = dp[n-1][0]+((long long)a[n-1]);
  if (ans > dp[n-1][1]+((long long)(m-a[n-1]))) {
    ans = dp[n-1][1]+((long long)(m-a[n-1]));
  }
  
  printf("%lld\n", ans/2LL);
  return 0;
}
0