結果

問題 No.1021 Children in Classrooms
ユーザー chocorusk
提出日時 2020-03-04 18:32:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 66,580 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 23:42:08
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cassert>
using namespace std;
int n, m;
string s;
int a[200020], ans[200020];
int main()
{
	cin>>n>>m;
	for(int i=0; i<n; i++) cin>>a[i];
	cin>>s;
	int l=1, r=1, k=0, d=n;
	for(int i=0; i<m; i++){
		if(s[i]=='L'){
			if(k>0) k--;
			else if(d>1) d--, l++;
		}else{
			if(k+d<n) k++;
			else if(d>1) k++, d--, r++;
		}
	}
	if(d==1) for(int i=0; i<n; i++) ans[k]+=a[i];
	else{
		assert(n-l-r+2==d);
		for(int i=0; i<l; i++) ans[k]+=a[i];
		for(int i=l; i<n-r; i++) ans[k+1+i-l]+=a[i];
		for(int i=n-r; i<n; i++) ans[k+d-1]+=a[i];
	}
	for(int i=0; i<n; i++){
		cout<<ans[i];
		if(i<n-1) cout<<" ";
	}
	cout<<endl;
    return 0;
}
0