結果
| 問題 |
No.2486 Don't come next to me
|
| ユーザー |
|
| 提出日時 | 2023-09-29 21:48:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 119 ms / 2,000 ms |
| コード長 | 4,350 bytes |
| コンパイル時間 | 1,560 ms |
| コンパイル使用メモリ | 181,740 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 15:48:52 |
| 合計ジャッジ時間 | 3,757 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const string Yes="Yes";
const string No="No";
const string YES="YES";
const string NO="NO";
const string abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD=1000000007;
const ll mod=998244353;
const ll big_prime=(1LL << 61)-1;
const long long INF = 1LL << 60;
const long double PI=3.141592653589793;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define inV(vec) for(ll i=0;i<vec.size();i++)cin>>vec[i];
#define outV(vec) for(ll i=0;i<vec.size();i++){cout<<vec[i]<<" ";}cout<<endl;
#define print(s) cout<<s<<endl;
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//エラトステネスの篩
vector<bool>Prime(2,false);//false=not Prime number, true=Prime Number
void Era(ll N){
for(ll i=0;i<N-1;i++){
Prime.pb(true);
}
for(ll i=2;i*i<=N;i++){
if(Prime[i]){
for(ll x=2*i;x<=N;x+=i)Prime[x]=false;
}
}
}
//繰り返し二乗法
ll modpow(ll a, ll n, ll mod) {
if(a==0){
return 0;
}
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
//素因数分解
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0; // 指数
// 割れる限り割り続ける
while (N % a == 0) {
++ex;
N /= a;
}
// その結果を push
res.push_back({a, ex});
}
// 最後に残った数について
if (N != 1) res.push_back({N, 1});
return res;
}
//割り算
ll Div(ll a,ll b,ll m){
return (a * modpow(b,m-2,m)) % m;
}
//階乗
vector<ll>fact(1);
void fac(ll N,ll m){
fact[0]=1;
for(int i=1;i<=N;i++){
fact.pb(fact[i-1]*(i));
fact[i]%=m;
}
}
//組み合わせ
ll comb(ll n,ll r,ll m){
return Div(fact[n],fact[r] * fact[n-r] % m,m);
}
//UnionFind
struct UnionFind {
vector<int> par, rank, siz;
// 構造体の初期化
UnionFind(int n) : par(n,-1), rank(n,0), siz(n,1) { }
// 根を求める
int root(int x) {
if (par[x]==-1) return x; // x が根の場合は x を返す
else return par[x] = root(par[x]); // 経路圧縮
}
// x と y が同じグループに属するか (= 根が一致するか)
bool same(int x, int y) {
return root(x)==root(y);
}
// x を含むグループと y を含むグループを併合する
bool unite(int x, int y) {
int rx = root(x), ry = root(y); // x 側と y 側の根を取得する
if (rx==ry) return false; // すでに同じグループのときは何もしない
// union by rank
if (rank[rx]<rank[ry]) swap(rx, ry); // ry 側の rank が小さくなるようにする
par[ry] = rx; // ry を rx の子とする
if (rank[rx]==rank[ry]) rank[rx]++; // rx 側の rank を調整する
siz[rx] += siz[ry]; // rx 側の siz を調整する
return true;
}
// x を含む根付き木のサイズを求める
int size(int x) {
return siz[root(x)];
}
};
//https://algo-method.com/descriptions/136
ll kansu(ll n){
ll ans=0;
if(n%2==0){
return n;
}else{
if(n==1){
return 1;
}else{
return kansu(n/2)*2;
}
}
}
int main(){
ll N,M;
cin>>N>>M;
vector<ll>A(M);
inV(A);
ll ans=0;
for(int i=0;i<M-1;i++){
ans+=kansu(A[i+1]-A[i]-1);
}
print(ans);
}