QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#57817 | #2513. A Color Game | As3b_team_f_masr# | ML | 0ms | 0kb | C++ | 1.6kb | 2022-10-23 00:26:24 | 2022-10-23 00:26:28 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define EPS 1e-9
#define PI acos(-1.0)
#define ll long long
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define pb push_back
#define ft first
#define sc second
#define pi pair<ll,ll>
#define vi vector<ll>
#define sz(s) s.size()
using namespace std;
const ll N = 2e5 + 5, M = 500 + 5, MOD = 1e4 + 5, INF = 1e18;
int dx[] = {-1, 1, 0, 0}, Dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};;
int dy[] = {0, 0, 1, -1}, Dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int n, m, t, dp[M][M][M][3];
string s;
int solve(int l, int r, int cnt, int dir) {
if (l == 0 && r == sz(s) - 1) return cnt >= m;
int &ret = dp[l][r][cnt][dir];
if (~ret)
return ret;
char tmp = (dir == 0 ? s[l] : s[r]);
ret = 0;
if (r < sz(s) - 1 && s[r + 1] == tmp)
ret = solve(l, r + 1, cnt + 1, 1);
if (l > 0 && s[l - 1] == tmp)
ret = max(ret, solve(l - 1, r, cnt + 1, 0));
if (cnt >= m) {
if (l > 0)
ret = max(ret, solve(l - 1, r, 1, 0));
if (r < sz(s) - 1)
ret = max(ret, solve(l, r + 1, 1, 1));
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);//freopen("lines.in", "r", stdin);
cin >> s >> m;
cout << sz(s) << endl;
if (m == 1) return cout << "Yes", 0;
memset(dp, -1, sizeof dp);
int mx = 0;
for (int i = 0; i < sz(s); ++i) mx = max(mx, solve(i, i, 1, 2));
cout << (mx ? "Yes" : "No");
return 0;
}
/*
*/
詳細信息
Test #1:
score: 0
Memory Limit Exceeded
input:
BBBRRRRRRGGGB 3
output:
13