結果
| 問題 | 
                            No.1021 Children in Classrooms
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Ricky_pon
                         | 
                    
| 提出日時 | 2020-04-10 22:05:10 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,318 bytes | 
| コンパイル時間 | 1,573 ms | 
| コンパイル使用メモリ | 169,512 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-15 20:25:52 | 
| 合計ジャッジ時間 | 3,574 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 1 | 
ソースコード
#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);
        }
        else{
            ++x; ++y; ++z;
            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]);
}
            
            
            
        
            
Ricky_pon