結果

問題 No.1021 Children in Classrooms
ユーザー yakkiyakki
提出日時 2020-04-11 07:13:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 2,097 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 124,372 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-10-17 13:09:51
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 107 ms
5,228 KB
testcase_10 AC 110 ms
5,228 KB
testcase_11 AC 112 ms
5,228 KB
testcase_12 AC 96 ms
5,228 KB
testcase_13 AC 94 ms
5,228 KB
testcase_14 AC 95 ms
5,228 KB
testcase_15 AC 67 ms
4,772 KB
testcase_16 AC 68 ms
4,776 KB
testcase_17 AC 71 ms
4,804 KB
testcase_18 AC 90 ms
5,228 KB
testcase_19 AC 10 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    string s; cin >> s;
    int ok = 0,ng = n;
    while(ng-ok > 1){
        int mid = (ok+ng)/2;
        int now = mid;
        rep(i,m){
            if(s[i] == 'L') now = max(0,now-1);
            else now = min(n-1,now+1);
            if(now == 0){
                ok = mid;
                break;
            }
        }
        if(ok != mid) ng = mid;
    }
    int ok2 = n-1, ng2 = -1;
    while(ok2-ng2 > 1){
        int mid = (ok2+ng2)/2;
        int now = mid;
        rep(i,m){
            if(s[i] == 'L') now = max(0,now-1);
            else now = min(n-1,now+1);
            if(now == n-1){
                ok2 = mid;
                break;
            }
        }
        if(ok2 != mid) ng2 = mid;
    }
    int now0 = 0;
    rep(i,m){
        if(s[i] == 'L') now0 = max(0,now0-1);
        else now0 = min(n-1,now0+1);
    }
    int nown = n-1;
    rep(i,m){
        if(s[i] == 'L') nown = max(0,nown-1);
        else nown = min(n-1,nown+1);
    }
    int last = 0;
    rep(i,m){
        if(s[i] == 'L') last--;
        else last++;
    }
    vector<int> ans(n);
    rep(i,n){
        if(i <= ok){
            ans[now0] += a[i];
        }
        else if(i < ok2){
            ans[i+last] += a[i];
        }
        else ans[nown] += a[i];
    }
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
}

0