CSES - Harjoituskisa 7.1.2018 - Results
Submission details
Task:Ruudukko
Sender:Nanohenry
Submission time:2018-01-07 21:27:16 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool isOK(long int, long int, std::vector<long int>, std::vector<long int>)':
input/code.cpp:13:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (long i = 0; i < xs.size(); i++) {
                     ^
input/code.cpp: In function 'int getB(std::string*, long int, long int, long int, std::vector<long int>, std::vector<long int>)':
input/code.cpp:26:57: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  } else if ((o1 < o2 && x < mi) || (o1 > o2 && y >= mi) && isOK(x + 1, y, xs, ys)) {
                                                         ^
input/code.cpp:28:57: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  } else if ((o1 > o2 && y < mi) || (o1 < o2 && x >= mi) && isOK(x, y + 1, xs, ys)) {
                                                         ^
input/code.cpp: In function 'long int getSum(std::string)':
input/code.cpp:36:20: warning: comparison between signed...

Code

#include <iostream>
#include <string>
#include <vector>

#define NONE 0
#define RIGHT 1
#define DOWN 2
#define BOTH 3

using namespace std;

bool isOK(long x, long y, vector<long> xs, vector<long> ys) {
	for (long i = 0; i < xs.size(); i++) {
		if (x == xs[i] && y == ys[i]) {
			return false;
		}
	}
	return true;
}

int getB(string t[], long x, long y, long mi, vector<long> xs, vector<long> ys) {
	int o1 = t[y][x + 1]; // Right
	int o2 = t[y + 1][x]; // Down
	if (o1 == o2 && x < mi && y < mi && isOK(x + 1, y, xs, ys) && isOK(x, y + 1, xs, ys)) {
		return BOTH;
	} else if ((o1 < o2 && x < mi) || (o1 > o2 && y >= mi) && isOK(x + 1, y, xs, ys)) {
		return RIGHT;
	} else if ((o1 > o2 && y < mi) || (o1 < o2 && x >= mi) && isOK(x, y + 1, xs, ys)) {
		return DOWN;
	}
	return NONE;
}

long getSum(string s) {
	long sum = 0;
	for (int i = 0; i < s.size(); i++) {
		sum += s[i];
	}
	return sum;
}

int main() {
	long n;
	cin >> n;
	vector<string> t;
	string tmp;
	for (long i = 0; i < n; i++) {
		cin >> tmp;
		t.push_back(tmp);
	}
	string smallest = "";
	long smallestNum = 4294967295;
	string p = "";
	long x = 0;
	long y = 0;
	p += t[x][y];
	vector<long> xs;
	vector<long> ys;

	while (1) {
		switch (getB(t, x, y, n - 1, xs, ys)) {
			case RIGHT:
				x++;
				break;
			case DOWN:
				y++;
				break;
			case BOTH:
				x++;
				xs.push_back(x);
				ys.push_back(y);
				break;
		}
		p += t[x][y];
		if (x == n - 1 && y = n - 1) {
			x = 0;
			y = 0;
			if (getSum(p) < smallestNum) {
				smallestNum = getSum(p);
				smallest = p;
			}
		}
	}
	cout << p;
	//while (1);
}