結果
| 問題 | 
                            No.2018 X-Y-X
                             | 
                    
| コンテスト | |
| ユーザー | 
                             沙耶花
                         | 
                    
| 提出日時 | 2022-07-22 21:45:49 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 602 bytes | 
| コンパイル時間 | 3,961 ms | 
| コンパイル使用メモリ | 250,900 KB | 
| 最終ジャッジ日時 | 2025-01-30 12:13:31 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 7 WA * 24 | 
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000
int main(){
	
	int n;
	cin>>n;
	
	string s,t;
	cin>>s>>t;
	
	if(s[0]!=t[0]||s[n-1]!=t[n-1]){
		cout<<-1<<endl;
		return 0;
	}
	vector<int> a,b;
	rep(i,n-1){
		if(s[i]!=s[i+1])a.push_back(i);
		if(t[i]!=t[i+1])b.push_back(i);
	}
	if(a.size()!=b.size()){
		cout<<-1<<endl;
		return 0;
	}
	long long ans = 0;
	rep(i,a.size())ans += abs(a[i]-b[i]);
	
	cout<<ans<<endl;
			
    return 0;
}
            
            
            
        
            
沙耶花