QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591223 | #2513. A Color Game | mrkiencf# | WA | 0ms | 3576kb | C++20 | 1.6kb | 2024-09-26 14:51:16 | 2024-09-26 14:51:16 |
Judging History
answer
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
const int MAXN = 5e5 + 5;
const i64 INF = LLONG_MAX/2;
int N, M;
string S;
bool f[505][505];
void Solve(void) {
cin >> S >> M;
N = S.size(); S = " " + S;
vector<int> pref(N + 2, 0), nxt(N + 2, 0);
pref[1] = 1; nxt[N] = N;
for (int i = 2; i <= N; i ++) {
pref[i] = (S[i] == S[i - 1] ? pref[i - 1] : i);
}
for (int i = N - 1; i >= 1; i --) {
nxt[i] = (S[i] == S[i + 1] ? nxt[i + 1] : i);
}
for (int l = N; l >= 1; l --) {
for (int r = l - 1; r >= 1; r --) {
f[l][r] = true;
}
}
for (int l = N; l >= 1; l --) {
for (int r = l; r <= N; r ++) {
if (r - l + 1 < M) f[l][r] = false;
else {
int ll = nxt[l];
int rr = pref[r];
if (ll >= r) f[l][r] = true;
if (rr <= l) f[l][r] = true;
if (ll - l + 1 >= M && r - rr + 1 >= M) {
f[l][r] |= f[ll + 1][rr - 1];
}
if (ll < rr && S[l] == S[r] && r - rr + 1 + ll - l + 1 >= M) {
f[l][r] |= f[ll + 1][rr - 1];
}
}
// cout << l << " " << r << " " << f[l][r] << " " << S.substr(l, r - l + 1) << "\n";
}
}
cout << (f[1][N] ? "Yes" : "No") << "\n";
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(10);
int Tests = 1; // cin >> Tests;
while (Tests --) {
Solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
BBBRRRRRRGGGB 3
output:
Yes
result:
ok single line: 'Yes'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
BBBRRRRRRGGGB 4
output:
No
result:
ok single line: 'No'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
RRRRGGGRRRRRG 3
output:
No
result:
wrong answer 1st lines differ - expected: 'Yes', found: 'No'