답안 #17859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17859 2016-01-12T14:22:21 Z Erzhann K번째 경로 (IZhO11_kthpath) C++
0 / 100
0 ms 2196 KB
/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's AdilkhanKo miaaaaaau      
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second 
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;
                                            
const int MaxN = int (2e5) + 256;
const int INF = int(1e9);  
const int mod = (int)(1e9) + 7;
ll n, a[44][44], k, m, t;
char c[44][44];
string ans;

void rec(int x, int y){
	ans = ans + c[x][y];
	if(x == n && y == m){
		cout << ans;
		exit(0);
	}
	char r, v;
	if(x + 1 <= n){
		v = c[x + 1][y];
	}else{
		rec(x, y + 1);
	}
	if(y + 1 <= m){
		r = c[x][y + 1];
	}else{
		rec(x + 1, y);
	}
	if(r < v){
		int I = n - x + 1;
		int J = m - y;
		if(a[I][J] >= k){
			rec(x, y + 1);			
		}else{
			k -= a[I][J];
			rec(x + 1, y);
		}		
	}else{
		int I = n - x;
		int J = m - y + 1;
		if(a[I][J] >= k)
			rec(x + 1, y);
		else{
			k -= a[I][J];
			rec(x, y + 1);
		}
	}
}
int main () { _
	/*#ifdef ONLINE_JUDGE
		freopen (name".in","r",stdin);
		freopen (name".out","w",stdout);
	#else
		freopen (".in","r",stdin);
		freopen (".out","w",stdout);
	#endif*/
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> c[i][j];
		}
	}
	cin >> k;
	for(int i = 2; i <= m; i++)
		a[1][i] = 1;
	for(int i = 2; i <= n; i++){
		a[i][1] = 1;
		for(int j = 2; j <= m; j++){
			a[i][j] = a[i - 1][j] + a[i][j - 1];
		}
	}
	rec(1, 1);
return 0;
}                   									

Compilation message

kthpath.cpp: In function 'void rec(int, int)':
kthpath.cpp:46:2: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if(r < v){
  ^
kthpath.cpp:46:2: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2196 KB Output is correct
2 Correct 0 ms 2196 KB Output is correct
3 Correct 0 ms 2196 KB Output is correct
4 Incorrect 0 ms 2196 KB Output isn't correct
5 Halted 0 ms 0 KB -