結果
| 問題 | 
                            No.2018 X-Y-X
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Haa
                         | 
                    
| 提出日時 | 2022-07-22 22:28:44 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,464 bytes | 
| コンパイル時間 | 1,603 ms | 
| コンパイル使用メモリ | 169,856 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-04 07:00:22 | 
| 合計ジャッジ時間 | 3,175 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 8 WA * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;
int main(){
    int n; cin >> n;
    string s, t; cin >> s >> t;
    int ans=0;
    VI f(n,0);
    REP(i,n){
        if(s[i]!=t[i]){
            f[i]=1;
            ans++;
        }
    }
    if(f[0]==1||f[n-1]==1){
        cout << -1 << endl;
        return 0;
    }
    REP(i,n-2){
        if(f[i]==1&&f[i+1]==1&&f[i+2]==1){
            if(s[i]==s[i+2]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    REP(i,n-1){
        if(f[i]==0&&f[i+1]==1){
            if(s[i]==s[i+2]){
                f[i+1]++;
            }
        }
        if(f[i]==1&&f[i+1]==0){
            if(s[i-1]==s[i+1]){
                f[i]++;
            }
        }
    }
    int len=0;
    bool flg=0;
    REP(i,n){
        if(f[i]>0){
            len++;
            if(f[i]==2)
                flg=1;
        }
        else{
            if(len>0&&!flg){
                cout << -1 << endl;
                return 0;
            }
            len=0;
        }
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        
            
Haa