This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM496 - div2 - level one | |
A string X is an anagram of string Y if X can be obtained by arranging | |
all characters of Y in some order, without removing any characters and | |
without adding new characters. For example, each of the strings "baba", | |
"abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", | |
"aab" and "aabc" are not anagrams of "aabb". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM488 - div2 - level one | |
John and Brus are bored. They have n+m common friends. | |
The first n of them are bored and other m are not. | |
John chooses the j-th (1-based) friend for a talk. | |
If the friend is not bored, he becomes bored after the talk. | |
Brus does the same with the b-th (1-based) friend. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM486 - div2 - level one | |
Strange abbreviations are often used to write text messages | |
on uncomfortable mobile devices. One particular strategy for | |
encoding texts composed of alphabetic characters and spaces | |
is the following: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM496 - div2 - level two | |
Manao has a bitmap H pixels high and W pixels wide. | |
Initially, each of the pixels is white. | |
Manao draws several (possibly zero) horizontal and/or | |
vertical strokes. A stroke is a line segment 1 pixel | |
thick and 1 or more pixels long. Manao only draws horizontal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM494 - div2 - level two | |
Normally Mr. Grey is not a painter, but he recently had | |
an absolutely brilliant idea for a picture. He thinks | |
that once drawn, it will bring him world-wide fame. | |
The picture will be painted on an NxM sheet of white paper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM493 - div2 - level two | |
Romeo and his friend Strangelet are playing a game. | |
There are N stones in a row, all of which are black | |
except for the M-th one, which is white (all positions | |
in this problem are 1-based). The players alternate turns, | |
and Romeo plays first. On each turn, a player must |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM490 - div2 - level two | |
A new starport has just started working. Starting from some | |
moment of time (call it minute 0), a new spaceship arrives | |
at the starport every M minutes. In other words, spaceships | |
arrive at the starport at minutes 0, M, 2*M, 3*M and so on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM497 - div2 - level two | |
The signature of a permutation is a string that is | |
computed as follows: for each pair of consecutive elements | |
of the permutation, write down the letter 'I' (increasing) | |
if the second element is greater than the first one, | |
otherwise write down the letter 'D' (decreasing). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM485 - div2 - level two | |
A sequence of integers a[0], a[1], ..., a[N-1], where N >= 3, | |
is called an arithmetic progression if the difference between | |
any two successive terms in the sequence is a constant. | |
More precisely, it is an arithmetic progression | |
if a[i] - a[i-1] = a[i+1] - a[i] for every integer i such |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""SRM484 - div2 - level two | |
When cat Taro and rabbit Hanako were practicing hard for SRM 484, | |
they noticed an interesting property of 484. | |
They called it Rabbit Number. | |
Let S(n) be the sum of the digits of n. For example, |