CSES - Datatähti 2022 loppu - Results
Submission details
Task:Pallo
Sender:Totska
Submission time:2022-01-22 15:07:59 +0200
Language:C++ (C++17)
Status:READY
Result:45
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED35
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s2, 3details
#3--3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:58:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(d > k){
                ~~^~~
input/code.cpp:112:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(d > k){
                    ~~^~~

Code

#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define fr(x) for(ll i = 0; i < x; i++)
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t, n, m, cycle, moves, x, y, changes, d;
unsigned ll k;
cin >> t;
fr(t)
{
cin >> n >> m >> k;
x = y = 1;
ll dv, dp;
dv = 1; dp = 1;
d = 0;
moves = cycle = changes = 0;
bool first = true;
while(true)
{
if(((x == 1 && y == 1) || (x == 1 && y == n) || (x == m && y == 1) || (x == m && y == n)) && !first){
cycle = changes;
break;
}
if(first){
first = false;
}
if(dv == 1){
if(dp == 1){
d = min(m-x, n-y);
}
else{
d = min(m-x, y-1);
}
}
else{
if(dp == 1){
d = min(x-1, n-y);
}
else{
d = min(x-1, y-1);
}
}
if(d > k){
break;
}
moves += d;
++changes;
k -= d;
x += dv * d; y += dp * d;
if(x == 1 || x == m){
dv *= -1;
}
if(y == 1 || y == n){
dp *= -1;
}
}
ll cyclesleft = 0;
if(cycle > 0){
changes += (k/moves) * cycle;
cyclesleft = k/moves;
k -= (k/moves) * moves;
}
if(k > 0){
if(cyclesleft % 2 == 1){
x = y = 1;
dv = 1; dp = 1;
}
while(true)
{
if(first){
first = false;
}
if(dv == 1){
if(dp == 1){
d = min(m-x, n-y);
}
else{
d = min(m-x, y-1);
}
}
else{
if(dp == 1){
d = min(x-1, n-y);
}
else{
d = min(x-1, y-1);
}
}
if(d > k){
break;
}
moves += d;
++changes;
k -= d;
x += dv * d; y += dp * d;
if(x == 1 || x == m){
dv *= -1;
}
if(y == 1 || y == n){
dp *= -1;
}
}
}
cout << changes << endl;
}
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
10 5 76
9 8 78
8 6 49
3 3 94
...

correct output
25
19
15
47
8
...

user output
25
19
15
47
8
...
Truncated

Test 2

Group: 2, 3

Verdict: ACCEPTED

input
1000
7 5 99033171167123849
6 8 472883555390027162
9 10 258937093512465880
10 6 691774305483997493
...

correct output
33011057055707949
148620545979722822
57541576336103529
199845910473154830
52151060432923288
...

user output
33011057055707949
148620545979722822
57541576336103529
199845910473154830
5215106043292328
...
Truncated

Test 3

Group: 3

Verdict:

input
1000
816332614 86098803 33572721929...

correct output
4310587870
45982113074
1550250683
717639357
3282221941
...

user output
(empty)