結果

問題 No.2486 Don't come next to me
ユーザー ruthenruthen
提出日時 2023-09-29 21:50:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 207,424 KB
実行使用メモリ 18,724 KB
最終ジャッジ日時 2023-09-29 21:50:18
合計ジャッジ時間 6,330 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 256 ms
16,172 KB
testcase_01 AC 227 ms
15,224 KB
testcase_02 AC 54 ms
6,456 KB
testcase_03 AC 150 ms
11,544 KB
testcase_04 AC 229 ms
14,360 KB
testcase_05 AC 156 ms
11,528 KB
testcase_06 AC 175 ms
12,488 KB
testcase_07 AC 26 ms
4,708 KB
testcase_08 AC 59 ms
6,832 KB
testcase_09 AC 237 ms
15,240 KB
testcase_10 AC 155 ms
11,768 KB
testcase_11 AC 85 ms
8,340 KB
testcase_12 AC 39 ms
5,480 KB
testcase_13 AC 334 ms
18,724 KB
testcase_14 AC 66 ms
7,492 KB
testcase_15 AC 156 ms
11,700 KB
testcase_16 AC 29 ms
4,932 KB
testcase_17 AC 57 ms
6,760 KB
testcase_18 AC 49 ms
6,224 KB
testcase_19 AC 63 ms
6,948 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0