結果

問題 No.2486 Don't come next to me
ユーザー nono00nono00
提出日時 2023-09-29 21:56:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 3,017 ms
コンパイル使用メモリ 252,260 KB
実行使用メモリ 29,660 KB
最終ジャッジ日時 2023-09-29 21:56:38
合計ジャッジ時間 7,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 303 ms
25,656 KB
testcase_01 AC 246 ms
23,708 KB
testcase_02 AC 52 ms
8,896 KB
testcase_03 AC 153 ms
17,604 KB
testcase_04 AC 231 ms
22,492 KB
testcase_05 AC 152 ms
17,596 KB
testcase_06 AC 174 ms
19,188 KB
testcase_07 AC 23 ms
6,060 KB
testcase_08 AC 55 ms
9,292 KB
testcase_09 AC 254 ms
23,884 KB
testcase_10 AC 164 ms
17,860 KB
testcase_11 AC 85 ms
12,060 KB
testcase_12 AC 35 ms
7,280 KB
testcase_13 AC 335 ms
29,660 KB
testcase_14 AC 65 ms
10,096 KB
testcase_15 AC 159 ms
17,860 KB
testcase_16 AC 26 ms
6,316 KB
testcase_17 AC 55 ms
9,368 KB
testcase_18 AC 47 ms
8,688 KB
testcase_19 AC 64 ms
9,672 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

namespace nono {

void solve() {
    long long n;
    int m;
    std::cin >> n >> m;
    std::vector<long long> a(m);
    for (int i = 0; i < m; i++) std::cin >> a[i];

    std::map<long long, long long> memo;
    auto calc = [&](auto self, long long v) -> long long {
        if (v <= 2) {
            return v;
        }
        if (memo.contains(v)) return memo[v];
        if (v % 2 == 0) {
            return memo[v] = v;
        } else {
            return memo[v] = 2 * self(self, v / 2);
        }
    };

    long long ans = 0;
    for (int i = 0; i + 1 < m; i++) {
        ans += calc(calc, a[i + 1] - a[i] - 1);
    }
    std::cout << ans << std::endl;
}

}  //  namespace nono

int main() {
    std::cin.tie(0)->sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    int t = 1;

    while (t--) nono::solve();
}
0