結果
問題 | No.1021 Children in Classrooms |
ユーザー |
![]() |
提出日時 | 2020-04-10 21:59:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,248 bytes |
コンパイル時間 | 981 ms |
コンパイル使用メモリ | 83,528 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 20:19:19 |
合計ジャッジ時間 | 2,640 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; int N, M; int a[200000]; int fin[200000]; int ans[200000]; string S; int sim(int s){ for(int i = 0; i < M; i++){ if(S[i] == 'L') s = max(s-1, 1); else s = min(s+1, N); } return s; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> M; for(int i = 0; i < N; i++) cin >> a[i]; cin >> S; int l = 0, r = 0; int sum = 0; for(int i = 0; i < M; i++){ if(S[i] == 'L') sum--; else sum++; l = min(l, sum); r = max(r, sum); } // cout << sum << ' ' << l << ' ' << r << endl; fin[0] = sim(1); fin[N-1] = sim(N); // cout << fin[0] << ' ' << fin[N-1] << endl; if(fin[0] == fin[N-1]){ for(int i = 0; i < N; i++) ans[fin[0]-1] += a[i]; }else{ for(int i = 0; i < N; i++){ if(i+1+l <= 1) ans[fin[0]-1] += a[i]; else if(i+r+1 >= N) ans[fin[N-1]-1] += a[i]; else ans[i+sum] += a[i]; } } for(int i = 0; i < N; i++) cout << ans[i] << ' '; cout << endl; }