結果

問題 No.2603 Tone Correction
ユーザー MisukiMisuki
提出日時 2024-01-12 23:12:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,552 bytes
コンパイル時間 2,944 ms
コンパイル使用メモリ 204,220 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-12 23:13:20
合計ジャッジ時間 5,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
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 2 ms
6,676 KB
testcase_34 AC 53 ms
6,676 KB
testcase_35 AC 53 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>

#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)

#ifdef DEBUG
#define dbg(x) cout << (#x) << " = " << x << '\n'
#else
#define dbg(x)
#endif

namespace R = std::ranges;
namespace V = std::views;

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldb = long double;
//#define double ldb

template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
  for(const T &X : arr)
    os << X << ' ';
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  for(const T &X : vec)
    os << X << ' ';
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T> &s) {
  for(const T &x : s)
    os << x << ' ';
  return os;
}

/**
 * template name: mint
 * author: Misuki
 * last update: 2022/06/01
 * note: inversion only works when MOD is a prime
 */

struct mint {
  static long long MOD;
  long long _val;

  mint(long long init = 0) {
    _val = init % MOD;
    (*this).norm();
  }

  mint POW(long long index) {
    if (index == 0)
      return mint(1ll);
    mint base = *this;
    mint res = (base == 0ll ? 0ll : 1ll);
    while(index) {
      if (index & 1)
        res *= base;
      base *= base, index >>= 1;
    }
    return res;
  }

  mint inv() { return (*this).POW(MOD - 2); }

  mint& norm() {
    if (_val >= MOD)
      _val -= MOD;
    if (_val < 0)
      _val += MOD;
    return *this;
  }

  mint& operator+=(mint b) {
    _val += b._val;
    return (*this).norm();
  }
  mint& operator-=(mint b) {
    _val -= b._val;
    return (*this).norm();
  }
  mint& operator*=(mint b) {
    _val = (_val * b._val) % MOD;
    return *this;
  }
  mint& operator/=(mint b) {
    _val = (_val * b.inv()._val) % MOD;
    return *this;
  }

  mint& operator++() {
    _val += 1;
    return (*this).norm();
  }
  mint& operator--() {
    _val -= 1;
    return (*this).norm();
  }
  mint operator++(signed) {
    mint tmp = *this;
    ++(*this);
    return tmp;
  }
  mint operator--(signed) {
    mint tmp = *this;
    --(*this);
    return tmp;
  }

  mint operator-() { return mint(-_val); }
  bool operator==(mint b) { return _val == b._val; }
  bool operator!=(mint b) { return _val != b._val; }
  
  friend mint operator+(mint a, mint b) { return a += b; }
  friend mint operator-(mint a, mint b) { return a -= b; }
  friend mint operator*(mint a, mint b) { return a *= b; }
  friend mint operator/(mint a, mint b) { return a /= b; }

  friend ostream& operator<<(ostream& os, const mint& b) {
    return os << b._val;
  }
  friend istream& operator>>(istream& is, mint& b) {
    long long val;
    is >> val;
    b = mint(val);
    return is;
  }
};

ll mint::MOD = 2;

void chmin(int &a, int b) { a = min(a, b); }

signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  int n; cin >> n >> mint::MOD;
  vector<int> a(n + 2), b(n + 2);
  for(int i = 1; i <= n; i++)
    cin >> a[i];
  for(int i = 1; i <= n; i++)
    cin >> b[i];

  auto f = [&](int i, int j) {
    if (i == 0 or i == n + 1)
      return 0ll;
    else if (j == 0)
      return b[i] - a[i];
    else if (j == 1)
      return b[i] + mint::MOD - a[i];
    else
      return b[i] - mint::MOD - a[i];
  };

  array<int, 3> dp = {};
  for(int i = 0; i <= n; i++) {
    array<int, 3> tmp = {LLONG_MAX, LLONG_MAX, LLONG_MAX};
    for(int j : {0, 1, 2})
      for(int k : {0, 1, 2})
        chmin(tmp[k], dp[j] + abs(f(i + 1, k) - f(i, j)));
    dp.swap(tmp);
  }

  cout << R::min(dp) / 2 << '\n';

  return 0;
}
0