(这次除了没写F题,比的还是挺好的)
(E题也没时间看,所以只A了前四题)
[Task]
A. Night at the Museum
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard outputGrigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to “print” the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it’s allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter ‘a’. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It’s not required to return the wheel to its initial position with pointer on the letter ‘a’.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It’s guaranteed that the string consists of only lowercase English letters.
Output
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
B. Coupons and Discounts
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard outputThe programming competition season has already started and it’s time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it’s not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition.
Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day.
There are two types of discounts in Sereja’s favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total).
As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days.
Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it’s also prohibited to have any active coupons after the end of the day n.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, …, an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.
Output
If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print “YES” (without quotes) in the only line of output. Otherwise, print “NO” (without quotes).
C. Socks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard outputArseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy’s clothes.
Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy’s family is a bit weird so all the clothes is enumerated. For example, each of Arseniy’s n socks is assigned a unique integer from 1 to n. Thus, the only thing his mother had to do was to write down two integers li and ri for each of the days — the indices of socks to wear on the day i (obviously, li stands for the left foot and ri for the right). Each sock is painted in one of k colors.
When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses k jars with the paint — one for each of k colors.
Arseniy wants to repaint some of the socks in such a way, that for each of m days he can follow the mother’s instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now.
The new computer game Bota-3 was just realised and Arseniy can’t wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother’s instructions and wear the socks of the same color during each of m days.
Input
The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively.
The second line contain n integers c1, c2, …, cn (1 ≤ ci ≤ k) — current colors of Arseniy’s socks.
Each of the following m lines contains two integers li and ri (1 ≤ li, ri ≤ n, li ≠ ri) — indices of socks which Arseniy should wear during the i-th day.
Output
Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.
D. 80-th Level Archeology
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard outputArcheologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of n words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hieroglyphs according to some rules. The instruction nearby says that the door will open only if words written on the lock would be sorted in lexicographical order (the definition of lexicographical comparison in given in notes section).
The rule that changes hieroglyphs is the following. One clockwise rotation of the round switch replaces each hieroglyph with the next hieroglyph in alphabet, i.e. hieroglyph x (1 ≤ x ≤ c - 1) is replaced with hieroglyph (x + 1), and hieroglyph c is replaced with hieroglyph 1.
Help archeologist determine, how many clockwise rotations they should perform in order to open the door, or determine that this is impossible, i.e. no cyclic shift of the alphabet will make the sequence of words sorted lexicographically.
Input
The first line of the input contains two integers n and c (2 ≤ n ≤ 500 000, 1 ≤ c ≤ 106) — the number of words, written on the lock, and the number of different hieroglyphs.
Each of the following n lines contains the description of one word. The i-th of these lines starts with integer li (1 ≤ li ≤ 500 000), that denotes the length of the i-th word, followed by li integers wi, 1, wi, 2, …, wi, li (1 ≤ wi, j ≤ c) — the indices of hieroglyphs that make up the i-th word. Hieroglyph with index 1 is the smallest in the alphabet and with index c — the biggest.
It’s guaranteed, that the total length of all words doesn’t exceed 106.
Output
If it is possible to open the door by rotating the round switch, print integer x (0 ≤ x ≤ c - 1) that defines the required number of clockwise rotations. If there are several valid x, print any of them.
If it is impossible to open the door by this method, print - 1.
E. Funny Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard outputOnce upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won’t stop them.
The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.
One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move.
Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.
Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya’s and Gena’s score if both players play optimally.
Input
The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall.
The second line contains n integers a1, a2, …, an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.
Output
Print one integer — the difference between the Petya’s score and Gena’s score at the end of the game if both players play optimally.
F. Video Cards
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard outputLittle Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.
There are n video cards in the shop, the power of the i-th video card is equal to integer value ai. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it’s required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can’t be reduced.
Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.
The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 200 000) — powers of video cards.
Output
The only line of the output should contain one integer value — the maximum possible total power of video cards working together.
[Solution]
A:
读题永远比做题久
每次判一下是顺时针转还是逆时针转,然后就好了.
B:
B题读了更久有两种决策:
- 一天买两个.
- 连续两天每天买一个.
显然从左往右先考虑第一种,再考虑第二种.
第一种只对一个数操作,不会影响其它数,选择它一定不会导致无解.
所以尽量选择第一种.
C:
把一天的两双袜子并成一个集合.
(把一天的两双袜子的集合并成一个集合)
一定会形成很多集合.一个集合的颜色要一样,.
所以选择一个颜色个数最多的颜色,把集合染成这个颜色.
D:
同时考虑全局的情况是很难考虑的
但是容易想到的一点是,每一段数对于下一段可行或不可行(即所有文字加一个数,字典序是否小于下一段)的转动次数一定是一段或两段连续的区间.
所以把不可行的区间求出来,就可以找到可行解了(求可行区间应该做不出来(后来发现差分前缀和一下就好了,更方便))
E:
E题其实做过,结果没时间写.
求出的值就是:
f(A)−f(B)+f(A)−f(B).........
即:
f(A)−(f(B)−(f(A)−(f(B)....)))
就是:
dp[x]=sum[x]−maxi=1x−1(dp[y])
F:
F题真是坑,E题根本没看也就算了,F题看了没时间写.
记一下前缀和,然后调和级数暴力就好了.
for (int i=1;i<=200000;++i) { if (!cnt[i]) continue; long long k=0; for (int j=i+i-1;j<=400000;j+=i) { k+=1LL*(sum[j]-sum[j-i])*(j-i+1); } ans=max(ans,k); }