結果
| 問題 | No.2018 X-Y-X |
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2026-03-25 10:13:49 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,134 bytes |
| 記録 | |
| コンパイル時間 | 2,656 ms |
| コンパイル使用メモリ | 335,556 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-03-25 10:13:54 |
| 合計ジャッジ時間 | 3,812 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
bool chmax(auto& a, auto b) { return a<b ? a=b, 1: 0; }
bool chmin(auto& a, auto b) { return a>b ? a=b, 1: 0; }
using ll=long long; const int INF=1e9+10; const ll INFL=4e18;
#ifdef DEBUG
#include "./debug.hpp"
#else
#define debug(...)
#define print_line
#endif
//------>8------------------------------------------->8------
void run() {
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;
}
vector<int> ones,onet;
rep(i,N-1) {
int ds=(S[i]==S[i+1]);
int dt=(T[i]==T[i+1]);
if(i%2) {
ds^=1;
dt^=1;
}
if(ds) ones.push_back(i);
if(dt) onet.push_back(i);
}
if(ones.size()!=onet.size()) {
cout<<-1<<endl;
return;
}
ll ans=0;
rep(i,ones.size()) ans+=abs(ones[i]-onet[i]);
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
run();
}
Today03