結果
| 問題 | No.3286 Make a Happy Connection | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-10-03 21:25:00 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,724 bytes | 
| コンパイル時間 | 1,614 ms | 
| コンパイル使用メモリ | 166,620 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-10-03 21:25:03 | 
| 合計ジャッジ時間 | 2,530 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;
void solve(){
    int n; cin >> n;
    vector<int> a(n); for(int i=0; i<n; i++) cin >> a[i];
    // swap the most left
    {
        swap(a[0], a[1]);
        int cnt = 0;
        for(int i=0; i<n-1; i++) if(a[i] == a[i+1]) cnt++;
        if(1 <= cnt){
            cout << "Yes\n";
            return;
        }
        swap(a[0], a[1]);
    }
    // swap the most right
    {
        swap(a[n-1], a[n-2]);
        int cnt = 0;
        for(int i=0; i<n-1; i++) if(a[i] == a[i+1]) cnt++;
        if(1 <= cnt){
            cout << "Yes\n";
            return;
        }
        swap(a[n-1], a[n-2]);
    }
    int cnt = 0; for(int i=0; i<n-1; i++) if(a[i] == a[i+1]) cnt++;
    for(int i=1; i<n-2; i++){
        if(a[i-1] == a[i]) cnt--;
        if(a[i+1] == a[i+2]) cnt--;
        swap(a[i], a[i+1]);
        if(a[i-1] == a[i]) cnt++;
        if(a[i] == a[i+1]) cnt++;
        if(1 <= cnt){
            cout << "Yes\n";
            return;
        }
        if(a[i] == a[i+1]) cnt--;
        if(a[i-1] == a[i]) cnt--;
        swap(a[i], a[i+1]);
        if(a[i+1] == a[i+2]) cnt++;
        if(a[i-1] == a[i]) cnt++;
    }
    cout << "No\n";
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
            
            
            
        