結果
問題 | No.2018 X-Y-X |
ユーザー |
|
提出日時 | 2022-07-23 18:36:28 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 724 bytes |
コンパイル時間 | 2,589 ms |
コンパイル使用メモリ | 247,496 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-05 08:34:57 |
合計ジャッジ時間 | 3,775 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 24 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); ++i)using std::cin;using std::cout;using std::vector;using std::string;using ll = long long;int main() {int n;cin >> n;string s, t;cin >> s >> t;if (s[0] != t[0] or s.back() != t.back()) {puts("-1");return 0;}vector<int> pos_s, pos_t;rep(i, n) {if (s[i] != s[i+1]) pos_s.push_back(i);if (t[i] != t[i+1]) pos_t.push_back(i);}if (pos_s.size() != pos_t.size()) {puts("-1");return 0;}ll ans = 0;rep(i, pos_s.size()) {ans += abs(pos_s[i]-pos_t[i]);}cout << ans << '\n';return 0;}