提出 #70617480


ソースコード 拡げる

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<string>
#include<cmath>
#include<set>
#include<queue>

using namespace std;

int n, a, b;
string s;
vector<int> psumA, psumB;

int get_a(int l, int r) {
	return psumA[r + 1] - psumA[l];
}

int get_b(int l, int r) {
	return psumB[r + 1] - psumB[l];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a >> b;
	cin >> s;
	psumA.resize(n + 1);
	psumB.resize(n + 1);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'a') {
			psumA[i + 1] = psumA[i] + 1;
			psumB[i + 1] = psumB[i];
		}
		else {
			psumA[i + 1] = psumA[i];
			psumB[i + 1] = psumB[i] + 1;
		}
	}

	long long ret = 0;
	int l = 0;
	int l2 = 0;

	for (int r = 0; r < n ; r++) {
		while (l < r && get_b(l, r) >= b) {
			l++;
		}
		if (l2 < l) l2 = l;

		while (l2 <= r && get_a(l2, r) >= a) {
			l2++;
		}
		if (get_a(l, r) >= a) {
			ret += l2 - l;
		}
	}

	cout << ret;
}

提出情報

提出日時
問題 C - Truck Driver
ユーザ cocoyi00
言語 C++23 (GCC 15.2.0)
得点 300
コード長 1064 Byte
結果 AC
実行時間 5 ms
メモリ 6224 KiB

コンパイルエラー

./Main.cpp: In function 'int main()':
./Main.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i = 0; i < s.size(); i++) {
      |                         ~~^~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 25
セット名 テストケース
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 3536 KiB
random_01.txt AC 4 ms 6092 KiB
random_02.txt AC 4 ms 6160 KiB
random_03.txt AC 4 ms 6156 KiB
random_04.txt AC 4 ms 6056 KiB
random_05.txt AC 4 ms 6164 KiB
random_06.txt AC 4 ms 6092 KiB
random_07.txt AC 4 ms 6064 KiB
random_08.txt AC 4 ms 6204 KiB
random_09.txt AC 4 ms 6004 KiB
random_10.txt AC 4 ms 6048 KiB
random_11.txt AC 5 ms 6096 KiB
random_12.txt AC 4 ms 6224 KiB
random_13.txt AC 5 ms 6152 KiB
random_14.txt AC 5 ms 6040 KiB
random_15.txt AC 5 ms 6044 KiB
random_16.txt AC 5 ms 6108 KiB
random_17.txt AC 4 ms 6052 KiB
random_18.txt AC 4 ms 5976 KiB
random_19.txt AC 4 ms 6100 KiB
random_20.txt AC 4 ms 6008 KiB
random_21.txt AC 4 ms 6040 KiB
random_22.txt AC 4 ms 6040 KiB
sample_01.txt AC 1 ms 3588 KiB
sample_02.txt AC 1 ms 3548 KiB