結果

問題 No.1021 Children in Classrooms
ユーザー _____TAB__________TAB_____
提出日時 2020-04-10 22:26:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 77,060 KB
実行使用メモリ 5,140 KB
最終ジャッジ日時 2023-10-14 01:12:40
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 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,352 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 70 ms
5,080 KB
testcase_10 AC 70 ms
5,136 KB
testcase_11 AC 71 ms
5,140 KB
testcase_12 AC 69 ms
5,100 KB
testcase_13 AC 69 ms
5,108 KB
testcase_14 AC 69 ms
5,100 KB
testcase_15 AC 53 ms
5,116 KB
testcase_16 AC 53 ms
4,960 KB
testcase_17 AC 55 ms
4,908 KB
testcase_18 AC 75 ms
5,116 KB
testcase_19 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <vector>
#include <iostream>
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;
  int l = 0, r = N-1, lc = 0, rc = 0;
  for(auto c : s){
    if(c == 'L'){
      if(lc){
        --lc;
        ++r;
        continue;
      }
      if(l == N-1) continue;
      ++l;
      ++rc;
      A[l] += A[l-1];
      A[l-1] = 0;
    }else{
      if(rc){
        --rc;
        --l;
        continue;
      }
      if(r == 0) continue;
      --r;
      ++lc;
      A[r] += A[r+1];
      A[r+1] = 0;
    }
  }
  cerr << lc << " " << rc << endl;
  cerr << l << " " << r << endl;
  vector<int> B;
  for(int i = 0; i < lc; ++i)
    B.push_back(0);
  for(int i = l; i <= r; ++i){
    if(i >= 0 and i < N) B.push_back(A[i]);
    else B.push_back(0);
  }
  for(int i = 0; i < rc; ++i)
    B.push_back(0);
  assert(B.size() == N);
  for(int i = 0; i < N; ++i)
    cout << B[i] << (i+1 < N ? " " : "\n");
}
0