Submission #882598

#TimeUsernameProblemLanguageResultExecution timeMemory
882598vjudge1Jakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1053 ms22456 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC targe("avx2,bmi,bmi2,sse4.2")
#include <bits/stdc++.h>
using namespace std;

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

int n, p[MAXM], B[MAXM], m, a[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) {}
};

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++) cin >> B[i] >> p[i];
	for(int i = 0; i < n; i++) a[i] = INT_MAX;
	unordered_map<int, queue<int>> b;
	queue<triple> curr, oth;
	curr.push({B[0], p[0], 3});
	for(int i = 0; i < m; i++) b[B[i]].push(i);
	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});
			}
			b.erase(cur.first);
		}
		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[B[1]] == INT_MAX ? -1 : a[B[1]]) << '\n';
}

Compilation message (stderr)

skyscraper.cpp:2: warning: ignoring '#pragma GCC targe' [-Wunknown-pragmas]
    2 | #pragma GCC targe("avx2,bmi,bmi2,sse4.2")
      |
#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...