Problem:
コンテストTシャツ (Contest T-shirts)
Segtree 君は、 $M$ 枚のコンテストTシャツを持っています。
彼は今から $N$ 日間、コンテストTシャツだけで過ごそうと考え、$i = 1, 2, 3, \dots, N$ に対して「 $i$ 日目に $A_i$ 枚目のTシャツを着る」という $N$ 個の計画を立てました。
しかし、今の計画のままだと洗濯が間に合わない可能性があるので、必要に応じて計画を変更し、2日連続で同じ服を着ないようにしたいです。
変更する必要のある計画の個数の最小値を求めてください。なお、与えられた制約の元で、計画の変更によって必ず条件を満たすようにできることが証明できます。
入力
入力は以下の形式で標準入力から与えられる。
$M$ $N$
$A_1$ $A_2$ $\ldots$ $A_N$
出力
変更する必要のある計画の個数の最小値を出力してください。
ただし、最後には改行を入れること。
制約
$2 \leq M \leq 10^9$
$1 \leq N \leq 10^5$
$1 \leq A_i \leq M$
入力は全て整数である。
入力例1
2 3
2 2 1
出力例1
1
入力例2
3 6
1 1 1 2 2 3
出力例2
2

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <limits>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <unordered_set>
#include <tuple>
#include <map>
#include <bitset>

using namespace std;

int main()
{
	int M, N;
	cin >> M >> N;

	vector<int> A(N);

	long long neccessaryChange = 0;

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];

		if (i != 0)
		{
			if (A[i] == A[i - 1])
			{
				neccessaryChange++;
			}
		}
	}

	cout << neccessaryChange << endl;

	return 0;
}
accuracy: 0.5833333333333334
time_ms: 20
memory_kb: 3624
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <limits>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <unordered_set>
#include <tuple>
#include <map>
#include <bitset>

using namespace std;

int main()
{
	int M, N;
	cin >> M >> N;

	vector<int> A(N);

	int neccessaryChange = 0;

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];

		if (i != 0)
		{
			if (A[i] == A[i - 1])
			{
				neccessaryChange++;
			}
		}
	}

	cout << neccessaryChange << endl;

	return 0;
}
accuracy: 0.5833333333333334
time_ms: 20
memory_kb: 3592
final_rank: 17

code_snippet: #include<iostream>
using namespace std;
int M,N,a[1<<17];
main(){
	cin>>M>>N;
	for(int i=0;i<N;i++)cin>>a[i];
	if(M==2){
		int a1=0,a2=0;
		for(int i=0;i<N;i++){
			if(a[i]==i%2+1)a1++;
			else a2++;
		}cout<<(a1<a2?a1:a2)<<endl;
		return 0;
	}int cnt=0;
	for(int i=1;i<N;i++){
		if(a[i-1]==a[i]){
			a[i]=-1; cnt++;
		}
	}cout<<cnt<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3516
final_rank: 5

code_snippet: #include<iostream>
#include<vector>
using namespace std;
signed main(){
    int n,m;
    cin>>m>>n;
    int ai,prv,ans=0;
    cin>>prv;
    for(int i=1;i<n;++i){
        cin>>ai;
        if(ai==prv){
            ans++;
            prv = -1;
        }
        else prv = ai;
    }
    cout<< ans <<endl;
}
accuracy: 0.625
time_ms: 20
memory_kb: 3100
final_rank: 9

code_snippet: #include<iostream>
using namespace std;

int main(){
    
    int m,n,a,b,cnt,ans;
    cin >> m >> n >> b;
    ans = 0;
    cnt = 1;
    for(int i=1;i<n;i++){
        cin >> a;
        if(a == b) cnt++;
        if(a != b && cnt > 1){
            ans += cnt/2;
            cnt = 1;
        }
        b = a;
    }
    cout << ans << endl;
    
    return(0);
}
accuracy: 0.5833333333333334
time_ms: 30
memory_kb: 3060
final_rank: 19

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

#define M 100000
int main(){
  int n,m,a[M],i,b[M],ca[M];
  int c=0,c2=0;
  cin>>m>>n;
  if(m>2){
    cin>>a[0];
    for(i=1;i<n;i++){
      cin>>a[i];
      if(a[i]==a[i-1])c++;
    }
    if(c>0)c=(c+1)/2;
    cout<<c<<endl;
  }
  else{
    for(i=0;i<n;i++){
      if(i%2==0){
	b[i]=1;
	ca[i]=2;
      }else{
	b[i]=2;
	ca[i]=1;
      }
    }

    for(i=0;i<n;i++){
      cin>>a[i];
      if(a[i]!=b[i])c++;
      if(a[i]!=ca[i])c2++;
    }
    if(c<c2)cout<<c<<endl;
    else cout<<c2<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4260
final_rank: 7

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

int main() {

  int M, N;
  cin>>M>>N;
  int a, b, c, count = 0, ren;
  for(int i = 0; i < N; i++) {
    cin>>a;
    if (a == b && i != 0 && ren % 2 == 0) {
      count++;
      ren++;
    } else if (a != b) ren = 0;
    b = a;
  }

  cout<<count<<endl;
  return 0;
}
accuracy: 0.5833333333333334
time_ms: 20
memory_kb: 3088
final_rank: 16

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

#define M 100000
int main(){
  int n,m,a[M],i;
  int c=0;
  cin>>m>>n;
  cin>>a[0];
  for(i=1;i<n;i++){
    cin>>a[i];
    if(a[i]==a[i-1])c++;
  }
  if(c>0)c=(c+1)/2;
  cout<<c<<endl;
  return 0;
}
accuracy: 0.625
time_ms: 30
memory_kb: 3472
final_rank: 14

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

#define M 100000
int main(){
  int n,m,a[M],i;
  int c=0;
  cin>>m>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]==a[i-1])c++;
  }
  if(c>0)c=c/2+1;
  cout<<c<<endl;
  return 0;
}
accuracy: 0.5833333333333334
time_ms: 30
memory_kb: 3504
final_rank: 20

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

int main(){
	int m,n,cnt=0,prev,ans=0;	cin>>m>>n;
	if(m==2){
		int ans1=0,ans2=0;
		for(int i=0;i<n;i++){
			int x;	cin>>x;
			
			if((i%2 +1 !=x)){
				ans1++;
			}else ans2++;
		}

		ans=min(ans1,ans2);
	}else{
		for(int i=0;i<n;i++){
			int x;	cin>>x;

			if(x==prev)cnt++;
			else{
				ans+=cnt/2;

				cnt=1;
				prev=x;
			}
		}
	}
	ans+=cnt/2;
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3116
final_rank: 1

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

int main(){
	int m,n,cnt=0,prev,ans=0;	cin>>m>>n;
	if(m==2){
		int flag=0;
		for(int i=0;i<n;i++){
			int x;	cin>>x;

			if(x==prev)cnt++;
			else{
				ans+=cnt/2;

				if(cnt%2==0 && flag==3)cnt=2;
				else cnt=1;
				prev=x;
			}

			flag|=x;
		}
	}else{
		for(int i=0;i<n;i++){
			int x;	cin>>x;

			if(x==prev)cnt++;
			else{
				ans+=cnt/2;

				cnt=1;
				prev=x;
			}
		}
	}
	ans+=cnt/2;
	cout<<ans<<endl;
	return 0;
}
accuracy: 0.6666666666666666
time_ms: 20
memory_kb: 3096
final_rank: 8

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

int main(){
	int m,n,prev=0,ans=0;	cin>>m>>n;
	for(int i=0;i<n;i++){
		int x;	cin>>x;

		if(prev==x){
			ans++;	prev=0;
		}else{
			prev=x;
		}
	}
	cout<<ans<<endl;

	return 0;
}
accuracy: 0.625
time_ms: 30
memory_kb: 3116
final_rank: 12

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

using namespace std;

int main() {
	int m,n; cin >> m >> n;
	vector<int> a(n);
	for(auto&e:a) cin >> e;
	int ans=0;
	if(m>2) {
		for(int i=1;i<n;++i) {
			if(a[i-1]==a[i]) {
				a[i]=-1;
				++ans;
			}
		}
	} else {
		int t1=0,t2=1;
		for(int i=1;i<n;++i) {
		    if(a[i]==a[0]) {
				if(i&1) ++t1;
				else ++t2;
			} else {
				if(i&1) ++t2;
				else ++t1;
			}
		}
		ans=min(t1,t2);
	}
	cout << ans << endl;
	
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3132
final_rank: 4

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

using namespace std;

int main() {
	int m,n; cin >> m >> n;
	vector<int> a(n);
	for(auto&e:a) cin >> e;
	int ans=0;
	if(m>2) {
		for(int i=1;i<n;++i) {
			if(a[i-1]==a[i]) {
				a[i]=-1;
				++ans;
			}
		}
	} else {
		for(int i=1;i<n;++i) {
			if(a[i-1]==a[i]) {
				if(i+1<n&&a[i]==a[i+1]) a[i]=(a[i]==1?2:1);
				++ans;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}
accuracy: 0.625
time_ms: 30
memory_kb: 3116
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
ll c[3][2];

int main(){
    ll m,n;cin>>m>>n;
    ll a[n];
    rep(i,0,n-1){
        cin>>a[i];
    }
    ll ans=0;
    if(m==2){
        rep(i,0,n-1){
            c[a[i]][i%2]++;
        }
        ans=min(c[2][0]+c[1][1],c[1][0]+c[2][1]);
        //cout<<c[2][0]<<c[1][1]<<c[1][0]<<c[2][1]<<endl;
        cout<<ans<<endl;
    }else{
        ll counter=1;
        if(n-1>=1){
            rep(i,1,n-1){
                if(a[i]==a[i-1]){
                    counter++;
                }else{
                    ans=ans+(counter/2);
                    counter=1;
                }
            }
        }
        ans=ans+(counter/2);
        cout<<ans<<endl;
    }
    
    
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3884
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll m,n;cin>>m>>n;
    ll a[n];
    ll c[3][2];
    rep(i,0,n-1){
        cin>>a[i];
    }
    ll ans=0;
    if(n==2){
        rep(i,0,n-1){
            c[a[i]][i%2]++;
        }
        ans=min(c[2][0]+c[1][1],c[1][0]+c[2][1]);
        cout<<ans<<endl;
    }else{
        ll counter=1;
        rep(i,1,n-1){
            if(a[i]==a[i-1]){
                counter++;
            }else{
                ans=ans+(counter/2);
                counter=1;
            }
        }
        ans=ans+(counter/2);
        cout<<ans<<endl;
    }
    
    
    return 0;
}
accuracy: 0.625
time_ms: 20
memory_kb: 3892
final_rank: 11

code_snippet: #include "bits/stdc++.h"
using namespace std;
int main() {
	long M, N;
	cin >> M >> N;
	vector<long>A(N);
	long ans = 0;
	for (long i = 0; i < N; i++) {
		cin >> A.at(i);
		if (i != 0) {
			if (A.at(i - 1) == A.at(i)) {
				ans++;
				A.at(i) = 0;
			}
		}
	}
	cout << ans << endl;
}
accuracy: 0.625
time_ms: 30
memory_kb: 3620
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	int m, n; std::cin >> m >> n;
	std::vector<int> plan(n); for (auto& p : plan) std::cin >> p;
	if (m == 2) {
		int odd{ 0 }, even{ 0 };
		for (auto i = 0; i < n; ++i) {
			if ((i + plan[i]) % 2 == 0) {
				++even;
			}
			else {
				++odd;
			}
		}
		std::cout << std::min(odd, even) << std::endl;
	}
	else {
		int prev = -1;
		int count = 0;
		for (const auto p : plan) {
			if (prev == p) {
				++count;
				prev = -1;
			}
			else {
				prev = p;
			}
		}
		std::cout << count << std::endl;
	}
}
accuracy: 1
time_ms: 20
memory_kb: 3132
final_rank: 3

code_snippet: //
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int m, n;
    cin >> m >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    if(m == 2){
        int x = 0, y = 0;
        rep(i, n){
            if(a[i] == 1 + i % 2) x++;
            else y++;
        }
        cout << min(x, y) << endl;
        return 0;
    }
    int ans = 0;
    int pre = -1;
    int l = 0;
    rep(i, n){
        if(a[i] != pre){
            pre = a[i];
            ans += l / 2;
            l = 1;
        }else{
            l++;
        }
    }
    ans += l / 2;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3116
final_rank: 1

code_snippet: //
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int m, n;
    cin >> m >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    int pre = -1;
    int l = 0;
    rep(i, n){
        if(a[i] != pre){
            pre = a[i];
            ans += l / 2;
            l = 1;
        }else{
            l++;
        }
    }
    ans += l / 2;
    cout << ans << endl;
    return 0;
}
accuracy: 0.625
time_ms: 20
memory_kb: 3132
final_rank: 10