結果

問題 No.2486 Don't come next to me
ユーザー daiota
提出日時 2023-09-30 07:12:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 167,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 01:26:36
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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