結果

問題 No.1405 ジグザグロボット
ユーザー SSRSSSRS
提出日時 2020-12-08 22:49:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,280 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 180,624 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-16 23:46:13
合計ジャッジ時間 9,918 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
4,348 KB
testcase_33 WA -
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 5 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  string S;
  cin >> S;
  int Scnt = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == 'S'){
      if (Scnt >= Y){
        S[i] == '.';
      } else {
        Scnt++;
      }
    }
  }
  if (Y > Scnt){
    cout << -1 << endl;
  } else {
    vector<string> T;
    T.push_back("");
    for (int i = 0; i < N; i++){
      if (S[i] == 'L' || S[i] == 'R'){
        T.back() += S[i];
      } else if (S[i] == 'S' && T.size() <= Scnt){
        T.push_back("");
      }
    }
    int cnt = T.size();
    /*
    cout << "cnt = " << cnt << endl;
    for (int i = 0; i < cnt; i++){
      cout << i << " " << T[i] << endl;
    }
    */
    vector<int> left(cnt), right(cnt), sum(cnt);
    for (int i = 0; i < cnt; i++){
      int sz = T[i].size();
      left[i] = 0, right[i] = 0, sum[i] = 0;
      for (int j = 0; j < sz; j++){
        if (T[i][j] == 'L'){
          left[i]--;
          right[i]--;
          sum[i]--;
        }
        if (T[i][j] == 'R'){
          left[i]++;
          right[i]++;
          sum[i]++;
        }
        left[i] = min(left[i], 0);
        right[i] = max(right[i], 0);
        //cout << "sum[i] = " << sum[i] << ", left[i] = " << left[i] << ", right[i] = " << right[i] << endl;
      }
      //cout << "sum[i] = " << sum[i] << ", left[i] = " << left[i] << ", right[i] = " << right[i] << endl;
    }
    int Rsum = 0;
    for (int i = 0; i < cnt; i++){
      Rsum += right[i];
    }
    //cout << "Rsum = " << Rsum << endl;
    if (X > Rsum){
      cout << -1 << endl;
    } else {
      vector<pair<int, int>> ob;
      int currX = 0;
      for (int i = 0; i < cnt; i++){
        if (currX + right[i] <= X){
          ob.push_back(make_pair(currX - 1, i));
          currX += right[i];
        } else if (currX == X){
          ob.push_back(make_pair(currX - 1, i));
          ob.push_back(make_pair(currX + 1, i));
        } else {
          ob.push_back(make_pair(currX - 1 - (X - currX - right[i]), i));
        }
      }
      if (Y < Scnt){
        ob.push_back(make_pair(X, Y + 1));
      }
      int M = ob.size();
      cout << M << endl;
      for (int i = 0; i < M; i++){
        cout << ob[i].first << ' ' << ob[i].second << endl;
      }
    }
  }
}
0