結果

問題 No.2486 Don't come next to me
ユーザー hiromi_ayase
提出日時 2023-09-29 21:54:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 5,442 ms
コンパイル使用メモリ 309,160 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 15:54:41
合計ジャッジ時間 6,923 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

i64 f(i64 x) {
  i64 ret = 0;

  if (x % 2 == 0) {
    return x;
  } else {
    if (x == 1) return 1;
    return f((x - 1) / 2) * 2;
  }
}

int main() {
  FAST_IO

  i64 n;
  int m;
  cin >> n >> m;
  vector a(m, 0LL);
  for (auto i : views::iota(0, m)) {
    cin >> a[i];
  }

  auto ans = 0LL;
  for (auto i : views::iota(0, m - 1)) {
    auto d = a[i + 1] - a[i] - 1;
    ans += f(d);
  }

  cout << ans << endl;
}
0