제출 #1275816

#제출 시각아이디문제언어결과실행 시간메모리
1275816benyJakarta Skyscrapers (APIO15_skyscraper)C++20
100 / 100
189 ms112160 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("O3") #pragma GCC optimization("Ofast,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define ll long long //#define smid (nl + nr) / 2 //#define lc id * 2 //#define rc id * 2 + 1 #define migmig std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL); template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; const int N = 30005; bitset<N>mark[N]; vector<int> doge[N]; void solve() { int n, m; scanf("%d%d", &n, &m); int b0, p0, b1, p1; for (int i = 0; i < m; i++) { int b, p; scanf("%d%d", &b, &p); doge[b].push_back(p); if (i == 1) { b1 = b; p1 = p; } if (i == 0) { b0 = b; p0 = p; } } queue<array<int, 3>> q; q.push({ 0, b0, p0 }); mark[b0][p0] = 1; while (!q.empty()) { int d = q.front()[0]; short int v = q.front()[1]; short int p = q.front()[2]; q.pop(); if (v == b1) { printf("%d", d); return; } if (v - p >= 0) { if (!mark[v - p][p]) { if (v - p == b1) { printf("%d", d + 1); return; } q.push({ d + 1, v - p, p }); mark[v - p][p] = 1; } } if (v + p < n) { if (!mark[v + p][p]) { if (v + p == b1) { printf("%d", d + 1); return; } q.push({ d + 1, v + p, p }); mark[v + p][p] = 1; } } for (short int pp : doge[v]) { if (mark[v][pp]) continue; mark[v][pp] = 1; if (v - pp >= 0 && !mark[v - pp][pp]) { if (v - pp == b1) { printf("%d", d + 1); return; } q.push({ d + 1, v - pp, pp }); mark[v - pp][pp] = 1; } if (v + pp < n && !mark[v + pp][pp]) { if (v + pp == b1) { printf("%d", d + 1); return; } q.push({ d + 1, v + pp, pp }); mark[v + pp][pp] = 1; } } doge[v].clear(); } printf("-1"); } int main() { migmig; int T = 1; //cin >> T; while (T--) { solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:25:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     int n, m; scanf("%d%d", &n, &m);
      |               ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:29:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         int b, p; scanf("%d%d", &b, &p);
      |                   ~~~~~^~~~~~~~~~~~~~~~
#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...