답안 #104333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104333 2019-04-05T08:16:53 Z leonarda Pohlepko (COCI16_pohlepko) C++14
45 / 80
1000 ms 25284 KB
#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

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) {
                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 4 ms 1408 KB Output is correct
6 Correct 9 ms 2560 KB Output is correct
7 Correct 44 ms 10248 KB Output is correct
8 Correct 82 ms 24920 KB Output is correct
9 Correct 21 ms 640 KB Output is correct
10 Execution timed out 1079 ms 1272 KB Time limit exceeded
11 Execution timed out 1077 ms 2544 KB Time limit exceeded
12 Execution timed out 1076 ms 5160 KB Time limit exceeded
13 Execution timed out 1051 ms 9520 KB Time limit exceeded
14 Execution timed out 1060 ms 25284 KB Time limit exceeded
15 Execution timed out 1073 ms 768 KB Time limit exceeded
16 Execution timed out 1073 ms 22520 KB Time limit exceeded