Submission #105946

# Submission time Handle Problem Language Result Execution time Memory
105946 2019-04-15T19:50:23 Z leonarda Pohlepko (COCI16_pohlepko) C++14
45 / 80
1000 ms 25612 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int maxn = 2000 + 5;
int n, m;
char a[maxn][maxn];
 
string fuki(string t1, string t2) {
	for(int i = 0; i < t1.size(); ++i) {
		if(t1[i] < t2[i]) return t1;
		if(t2[i] < t1[i]) return t2;
	}
	return t1;
}
 
string solve(int x, int y, string dosad) {
	
	if(x == n - 1 and y == m - 1)
		return dosad;
		
	else if(x == n - 1 and y != m - 1)
		return solve(x, y + 1, dosad + a[x][y + 1]);
		
	else if(x != n - 1 and y == m - 1)
		return solve(x + 1, y, dosad + a[x + 1][y]);
		
	else if(x != n - 1 and y != m - 1 and a[x + 1][y] < a[x][y + 1])
		return solve(x + 1, y, dosad + a[x + 1][y]);
		
	else if(x != n - 1 and y != m - 1 and a[x][y + 1] < a[x + 1][y])
		return solve(x, y + 1, dosad + a[x][y + 1]);
	
	else
		return fuki(solve(x, y + 1, dosad + a[x][y + 1]), solve(x + 1, y, dosad + a[x + 1][y]));
}
 
int main ()
{
	ios::sync_with_stdio(0);
  	cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			cin >> a[i][j];
	
	string geez; geez.pb(a[0][0]);
	cout << solve(0, 0, geez);
 
return 0;
}

Compilation message

pohlepko.cpp: In function 'std::__cxx11::string fuki(std::__cxx11::string, std::__cxx11::string)':
pohlepko.cpp:9:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < t1.size(); ++i) {
                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 1408 KB Output is correct
6 Correct 7 ms 2560 KB Output is correct
7 Correct 27 ms 10368 KB Output is correct
8 Correct 72 ms 25264 KB Output is correct
9 Correct 29 ms 640 KB Output is correct
10 Execution timed out 1074 ms 1400 KB Time limit exceeded
11 Execution timed out 1055 ms 2392 KB Time limit exceeded
12 Execution timed out 1078 ms 5024 KB Time limit exceeded
13 Execution timed out 1077 ms 9664 KB Time limit exceeded
14 Execution timed out 1068 ms 25612 KB Time limit exceeded
15 Execution timed out 1075 ms 888 KB Time limit exceeded
16 Execution timed out 1078 ms 22520 KB Time limit exceeded