結果

問題 No.1021 Children in Classrooms
ユーザー milanis48663220milanis48663220
提出日時 2020-04-10 21:59:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,248 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 83,160 KB
実行使用メモリ 5,124 KB
最終ジャッジ日時 2023-10-14 00:30:17
合計ジャッジ時間 2,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 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 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 32 ms
5,124 KB
testcase_10 AC 32 ms
4,988 KB
testcase_11 AC 33 ms
5,016 KB
testcase_12 AC 30 ms
5,008 KB
testcase_13 AC 30 ms
4,948 KB
testcase_14 AC 30 ms
4,944 KB
testcase_15 AC 22 ms
4,348 KB
testcase_16 AC 22 ms
4,408 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 AC 29 ms
4,484 KB
testcase_19 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, M;
int a[200000];
int fin[200000];
int ans[200000];
string S;

int sim(int s){
    for(int i = 0; i < M; i++){
        if(S[i] == 'L') s = max(s-1, 1);
        else s = min(s+1, N);
    }
    return s;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < N; i++) cin >> a[i];
    cin >> S;
    int l = 0, r = 0;
    int sum = 0;
    for(int i = 0; i < M; i++){
        if(S[i] == 'L') sum--;
        else sum++;
        l = min(l, sum);
        r = max(r, sum);
    }
    // cout << sum << ' ' << l << ' ' << r << endl;
    fin[0] = sim(1);
    fin[N-1] = sim(N);
    // cout << fin[0] << ' ' << fin[N-1] << endl;
    if(fin[0] == fin[N-1]){
        for(int i = 0; i < N; i++) ans[fin[0]-1] += a[i];
    }else{
        for(int i = 0; i < N; i++){
            if(i+1+l <= 1) ans[fin[0]-1] += a[i];
            else if(i+r+1 >= N) ans[fin[N-1]-1] += a[i];
            else ans[i+sum] += a[i];
        }
    }
    for(int i = 0; i < N; i++) cout << ans[i] << ' ';
    cout << endl;
}
0