제출 #994759

#제출 시각아이디문제언어결과실행 시간메모리
994759hmm789Portal (BOI24_portal)C++14
1 / 100
2093 ms1372 KiB
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, ans = 0;
	cin >> n;
	int x[n], y[n];
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	int X = 301, Y = 301;
	int grid[X][Y];
	memset(grid, -1, sizeof(grid));
	bool inf = false;
	for(int i = 0; i < X; i++) {
		for(int j = 0; j < Y; j++) {
			if(grid[i][j] != -1) continue;
			queue<pair<int, int>> q;
			q.push({i,j});
			grid[i][j] = ans;
			while(!q.empty()) {
				pair<int, int> c = q.front();
				q.pop();
				for(int r = 0; r < n; r++) {
					for(int s = 0; s < n; s++) {
						int nx = c.first+x[r]-x[s];
						int ny = c.second+y[r]-y[s];
						if(nx < 0 || nx >= X || ny < 0 || ny >= Y) continue;
						if(grid[nx][ny] != -1) continue;
						grid[nx][ny] = ans;
						q.push({nx, ny});
					}
				}
			}
			ans++;
			if(i == X-1 && j == Y-1) inf = true;
		}
	}
	if(inf) cout << -1;
	else cout << ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...