FRI Summer School Final Contest. A. Flipping Game

Similar documents
Southeastern European Regional Programming Contest Bucharest, Romania Vinnytsya, Ukraine October 21, Problem A Concerts

Problem Set 7: Games Spring 2018

Problem F. Chessboard Coloring

Problem A To and Fro (Problem appeared in the 2004/2005 Regional Competition in North America East Central.)

Problem A. First Mission

Problem 2A Consider 101 natural numbers not exceeding 200. Prove that at least one of them is divisible by another one.

The 2016 ACM-ICPC Asia China-Final Contest Problems

CS 787: Advanced Algorithms Homework 1

UCF Local Contest August 31, 2013

Problem A. Worst Locations

Problem Set 7: Network Flows Fall 2018

Q i e v e 1 N,Q 5000

ProCo 2017 Advanced Division Round 1

Junior Circle Meeting 5 Probability. May 2, ii. In an actual experiment, can one get a different number of heads when flipping a coin 100 times?

Problem A Rearranging a Sequence

COCI 2017/2018. Round #1, October 14th, Tasks. Task Time limit Memory limit Score. Cezar 1 s 64 MB 50. Tetris 1 s 64 MB 80

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

12. 6 jokes are minimal.

TASK NOP CIJEVI ROBOTI RELJEF. standard output

COCI 2008/2009 Contest #4, 17 th January 2009 TASK MJEHURIC DATUM ROT SLIKAR TREZOR PERIODNI

2015 ACM ICPC Southeast USA Regional Programming Contest. Division 1

ACM International Collegiate Programming Contest 2010

SMT 2014 Advanced Topics Test Solutions February 15, 2014

1. Completing Sequences

PUTNAM PROBLEMS FINITE MATHEMATICS, COMBINATORICS

COCI 2008/2009 Contest #1, 18 th October 2008 TASK SKOCIMIS PTICE MRAVOJED JEZ SKAKAVAC KRTICA

SGU 149. Computer Network. time limit per test: 0.50 sec. memory limit per test: 4096 KB input: standard input output: standard output

1. An office building contains 27 floors and has 37 offices on each floor. How many offices are in the building?

The Product Rule can be viewed as counting the number of elements in the Cartesian product of the finite sets

Buzz Contest Rules and Keywords

Problem A: Ordering supermarket queues

Problem A. Alignment of Code

George Fox University H.S. Programming Contest Division - I 2018

INTERNATIONAL MATHEMATICS TOURNAMENT OF TOWNS Junior A-Level Paper, Spring 2014.

Theory of Probability - Brett Bernstein

COCI 2008/2009 Contest #5, 7 th February 2009 TASK LJESNJAK JABUKA JAGODA LUBENICA TRESNJA KRUSKA

2009 ACM ICPC Southeast USA Regional Programming Contest. 7 November, 2009 PROBLEMS

Outcome X (1, 1) 2 (2, 1) 3 (3, 1) 4 (4, 1) 5 {(1, 1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (6, 1) (6, 2) (6, 3) (6, 4) (6, 5) (6, 6)}

MATH 215 DISCRETE MATHEMATICS INSTRUCTOR: P. WENG

ACM ICPC World Finals Warmup 2 At UVa Online Judge. 7 th May 2011 You get 14 Pages 10 Problems & 300 Minutes

Random Variables. A Random Variable is a rule that assigns a number to each outcome of an experiment.

BAPC The Problem Set

Random Variables. Outcome X (1, 1) 2 (2, 1) 3 (3, 1) 4 (4, 1) 5. (6, 1) (6, 2) (6, 3) (6, 4) (6, 5) (6, 6) }

2013 Mid-Atlantic Regional Programming Contest

Sponsored by IBM. 2. All programs will be re-compiled prior to testing with the judges data.

BALDWIN WALLACE UNIVERSITY 2016 HIGH SCHOOL PROGRAMMING CONTEST

Contest 1. October 20, 2009

Problem A The Amazing Human Cannonball

Fall 2018 #8 DFS-Strong-Comps. A. Cut 'em all! 1 second, 256 megabytes

THE G C SCHOOL OF CAREERS MATHEMATICS SCHOOL

2016 Canadian Computing Olympiad Day 2, Problem 1 O Canada

TASK PATRIK POLICIJA SABOR

4th Pui Ching Invitational Mathematics Competition. Final Event (Secondary 1)

2009 Philippine Elementary Mathematics International Contest Page 1

Table of Contents. Table of Contents 1

TASK BELA PUTOVANJE PIANINO PAROVI KRUMPIRKO SAN. standard input (stdin) standard output (stdout)

Discrete Structures Lecture Permutations and Combinations

Grade 7/8 Math Circles Game Theory October 27/28, 2015

Foundations of Computing Discrete Mathematics Solutions to exercises for week 12

Lecture 2: Sum rule, partition method, difference method, bijection method, product rules

16.410/413 Principles of Autonomy and Decision Making

4. The terms of a sequence of positive integers satisfy an+3 = an+2(an+1 + an), for n = 1, 2, 3,... If a6 = 8820, what is a7?

Philadelphia Classic 2013 Hosted by the Dining Philosophers University of Pennsylvania

NIM Games: Handout 1

2013 ACM ICPC Southeast USA Regional Programming Contest. 2 November, Division 1

Counters in a Cup In and Out. The student sets up the cup, drops the counters on it, and records how many landed in and out of the cup.

Detailed Solutions of Problems 18 and 21 on the 2017 AMC 10 A (also known as Problems 15 and 19 on the 2017 AMC 12 A)

COUNTING AND PROBABILITY

UNC Charlotte 2012 Comprehensive

BMT 2018 Combinatorics Test Solutions March 18, 2018

PRIMES STEP Plays Games

Section 6.1 #16. Question: What is the probability that a five-card poker hand contains a flush, that is, five cards of the same suit?

CS1800: More Counting. Professor Kevin Gold

Game Theory and Algorithms Lecture 19: Nim & Impartial Combinatorial Games

Problem A. Subway Tickets

4.12 Practice problems

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

The 2012 ACM-ICPC Asia Regional Contest Chengdu Site

2. The Extensive Form of a Game

Final Practice Problems: Dynamic Programming and Max Flow Problems (I) Dynamic Programming Practice Problems

Solving Big Problems

Section Notes 6. Game Theory. Applied Math 121. Week of March 22, understand the difference between pure and mixed strategies.

6.1 Basics of counting

TASK FUNGHI ZMIJA TRAKTOR ZGODAN JABUKE DIVLJAK. standard input (stdio) standard output (stdout)

Love Is The Answer Lyrics

SAPO Finals 2017 Day 2 Cape Town, South Africa, 8 October standard output

Problems translated from Croatian by: Ivan Pilat

I.M.O. Winter Training Camp 2008: Invariants and Monovariants

The tenure game. The tenure game. Winning strategies for the tenure game. Winning condition for the tenure game

Date. Probability. Chapter

Dependence. Math Circle. October 15, 2016

Introduction to Mathematical Reasoning, Saylor 111

6 Sources of Acting Career Information

The $1,000,000 MathPickle Problems

Today s Topics. Sometimes when counting a set, we count the same item more than once

Problem A. Vera and Outfits

1. Let X be a continuous random variable such that its density function is 8 < k(x 2 +1), 0 <x<1 f(x) = 0, elsewhere.

Data Collection Sheet

! Denver, CO! Demystifying Computing with Magic, continued

Senior Math Circles February 10, 2010 Game Theory II

Transcription:

Iahub got bored, so he invented a game to be played on paper. FRI Summer School 201 - Final Contest A. Flipping Game : standard : standard He writes n integers a 1, a 2,..., a n. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 i j n) and flips all values a for which their positions are in range [i, j] (that is i k j). Flip the value of x means to apply operation x = 1 - x. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. The first line of the contains an integer n (1 n 100). In the second line of the there are n integers: a 1, a 2,..., a n. It is guaranteed that each of those n values is either 0 or 1. Print an integer the maximal number of 1s that can be obtained after exactly one move. 5 10010 1001 k Note In the first case, flip the segment from 2 to 5 (i = 2, j = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (i = 2, j = 3) will turn all numbers into 1.

B. Prison Transfer : standard : standard The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was. Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are, The chosen c prisoners has to form a contiguous segment of prisoners. Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer. Find the number of ways you can choose the c prisoners. 5 The first line of will contain three space separated integers n (1 n 2 10 ), t (0 t 10 ) and c (1 c n). The next line will contain n th th space separated integers, the i integer is the severity i prisoner's crime. The value of crime severities will be non-negative and will not exceed 10. Print a single integer the number of ways you can choose the c prisoners. 33 2311 2 111 2 0 112 22073221 6

C. Inna and Choose Options : standard : standard There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers a and b (a b = 12), after that he makes a table of size a b from the cards he put on the table as follows: the first b cards form the first row of the table, the second b cards form the second row of the table and so on, the last b cards form the last (number a) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses. Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers a and b to choose. Help her win the game: print to her all the possible ways of numbers a, b that she can choose and win. The first line of the contains integer t (1 t 100). This value shows the number of sets of test data in the. Next follows the description of each of the t tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The i-th character of the string shows the character that is written on the i-th card from the start. For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair a, b. Next, print on this line the pairs in the format axb. Print the pairs in the order of increasing first parameter (a). Separate the pairs in the line by whitespaces. OXXXOXOOXOOX OXOXOXOXOXOX XXXXXXXXXXXX OOOOOOOOOOOO 31x122x6x3 1x122x63x6x2 61x122x63xx36x212x1 0

D. Palindromic Times time limit per test: 2 seconds : standard : standard Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues. On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome. In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment. However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him. The first and only line of the starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "5". Both "HH" and "MM" have exactly two digits. Print the palindromic time of day that comes soonest after the time given in the. If the time is palindromic, the soonest palindromic time after the time. 12:21 13:31 23:5 00:00

E. k-tree : standard : standard Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree. A k-tree is an infinite rooted tree where: each vertex has exactly k children; each edge has some weight; if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3,..., k. The picture below shows a part of a 3-tree. As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?". Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (10 + 7). A single line contains three space-separated integers: n, k and d (1 n, k 100; 1 d k). Print a single integer the answer to the problem modulo 1000000007 (10 + 7). 332 3 333 1 32 6 52 7

F. Queue time limit per test: 2 seconds : standard : standard There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to a i. The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that a > a. The displeasure i j of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is. The airport manager asked you to count for each of n walruses in the queue his displeasure. 5 The first line contains an integer n (2 n 10 ) the number of walruses in the queue. The second line contains integers a i (1 a i 10 ). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. 6 10853505 210-10-1 7 10632815 210-1-1-1 5 10311011 10-1-1-1

G. Long Path : standard : standard One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 i n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number p, where 1 p i. In order not to get lost, Vasya decided to act as follows. Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room p i), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. 3 The first line contains integer n (1 n 10 ) the number of rooms. The second line contains n integers p i (1 p i i). Each p i denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Print a single number the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (10 + 7). 2 12 1123 20 5 11111 62 i i

H. Match & Catch memory limit per test: 512 megabytes : standard : standard Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings s and s from two different 1 2 frequencies as signals. They are suspecting that these two strings are from two different criminals and they are planning to do some evil task. Now they are trying to find a common substring of minimum length between these two strings. The substring must occur only once in the first string, and also it must occur only once in the second string. Given two strings s 1 and s 2 consist of lowercase Latin letters, find the smallest (by length) common substring p of both s 1 and s 2, where p is a unique substring in s and also in s. See notes for formal definition of substring and uniqueness. The first line of contains s 1 and the second line contains s 2 (1 s 1, s 2 5000). Both strings consist of lowercase Latin letters. Print the length of the smallest common unique substring of s 1 and s 2. If there are no common unique substrings of s 1 and s 2 print -1. apple pepperoni 2 lover driver 1 bidhan roy -1 testsetses teeptes 3 1 2 Note th Imagine we have string a = a1a2a 3...a a, where a is the length of string a, and a i is the i letter of the string. We will call string a a a...a (1 l r a ) the substring [l, r] of the string a. l l + 1 l + 2 r The substring [l, r] is unique in a if and only if there is no pair l, r such that l l and the substring [l, r ] is equal to the substring [l, r] in a. 1 1 1 1 1 Codeforces (c) Copyright 2010-201 Mike Mirzayanov The only programming contests Web 2.0 platform