제출 #882697

#제출 시각아이디문제언어결과실행 시간메모리
882697aegJakarta Skyscrapers (APIO15_skyscraper)C++14
0 / 100
1061 ms20584 KiB
#pragma GCC optimize("Ofast,unroll-all-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #include <bits/stdc++.h> using namespace std; const unsigned short MAXM = 3e4+5, MAXN = 3e4+5; unsigned short n, m, secloc, p[MAXM]; vector<int> a(MAXN, INT_MAX); queue<unsigned short> b[MAXN]; struct triple { unsigned short first, second; char third; triple() : first(0), second(0), third(0) {} triple(unsigned short a, unsigned short b, char c) :first(a), second(b), third(c) {} }; queue<triple> curr, oth; signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; { unsigned short tmp; cin >> tmp >> p[0]; curr.push({tmp, p[0], 3}); b[tmp].push(0); } { unsigned short tmp; cin >> tmp >> p[1]; secloc = tmp; b[tmp].push(1); } for(int i = 2; i < m; i++) { unsigned short tmp; cin >> tmp >> p[i]; b[tmp].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}); } } a[cur.first] = min(a[cur.first], curval); unsigned short tmp = cur.first - cur.second; if(tmp >= 0 && cur.third & 1) oth.push({tmp, cur.second, 1}); tmp = cur.first + cur.second; if(tmp < n && cur.third & 2) oth.push({tmp, cur.second, 2}); if(curr.empty()) { swap(curr, oth); curval ++; } } cout << (a[secloc] == INT_MAX ? -1 : a[secloc]) << '\n'; }
#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...