提出 #49802272
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void O(const T &x) { cout << x << '\n'; }
template <typename T, typename... W> inline void O(const T &x, const W &...b) {
cout << x << ' ';
O(b...);
}
template <typename T> inline void rd(T &x) { cin >> x; }
template <typename T, typename... W> inline void rd(T &x, W &...b) {
cin >> x;
rd(b...);
}
#ifndef MISAKA
#define err(...)
#else
#define err(...) fprintf(stderr, __VA_ARGS__)
#endif
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef long double dbl;
typedef pair<int, int> pii;
typedef uniform_int_distribution<int> r32;
typedef uniform_int_distribution<i64> r64;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline void ckmin(T &a, const T &b) { a = min(a, b); }
template <typename T> inline void ckmax(T &a, const T &b) { a = max(a, b); }
//#define IOFILE "filename"
//#define MULTI
const int N = 0;
inline int sol() {
int n;
string S, T;
rd(n, S, T);
for (int i = 0; i < n; ++i) {
if (T[i] == 'A') break;
if (S[i] != 'B') return -1;
}
for (int i = n - 1; i >= 0; --i) {
if (T[i] == 'B') break;
if (S[i] != 'A') return -1;
}
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; ++i) {
if (S[i] != T[i]) {
++x;
if (T[i] == 'A') ++y;
else if (y) {
--y;
++z;
}
}
}
return x - z;
}
int main() {
#ifndef MISAKA
#ifdef IOFILE
freopen(IOFILE ".in", "r", stdin);
freopen(IOFILE ".out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
#endif
#ifdef MULTI
int T;
cin >> T;
while (T--)
#endif
O(sol());
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | A - Yet Another AB Problem |
| ユーザ | misaka18931 |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 400 |
| コード長 | 1765 Byte |
| 結果 | AC |
| 実行時間 | 2 ms |
| メモリ | 3832 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_01.txt | AC | 1 ms | 3416 KiB |
| 00_sample_02.txt | AC | 1 ms | 3580 KiB |
| 01_test_01.txt | AC | 1 ms | 3476 KiB |
| 01_test_02.txt | AC | 1 ms | 3472 KiB |
| 01_test_03.txt | AC | 1 ms | 3756 KiB |
| 01_test_04.txt | AC | 2 ms | 3640 KiB |
| 01_test_05.txt | AC | 2 ms | 3644 KiB |
| 01_test_06.txt | AC | 1 ms | 3688 KiB |
| 01_test_07.txt | AC | 1 ms | 3740 KiB |
| 01_test_08.txt | AC | 2 ms | 3592 KiB |
| 01_test_09.txt | AC | 2 ms | 3596 KiB |
| 01_test_10.txt | AC | 2 ms | 3712 KiB |
| 01_test_11.txt | AC | 2 ms | 3736 KiB |
| 01_test_12.txt | AC | 1 ms | 3680 KiB |
| 01_test_13.txt | AC | 1 ms | 3700 KiB |
| 01_test_14.txt | AC | 2 ms | 3736 KiB |
| 01_test_15.txt | AC | 1 ms | 3684 KiB |
| 01_test_16.txt | AC | 1 ms | 3728 KiB |
| 01_test_17.txt | AC | 1 ms | 3728 KiB |
| 01_test_18.txt | AC | 1 ms | 3716 KiB |
| 01_test_19.txt | AC | 2 ms | 3716 KiB |
| 01_test_20.txt | AC | 1 ms | 3832 KiB |