To solve this problem, you just had to read the problem statement carefully. Looking through the explanations for the example cases was pretty useful.
How do we check if the round is rated for sure?
The round is rated for sure if anyone's rating has changed, that is, if ai ≠ bi for some i.
How do we check if the round is unrated for sure?
Given that all ai = bi, the round is unrated for sure if for some i < j we have ai < aj. This can be checked using two nested for-loops over i and j.
Exercise: can you check the same using one for-loop?
How do we find that it's impossible to determine if the round is rated or not?
If none of the conditions from steps 1 and 2 is satisfied, the answer is "maybe
".
n = int(input())
results = []
for i in range(n):
results.append(list(map(int, input().split())))
for r in results:
if r[0] != r[1]:
print("rated")
exit()
for i in range(n):
for j in range(i):
if results[i][0] > results[j][0]:
print("unrated")
exit()
print("maybe")
This problem was inspired by this comment. The hacks don't necessarily have to be stupid, though :)
Initially, we have x points. To win the current round, we need to score any number of points s such that s ≥ y.
If we know our final score s, we can check if we get the T-shirt using the given pseudocode. Moreover, since hacks change our score only by multiples of 50, the difference s - x has to be divisible by 50.
Naturally, out of all s satisfying the conditions above, we need to aim at the smallest possible s, since it's easy to decrease our score, but difficult to increase.
How many successful hacks do we need to make our score equal to s?
If s ≤ x, we need 0 successful hacks, since we can just make (x - s) / 50 unsuccessful hacks.
If s > x and s - x is divisible by 100, we need exactly (s - x) / 100 successful hacks.
If s > x and s - x is not divisible by 100, we need (s - x + 50) / 100 successful hacks and one unsuccessful hack.
All these cases can be described by a single formula for the number of successful hacks: (max(0, s - x) + 50) / 100 (here " / " denotes integer division).
#include <bits/stdc++.h>
using namespace std;
int main() {
int p, x, y;
cin >> p >> x >> y;
for (int s = y; ; s++) {
if (s % 50 != x % 50) {
continue;
}
bool me = false;
int i = s / 50 % 475;
for (int j = 0; j < 25; j++) {
i = (i * 96 + 42) % 475;
if (i + 26 == p) {
me = true;
break;
}
}
if (me) {
printf("%d\n", (max(0, s - x) + 50) / 100);
break;
}
}
return 0;
}
The constraints were low enough, and the number of required hacks was also low enough. A less effective but easier solution can be achieved if we just iterate over both the number of successful and unsuccessful hacks we make. Once we know these two numbers, we know our final score s and we can explicitly check if this score gives us both the victory and the T-shirt.
p, x, y = map(int, input().split())
def check(s):
i = (s // 50) % 475
for t in range(25):
i = (i * 96 + 42) % 475
if 26 + i == p:
return True
return False
for up in range(500):
for down in range(500):
if x + 100 * up - 50 * down >= y and check(x + 100 * up - 50 * down):
print(up)
exit()
assert(False)