結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
コンテスト
ユーザー vjudge1
提出日時 2026-01-03 18:21:44
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 4,484 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,641 ms
コンパイル使用メモリ 372,120 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-03 18:21:55
合計ジャッジ時間 10,196 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other AC * 11 WA * 2 RE * 4 TLE * 1 -- * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std ;
using namespace __gnu_pbds ;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// Ordered Set (PBDS): Used when need indexing in sets for keys NOT duplicates. To use dups; replace 'T' with pair<T, int> and use counter for 2nd with increasing value.
// os.order_of_key(x) -> # elements strictly < x (like lower_bound index)
// osind_by_order(k) -> iterator to k-th smallest (0-based)
// Think of:
//   order_of_key(x)  -> "index of x" if sorted
//   find_by_order(k) -> "element at index k"
// Use for: rank queries, inversion count, kth smallest/largest, etc.

#define int long long
using pi = pair<int, int> ;
using ppi = pair<int , pi> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vs = vector<string> ;
using vpi = vector<pi> ;
using vvi = vector<vi> ;
template <size_t N>
using ai = array<int, N>;
const int MOD = 1e9 + 7 ;
const int INF = LLONG_MAX ;

#define all(x) begin(x), end(x)
#define nl "\n"
#define f first
#define ss second
void yesNo( bool b ) { cout << ( b ? "YES" : "NO" ) << nl ; }
int binaryExp( int base , int exp , int mod ) { int res = 1LL ; base %= mod ;  while ( exp > 0 ) {  if ( exp & 1 ) res = (res * base) % mod ;  base = (base * base) % mod ;  exp >>= 1LL ;  }  return res ; }
vi sieve( int n ) { vb isPrime( n + 1 , true ) ; isPrime[0] = isPrime[1] = false ;  vi primes ; for( int i = 2 ; i * i <= n ; i++ ) {  if( isPrime[i] ) {  primes.push_back( i ) ;  for( int j = i * i ; j <= n ; j += i )  isPrime[j] = false ;  }  }  return primes ;  }

// int check( int n ) {
//     if( n == 1 )
//         return 0 ;
//     // else if( n < 1 ) return 1 

//     int cur = 0 ;
//     for( int i = 1 ; i <= n ; i++ ) {
//         if( !check( n - 2 ) || !check( n - 3  ) || !check( n - 5 ) ) {
//             return 1 ;
//         }
//     }
//     return 0 ;
// }
void solve() {
    int n ;
    cin >> n ;
   
    string s ;
    cin >> s ;

    vi a(n) ;
    vpi pref( n + 1 , { 0 , 0 } ) ;
    pref[0] = { 0 , 0 };
    for( int i = 0 ; i < n ; i++ ) {
        cin >> a[i] ;
        if( s[i] == 'E' ) {
            pref[i + 1].f += pref[i].f + a[i] ;
            pref[i + 1].ss += pref[i].ss + 1 ;
        }
        else {
            pref[i + 1].f += pref[i].f + a[i] ;
            pref[i + 1].ss += pref[i].ss ;
        }
    }

    // for( int i = 0 ; i <= n ; i++ ) cout << pref[i].f << " \n"[i == n] ;
    // for( int i = 0 ; i <= n ; i++ ) cout << pref[i].ss << " \n"[i == n] ;
    int q ;
    cin >> q ;
    vi b(n) ;
    for( int i = 0 ; i < q ;i++ ) cin >> b[i] ;

    
    for( int i = 0 ; i < q ; i++ ) {
        int res = 0 ;
        for( int j = 0 ; j < n ; j++ ) {
            // int l = 1 , r = n ;
            // while( l <= r ) {
            //     int md = l + (r - l) / 2 ;
            //     if( pref[md].f <= b[i] ) {
            //         l = md + 1 ;
            //         res = pref[md].ss ;
            //     }
            //     else
            //         r = md - 1 ;
            // }
    
            // cout << res << nl ;
            int tot = n , sum = 0 , cur = 0 ;
            for( int k = 1 ; k < n ; k++ ) {
                if( a[( j + k ) % n] + sum <= b[i] )
                    sum += a[ ( j + k ) % n ] ;
                else
                    break ; 

                if( s[ ( j + k ) % n ] == 'E' ) cur++ ;
            }
            res = max( res,  cur ) ;
        }
        cout << res << nl ;
    }


    // int n , m ;
    // cin >> n >> m ;

    // vvi adj(n + 1) ;
    // for( int i = 1; i <= m ; i++ ) {
    //     int u , v ;
    //     cin >> u >> v ;
    //     adj[u].push_back(v) ;
    //     adj[v].push_back(u) ;
    // }

    // int cur = 0 ;
    // for( int i = 1 ; i <= n ; i++ ) cur += adj[i].size() ;

    // cur /= 2 ;
    // if( cur + 1 < n ) {
    //     yesNo(0) ;
    //     return ;
    // }
    
    // yesNo(1) ;
}

signed main() {
    FAST_IO
    if ( FILE* file = fopen("input.txt", "r") ) {
        freopen("input.txt", "r", stdin) ;
        freopen("output.txt", "w", stdout) ;
        fclose(file) ;
    }

    int t = 1 ;
    // cin >> t ;
    for( int i = 1 ; i <= t ; i++ ) { 
        // cout << "Case " << i << ": " << nl ; 
        solve() ; 
    } 
    return 0;
}
0