CSES - Harjoituskisa 7.1.2018 - Results
Submission details
Task:Ruudukko
Sender:Nanohenry
Submission time:2018-01-07 21:29:00 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1--1details
#20.21 s1details
#30.24 s1details
#40.18 s1details
#5--1details
#6--2details
#70.20 s2details
#8--2details
#90.22 s2details
#10--2details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details

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::vector<std::basic_string<char> >, 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: c...

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(vector<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);
}

Test details

Test 1

Group: 1

Verdict:

input
5
ILRBG
SBRHV
PAGKM
YKKNG
...

correct output
ILBAGKMGQ

user output
(empty)

Test 2

Group: 1

Verdict:

input
5
KQQBB
IWDQN
TENSD
PGXMV
...

correct output
KITEGMIWH

user output
(empty)

Test 3

Group: 1

Verdict:

input
5
DSWIO
RWFDY
ISZRK
GBVYS
...

correct output
DRIGBJDLU

user output
(empty)

Test 4

Group: 1

Verdict:

input
5
VGQFP
FTISL
QCLYU
EYNZZ
...

correct output
VFQCLNRZP

user output
(empty)

Test 5

Group: 1

Verdict:

input
5
WCSNV
UWNDB
WDHZA
XGRBQ
...

correct output
WCSNDBAQW

user output
(empty)

Test 6

Group: 2

Verdict:

input
100
WFNOQZOAMZPHFRDYGXQNUPWVMFDNJF...

correct output
WFAHHJDEVFSGGOGMIFDEEDKPSHBBRX...

user output
(empty)

Test 7

Group: 2

Verdict:

input
100
UEOPTOSBCABXIPUOQRKWKMZRGRZUSS...

correct output
UEGHLIWDHDVKTECPACBJABFMBOASOF...

user output
(empty)

Test 8

Group: 2

Verdict:

input
100
XCKBHDFAPMFZNJANJUENHGXYBBHFJR...

correct output
XCCENJBCBUFBIOJOJDREIBGRUKVRQS...

user output
(empty)

Test 9

Group: 2

Verdict:

input
100
YEBXYYLVUDYIHNUMRCUTAYVTNLMEZL...

correct output
YDJNBALIRDOVFBKDDJDFNSSMIDMFRM...

user output
(empty)

Test 10

Group: 2

Verdict:

input
100
MVONBCDHJUKRKDGPNYSYGRXBLZOMLD...

correct output
MMSJFIKBSFCUMBBLXJCOUIRAPOKEJS...

user output
(empty)

Test 11

Group: 3

Verdict:

input
2500
LKEFOYQTRZJHADSYBRGQCUDOPMGYOF...

correct output
LDHPNOFPFOCGKPNCEQKANCJCBLGDKC...

user output
(empty)

Test 12

Group: 3

Verdict:

input
2500
UGPBLFMZGVIANZLHRTPJIHMUZWOXKA...

correct output
UGLSEBMGHSONFJBGOJJAGBJCLFAHAP...

user output
(empty)

Test 13

Group: 3

Verdict:

input
2500
YRUOZBRTLLMMAHNIHQLZHBYCDHTHMS...

correct output
YELLJAAKETHCOWAJNDGJBOFNTCCEDA...

user output
(empty)

Test 14

Group: 3

Verdict:

input
2500
RXZEOTVYZBQUOJJFLCJCYCZDONBLUR...

correct output
RTDHUEBGLTKRHKIQLGKILATNHWPIBO...

user output
(empty)

Test 15

Group: 3

Verdict:

input
2500
IOTRAMNHKWWBVPQPPWTTBHOYDFXPOX...

correct output
IOTQTIDOBFMJBDNOFEFGGIBGAGQBIC...

user output
(empty)