Codeforces Round 472-2A题解报告

Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.

Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into n consecutive segments, each segment needs to be painted in one of the colours.

Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.

Input

The first line contains a single positive integer n (1 ≤ n ≤ 100) — the length of the canvas.

The second line contains a string s of n characters, the i-th of which is either ‘C’ (denoting a segment painted in cyan), ‘M’ (denoting one painted in magenta), ‘Y’ (one painted in yellow), or ‘?’ (an unpainted one).

Output

If there are at least two different ways of painting, output “Yes”; otherwise output “No” (both without quotes).

You can print each character in any case (upper or lower).

Examples

input
5
CY??Y
output
Yes
input
5
C?C?Y
output
Yes
input
5
?CYC?
output
Yes
input
5
C??MM
output
No
input
3
MMY
output
No

分析

如果所有的问号处,有两种或两种以上的颜色方案,使得任意两个相邻的颜色不一样,结果为”Yes”。否则为”No“

可以枚举以下几种场景:
(1)只要出现相邻两个颜色一样的,结果为”No”
在没有相邻两个颜色一样的前提下:
(2)第一个字符若是为’?’,则这个问号至少可以用两种颜色替换,结果为”Yes”。比如”?MC”可以替换为”YMC”或“CMC”
(3)最后一个字符若是为’?’,则这个问号至少可以用两种颜色替换,结果为”Yes“
(4)若出现连续两个’?’,结果为”Yes”。比如”C??M”可以替换为”CYCM”和”CMCM”
(5)若’?’的左右字符一样,结果为”Yes”。比如”C?C”可以替换为”CMC”和”CYC”

代码

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

void NO()
{
    puts("No");
    exit(0);
}

void YES()
{
    puts("Yes");
    exit(0);
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < n - 1; ++i)
    {
        if(s[i] != '?' && s[i] == s[i+1])
        {
            NO();
        }
    }

    for(int i = 0; i < n; ++i)
    {
        if(s[i] == '?')
        {
            if(i == 0 || i == n - 1)
            {
                YES();
            }

            if(s[i+1] == '?')
            {
                YES();
            }

            if(s[i-1] == s[i+1])
            {
                YES();
            }
        }
    }

    NO();
}


Codeforces & TopCoder QQ交流群:648202993
更多内容请关注微信公众号
feicuisenlin_12x12.jpg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值