結果

問題 No.1021 Children in Classrooms
ユーザー monnu
提出日時 2020-05-27 21:33:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,377 bytes
コンパイル時間 1,440 ms
コンパイル使用メモリ 171,172 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 03:48:39
合計ジャッジ時間 3,859 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define INF 1000000000000000000
#define MOD 1000000007

int main(){
  int N,M;
  cin>>N>>M;
  vector<ll> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  string S;
  cin>>S;
  int left=0;
  int right=N-1;
  int left2=0;
  int right2=N-1;
  for(int i=0;i<M;i++){
    if(S.at(i)=='L'){
      if(right!=0){
        if(left==0){
          left2++;
        }else{
          left--;
        }
        right--;
      }
    }else{
      if(left!=N-1){
        if(right==N-1){
          right2--;
        }else{
          right++;
        }
        left++;
      }
    }
  }

  //cout<<left<<" "<<right<<" "<<left2<<" "<<right2<<endl;

  if(left==right){
    ll sum=0;
    for(int i=0;i<N;i++){
      sum+=a.at(i);
    }
    for(int i=0;i<N;i++){
      if(i==left){
        cout<<sum<<" ";
      }else{
        cout<<0<<" ";
      }
    }
    cout<<endl;
  }else{
    ll sum1=0;
    for(int i=0;i<=left2;i++){
      sum1+=a.at(i);
    }
    ll sum2=0;
    for(int i=right2;i<N;i++){
      sum2+=a.at(i);
    }
    for(int i=0;i<left;i++){
      cout<<0<<" ";
    }
    cout<<sum1<<" ";
    for(int i=left+1;i<right;i++){
      cout<<a.at(left2+(i-left-1)+1)<<" ";
    }
    cout<<sum2<<" ";
    for(int i=right+1;i<N;i++){
      cout<<0<<" ";
    }
    cout<<endl;
  }

}
0