結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> a( N );
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}
	string S;
	cin >> S;

	long long l = a[0];
	long long r = a[N - 1];
	deque<long long> que;
	for( int i = 1; i < N - 1; i++ ) {
		que.push_back( a[i] );
	}
	for( int i = 0; i < M; i++ ) {
		if( S[i] == 'L' ) {
			if( que.size() ) {
				l += que.front();
				que.pop_front();
				que.push_back( r );
				r = 0;
			}
			else {
				l += r;
				r = 0;
			}
		}
		else if( S[i] == 'R' ) {
			if( que.size() ) {
				r += que.back();
				que.pop_back();
				que.push_front( l );
				l = 0;
			}
			else {
				r += l;
				l = 0;
			}
		}
	}

	cout << l << " ";
	if( que.size() ) {
		for( int i = 0; i < que.size(); i++ ) {
			cout << que[i];
			cout << " ";
		}
	}
	cout << r << endl;
}
0