제출 #926494

#제출 시각아이디문제언어결과실행 시간메모리
926494Boycl07Jakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
84 ms12488 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 1; i <= n; ++i) #define forn(i, l, r) for(int i = l; i <= r; ++i) #define ford(i, r, l) for(int i = r; i >= l; --i) #define FOR(i, n) for(int i = 0; i < n; ++i) #define FORD(i, n) for(int i = n - 1; i >= 0; --i) #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define endl "\n" #define task "skycrapers" #define sz(a) int(a.size()) #define C(x, y) make_pair(x, y) #define all(a) (a).begin(), (a).end() #define bit(i, mask) (mask >> i & 1) template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;} inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;} inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;} const int N = 1e5 + 10; const int M = 1e3 + 3; const int N1 = 2e3 + 10; const int K = 1e2 + 1; const int MOD = 1e9 + 7; const int INF = 1e9 + 3; const ll LINF = 1e17 + 2; const int block_size = 500; const int LOG = 40; const int offset = N; const int LIM = 11 ; const int AL = 26; int n, m, s, t; set<int> doges[N]; int d[N]; void solve() { cin >> n >> m; FOR(i, m) { int x, y; cin >> x >> y; doges[x].insert(y); if(i == 0) s = x; else if(i == 1) t = x; } priority_queue<pii, vector<pii>, greater<pii>> pq; FOR(i, n) d[i] = INF; d[s] = 0; pq.push({0, s}); while(!pq.empty()) { pii tmp = pq.top(); pq.pop(); int u = tmp.se, dist = tmp.fi; if(d[u] != dist) continue; if(u == t) return cout << dist, void(); for(int p : doges[u]) { for(int j = 1; u + p * j < n; ++j) { int v = u + p * j; if(minimize(d[v], d[u] + j)) pq.push({d[v], v}); if(doges[v].find(p) != doges[v].end()) break; } for(int j = 1; u - p * j >= 0; ++j) { int v = u - p * j; if(minimize(d[v], d[u] + j)) pq.push({d[v], v}); if(doges[v].find(p) != doges[v].end()) break; } } } cout << -1; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC = 1; if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } while(TC--) { solve(); cout << endl; } return 0; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...