이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-all-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt,abm,sse4.2")
#include <bits/stdc++.h>
using namespace std;
const unsigned short MAXM = 3e4+5, MAXN = 3e4+5;
unsigned short n, m, secloc, p[MAXM];
vector<unsigned short> a(MAXN, UINT16_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);
}
unsigned short curval = 0;
while(!curr.empty()) {
auto cur = curr.front(); curr.pop();
if(a[cur.first] == UINT16_MAX) {
while(!b[cur.first].empty()) {
unsigned short 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 & 1)
oth.push({cur.first - cur.second, cur.second, 1});
if(cur.first < n - cur.second && cur.third & 2)
oth.push({cur.first + cur.second, cur.second, 2});
if(curr.empty()) {
swap(curr, oth);
curval ++;
}
}
cout << (a[secloc] == UINT16_MAX ? -1 : a[secloc]) << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:54:24: warning: narrowing conversion of '(((int)cur.triple::first) - ((int)cur.triple::second))' from 'int' to 'short unsigned int' [-Wnarrowing]
54 | oth.push({cur.first - cur.second, cur.second, 1});
| ~~~~~~~~~~^~~~~~~~~~~~
skyscraper.cpp:56:24: warning: narrowing conversion of '(((int)cur.triple::first) + ((int)cur.triple::second))' from 'int' to 'short unsigned int' [-Wnarrowing]
56 | oth.push({cur.first + cur.second, cur.second, 2});
| ~~~~~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |