結果

問題 No.2018 X-Y-X
ユーザー Caiiiiiiii
提出日時 2024-10-02 22:56:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 192,256 KB
最終ジャッジ日時 2025-02-24 14:39:31
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |   scanf("%d%s%s", &n, s + 1, t + 1);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using LL = long long;

const int N = 2e5 + 7;

int n, a[N], ca, b[N], cb;
char s[N], t[N];

int main() {

  scanf("%d%s%s", &n, s + 1, t + 1);

  if(s[1] != t[1] || s[n] != t[n]) {
    puts("-1");
    return 0;
  }

  for(int i = 2; i <= n; ++i) {
    if((s[i] != s[i - 1]) ^ (i & 1))
      a[++ca] = i;
    if((t[i] != t[i - 1]) ^ (i & 1))
      b[++cb] = i;
  }

  if(ca != cb) {
    puts("-1");
    return 0;
  }

  LL ans = 0;
  for(int i = 1; i <= ca; ++i)
    ans += std::abs(a[i]- b[i]);

  printf("%lld\n", ans);

  return 0;
}
0