結果

問題 No.1021 Children in Classrooms
ユーザー どららどらら
提出日時 2020-04-10 22:12:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,459 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 172,424 KB
実行使用メモリ 5,020 KB
最終ジャッジ日時 2023-10-14 00:49:34
合計ジャッジ時間 4,096 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 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,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 71 ms
4,996 KB
testcase_10 AC 71 ms
4,908 KB
testcase_11 AC 71 ms
4,864 KB
testcase_12 AC 70 ms
4,984 KB
testcase_13 AC 71 ms
5,020 KB
testcase_14 AC 70 ms
4,852 KB
testcase_15 AC 53 ms
4,616 KB
testcase_16 AC 53 ms
4,652 KB
testcase_17 AC 57 ms
4,592 KB
testcase_18 AC 75 ms
4,916 KB
testcase_19 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  string S;
  cin >> S;

  int L = 0, R = N-1;
  int PL = 0, PR = N-1;
  rep(i,S.size()){
    if(S[i] == 'L'){
      PL--;
      PR--;
      if(PL == PR){
        if(PL < 0){
          PL = 0;
          PR = 0;
        }
      }else{
        if(PL < 0){
          PL = 0;
          L++;
        }
      }
    }else{
      PL++;
      PR++;
      if(PL == PR){
        if(PR >= N){
          PL = N-1;
          PR = N-1;
        }
      }else{
        if(PR >= N){
          PR = N-1;
          R--;
        }
      }
    }
  }

  deque<int> deq;

  if(PL==PR){
    int sum = 0;
    rep(i,N) sum += v[i];
    deq.push_back(sum);
  }else{
    {
      int sum = 0;
      rep(i,L+1) sum += v[i];
      deq.push_back(sum);
    }
    {
      REP(i,L+1,R) deq.push_back(v[i]);
    }
    {
      int sum = 0;
      REP(i,R,N) sum += v[i];
      deq.push_back(sum);
    }
  }
  rep(i,PL) deq.push_front(0);
  REP(i,PR+1,N) deq.push_back(0);

  rep(i,deq.size()){
    if(i>0) cout << " ";
    cout << deq[i];
  }
  cout << endl;
  
  return 0;
}

0