結果
問題 |
No.2018 X-Y-X
|
ユーザー |
|
提出日時 | 2024-10-02 22:52:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 635 bytes |
コンパイル時間 | 1,868 ms |
コンパイル使用メモリ | 191,128 KB |
最終ジャッジ日時 | 2025-02-24 14:39:23 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 24 |
コンパイルメッセージ
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); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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 += 2) { s[i] = 'A' + 'B' - s[i]; t[i] = 'A' + 'B' - t[i]; } for(int i = 2; i <= n; ++i) { if(s[i] != s[i - 1]) a[++ca] = i; if(t[i] != t[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; }