結果

問題 No.2018 X-Y-X
ユーザー startcppstartcpp
提出日時 2022-07-30 04:59:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 73,688 KB
実行使用メモリ 9,524 KB
最終ジャッジ日時 2023-09-27 05:52:31
合計ジャッジ時間 2,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 11 ms
6,948 KB
testcase_07 AC 12 ms
7,124 KB
testcase_08 AC 14 ms
8,528 KB
testcase_09 AC 13 ms
8,440 KB
testcase_10 AC 8 ms
6,820 KB
testcase_11 AC 10 ms
7,128 KB
testcase_12 AC 11 ms
7,328 KB
testcase_13 AC 11 ms
6,824 KB
testcase_14 AC 11 ms
7,236 KB
testcase_15 AC 13 ms
7,548 KB
testcase_16 AC 8 ms
5,868 KB
testcase_17 AC 10 ms
7,048 KB
testcase_18 AC 8 ms
5,972 KB
testcase_19 AC 9 ms
6,504 KB
testcase_20 AC 14 ms
8,172 KB
testcase_21 AC 10 ms
6,356 KB
testcase_22 AC 10 ms
6,464 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 16 ms
9,524 KB
testcase_25 AC 14 ms
7,948 KB
testcase_26 AC 13 ms
8,784 KB
testcase_27 AC 5 ms
4,916 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 4 ms
4,608 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 9 ms
6,508 KB
testcase_32 AC 11 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define int long long
using namespace std;

int n;
string s;
string t;
int a[200000];
int b[200000];

signed main() {
	int i;
	
	cin >> n >> s >> t;
	if (s[0] != t[0] || s[n - 1] != t[n - 1]) {
		cout << -1 << endl;
		return 0;
	}
	
	vector<int> oneA;
	vector<int> oneB;
	for (i = 0; i < n - 1; i++) {
		a[i] = (s[i + 1] != s[i]);
		b[i] = (t[i + 1] != t[i]);
		if (i % 2 == 1) {
			a[i] = !a[i];
			b[i] = !b[i];
		}
		if (a[i]) oneA.push_back(i);
		if (b[i]) oneB.push_back(i);
	}
	if (oneA.size() != oneB.size()) {
		cout << -1 << endl;
		return 0;
	}
	
	int hanten = 0;
	for (i = 0; i < oneA.size(); i++) {
		hanten += abs(oneB[i] - oneA[i]);
	}
	
	cout << hanten << endl;
	return 0;
}
0