Codeforces Beta Round #97 (Div. 2)

E. Zero-One
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.

Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card contains a digit: 0 or 1. Players move in turns and Masha moves first. During each move a player should remove a card from the table and shift all other cards so as to close the gap left by the removed card. For example, if before somebody's move the cards on the table formed a sequence 01010101, then after the fourth card is removed (the cards are numbered starting from 1), the sequence will look like that: 0100101.

The game ends when exactly two cards are left on the table. The digits on these cards determine the number in binary notation: the most significant bit is located to the left. Masha's aim is to minimize the number and Petya's aim is to maximize it.

An unpleasant accident occurred before the game started. The kids spilled juice on some of the cards and the digits on the cards got blurred. Each one of the spoiled cards could have either 0 or 1 written on it. Consider all possible variants of initial arrangement of the digits (before the juice spilling). For each variant, let's find which two cards are left by the end of the game, assuming that both Petya and Masha play optimally. An ordered pair of digits written on those two cards is called an outcome. Your task is to find the set of outcomes for all variants of initial digits arrangement.

<p< p=""><p< p="">
Input
<p< p="">

The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, inclusive.

<p< p=""><p< p="">
Output
<p< p="">

Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the first sample).

<p< p=""><p< p="">
Sample test(s)
<p< p=""><p< p="">
input
????
output
00
01
10
11
input
1010
output
10
input
1?1
output
01
11
<p< p=""><p< p="">
Note
<p< p="">

In the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will contain all 4 possible outcomes.

In the third sample only 2 variants of numbers arrangement are possible: 111 and 101. For the variant 111 the outcome is 11. For the variant 101 the outcome is 01, because on the first turn Masha can remove the first card from the left after which the game will end.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    char str[100009];
    char table[4][3] = {{'0','0','\0'},{'0','1','\0'},{'1','0','\0'},{'1','1','\0'}};
    bool flag[4] = {0};

    scanf("%s",str);
    int l = strlen(str), step0, step1;
    int zero = 0, one = 0, mark = 0;
    if ( l % 2 )
    {
        step0 = max ( 0, (l-3) / 2);
        step1 = max ( 0, (l-1) / 2);
    }
    else step0 = step1 = (l-2) / 2;


    for ( int i = 0; i < l; i++ )
    {
        if ( str[i] == '0' ) zero++;
        if ( str[i] == '1' ) one++;
        if ( str[i] == '?' ) mark++;
    }

    if ( zero + mark > step0 && one <= step1 ) flag[0] = true;
    if ( one + mark > step1 && zero <= step0 ) flag[3] = true;
    if ( zero <= step0 + 1 && one <= step1 + 1 )
    {
        if ( zero == step0 + 1 && str[l-1] == '0' ) flag[2] = true;
        if ( zero < step0 + 1 && str[l-1] != '1' ) flag[2] = true;
        if ( one == step1 + 1 && str[l-1] == '1' ) flag[1] = true;
        if ( one < step1 + 1 && str[l-1] != '0' ) flag[1] = true;
    }
    for ( int i = 0; i <= 3; i++ )
        if ( flag[i] ) printf("%s\n",table[i]);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值