Problem:
Gossip
Problem
1から
n
までの番号が順番に割り当てられている
n
人のアイドルが横一列に並んでいる。
アイドル
i
は単位時間でアイドル
i
-1とアイドル
i
+1に情報を伝達することができる。ただし、アイドル1はアイドル2にしか情報を伝達できず、アイドル
n
はアイドル
n
-1にしか情報を伝達できない。
時刻0の時点で、番号が
a
1
,
a
2
, ...,
a
m
である
m
人のアイドルが秘密の情報を持っている。すべてのアイドルが秘密の情報を得ることのできる最小の時間を求めよ。
Input
入力は以下の形式で与えられる。
n
m
a
1
a
2
...
a
m
1行目に2つの整数
n
と
m
が空白区切りで与えられる。
2行目に
m
個の整数
a
1
,
a
2
, ...,
a
m
が空白区切りで与えられる。
Constraints
2 ≤
n
≤ 10
5
1 ≤
m
≤
n
1 ≤
a
i
≤
n
a
i
の値は全て異なる
a
i
は昇順で与えられる
Output
すべてのアイドルに情報が伝わる最小の時間を1行に出力する。
Sample Input 1
3 2
1 3
Sample Output 1
1
Sample Input 2
10 3
2 5 7
Sample Output 2
3
Sample Input 3
10 5
2 5 6 8 10
Sample Output 3
1
Sample Input 4
100000 1
1
Sample Output 4
99999

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  rep(i,m) cin>>a[i];

  int ans = max(a[0]-1, n - a.back());
  rep(i,m-1){
    ans = max(ans, (a[i+1] - a[i])/2);
  }
  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3152
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m;cin>>n>>m;
	int ans=0;
	int b;
	for(int i=0;i<m;i++){
		int a;cin>>a;
		if(i==0)ans=max(ans,a-1);
		else ans=max(ans,(a-b)/2);
		b=a;
	}
	ans=max(ans,n-b);
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3112
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m,sum=0,ans=0,x;
  cin>>n>>m;
  int a[n]={};
  r(i,m){
    cin>>x;
    x--;
    a[x]=1;
  }
  r(i,n){
    if(!a[i])a[i]=1,sum++;
    else{
      ans=max(ans,sum);
      break;
    }
  }
  sum=0;
  for(int i=n-1;i>=0;i--){
    if(!a[i])a[i]=1,sum++;
    else{
      ans=max(ans,sum);
      break;
    }
  }
  int p=0;
  r(i,n){
    if(!a[i])p++;
    else{
      ans=max(ans,(p+1)/2);
      p=0;
    }
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3488
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  int d[n],d2[n],ans=0;
  fill(d,d+n,1<<29);
  fill(d2,d2+n,1<<29);
  for(int i=0,x; i<m; i++) {
    cin >> x;
    d[x-1]=d2[x-1]=0;
  }
  for(int i=1; i<n; i++) d[i]=min(d[i],d[i-1]+1);
  for(int i=n-2; i>=0; i--) d2[i]=min(d2[i],d2[i+1]+1);
  for(int i=0; i<n; i++) ans=max(ans,min(d[i],d2[i]));
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3884
final_rank: 17

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
#define INF 100000000
#define MAX_N 1000000
using namespace std;

int main(){
    int n,m,a=0,b=0;
    cin>>n>>m;
    int ans=0;
    cin>>a;
    int z=a;
    b=a;
    rep(i,1,m){
        cin>>a;
        ans=max(a-b,ans);
        //cout<<ans<<endl;
        b=a;
    }
    //cout<<ans<<endl;
    if(ans/2<n-a&&z-1<n-a){
        cout<<n-a<<endl;
    }else{
        cout<<max(ans/2,z-1)<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 12

code_snippet: #include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>


using namespace std;


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

	int count = 0;
	int input;
	int ex;
	for(int i=0; i<m; i++) {
		cin >> input;
		if(i == 0 && input-1 > count) count = input-1;
		if(i == m-1 && n-input > count) count = n-input;
		if(i != 0 && (input-ex)/2 > count) count = (input-ex)/2;
		ex=input;
	}

	cout << count << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1164
final_rank: 1

code_snippet: #include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(ll i=0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;
int main(){
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cout << fixed << setprecision(8);
	ll n, m; cin >> n >> m;
	vl a(m); REP(i, m) cin >> a[i];
	REP(i, m) a[i]--;

	sort(ALL(a));
	ll mi = 0;
	REP(i, n){
		auto it = lower_bound(ALL(a), i);
		ll mii = 100000;
		if(it != a.end()) mii = min<ll>(mii, abs(*it - i));
		if (it != a.begin()) mii = min<ll>(mii, abs(*--it - i));
		mi = max(mi, mii);
	}

	cout << mi << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3176
final_rank: 15

code_snippet: /*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) (cin >> as[i]), as[i]--;

  int ans = max(as[0], n - 1 - as[m - 1]);

  for (int i = 0; i < m - 1; i++) {
    int c = (as[i + 1] - as[i]) / 2;
    if (ans < c) ans = c;
  }

  printf("%d\n", ans);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1280
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(m);
	rep(i,m)cin>>in[i];
	int ma=in[0]-1;
	rep(i,m-1){
		int q=in[i+1]-in[i];
		q/=2;
		ma=max(ma,q);
	}
	ma=max(ma,n-in[m-1]);
	cout<<ma<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1308
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
int n,m;
int a[200005];
int b[200005];

int main() {
    cin>>n>>m;
    rep(i,m) cin>>a[i];
    rep(i,m) a[i]--;
    rep(i,200005) b[i]=1e8;
    rep(i,m) b[a[i]]=0;
    rep(i,n) if(i) {
        b[i]=min(b[i],b[i-1]+1);
    }
    for(int i=n-1;i>=0;i--) if(i+1!=n) b[i]=min(b[i],b[i+1]+1);

    int ans=0;
    rep(i,n) ans=max(ans,b[i]);
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2084
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
int t[100000];
int main(){
	int n,m;	cin>>n>>m;
	vector<int> a(m);
	for(int i=0;i<n;i++)	t[i]=1e9;
	queue<int> q;
	for(int i=0;i<m;i++){
		cin>>a[i];	a[i]--;
		t[a[i]]=0;
		q.push(a[i]);
	}
	while(!q.empty()){
		int cur=q.front();	q.pop();
		if(cur+1<n){
			if(t[cur+1]>t[cur]+1){
				t[cur+1]=t[cur]+1;
				q.push(cur+1);
			}
		}
		if(cur-1>=0){
			if(t[cur-1]>t[cur]+1){
				t[cur-1]=t[cur]+1;
				q.push(cur-1);
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++)	ans=max(ans,t[i]);
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1728
final_rank: 9

code_snippet: #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<int> se;
  se.resize(m);
  REP(i,m) cin >> se[i];
  int answer=0;
  answer=max(answer,se[0]-1);
  REP(i,m-1) answer=max(answer,(se[i+1]-se[i])/2);
  answer=max(answer,n-se[m-1]);
  cout << answer << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1308
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;


int main()
{
	int n ;
	int m;
	int a[100000];
	int b;
	int ans = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> a[i];
	}

	for (int i = 0; i < m + 1; i++){
		if (i == 0){
			b = a[i] - 1;
		} else if (i == m){
			b = n - a[i - 1];
		}
		else{
			b = a[i] - a[i-1] - 1;
			if (b % 2 == 0){
				b /= 2;
			}
			else{
				b++;
				b /= 2;
			}
		}
		ans = max(b, ans);
	}

	cout << ans << endl;
		
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1304
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;

int N, M, B[100000];
int dp[100000][4];

int rec(int idx, int dir)
{
  if(idx < 0 || idx >= N) return(INF);
  if(~dp[idx][dir + 1]) return(dp[idx][dir + 1]);
  if(B[idx])   return(0);
  return(dp[idx][dir + 1] = rec(idx + dir, dir) + 1);
}

int main()
{
  fill_n(*dp, 4 * 100000, -1);

  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    int A;
    cin >> A;
    B[--A] = true;
  }
  int ret = 0;
  for(int i = 0; i < N; i++) {
    ret = max(ret, min(rec(i, -1), rec(i, +1)));
  }
  cout << ret << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4284
final_rank: 18

code_snippet: #include<iostream>
using namespace std;

int main(){
	int sum;
	while(cin >> sum){
		int number, info[100005], ans;
		cin >> number;
		for(int i = 0; i < number; i++){
			cin >> info[i];
		}
	
			for(int i = 0; i < number + 1; i++){
				if(!i){
					ans = info[i] - 1;
				}else if(i == number){
					ans = max(ans, sum - info[i - 1]);
				}else{
					int a = (info[i] - info[i - 1]) / 2;
					ans = max(ans, a);
				}	
			}		
			cout << ans << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1304
final_rank: 4

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define Fi first
#define Se second
using namespace std;
static const LL INF = 1LL<<61LL;
typedef pair<int,int> PII;

int N,M;
int A[100010];
int temp=1;
int ans;

int main(){
    cin>>N>>M;
    rep(i,M){
        int a;
        cin>>a;
        A[a]=1;
    }
    FOR(i,1,N){
        //cout<<temp<<endl;
        if(A[i]==1){
            if(temp==1&&A[1]!=1){
                int t=(i-temp);
                temp=i;
                ans=max(ans,t);
                continue;
            }
            int t=(i-temp-1)/2;
            if(i-temp-1<=0)t=0;
            else if((i-temp-1)%2!=0)t++;
            temp=i;
            ans=max(ans,t);
        }
        else if(i==N){
            ans=max(ans,N-temp);
        }
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1492
final_rank: 8

code_snippet: /*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            pass System Test!
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
  if (!v.empty()) {
    out << '[';
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  set<int> a;
  for (int i = 0; i < M; ++i) {
    int b;
    cin >> b;
    b--;
    a.insert(b);
  }

  int ma = 0;
  for (int i = 0; i < N; ++i) {
    if (i >= *(a.rbegin())) {
      ma = max(ma, i - *(a.rbegin()));
      continue;
    }

    auto it = a.lower_bound(i);
    int mi = N;
    mi = min(mi, *it - i);
    if (it != a.begin()) {
      it--;
      mi = min(mi, i - *it);
    }
    // cerr << mi << endl;
    ma = max(ma, mi);
  }
  cout << ma << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4784
final_rank: 19

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int main() {

  int n, m, i, in, def = 0, ans = 0, before = 0;

  cin >> n >> m;
  
  for(i = 0; i < m; i++) {
    cin >> in;
    
    if(i == 0 && in != 1) {
      def = in - 1;
    }

    else def = (in-before)/2 +0.5;

    ans = max(ans, def);

    before = in;
  }

  ans = max(ans, n - in);
  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1164
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int n,m;
  cin>>n>>m;
  vi a(m);
  REP(i,m)cin>>a[i];
  REP(i,m)--a[i];
  vi d(n,1145141919);
  queue<int> Q;
  REP(i,m){
    d[a[i]]=0;
    Q.push(a[i]);
  }
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    if(p>0){
      if(d[p-1]>d[p]+1){
        d[p-1] = d[p]+1;
        Q.push(p-1);
      }
    }
    if(p<n-1){
      if(d[p+1]>d[p]+1){
        d[p+1] = d[p]+1;
        Q.push(p+1);
      }
    }
  }
  int res = 0;
  REP(i,n)res=max(res,d[i]);
  cout<<res<<endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1732
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,M;
int dp[111111];
signed main(){
    cin>>N>>M;
    fill_n(dp,N,1<<25);
    rep(i,M){
        int a;
        cin>>a;
        dp[--a]=0;
    }

    reps(i,1,N)chmin(dp[i],dp[i-1]+1);
    for(int i=N-2;i>=0;i--)chmin(dp[i],dp[i+1]+1);

    cout<<*max_element(dp,dp+N)<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1940
final_rank: 10