# 【SoundHound Inc. Programming Contest 2018】 解题报告

Posted on

#### 比赛地址

– F
– Acrostic
– Ordinary Beauty
– Saving Snuuk
– Plus Graph

AB不讲。

### C – Ordinary Beauty

#### Statement

Let us define the beauty of a sequence $(a_1,… ,a_n)$ as the number of pairs of two adjacent elements in it whose absolute differences are $d$.
For example, when $d=1$, the beauty of the sequence $(3, 2, 3, 10, 9)$ is $3$.

There are a total of $n^m$sequences of length $m$ where each element is an integer between $1$ and $n$ (inclusive).
Find the beauty of each of these $n^m$ sequences, and print the average of those values.

### D – Saving Snuuk

#### Statement

Kenkoooo is planning a trip in Republic of Snuke.
In this country, there are $n$ cities and $m$ trains running.
The cities are numbered $1$ through $n$, and the $i$-th train connects City $u_i$ and $v_i$ bidirectionally.
Any city can be reached from any city by changing trains.

Two currencies are used in the country: yen and snuuk.
Any train fare can be paid by both yen and snuuk.
The fare of the $i$-th train is $a_i$ yen if paid in yen, and $b_i$ snuuk if paid in snuuk.

In a city with a money exchange office, you can change $1$ yen into $1$ snuuk.
However, when you do a money exchange, you have to change all your yen into snuuk.
That is, if Kenkoooo does a money exchange when he has $X$ yen, he will then have $X$ snuuk.
Currently, there is a money exchange office in every city, but the office in City $i$ will shut down in $i$ years and can never be used in and after that year.

Kenkoooo is planning to depart City $s$ with $10^{15}$ yen in his pocket and head for City $t$, and change his yen into snuuk in some city while traveling.
It is acceptable to do the exchange in City $s$ or City $t$.

Kenkoooo would like to have as much snuuk as possible when he reaches City $t$ by making the optimal choices for the route to travel and the city to do the exchange.
For each $i=0,…,n-1$, find the maximum amount of snuuk that Kenkoooo has when he reaches City $t$ if he goes on a trip from City $s$ to City $t$ after $i$ years.
You can assume that the trip finishes within the year.

### E – Plus Graph

#### Statement

Kenkoooo found a simple connected graph.
The vertices are numbered $1$ through $n$.
The $i$-th edge connects Vertex $u_i$ and $v_i$, and has a fixed integer $s_i$.

Kenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:

• For every edge $i$, the sum of the positive integers written in Vertex $u_i$ and $v_i$ is equal to $s_i$.

Find the number of such ways to write positive integers in the vertices.