CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:Sahari Kempo
Submission time:2021-10-10 21:17:19 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:14:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < m.size(); i++) m[i].resize(n);
              ~~^~~~~~~~~~
input/code.cpp:18:14: error: 'powl' was not declared in this scope
  while (x <= powl(n + 1, 2))
              ^~~~
input/code.cpp:18:14: note: suggested alternative: 'bool'
  while (x <= powl(n + 1, 2))
              ^~~~
              bool

Code

#include <iostream>
#include <vector>
using namespace std;



int main()
{
	long long n, t, x = 1, i, y;
	int p = 0;
	cin >> n >> t;
	vector<vector<long long>> m(1);
	m.resize(n);
	for (i = 0; i < m.size(); i++) m[i].resize(n);

	int b = 0;
	n -= 1;
	while (x <= powl(n + 1, 2))
	{
		for (i = 0; i <= n; i++) {
			if (b == 0) {
				if (m[i][p] == 0) m[i][p] = x;
				else x--;
			}
			else if (b == 1) {
				if (m[n - p][i] == 0) m[n - p][i] = x;
				else x--;
			}
			else if (b == 2) {
				if (m[n - i][n - p] == 0) m[n - i][n - p] = x;
				else x--;
			}
			else if (b == 3) {
				if (m[p][n - i] == 0) m[p][n - i] = x;
				else x--;
			}
			x++;
		}
		if (b == 3) {
			b = 0;
			p++;
		}
		else b++;
		if (p > n) p = n;
	}

	vector<long long> l;
	for (i = 0; i < t; i++)
	{
		cin >> x >> y;
		l.push_back(m[x - 1][y - 1]);
	}

	for (i = 0; i < t; i++)
	{
		cout << l[i] << "\n";
	}
}