結果

問題 No.2486 Don't come next to me
ユーザー daiotadaiota
提出日時 2023-09-30 07:12:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 1,475 ms
コンパイル使用メモリ 164,408 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-09-30 07:12:03
合計ジャッジ時間 3,683 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
4,780 KB
testcase_01 AC 32 ms
4,560 KB
testcase_02 AC 10 ms
4,376 KB
testcase_03 AC 23 ms
4,376 KB
testcase_04 AC 30 ms
4,504 KB
testcase_05 AC 23 ms
4,376 KB
testcase_06 AC 26 ms
4,404 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 32 ms
4,576 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 41 ms
4,928 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 23 ms
4,376 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 11 ms
4,376 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 ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)

ll a[200010];


int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	ll i,j,k;

	ll N,M;
	cin >> N >> M;
	for(i=1;i<=M;i++) cin >> a[i];

	ll ans=0;
	for(i=2;i<=M;i++){
		ll x=a[i]-a[i-1]-1;

		if(x%2==0){
			ans+=x;
			continue;
		}

		ll e=1;
		while(1){
			if(x==1){
				ans+=e;
				break;
			}

			x--;
			x/=2;
			e*=2;
			if(x%2==0){
				ans+=e*x;
				break;
			}
		}

	}

	cout << ans << endl;

	return 0;
}
0