結果

問題 No.2018 X-Y-X
ユーザー vjudge1
提出日時 2025-07-19 14:59:35
言語 C++17(gnu拡張)
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,590 bytes
コンパイル時間 2,249 ms
コンパイル使用メモリ 201,616 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2025-07-19 14:59:40
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void SOLVER::MAIN()’:
main.cpp:25:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |     n = rd(); scanf("%s%s", s + 1, t + 1);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

//Date: 2025-07-19 13:53:49
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P emplace_back
#define CLEAR(a, v) memset(a, (v), sizeof(a))
#define pii pair<int, int>
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
//char buf[1 << 20], *p1, *p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)
inline int rd() {
    int s = 0, m = 0; char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') m = 1; ch = getchar();}
    while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return m ? -s : s;
}
bool MBE;
namespace SOLVER {
const int N = 2e5 + 5;
int n, a[N], b[N]; char s[N], t[N]; vector<int> g1, g2;
void MAIN() {
    n = rd(); scanf("%s%s", s + 1, t + 1);
    rep(i, 1, n - 1) a[i] = (s[i] - 'A') ^ (s[i + 1] - 'A'), b[i] = (t[i] - 'A') ^ (t[i + 1] - 'A');
    for(int i = 2; i <= n; i += 2) a[i] ^= 1, b[i] ^= 1;
    rep(i, 1, n) {if(a[i]) g1.P(i); if(b[i]) g2.P(i);} sort(g1.begin(), g1.end()); sort(g2.begin(), g2.end());
    if(g1.size() != g2.size()) {return puts("-1"), void();}
    int ans = 0; rep(i, 0, (int)g1.size() - 1) ans += abs(g1[i] - g2[i]); cout << ans << endl;
}
}
bool MED;
signed main() {
    // freopen(".in", "r", stdin); freopen(".out", "w", stdout);
    // cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
    for(int tt = 1; tt; tt--) SOLVER::MAIN();
    cerr << (&MBE - &MED) / 1024 << " KB, " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
    return 0;
}
0