답안 #882670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882670 2023-12-03T12:52:00 Z vjudge1 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
11 ms 20608 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
using namespace std;

const int MAXM = 3e4+5, MAXN = 3e4+5;

int n, p[MAXM], m, secloc;
vector<int> a(MAXN, INT_MAX);
queue<int> b[MAXN];

struct triple {
	int first, second, third;
	triple() : first(0), second(0), third(0) {}
	triple(int a, int b, int c) :first(a), second(b), third(c) {}
};

queue<triple> curr, oth;

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int tmp;
		cin >> tmp >> p[i];
		if(i==0) curr.push({tmp, p[0], 3});
		b[tmp].push(i);
		if(i==1) secloc = tmp;
	}
	int curval = 0;
	while(!curr.empty()) {
		auto cur = curr.front(); curr.pop();
		if(a[cur.first] == INT_MAX) {
			while(!b[cur.first].empty()) {
				int x = b[cur.first].front();
				b[cur.first].pop();
				if(p[x] != cur.second)
					curr.push({cur.first, p[x], 3});
			}
		}
		a[cur.first] = min(a[cur.first], curval);
		if(cur.first >= cur.second && cur.third != 2)
			oth.push({cur.first - cur.second, cur.second, 1});
		if(cur.first < n - cur.second && cur.third != 1)
			oth.push({cur.first + cur.second, cur.second, 2});
		if(curr.empty()) {
			swap(curr, oth);
			curval ++;
		}
	}
	cout << (a[secloc] == INT_MAX ? -1 : a[secloc]) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 20568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 20572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 20568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 20608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 20568 KB Output isn't correct
2 Halted 0 ms 0 KB -