0%

Codeforces 758C - Unfair Poll

Description

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. If there is only one row in the class, then the teacher always asks children from this row.

Input

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei. # Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
input
1 3 8 1 1
output
3 2 3
input
4 2 9 4 2
output
2 1 1
input
5 5 25 4 3
output
1 1 1
input
100 100 1000000000000000000 100 100
output
101010101010101 50505050505051 50505050505051

Note

The order of asking pupils in the first test:

the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; The order of asking pupils in the second test:

the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table;

Key

如此简单的题目竟然当时没做出来,心态爆炸。死在了边界和自作聪明上。 每个人从0开始编号,即0~m-1,以便于取模运算等。以提问第\(1, 2, 3, ....., n-1, n, n-1, ...4, 3, 2\)排的所有人为一轮,提问次数记为round,计算出除了最后一轮外一共的轮数rounds以及最后一轮被提问的最后一个人的位置。 若n=1或者n=2,单独考虑,此时相当于每一个人在每一轮里只被问了一遍。否则:

  1. 当最后一个人在第一排,则最小值为rounds,最大值为max(rounds+1,2*rounds),讨论Sergei有没有在最后一轮被提问且Sergei是不是第一排或最后一排的;
  2. 当最后一个人在第一排与最后一排之间且是第一次被提问,则最小值为rounds,最大值为2*rounds+1,讨论Sergei有没有在最后一轮被提问且Sergei是不是第一排或最后一排的;
  3. 当最后一个人在最后一排且不是最后一排最后一个人,则最小值为rounds,最大值为2*rounds+1,一样的还是要讨论Sergei情况;
  4. 当最后一个人在最后一排最后一个人时,则最小值为rounds+1,最大值为2*rounds+1,一样的还是要讨论Sergei情况;
  5. 当最后一个人在从后向前提问顺序(即第二次被提问)时,则最小值为rounds+1,最大值为2*rounds+2,一样的还是要讨论Sergei情况;

所以可能性还是稍微有点复杂的,尤其是讨论Sergei在不在第一排或最后一排的问题上。我还吃力不讨好地在一两种情况上面把完全不耗时间的(x == 1 || x == n) ? :优化成(x == 1) ? :(x == n) ? :,结果就优化出问题了。你说我何必呢。。。

最气的是,网上看到的题解都是模拟。。。二维数组一开,美滋滋。。。心态崩了。

Code

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
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n, m, k, x, y;
LL maxn, minn, midn;
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m >> k >> x >> y;
--k;
LL round = (n == 1 ? m : (2 * n - 2)*m);
LL rounds = k / round;
LL last = k % round;
if (n < 3) {
maxn = rounds + 1;
minn = ((last == round - 1) ? rounds + 1 : rounds);
midn = ((x - 1)*m + y - 1 > last ? minn : maxn);
}
else {
maxn = rounds * 2;
minn = rounds;
if (last < m) {
maxn = max(rounds * 2, rounds + 1);
if ((x - 1)*m + y - 1 > last) midn = ((x == 1 || x == n) ? rounds : rounds * 2);
else midn = rounds + 1;
}
else if (last < m*(n - 1)) {
++maxn;
if ((x - 1)*m + y - 1 > last) midn = ((x == n) ? rounds : rounds * 2);
else midn = ((x == 1) ? rounds + 1 : rounds * 2 + 1);
}
else if (last < m*n) {
++maxn;
if (last == m*n - 1)++minn;
if ((x - 1)*m + y - 1 > last) midn = rounds;
else midn = ((x == 1 || x == n) ? rounds + 1 : rounds * 2 + 1);
}
else {
maxn += 2;
++minn;
if (n*m + (n - x - 1)*m + y - 1 > last) midn = ((x == 1 || x == n) ? rounds + 1 : rounds * 2 + 1);
else midn = ((x == 1 || x == n) ? rounds + 1 : rounds * 2 + 2);
}
}
cout << maxn << ' ' << minn << ' ' << midn;
return 0;
}