CSES - Datatähti 2022 loppu - Results
Submission details
Task:Pallo
Sender:andreibe
Submission time:2022-01-22 15:13:38 +0200
Language:C++ (C++11)
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.64 s1, 2, 3details
#2--2, 3details
#30.03 s3details

Code

#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <algorithm>
#include <vector>
#include <fstream>
#include <set>
#include <unordered_map>
#include <queue>
#include <climits>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define LOOP(i,a,l) for (int i = a; i < l; i++)
#define LUO_VERKKO LOOP(i,0,m) {int a,b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a);}
#define COLLECT for (int i = 0; i < n; i++) cin >> s[i]
#define PRINT_LIST(l) for (int i = 0; i < l.size(); i++) cout << l[i] << " "
#define S second
#define F first
#define A 999999999999999999LL
#define M 1000000007
//https://cses.fi/dt/
int n;
int t;
pair<int, int> d[1000][1000][5];
#define N (1<<17)
int main() {
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		int n, m; cin >> n >> m;
		ll k; cin >> k;
		k--;
		int x = 1;
		int y = 1;
		int c = 0;
		int dir = 3;
		int moves = 0;
		for (int o = 0; o < 1000; o++)
		{
			for (int j = 0; j < 1000; j++)
			{
				for (int l = 0; l < 5; l++)
				{
					d[o][j][l] = { 0,0 };
				}
			}
		}
		while (k >= 0) {
			if (d[x][y][dir].first) {
				//loop
				int org = c;
				int lol = k / moves;
				k -= (lol * (ll)moves);
				c += (org * lol);
				moves += lol * moves;
			}
			if (x == 0 || y == 0 || x == m - 1 || y == n - 1) c++;
			if (x == 0) {
				if (dir == 2) dir = 3;
				if (dir == 1) dir = 4;
			}
			if (y == 0) {
				if (dir == 1) dir = 2;
				if (dir == 4) dir = 3;
			}
			if (x == m - 1) {
				if (dir == 3) dir = 2;
				if (dir == 4) dir = 1;
			}
			if (y == n - 1) {
				if (dir == 2) dir = 1;
				if (dir == 3) dir = 4;
			}
			moves++;
			d[x][y][dir] = { moves,c };
			k--;
			if (dir == 1) {
				x--;
				y--;
			}
			if (dir == 2) {
				x--;
				y++;
			}
			if (dir == 3) {
				x++;
				y++;
			}
			if (dir == 4) {
				x++;
				y--;
			}
		}
		cout << c << "\n";
	}
}

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:

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

correct output
33011057055707949
148620545979722822
57541576336103529
199845910473154830
52151060432923288
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
1000
816332614 86098803 33572721929...

correct output
4310587870
45982113074
1550250683
717639357
3282221941
...

user output
(empty)