結果
| 問題 | No.2018 X-Y-X |
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2026-01-11 16:16:44 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,302 bytes |
| 記録 | |
| コンパイル時間 | 3,323 ms |
| コンパイル使用メモリ | 341,260 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-11 16:16:50 |
| 合計ジャッジ時間 | 5,399 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint998244353;
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define siz(x) (int)x.size()
const int inf = 1e9;
const ll INF = 4e18;
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main() {
int N; string S, T;
cin >> N >> S >> T;
if (S[0] != T[0] or S[N-1] != T[N-1]) {
//NG
cout << -1 << endl;
return 0;
}
vector<int> A(N - 1), B(N - 1);
rep(i, 0, N-1) {
A[i] = (S[i] != S[i+1]);
B[i] = (T[i] != T[i+1]);
}
//偶数bitを反転(天才?)
rep(i, 0, N-1) {
if (i % 2 == 0) {
A[i] = 1 - A[i];
B[i] = 1 - B[i];
}
}
vector<int> P, Q;
rep(i, 0, N - 1) {
if (A[i] == 1) P.push_back(i);
if (B[i] == 1) Q.push_back(i);
}
if (siz(P) != siz(Q)) {
cout << -1 << endl;
return 0;
}
ll answer = 0;
rep(i, 0, siz(P)) answer += abs(P[i] - Q[i]);
cout << answer << endl;
}
Iroha_3856