제출 #654337

#제출 시각아이디문제언어결과실행 시간메모리
654337nguyentunglamJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
244 ms262144 KiB
#include<bits/stdc++.h> #define forin(i, a, b) for(int i = a; i <= b; i++) #define forde(i, a, b) for(int i = a; i >= b; i--) #define forv(a, b) for(auto & a : b) #define fi first #define se second #define ii pair<int, int> #define endl "\n" using namespace std; const int N = 3e4 + 10, M = 1e7 + 10; int b[N], p[N], cnt, f[M], d[N], c[N]; bool check[N]; pair<int, int> a[M]; vector<int> v[N], adj[M], g[N]; map<pair<int, int>, bool> mp; int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int n, m; cin >> n >> m; int start = clock(); for(int i = 0; i < m; i++) { cin >> b[i] >> p[i]; p[i] = min(p[i], n); g[p[i]].push_back(b[i]); } for(int val = 1; val <= n; val++) { vector<int> tmp; for(int j : g[val]) { if (!c[j % val]) tmp.push_back(j % val), c[j % val] = 1; } for(int j : tmp) { for(int k = j; k < n; k += val) { d[k] = ++cnt; a[cnt] = {k, val}; if (k >= val) { adj[cnt].push_back(d[k - val]); adj[d[k - val]].push_back(cnt); } } } for(int j : g[val]) v[j].push_back(d[j]), c[j % val] = 0; } // cout << cnt << endl; // for(int i = 1; i <= cnt; i++) cout << a[i].fi << " " << a[i].se << endl; queue<int> q; for(int j : v[b[0]]) if (!f[j]) f[j] = 1, q.push(j); check[b[0]] = 1; while (!q.empty()) { int id = q.front(); q.pop(); int u = a[id].fi, w = a[id].se; if (u - w >= 0 && !check[u - w]) { check[u - w] = 1; for(int j : v[u - w]) f[j] = f[id] + 1, q.push(j); } if (u + w < n && !check[u + w]) { check[u + w] = 1; for(int j : v[u + w]) f[j] = f[id] + 1, q.push(j); } forv(v, adj[id]) if (!f[v]) f[v] = f[id] + 1, q.push(v); } int ans; for(int i = 1; i <= cnt; i++) if (a[i].fi == b[1] && a[i].se == p[1]) ans = i; cout << f[ans] - 1; int finish = clock(); cerr << 1.0 * (finish - start) / CLOCKS_PER_SEC; }

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:21:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:24:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:25:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:72:18: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |     cout << f[ans] - 1;
      |             ~~~~~^
#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...