結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー tkmst201tkmst201
提出日時 2019-11-29 22:23:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 3,061 ms
コンパイル使用メモリ 170,464 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 06:25:54
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 5 ms
4,348 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 5 ms
4,352 KB
testcase_04 AC 5 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 7 ms
4,356 KB
testcase_08 AC 13 ms
4,348 KB
testcase_09 AC 9 ms
4,348 KB
testcase_10 AC 10 ms
4,348 KB
testcase_11 AC 12 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 4 ms
4,352 KB
testcase_19 AC 8 ms
4,352 KB
testcase_20 AC 6 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 6 ms
4,348 KB
testcase_34 AC 10 ms
4,352 KB
testcase_35 AC 9 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 7 ms
4,352 KB
testcase_38 AC 7 ms
4,356 KB
testcase_39 AC 11 ms
4,348 KB
testcase_40 AC 12 ms
4,352 KB
testcase_41 AC 11 ms
4,352 KB
testcase_42 AC 9 ms
4,352 KB
testcase_43 AC 12 ms
4,352 KB
testcase_44 AC 5 ms
4,348 KB
testcase_45 AC 12 ms
4,356 KB
testcase_46 AC 3 ms
4,352 KB
testcase_47 AC 7 ms
4,352 KB
testcase_48 AC 5 ms
4,348 KB
testcase_49 AC 6 ms
4,348 KB
testcase_50 AC 6 ms
4,348 KB
testcase_51 AC 7 ms
4,352 KB
testcase_52 AC 7 ms
4,348 KB
testcase_53 AC 11 ms
4,352 KB
testcase_54 AC 4 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 9 ms
4,352 KB
testcase_57 AC 6 ms
4,348 KB
testcase_58 AC 2 ms
4,352 KB
testcase_59 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N, Q;
string S;
int A[2123], K[2123];
int mxpos[2123];
ll sum[2123], cnt[2123]; // 1-indexed
int ans[2123];

int main() {
	cin >> N >> S;
	REP(i, N) scanf("%d", A + i);
	cin >> Q;
	REP(i, Q) scanf("%d", K + i);
	
	vector<int> ord(Q);
	iota(ALL(ord), 0);
	
	sort(ALL(ord), [&](int x, int y) {
		return K[x] < K[y];
	});
	
	REP(i, N) {
		sum[i + 1] = sum[i] + A[i];
		cnt[i + 1] = cnt[i] + (S[i] == 'E');
	}
	
	iota(mxpos, mxpos + N, 0);
	
	int mx = 0;
	for (int curq : ord) {
		// K[curq]までいける
		REP(i, N) {
			int cur = mxpos[i];
			while (cur < N && sum[cur + 1] - sum[i] <= K[curq]) cur++;
			mxpos[i] = cur;
			chmax(ans[curq], cnt[cur] - cnt[i]);
		}
	}
	
	REP(i, Q) printf("%d\n", ans[i]);
	
	return 0;
}
0