Submission #28964162
Source Code Expand
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
// using P = pair<ll,ll>;
using P = pair<int,int>;
using vint = vector<int>;
using vll = vector<ll>;
using vvint = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// const ll INF = (ll)2e18+9;
const int INF = (int)2e9+7;
// const ll MOD = (ll)1e9+9;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }
template<typename T>
void print(vector<T> v) {
int n = v.size();
rep(i,n) {
if (i == 0) cout << v[i];
else cout << ' ' << v[i];
}
cout << endl;
}
void solve() {
ll n;
cin >> n;
string s;
cin >> s;
s = "0" + s;
// 一番左にある数
int lnum = 0;
rep2(i,1,n+1) {
if (s[i] == 'L') {
if (lnum == i-1) lnum = i;
}
}
// cout << lnum << endl;
vvint config(n+1, vint(2, -1));
rep2(i,1,n+1) {
if (s[i] == 'L') {
int x = config[i-1][0];
config[i][0] = x;
config[i][1] = i-1;
config[i-1][0] = i;
if (x != -1) config[x][1] = i;
} else {
int x = config[i-1][1];
config[i][1] = x;
config[i][0] = i-1;
config[i-1][1] = i;
if (x != -1) config[x][0] = i;
}
}
vint ans;
int x = lnum;
while (config[x][1] != -1) {
ans.push_back(x);
x = config[x][1];
}
ans.push_back(x);
print(ans);
// rep(i,n+1)print(config[i]);
}
int main() {
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - LR insertion |
| User | goropikari |
| Language | C++ (GCC 9.2.1) |
| Score | 400 |
| Code Size | 1980 Byte |
| Status | AC |
| Exec Time | 103 ms |
| Memory | 36664 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 8 ms | 3588 KiB |
| 001.txt | AC | 2 ms | 3616 KiB |
| 002.txt | AC | 4 ms | 3628 KiB |
| 003.txt | AC | 4 ms | 3792 KiB |
| 004.txt | AC | 101 ms | 36648 KiB |
| 005.txt | AC | 94 ms | 36652 KiB |
| 006.txt | AC | 95 ms | 36660 KiB |
| 007.txt | AC | 96 ms | 36648 KiB |
| 008.txt | AC | 6 ms | 3616 KiB |
| 009.txt | AC | 2 ms | 3588 KiB |
| 010.txt | AC | 3 ms | 3724 KiB |
| 011.txt | AC | 5 ms | 3848 KiB |
| 012.txt | AC | 103 ms | 36656 KiB |
| 013.txt | AC | 98 ms | 36656 KiB |
| 014.txt | AC | 101 ms | 36664 KiB |
| 015.txt | AC | 98 ms | 36644 KiB |
| example0.txt | AC | 5 ms | 3484 KiB |
| example1.txt | AC | 3 ms | 3496 KiB |