結果

問題 No.2486 Don't come next to me
ユーザー milanis48663220milanis48663220
提出日時 2023-09-29 21:24:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,967 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 125,392 KB
実行使用メモリ 16,868 KB
最終ジャッジ日時 2023-09-29 21:24:33
合計ジャッジ時間 4,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
14,836 KB
testcase_01 AC 174 ms
13,900 KB
testcase_02 AC 43 ms
6,116 KB
testcase_03 AC 115 ms
10,716 KB
testcase_04 AC 171 ms
13,356 KB
testcase_05 AC 115 ms
10,520 KB
testcase_06 AC 145 ms
11,636 KB
testcase_07 AC 21 ms
4,792 KB
testcase_08 AC 46 ms
6,512 KB
testcase_09 AC 176 ms
14,096 KB
testcase_10 AC 119 ms
10,872 KB
testcase_11 AC 66 ms
7,612 KB
testcase_12 AC 29 ms
5,220 KB
testcase_13 AC 242 ms
16,868 KB
testcase_14 AC 52 ms
6,688 KB
testcase_15 AC 119 ms
10,944 KB
testcase_16 AC 22 ms
4,752 KB
testcase_17 AC 44 ms
6,452 KB
testcase_18 AC 39 ms
5,904 KB
testcase_19 AC 48 ms
6,544 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n, m; cin >> n >> m;
    vector<ll> a(m);
    for(int i = 0; i < m; i++) {
        cin >> a[i];
    }
    map<ll, ll> memo;
    function<ll(ll)> f = [&](ll x){
       
        if(memo.count(x)) return memo[x];
        if(x == 1) return 1ll;
        if(x == 0) return 0ll;
         if(x%2 == 0) return x;
        ll ans = 0;
        ans = f(x/2) + f(x/2);
        memo[x] = ans;
        return ans;
    };
    ll ans = 0;
    for(int i = 0; i < m-1; i++) {
        ans += f(a[i+1]-a[i]-1);
        // cout << a[i+1]-a[i]-1 << ":" << f(a[i+1]-a[i]-1) << endl;
    }
    cout << ans << endl;

    // for(int x = 1; x <= 20; x++){
    //     cout << x << ":" << f(x) << endl;
    // }
}
0