結果
問題 | No.2018 X-Y-X |
ユーザー |
![]() |
提出日時 | 2022-07-23 17:20:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 1,066 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 42,240 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-07-05 06:45:30 |
合計ジャッジ時間 | 1,625 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 |
ソースコード
/* -*- 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); if (s[0] != t[0] || s[n - 1] != t[n - 1]) { puts("-1"); return 0; } 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; }