提出 #70610428
ソースコード 拡げる
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int N, A, B;
string S;
signed main() {
cin >> N >> A >> B;
cin >> S;
vector<int> X(N + 1, 0), Y(N + 1, 0);
for (int i = 0; i < N; ++i) {
X[i + 1] = X[i];
Y[i + 1] = Y[i];
if (S[i] == 'a') {
X[i + 1]++;
} else {
Y[i + 1]++;
}
}
// for (int i = 0; i < N; ++i) {
// cout << X[i] << " " << Y[i] << endl;
// }
int ans = 0;
for (int i = 0; i < N; ++i) {
// cout << "i: " << i << endl;
auto itr_a = lower_bound(X.begin() + i + 1, X.end(), A + X[i]);
if (itr_a != X.end()) {
auto itr_b = lower_bound(Y.begin() + i + 1, Y.end(), B + Y[i]);
int idx_a = itr_a - X.begin();
int idx_b = itr_b - Y.begin();
chmin(idx_a, N + 1);
chmin(idx_b, N + 1);
// cout << "idx_a: " << idx_a << endl;
// cout << "idx_b: " << idx_b << endl;
if (idx_a < idx_b) {
ans += idx_b - idx_a;
}
}
}
cout << ans << endl;
}
提出情報
| 提出日時 |
|
| 問題 |
C - Truck Driver |
| ユーザ |
tsuyosshi |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
300 |
| コード長 |
2007 Byte |
| 結果 |
AC |
| 実行時間 |
21 ms |
| メモリ |
8648 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
300 / 300 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt |
| All |
hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| hand.txt |
AC |
1 ms |
3600 KiB |
| random_01.txt |
AC |
21 ms |
8596 KiB |
| random_02.txt |
AC |
19 ms |
8540 KiB |
| random_03.txt |
AC |
20 ms |
8556 KiB |
| random_04.txt |
AC |
20 ms |
8536 KiB |
| random_05.txt |
AC |
18 ms |
8488 KiB |
| random_06.txt |
AC |
18 ms |
8648 KiB |
| random_07.txt |
AC |
18 ms |
8464 KiB |
| random_08.txt |
AC |
15 ms |
8536 KiB |
| random_09.txt |
AC |
18 ms |
8488 KiB |
| random_10.txt |
AC |
20 ms |
8536 KiB |
| random_11.txt |
AC |
20 ms |
8456 KiB |
| random_12.txt |
AC |
18 ms |
8484 KiB |
| random_13.txt |
AC |
14 ms |
8460 KiB |
| random_14.txt |
AC |
17 ms |
8460 KiB |
| random_15.txt |
AC |
14 ms |
8460 KiB |
| random_16.txt |
AC |
14 ms |
8556 KiB |
| random_17.txt |
AC |
12 ms |
8616 KiB |
| random_18.txt |
AC |
12 ms |
8392 KiB |
| random_19.txt |
AC |
10 ms |
8392 KiB |
| random_20.txt |
AC |
10 ms |
8468 KiB |
| random_21.txt |
AC |
12 ms |
8496 KiB |
| random_22.txt |
AC |
10 ms |
8556 KiB |
| sample_01.txt |
AC |
1 ms |
3600 KiB |
| sample_02.txt |
AC |
1 ms |
3524 KiB |