結果

問題 No.1021 Children in Classrooms
ユーザー carrot46carrot46
提出日時 2020-04-10 21:38:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 168,456 KB
実行使用メモリ 6,648 KB
最終ジャッジ日時 2023-10-13 23:39:55
合計ジャッジ時間 3,356 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 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,352 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,348 KB
testcase_09 AC 62 ms
6,576 KB
testcase_10 AC 64 ms
6,576 KB
testcase_11 AC 63 ms
6,648 KB
testcase_12 AC 65 ms
6,580 KB
testcase_13 AC 65 ms
6,572 KB
testcase_14 AC 67 ms
6,616 KB
testcase_15 AC 47 ms
5,840 KB
testcase_16 AC 51 ms
5,608 KB
testcase_17 AC 51 ms
5,932 KB
testcase_18 AC 70 ms
6,596 KB
testcase_19 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N>>M;
    vec a(N);
    rep(i,N) cin>>a[i];
    cin>>S;
    ll l = 0, r = N - 1, ml = 0, mr = 0, total = 0;
    rep(i,M){
        if(S[i] == 'L'){
            --total;
            l = max(0LL, l - 1);
            r = max(0LL, r - 1);
        }else{
            ++total;
            l = min(N - 1, l + 1);
            r = min(N - 1, r + 1);
        }
        ml = min(ml, total);
        mr = max(mr, total);
    }
    int id = l;
    vec ans(N, 0);
    //cout<<l<<' '<<r<<' '<<ml<<' '<<mr<<' '<<total<<endl;
    if(mr - ml >= N) {
        ans[l] = accumulate(ALL(a), 0);
    }else{
        rep(i, -ml) ans[l] += a[i];
        reps(i, N - mr, N) ans[r] += a[i];
        int id = -ml;
        reps(i, l, r + 1) ans[i] += a[id++];
    }
    rep(i,N){
        cout<<ans[i];
        (i != N - 1 ? cout<<' ' : cout<<endl);
    }
}
0