結果

問題 No.2018 X-Y-X
ユーザー HaaHaa
提出日時 2022-07-22 22:28:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,464 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 168,608 KB
実行使用メモリ 5,528 KB
最終ジャッジ日時 2023-09-17 10:54:16
合計ジャッジ時間 3,209 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 11 ms
5,268 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 4 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0