結果
問題 | No.1021 Children in Classrooms |
ユーザー |
![]() |
提出日時 | 2020-04-10 22:24:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 2,346 bytes |
コンパイル時間 | 1,616 ms |
コンパイル使用メモリ | 167,976 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 20:56:18 |
合計ジャッジ時間 | 3,626 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#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 secondusing 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); chmax(z, 0);}else{++x; ++y; ++z;chmin(x, n-1); 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]);}