답안 #133377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133377 2019-07-20T12:59:50 Z tdwn Jetpack (COCI16_jetpack) C++17
80 / 80
131 ms 11200 KB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
char maze[11][maxn];
int t[11][maxn];
int direction[11][maxn];
int n;

int main() {
	cin>>n;
	for(int i=1;i<=10;i++) {
		for(int j=1;j<=n;j++) {
			cin>>maze[i][j];
			t[i][j] = -1;
		}
	}

	t[10][1] = 0;

	// Direction:
	// 0 -> from left (only last row)
	// 1 -> felt from above
	// 2 -> from down
	// 3 -> felt from above (directly)

	for(int j=2;j<=n;j++) {
		for(int i=1;i<=10;i++) {
			if(maze[i][j] == 'X') continue;
			if(i == 10) {
				if(t[i][j-1] != -1) {
					direction[i][j] = 0;
					t[i][j] = t[i][j-1] + 1;
				}
				if(t[i-1][j-1] != -1) {
					direction[i][j] = 1;
					t[i][j] = t[i-1][j-1] + 1;
				}
			}
			else if(i == 1) {
				if(t[i+1][j-1] != -1) {
					t[i][j] = t[i+1][j-1] + 1;
					direction[i][j] = 2;
				}
				if(t[i][j-1] != -1) {
					t[i][j] = t[i][j-1] + 1;
					direction[i][j] = 3;
				}
			}
			else {
				if(t[i-1][j-1] != -1) {
					t[i][j] = t[i-1][j-1] + 1;
					direction[i][j] = 1;
				}
				if(t[i+1][j-1] != -1) {
					t[i][j] = t[i+1][j-1] + 1; 
					direction[i][j] = 2;
				}
			}
		}
	}

	/*for(int i=1;i<=10;i++) {
		for(int j=1;j<=n;j++) {
			cout<<setw(5)<<t[i][j]<<" ";
		} cout<<"\n";
	}*/

	int ind = -1;
	for(int i=1;i<=10;i++) {
		if(t[i][n] != -1) {
			ind = i;
		}
	}

	vector<pair<int,int> > v;
	for(int j=n;j>=1;j--) {
		if(direction[ind][j] == 0) {
			continue;
		}
		else if(direction[ind][j] == 1) {
			ind--;
		}	
		else if(direction[ind][j] == 2){
			v.pb(mp(t[ind+1][j-1],1));
			ind++;
		}
		else if(direction[ind][j] == 3) {
			v.pb(mp(t[ind][j-1], 1));
		}
	}

	cout<<v.size()<<"\n";
	reverse(v.begin(), v.end());
	for(auto i:v) {
		cout<<i.first<<" "<<i.second<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 8 ms 888 KB Output is correct
6 Correct 10 ms 1144 KB Output is correct
7 Correct 27 ms 2652 KB Output is correct
8 Correct 61 ms 5664 KB Output is correct
9 Correct 93 ms 8292 KB Output is correct
10 Correct 131 ms 11200 KB Output is correct