結果

問題 No.2209 Flip and Reverse
コンテスト
ユーザー daiota
提出日時 2023-02-10 23:18:14
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 777 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 891 ms
コンパイル使用メモリ 185,792 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-29 08:18:06
合計ジャッジ時間 2,110 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)

int a[110];

int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j,k;

	int N;
	string S,T;
	cin >> N >> S >> T;

	if(N==1){
		cout << 1 << endl;
		return 0;
	}

	int c=0,ans=0;
	for(i=1;i<=N-2;i++){
		if(S[i]!=T[i]) c++;
	}

	if(c%2==0){
		ans+=c;
		if((S[0]==T[0] && S[N-1]!=T[N-1]) || (S[0]!=T[0] && S[N-1]==T[N-1])) ans++;
		else if(S[0]!=T[0] && S[N-1]!=T[N-1]) ans+=2;
	}else{
	    ans+=c;
	    if((S[0]==T[0] && S[N-1]!=T[N-1]) || (S[0]!=T[0] && S[N-1]==T[N-1])) ans++;
	    else if(S[0]==T[0] && S[N-1]==T[N-1]){
	    	if(S[0]==S[N-1]) ans+=2;
	    	else ans++;
	    }
	}

	cout << ans << endl;

	return 0;
}
0