結果

問題 No.1021 Children in Classrooms
ユーザー minatominato
提出日時 2020-04-10 22:06:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,980 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 175,408 KB
実行使用メモリ 6,740 KB
最終ジャッジ日時 2023-10-14 00:41:10
合計ジャッジ時間 4,120 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 70 ms
6,640 KB
testcase_10 AC 74 ms
6,596 KB
testcase_11 AC 76 ms
6,700 KB
testcase_12 AC 56 ms
6,644 KB
testcase_13 AC 55 ms
6,740 KB
testcase_14 AC 56 ms
6,592 KB
testcase_15 AC 37 ms
5,696 KB
testcase_16 AC 38 ms
5,740 KB
testcase_17 AC 39 ms
6,132 KB
testcase_18 AC 43 ms
6,408 KB
testcase_19 AC 5 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int N,M;
string S;
ll A[202020];
bool f(int x) {
    rep(i,M) {
        if (x==0) return true;
        if (S[i]=='L') x--;
        else x = min(x+1,N-1);
    }
    if (x==0) return true;
    else return false;
}

bool g(int x) {
    rep(i,M) {
        if (x==N-1) return true;
        if (S[i]=='L') x = max(0,x-1);
        else x++;
    }
    if (x==N-1) return true;
    return false;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> M;
    rep(i,N) cin >> A[i];
    cin >> S;

    int ok1 = 0;
    int ng1 = N;
    while (ng1 - ok1 > 1) {
        int mid = (ok1+ng1)/2;
        if (f(mid)) ok1 = mid;
        else ng1 = mid;
    }
    int ok2 = N-1;
    int ng2 = -1;
    while (ok2 - ng2 > 1) {
        int mid = (ok2+ng2)/2;
        if (g(mid)) ok2 = mid;
        else ng2 = mid;
    }
    int l = ok1;
    rep(i,M) {
        if (S[i]=='L') l = max(0,l-1);
        else l = min(N-1,l+1);
    }
    int r = ok2;
    rep(i,M) {
        if (S[i]=='L') r = max(0,r-1);
        else r = min(N-1,r+1);
    }
    vector<ll> ans(N);
    rep(i,N) {
        if (i <= ok1) ans[l] += A[i];
        else if (i >= ok2) ans[r] += A[i];
        else ans[l + i-ok1] += A[i];
    }

    rep(i,N) cout << ans[i] << " ";
    cout << ln; 
    
}
0