結果
| 問題 |
No.2486 Don't come next to me
|
| ユーザー |
|
| 提出日時 | 2023-09-29 21:50:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 351 ms / 2,000 ms |
| コード長 | 688 bytes |
| コンパイル時間 | 2,095 ms |
| コンパイル使用メモリ | 201,568 KB |
| 最終ジャッジ日時 | 2025-02-17 03:14:10 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
long long N, M;
cin >> N >> M;
vector<long long> A(M);
REP(i, M) cin >> A[i];
vector<long long> B(M - 1);
REP(i, M - 1) B[i] = A[i + 1] - A[i] - 1;
map<long long, long long> mp;
auto rec = [&](auto f, long long x) -> long long {
if (mp.count(x) > 0) return mp[x];
if (x == 0) return 0;
if (x == 1) return 1;
if (x == 2) return 2;
if (x % 2 == 0) return x;
return mp[x] = 2 * f(f, x / 2);
};
long long ans = 0;
REP(i, M - 1) ans += rec(rec, B[i]);
cout << ans << '\n';
return 0;
}