結果

問題 No.2486 Don't come next to me
ユーザー PAKACHUPAKACHU
提出日時 2023-09-29 22:39:18
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 6,080 ms
コンパイル使用メモリ 136,808 KB
実行使用メモリ 29,740 KB
最終ジャッジ日時 2023-09-29 22:39:31
合計ジャッジ時間 12,627 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 342 ms
25,836 KB
testcase_01 AC 287 ms
23,652 KB
testcase_02 AC 66 ms
8,952 KB
testcase_03 AC 181 ms
17,636 KB
testcase_04 AC 278 ms
22,632 KB
testcase_05 AC 203 ms
17,572 KB
testcase_06 AC 239 ms
19,208 KB
testcase_07 AC 31 ms
6,212 KB
testcase_08 AC 70 ms
9,392 KB
testcase_09 AC 281 ms
23,964 KB
testcase_10 AC 191 ms
17,900 KB
testcase_11 AC 103 ms
12,076 KB
testcase_12 AC 51 ms
7,348 KB
testcase_13 AC 383 ms
29,740 KB
testcase_14 AC 80 ms
10,236 KB
testcase_15 AC 193 ms
17,896 KB
testcase_16 AC 34 ms
6,376 KB
testcase_17 AC 68 ms
9,456 KB
testcase_18 AC 61 ms
8,592 KB
testcase_19 AC 75 ms
10,012 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const long long mod = 998244353;
const ll inf = 1LL << 60;
const int INF = 5e8;

int main()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> a(m);
    for (int i = 0; i < m; i++)
        cin >> a[i];

    ll ans = 0;

    map<ll, ll> mp;
    auto f = [&](auto self, ll x) {
        if (mp.count(x))
            return mp[x];
        if (x == 0)
            return 0LL;
        if (x == 1)
            return 1LL;
        ll ret = 0;
        if (x % 2 == 0) {
            ret = x;
        } else {
            ret = 2 * self(self, x / 2);
        }
        return mp[x] = ret;
    };

    for (int i = 0; i < m; i++) {
        ll x = a[i] - (i == 0 ? 0 : a[i - 1]) - 1;
        ans += f(f, x);
    }
    cout << ans << endl;
}
0