結果

問題 No.1021 Children in Classrooms
ユーザー NewGardenNewGarden
提出日時 2020-04-10 22:16:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,359 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 168,584 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-14 00:55:58
合計ジャッジ時間 3,666 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 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 AC 2 ms
4,352 KB
testcase_09 AC 64 ms
4,352 KB
testcase_10 AC 64 ms
4,500 KB
testcase_11 AC 64 ms
4,352 KB
testcase_12 AC 65 ms
4,348 KB
testcase_13 AC 64 ms
4,348 KB
testcase_14 AC 67 ms
4,348 KB
testcase_15 AC 51 ms
4,352 KB
testcase_16 AC 49 ms
4,376 KB
testcase_17 AC 54 ms
4,352 KB
testcase_18 AC 72 ms
4,372 KB
testcase_19 AC 6 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,m;
  string s;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  cin >> s;
  int pos = 0;
  rep(i,m){
    if(s[i]=='L'){
      pos--;
    } else {
      pos++;
    }
    if(pos<0 && abs(pos)<n){
      int it = -pos-1;
      a[it+1] += a[it];
      a[it] = 0;
    }
    if(pos>0 && abs(pos)<n){
      int it = n-pos;
      a[it-1] += a[it];
      a[it] = 0;
    }
    if(pos>n-1) pos=n-1;
    if(pos<-(n-1)) pos=-(n-1);    
  }

  if(n-1<=pos){
    rep(i,n-1) cout << 0 << " ";
    cout << a[0] << endl;
    return 0;
  }
  if((1-n)>=pos){
    cout << a[n-1] << " ";
    rep(i,n-1) cout << 0 << " ";
    cout << endl; return 0;
  }
  if(pos>0){
    rep(i,pos) cout << 0 << " ";
    for(int i=0; i<n-pos; i++) cout << a[i] << " ";
    cout << endl; return 0;
  }
  if(pos<0){
    pos *= -1;
    for(int i=pos; i<n; i++) cout << a[i] << " ";
    rep(i,pos) cout << 0 << " ";
    cout << endl; return 0;
  }
  if(pos==0){
    rep(i,n) cout << a[i] << " ";
    cout << endl; return 0;
  }
  return 0;
}
0