結果

問題 No.1021 Children in Classrooms
ユーザー startcppstartcpp
提出日時 2020-04-10 22:29:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,395 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 74,108 KB
実行使用メモリ 5,112 KB
最終ジャッジ日時 2023-10-14 01:15:13
合計ジャッジ時間 2,960 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 AC 73 ms
5,096 KB
testcase_10 AC 72 ms
5,064 KB
testcase_11 AC 72 ms
5,060 KB
testcase_12 AC 70 ms
5,056 KB
testcase_13 AC 70 ms
5,112 KB
testcase_14 AC 71 ms
5,036 KB
testcase_15 AC 54 ms
4,812 KB
testcase_16 WA -
testcase_17 AC 56 ms
4,888 KB
testcase_18 WA -
testcase_19 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int a[200000];
string s;

int main() {
	int i;
	
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	cin >> s;
	
	int pos = 0;
	int minP = 0, maxP = 0;
	rep(i, m) {
		if (s[i] == 'L') pos--;
		else pos++;
		minP = min(minP, pos);
		maxP = max(maxP, pos);
	}
	
	int l = -minP;
	int r = n - 1 - maxP;
	
	l = min(l, n - 1);
	r = max(l, r);
	
	pos = 0;
	rep(i, m) {
		if (s[i] == 'L') pos = max(0, pos - 1);
		else pos = min(n - 1, pos + 1);
	}
	
	//cout << l << ", " << r << ", " << pos << endl;
	
	vector<int> ans;
	for (i = 0; i < pos; i++) ans.push_back(0);
	for (i = pos; i <= pos + r - l; i++) {
		if (i == pos) {
			int sumA = 0;
			for (int j = 0; j <= l; j++) sumA += a[j];
			ans.push_back(sumA);
		}
		else if (i == pos + r - l) {	//lと1をタイポしてた!
			int sumA = 0;
			for (int j = r; j < n; j++) sumA += a[j];
			ans.push_back(sumA);
		}
		else {
			//i == pos + 1のとき、a[l + 1]を出力したいのだから、
			//i == i'のとき、a[l + 1 - (pos + 1) + i'] = a[l - pos + i']
			//を出力すればいいはず。
			ans.push_back(a[l - pos + i]);
		}
	}
	for (i = pos + r - l + 1; i < n; i++) ans.push_back(0);
	
	rep(i, ans.size()) {
		cout << ans[i];
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	return 0;
}
0