結果

問題 No.1021 Children in Classrooms
ユーザー misora192misora192
提出日時 2020-04-12 08:34:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 175,780 KB
実行使用メモリ 16,104 KB
最終ジャッジ日時 2023-10-22 00:40:11
合計ジャッジ時間 5,603 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 37 ms
6,720 KB
testcase_10 AC 37 ms
6,724 KB
testcase_11 AC 37 ms
6,716 KB
testcase_12 AC 42 ms
7,776 KB
testcase_13 AC 41 ms
7,768 KB
testcase_14 AC 41 ms
7,772 KB
testcase_15 AC 67 ms
12,712 KB
testcase_16 AC 68 ms
13,000 KB
testcase_17 AC 72 ms
13,276 KB
testcase_18 AC 89 ms
16,104 KB
testcase_19 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	cin >> n >> m;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	string s;
	cin >> s;

	int lp = 0, rp = n - 1;
	int lev = 0;
	set<int> ls, rs;
	ls.insert(0);
	rs.insert(n - 1);

	rep(i, m){
		if(s[i] == 'L'){
			if(-(n - 1) < lev) lev--;
			if(lev < 0) ls.insert(-lev);
			if(lp > 0) lp--;
			if(rp > 0) rp--;
		}else{
			if(lev < n - 1) lev++;
			if(lev > 0) rs.insert(n - 1 - lev);
			if(lp < n - 1) lp++;
			if(rp < n - 1) rp++;
		}
	}
	
	vector<ll> ans(n, 0);
	if(ls.size() == n || rs.size() == n){
		ll sm = 0;
		rep(i, n) sm += a[i];
		ans[lp] = sm;
	}else{
		ll lsm = 0;
		for(int i : ls) lsm += a[i];

		ll rsm = 0;
		for(int i : rs) rsm += a[i];

		ans[lp] = lsm;
		int lc = ls.size();
		for(int i = lp + 1; i < rp; i++){
			ans[i] = a[lc + i - lp - 1];
		}
		ans[rp] = rsm;
	}

	rep(i, n) cout << ans[i] << (i == n - 1 ? "\n" : " ");
}
0