結果
| 問題 |
No.2018 X-Y-X
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-07-23 17:17:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 995 bytes |
| コンパイル時間 | 264 ms |
| コンパイル使用メモリ | 42,368 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2024-07-05 06:41:53 |
| 合計ジャッジ時間 | 2,006 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 2 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2018.cc: No.2018 X-Y-X - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
typedef long long ll;
/* global variables */
char s[MAX_N + 4], t[MAX_N + 4];
int as[MAX_N], bs[MAX_N], ps[MAX_N], qs[MAX_N];
/* subroutines */
int s2v(int n, char s[], int as[], int ps[]) {
int oc = 0;
for (int i = 0; i + 1 < n; i++) {
int a0 = s[i] - 'A', a1 = s[i + 1] - 'A';
as[i] = a0 ^ a1 ^ (i & 1);
if (as[i]) ps[oc++] = i;
}
return oc;
}
/* main */
int main() {
int n;
scanf("%d%s%s", &n, s, t);
int m = n - 1;
int ac = s2v(n, s, as, ps);
int bc = s2v(n, t, bs, qs);
//for (int i = 0; i < m; i++) printf("%d", as[i]); putchar('\n');
//for (int i = 0; i < m; i++) printf("%d", bs[i]); putchar('\n');
if (ac != bc) { puts("-1"); return 0; }
ll sum = 0;
for (int i = 0; i < ac; i++) sum += abs(qs[i] - ps[i]);
printf("%lld\n", sum);
return 0;
}
tnakao0123