結果

問題 No.1021 Children in Classrooms
ユーザー auauaauaua
提出日時 2020-04-10 21:53:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 2,183 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 167,216 KB
実行使用メモリ 7,916 KB
最終ジャッジ日時 2023-10-14 00:24:36
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 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,352 KB
testcase_09 AC 79 ms
7,752 KB
testcase_10 AC 83 ms
7,912 KB
testcase_11 AC 85 ms
7,860 KB
testcase_12 AC 85 ms
7,804 KB
testcase_13 AC 84 ms
7,748 KB
testcase_14 AC 84 ms
7,916 KB
testcase_15 AC 56 ms
7,288 KB
testcase_16 AC 58 ms
7,148 KB
testcase_17 AC 59 ms
6,956 KB
testcase_18 AC 78 ms
7,764 KB
testcase_19 AC 12 ms
4,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n,m;cin>>n>>m;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    vector<ll>b(m);
    rep(i,m){
        char c;cin>>c;
        if(c=='L')b[i]=-1;
        else b[i]=1;
    }
    vector<ll>ans(n);
    ll cnt=0;
    ll L=0,R=n-1;
    rep(i,m){
        L+=b[i];
        R+=b[i];
        cnt+=b[i];
        if(R>n-1)R=n-1;
        if(L>n-1)L=n-1;
        if(R<0)R=0;
        if(L<0)L=0;
    }
    if(R==L){
        rep(i,n){
            ans[R]+=a[i];
        }
        rep(i,n){
            cout<<ans[i]<<' ';
        }
        cout<<endl;
        return 0;
    }
    ll l=0,r=n-1;
    while(r-l>1){
        ll mid=(r+l)/2;
        bool f=0;
        ll cnt=mid;
        rep(i,m){
            cnt+=b[i];
            if(cnt==0){
                f=1;
                break;
            }
            if(cnt==n-1){
                f=0;
                break;
            }
            if(cnt<0)cnt=0;
            if(cnt>=n)cnt=n-1;
        }
        if(f)l=mid;
        else{
            r=mid;
        }
    }
    ll LL=l;
    l=0,r=n-1;
    while(r-l>1){
        ll mid=(r+l)/2;
        bool f=0;
        ll cnt=mid;
        rep(i,m){
            cnt+=b[i];
            if(cnt==0){
                f=0;
                break;
            }
            if(cnt==n-1){
                f=1;
                break;
            }
            if(cnt<0)cnt=0;
            if(cnt>=n)cnt=n-1;
        }
        if(f)r=mid;
        else{
            l=mid;
        }
    }
    ll RR=r;
    //cout<<LL<<' '<<RR<<endl;
    rep(i,n){
        if(i<=LL){
            ans[L]+=a[i];
        }else if(i>=RR){
            ans[R]+=a[i];
        }else{
            ans[i+cnt]+=a[i];
        }
    }
    rep(i,n){
        cout<<ans[i]<<' ';
    }
    cout<<endl;
}
0