Submission #104333

#TimeUsernameProblemLanguageResultExecution timeMemory
104333leonardaPohlepko (COCI16_pohlepko)C++14
45 / 80
1079 ms25284 KiB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef pair<int, int> pi;
typedef long long int lint;
const int inf = 0x3f3f3f3f;
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) {
	
//	cout << "x " << x << " y " << y << " dosad " << dosad << endl;
	
	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 >> 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 (stderr)

pohlepko.cpp: In function 'std::__cxx11::string fuki(std::__cxx11::string, std::__cxx11::string)':
pohlepko.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < t1.size(); ++i) {
                 ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...