QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#853671#9925. LR Stringucup-team3691#WA 43ms3712kbC++202.4kb2025-01-11 18:05:182025-01-11 18:05:19

Judging History

你现在查看的是最新测评结果

  • [2025-01-11 18:05:19]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:3712kb
  • [2025-01-11 18:05:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

int get_val(char ch) {
    return (ch == 'L') ? 0 : 1;
}

void solve() {
  string s;
  int n;
  cin >> s;

  vector<vector<int>> nxt(s.size(), vector<int>(s.size(), -1));
  for (int i = s.size() - 1; i >= 0; --i) {
    if (i + 1 < s.size()) {
      nxt[i][0] = nxt[i + 1][0];
      nxt[i][1] = nxt[i + 1][1];

      int val = (s[i + 1] == 'L') ? 0 : 1;
      nxt[i][val] = i + 1;
    }
  //  debug(i, nxt[i][0], nxt[i][1]);
  }

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    bool ok = true;
    string s2;
    cin >> s2;

    if (s2[0] == 'R' && s[0] == 'L') {
      cout << "NO\n";
      continue;
    }

    int p = 0, j = 0;
    if (s2[0] == s[0]) {
      p = 0;
    } else {
      p = nxt[0][get_val(s2[0])];
      if (p < 0) {
        cout << "NO";
        continue;
      }
    }
    j = 1;

    while (j < s2.size()) {
      p = nxt[p][get_val(s2[j])];
      if (p < 0) {
        ok = false;
        break;
      }
      ++j;
    }
    cout << (ok ? "YES" : "NO") << "\n";
  }

}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
  cin >> t;
  while (t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

2
RRLLRRLL
4
LLLLL
LLR
LRLR
R
RLLLLLL
3
LLLLL
RL
RRL

output:

NO
YES
NO
YES
YES
YES
NO

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 43ms
memory: 3660kb

input:

100000
RRLLR
4
R
R
R
R
LRLLL
6
R
L
L
L
L
R
RLLRR
1
L
LRLLL
3
R
L
L
RLRRL
2
LRRRR
RRRL
LRLRR
2
L
R
RRLRL
4
RLRLR
RLLL
LR
RLL
RLRLL
8
R
R
R
L
L
L
R
L
RLLRR
7
R
LL
RL
R
L
L
L
LLRLR
2
L
R
RRRRL
1
RLLLR
RRLLL
2
L
L
RLLRL
1
RLLRL
LRLLL
5
RLRLL
RLLLR
RRRRL
LLRRR
RLLRR
LRLLL
3
RRLL
R
RL
LLRRL
3
L
R
LLLRR
RR...

output:

YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES...

result:

wrong answer 11th lines differ - expected: 'NO', found: 'YES'