結果

問題 No.1021 Children in Classrooms
ユーザー Ricky_ponRicky_pon
提出日時 2020-04-10 22:24:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,346 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 166,976 KB
実行使用メモリ 5,260 KB
最終ジャッジ日時 2023-10-14 01:11:52
合計ジャッジ時間 3,563 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 77 ms
5,184 KB
testcase_10 AC 81 ms
5,192 KB
testcase_11 AC 84 ms
5,180 KB
testcase_12 AC 63 ms
5,192 KB
testcase_13 AC 63 ms
5,232 KB
testcase_14 AC 64 ms
5,176 KB
testcase_15 AC 32 ms
4,804 KB
testcase_16 AC 38 ms
4,816 KB
testcase_17 AC 34 ms
5,008 KB
testcase_18 AC 46 ms
5,260 KB
testcase_19 AC 7 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, m, a[MAX];
string s;

bool check_L(int mid){
    if(mid == 0) return true;
    for(auto c: s){
        (c == 'L' ? --mid : ++mid);
        if(mid == 0) return true;
    }
    return false;
}

bool check_R(int mid){
    if(mid == n-1) return true;
    for(auto c: s){
        (c == 'L' ? --mid : ++mid);
        if(mid == n-1) return true;
    }
    return false;
}

int main(){
    scanf("%d%d", &n, &m);
    rep(i, n) scanf("%d", &a[i]);
    cin >> s;

    int x = 0, y = 0, z = n-1;
    for(auto c: s){
        if(c == 'L'){
            --x; --y; --z;
            chmax(x, 0); chmax(z, 0);
        }
        else{
            ++x; ++y; ++z;
            chmin(x, n-1); chmin(z, n-1);
        }
    }

    int ans[n];
    memset(ans, 0, sizeof(ans));

    int L, R, low = 0, high = n-1;
    if(check_L(n-1)){
        ans[x] = accumulate(a, a+n, 0);
        rep(i, n) printf("%d ", ans[i]);
        return 0;
    }
    while(high - low > 1){
        int mid = (high + low) / 2;
        (check_L(mid) ? low : high) = mid;
    }

    L = low;
    low = L, high = n-1;
    if(check_R(0)){
        ans[z] = accumulate(a, a+n, 0);
        rep(i, n) printf("%d ", ans[i]);
        return 0;
    }
    while(high - low > 1){
        int mid = (high + low) / 2;
        (check_R(mid) ? high : low) = mid;
    }
    R = high;

    rep(i, n){
        if(i <= L) ans[x] += a[i];
        else if(i >= R) ans[z] += a[i];
        else ans[i+y] += a[i];
    }
    rep(i, n) printf("%d ", ans[i]);
}
0