Codeforces Beta Round #97 (Div. 2)

來源:互聯網
上載者:User
E. Zero-Onetime 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
00011011
input
1010
output
10
input
1?1
output
0111

<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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.