Submission #6731379


Source Code Expand

Copy
#include <bits/stdc++.h>

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  string s;
  cin>>s;
  ll N = s.size();
  vector<ll> ans(N, 0);
  set<ll> se;

  // "RL" の組を見つける
  // 入ったら抜け出せない
  rep(i,0,N-1){
    if (s[i]=='R' && s[i+1]=='L') {
      se.insert(i);
      se.insert(i+1);
      ans[i] = ans[i+1] = 1;
    }
  }
  
  // 偶数回移動して "RL" の組にくっつける
  rep(i,0,N){
    if (se.find(i) != se.end())
      continue;
    if (s[i] ==  'R') {
      auto it = se.lower_bound(i);
      if ((*it - i)%2 == 1)
        it++;
      ans[*it]++;
    } else {
      auto it = se.lower_bound(i);
      it--;
      if ((i - *it)%2 == 1)
        it--;
      ans[*it]++;
    } 
  }
  rep(i,0,N){
    cout<<ans[i];
    if (i==N-1){
      cout<<endl;
    } else {
      cout<<" ";
    }
  }
  return 0;
}

Submission Info

Submission Time
Task D - Gathering Children
User bobuhiro11
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1017 Byte
Status
Exec Time 45 ms
Memory 6016 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB
testcase_01 19 ms 2432 KB
testcase_02 18 ms 2304 KB
testcase_03 32 ms 3712 KB
testcase_04 32 ms 3712 KB
testcase_05 10 ms 1024 KB
testcase_06 13 ms 1280 KB
testcase_07 15 ms 1408 KB
testcase_08 16 ms 1408 KB
testcase_09 4 ms 512 KB
testcase_10 14 ms 1408 KB
testcase_11 45 ms 6016 KB
testcase_12 17 ms 1408 KB
testcase_13 15 ms 1408 KB
testcase_14 13 ms 1408 KB
testcase_15 13 ms 1408 KB
testcase_16 14 ms 1408 KB
testcase_17 14 ms 1408 KB
testcase_18 1 ms 256 KB