QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#57820#2513. A Color GameAmrMohameDWA 44ms258960kbC++1.8kb2022-10-23 00:32:082022-10-23 00:32:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-23 00:32:11]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:258960kb
  • [2022-10-23 00:32:08]
  • 提交

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()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll N = 2e5+5, M = 500+2, 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 ;
bool dp[M][M][M][2],vis[M][M][M][2];
string s;
int solve(int l,int r,int cnt,int dir)
{
   // if(l == 0) cout << l << ' ' << r << ' ' << cnt << endl;
    if(l == 0 && r == sz(s)-1) return cnt >= m;
    bool &ret = dp[l][r][cnt][dir];
    if(vis[l][r][cnt][dir])
        return ret;
    vis[l][r][cnt][dir] = true;
    char tmp = (dir?s[r] : s[l]);
    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 |= solve(l-1,r,cnt+1,0);
    if(cnt >= m){
        if(l > 0)
            ret |= solve(l-1,r,1,0);
        if(r < sz(s)-1)
            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;
    if(m == 1) return cout << "Yes",0;
    memset(dp,0,sizeof dp);
    int mx = 0;
    for(int i = 0; i < sz(s) ;++i) mx |= solve(i,i,1,0);
    cout << (mx?"Yes":"No");
    return 0;
}
/*

*/

详细

Test #1:

score: 100
Accepted
time: 39ms
memory: 250792kb

input:

BBBRRRRRRGGGB 3

output:

Yes

result:

ok single line: 'Yes'

Test #2:

score: 0
Accepted
time: 44ms
memory: 250892kb

input:

BBBRRRRRRGGGB 4

output:

No

result:

ok single line: 'No'

Test #3:

score: 0
Accepted
time: 27ms
memory: 250880kb

input:

RRRRGGGRRRRRG 3

output:

Yes

result:

ok single line: 'Yes'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

GMYCGMRMGYMRMKCBKBMKKBMMKBBKMBMRRMGYKKMBKMYRGGBMRMKKKBRCMKYCCKYGYYKKCKRCYGGKGRBCKMYMRCRGBRRYCCKKRRKRCKMMMGCCGYYKMCRGMKCYBMRRKYYRRKGGRBMCKGBBYYGGGBBYBBRCCMGKKGRGRMRRBRCYGGGKBRKCBYCKMMBRCGKCCYYMMCKGRBYRRGBBCGYKBBMKRBBKGCRBYCKMYKMCKMBRMGGYBKBRBMYGGCKYCMYKBRCCGCYRRRKCKCBKCMCYBKRBKMCCYRBKBGGMGMCBGMBMYCCK 1

output:

Yes

result:

ok single line: 'Yes'

Test #5:

score: -100
Wrong Answer
time: 40ms
memory: 258960kb

input:

KKCCCCCKYYYYYYKKKCRRCCBBBGGMMGCKKBBBBBRCCRRCRRYYCCYYBGGGBKKKBKKKCMKKMCCCGGGCCCCBBBCCKMMMKCCYYBBCCCCCCCCCYYCCCCBMMBRRRBBGGMKKBYMMMYYBBBBYYYYKCCCMMCKKMMMKKGGMBBRRBBBBKKBBBMMMMKKMMMKKKMMYYGMYYYMRRBMMMBGRRGGMMCCGRRBBBGCGGGCBBBCCBGGGGCRKKBBBRRYYYBBBYYKKKYYYBBYYBBBBCCCRKYGGGYYKKKKKKKKKRCCCYKKRRRKKMMMKMMC 2

output:

No

result:

wrong answer 1st lines differ - expected: 'Yes', found: 'No'