제출 #882722

#제출 시각아이디문제언어결과실행 시간메모리
882722aegJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1029 ms22564 KiB
#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; #define int uint16_t const int MAXM = 3e4+5, MAXN = 3e4+5; int n, m, secloc, p[MAXM]; vector<int> a(MAXN, UINT16_MAX); queue<int> b[MAXN]; struct triple { int first, second; char third; triple() : first(0), second(0), third(0) {} triple(int a, int 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; { int tmp; cin >> tmp >> p[0]; curr.push({tmp, p[0], 3}); b[tmp].push(0); } { int tmp; cin >> tmp >> p[1]; secloc = tmp; b[tmp].push(1); } for(int i = 2; i < m; i++) { int 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] == UINT16_MAX) { set<int> ss; while(!b[cur.first].empty()) { int x = b[cur.first].front(); b[cur.first].pop(); if(p[x] != cur.second) ss.insert(x); } for(auto x:ss) { 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:59:24: warning: narrowing conversion of '(((int)cur.triple::first) - ((int)cur.triple::second))' from 'int' to 'uint16_t' {aka 'short unsigned int'} [-Wnarrowing]
   59 |    oth.push({cur.first - cur.second, cur.second, 1});
      |              ~~~~~~~~~~^~~~~~~~~~~~
skyscraper.cpp:61:24: warning: narrowing conversion of '(((int)cur.triple::first) + ((int)cur.triple::second))' from 'int' to 'uint16_t' {aka 'short unsigned int'} [-Wnarrowing]
   61 |    oth.push({cur.first + cur.second, cur.second, 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...