結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 10 ms
5,244 KB
testcase_07 AC 11 ms
5,508 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 7 ms
5,196 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 10 ms
5,304 KB
testcase_14 AC 9 ms
5,280 KB
testcase_15 AC 11 ms
5,424 KB
testcase_16 AC 7 ms
4,652 KB
testcase_17 AC 10 ms
5,528 KB
testcase_18 AC 7 ms
4,740 KB
testcase_19 AC 8 ms
5,068 KB
testcase_20 AC 12 ms
5,840 KB
testcase_21 AC 9 ms
4,928 KB
testcase_22 AC 9 ms
4,924 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 13 ms
6,616 KB
testcase_25 AC 12 ms
5,812 KB
testcase_26 AC 11 ms
6,052 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 5 ms
4,380 KB
testcase_31 AC 8 ms
4,984 KB
testcase_32 AC 10 ms
5,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int 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