Codeforces Round #412 (Div. 2)

A. Is it rated?

原题

Is it rated?

Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.

Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.

It’s known that if at least one participant’s rating has changed, then the round was rated for sure.

It’s also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant’s rating has changed.

In this problem, you should not make any other assumptions about the rating system.

Determine if the current round is rated, unrated, or it’s impossible to determine whether it is rated of not.

Input

The first line contains a single integer $n$ $(2 ≤ n ≤ 1000)$ — the number of round participants.

Each of the next n lines contains two integers $a_i$ and $b_i$ $(1 ≤ a_i, b_i ≤ 4126)$ — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.

Output

If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it’s impossible to determine whether the round is rated or not, print "maybe".

Examples

  • input
1
2
3
4
5
6
7
6
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884
  • output
1
rated
  • input
1
2
3
4
5
4
1500 1500
1300 1300
1200 1200
1400 1400
  • output
1
unrated
  • input
1
2
3
4
5
6
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
  • output
1
maybe

Note

In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.

In the second example, no one’s rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone’s rating would’ve changed for sure.

In the third example, no one’s rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it’s impossible to determine whether the round is rated or not.

思路

  • 根据题目的意思,如果有人的分数发生了变化,则一定是评级过的;而如果分数都是一样的,检查是否是降序排列,如果不是,则没有进行评级,否则便无法确定。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n;
int a[1002], b[1002];
while (cin >> n)
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
bool flag = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i] >> b[i];
if (a[i] != b[i])
flag = 1;
}
if (flag)
cout << "rated" << endl;
else
{
for (int i = 1; i < n; i++)
if (a[i] > a[i - 1] || b[i] > b[i - 1])
{
flag = 1;
break;
}
if (flag)
cout << "unrated" << endl;
else
cout << "maybe" << endl;
}
}
return 0;
}

B. T-Shirt Hunt

原题

Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.

Unfortunately, you didn’t manage to get into top 25, but you got into top 500, taking place $p$.

Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:

1
2
3
4
i := (s div 50) mod 475
repeat 25 times:
i := (i * 96 + 42) mod 475
print (26 + i)

Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.

As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.

You’re in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.

To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It’s difficult to do successful hacks, though.

You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?

Input

The only line contains three integers $p$, $x$ and $y$ $(26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000)$ — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.

Output

Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.

It’s guaranteed that your goal is achievable for any valid input data.

Examples

  • input
1
239 10880 9889
  • output
1
0
  • input
1
26 7258 6123
  • output
1
2
  • input
1
493 8000 8000
  • output
1
24
  • input
1
101 6800 6500
  • output
1
0
  • input
1
329 19913 19900
  • output
1
8

Note

In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places:

475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343

In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.

In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.

In the fourth example, it’s sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.

思路

  • 暴力搜索
  • 只要可以保证$x>y$,就能一直减50分; 然后看看你的分数能不能让你在第$p$名拿到奖品; 这种情况下,成功hack次数都为0。
  • 否则,每次考虑hack成功一次以及hack成功和失败各一次的情况。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;

int p;
bool judge(int s)
{
int i = (s / 50) % 475;
for (int j = 0; j < 25; j++)
{
i = (i * 96 + 42) % 475;
if (i + 26 == p)
return true;
}
return false;
}

int main()
{
int x, y;
while (cin >> p >> x >> y)
{
int cnt = 0;
int t = x;
bool flag = 0;
while (t - 50 >= y)
{
t -= 50;
if (judge(t))
{
flag = 1;
break;
}
}
if (flag)
cout << cnt << endl;
else
{
while (!judge(x))
{
cnt++;
x += 50;
if (judge(x))
break;
x += 50;
}
cout << cnt << endl;
}
}
return 0;
}

C. Success Rate

原题

You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to $x / y$.

Your favorite rational number in the $[0;1]$ range is $p / q$. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be $p / q$?

Input

The first line contains a single integer $t$ $(1 ≤ t ≤ 1000)$ — the number of test cases.

Each of the next t lines contains four integers $x$, $y$, $p$ and $q$ $(0 ≤ x ≤ y ≤ 10^9; 0 ≤ p ≤ q ≤ 10^9; y > 0; q > 0)$.

It is guaranteed that $p / q$ is an irreducible fraction.

Hacks. For hacks, an additional constraint of $t ≤ 5$ must be met.

Output

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

Example

  • input
1
2
3
4
5
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
  • output
1
2
3
4
4
10
0
-1

Note

In the first example, you have to make 4 successful submissions. Your success rate will be equal to $7 / 14$, or $1 / 2$.

In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to $9 / 24$, or $3 / 8$.

In the third example, there is no need to make any new submissions. Your success rate is already equal to $20 / 70$, or $2 / 7$.

In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to $1$.

思路

  • 题目意思为$$(x+a)/(y+b)=p/q$$

    $$x+a=np$$$$y+b=nq$$
    于是
    $$a=np-x$$$$b=nq-y$$
  • 可以得出,当$n$增大时,$a,b$也单调增加。
  • 可以使用二分法求得$n$的值从而计算出$b$。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;
while (t--)
{
int x, y, p, q;
long long a, b, mid, l = 0, r = 1e9, ans = -1;
cin >> x >> y >> p >> q;
while (l <= r)
{
mid = (l + r) / 2;
a = mid * p - x, b = mid * q - y;
if (a >= 0 && b >= 0 && a <= b)
{
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
if (ans == -1)
cout << -1 << endl;
else
cout << ans * q - y << endl;
}
return 0;
}

D. Dynamic Problem Scoring

原题

Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.

For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.

solvers fraction Maximum point value
$(1/2,1]$ $500$
$(1/4,1/2]$ $1000$
$(1/8,1/4]$ $1500$
$(1/16,1/8]$ $2000$
$(1/32,1/16]$ $2500$
$[0,1/32]$ $3000$

Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to $1 / 4$, and the problem’s maximum point value is equal to 1500.

If the problem’s maximum point value is equal to $x$, then for each whole minute passed from the beginning of the contest to the moment of the participant’s correct submission, the participant loses $x / 250$ points. For example, if the problem’s maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with $2000·(1 - 40 / 250) = 1680$ points for this problem.

There are $n$ participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It’s also possible that this participant made no submissions to this problem.

With two seconds until the end of the round, all participants’ submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.

Unfortunately, Vasya is a cheater. He has registered $10^9 + 7$ new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn’t solved.

Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn’t want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.

Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya’s assumptions are correct), or report that Vasya can’t achieve his goal.

Input

The first line contains a single integer $n$ $(2 ≤ n ≤ 120)$ — the number of round participants, including Vasya and Petya.

Each of the next $n$ lines contains five integers $a_{i, 1}, a_{i, 2}…, a_{i, 5}$ $( - 1 ≤ a_{i, j} ≤ 119)$ — the number of minutes passed between the beginning of the round and the submission of problem $j$ by participant $i$, or -1 if participant $i$ hasn’t solved problem $j$.

It is guaranteed that each participant has made at least one successful submission.

Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.

Output

Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can’t achieve his goal.

Examples

  • input
1
2
3
2
5 15 40 70 115
50 45 40 30 15
  • output
1
2
  • input
1
2
3
4
3
55 80 10 -1 -1
15 -1 79 60 -1
42 -1 13 -1 -1
  • output
1
3
  • input
1
2
3
4
5
6
5
119 119 119 119 119
0 0 0 0 -1
20 65 12 73 77
78 112 22 23 11
1 78 60 111 62
  • output
1
27
  • input
1
2
3
4
5
4
-1 20 40 77 119
30 10 73 50 107
21 29 -1 64 98
117 65 -1 -1 -1
  • output
1
-1

思路

  • 暴力搜索
  • 枚举有$k$人加入作弊,根据题目要求可以得到贪心方案:
    • 对于自己做得快的题,让这道题的解决率变低,让这题价值变高,即这$k$个人都没做对;
    • 对于自己做得慢的题,让这道题的解决率变高,让这题价值变低,即这$k$个人都做对;
    • 对于你自己都没做对的题,这$k$人也没法做对。
  • 注意搜索退出条件不需要很大(不然遇到无解会超时),当人数超过现有人数32倍的时候,再增加人数也对得分没有影响了。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;

int n;
int a[120][5];
int solve[5];
int cheat[5];

int cal(int time, int ac, int total)
{
if (time == -1)
return 0;
if (2 * ac > total)
return 2 * (250 - time);
if (4 * ac > total)
return 4 * (250 - time);
if (8 * ac > total)
return 6 * (250 - time);
if (16 * ac > total)
return 8 * (250 - time);
if (32 * ac > total)
return 10 * (250 - time);
return 12 * (250 - time);
}

bool check(int k)
{
for (int i = 0; i < 5; i++)
cheat[i] = solve[i];
for (int i = 0; i < 5; i++)
if (a[0][i] != -1)
{
if (a[1][i] == -1)
continue;
else if (a[0][i] > a[1][i])
cheat[i] += k;
}
int vasya = 0, petya = 0;
for (int i = 0; i < 5; i++)
{
vasya += cal(a[0][i], cheat[i], n + k);
petya += cal(a[1][i], cheat[i], n + k);
}
return vasya > petya;
}

int main()
{
bool flag = 0;
while (cin >> n)
{
memset(a, 0, sizeof(a[0][0]) * 120 * 5);
memset(solve, 0, sizeof(solve));
for (int i = 0; i < n; i++)
for (int j = 0; j < 5; j++)
{
cin >> a[i][j];
if (a[i][j] != -1)
solve[j]++;
}
for (int i = 0; i < 33 * n; i++)
if (check(i))
{
cout << i << endl;
flag = 1;
break;
}
if (!flag)
cout << -1 << endl;
}
return 0;
}

题目来源:Codeforces Round #412 (Div. 2)

捐助作者