Submission #1120815

#TimeUsernameProblemLanguageResultExecution timeMemory
1120815mmdrzadaJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1055 ms4248 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef vector<char> vc; typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; #define sep ' ' #define F first #define S second #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define kill(x) {cout << x << endl;return;} #define sz(x) int(x.size()) #define SP(x) setprecision(x) #define mod(x) (1ll*x%M+M)%M #define pq priority_queue #define mid (l+r)/2 // #define mid2 (l+r+1)/2 #define pll pair<ll, ll> #define REP(i, k) for (int i = 0 ; i < k ; i ++) #define MP make_pair const int M = 998244353; const int N = 3e4+1; const int T = 140; int n, m; vector<pair<int, int>> adj[N]; ll dis[N]; bool vis[N]; int b[N], p[N]; vi D[N]; bitset<T> Y[N]; void solve() { // input in 0-index itself cin >> n >> m; for(int i = 0 ; i < m ; i ++) { cin >> b[i] >> p[i]; D[b[i]].pb(p[i]); } for(int i = 0 ; i < n ; i ++) sort(D[i].begin(), D[i].end()); fill(dis, dis+n, n*n+1); dis[b[0]] = 0; priority_queue<pii, vector<pii>, greater<pii> > q; q.push({0, b[0]}); while(!q.empty()) { int u = q.top().S; q.pop(); for(int i = 0 ; i < D[u].size() ; i ++) { int s = D[u][i]; if (D[u][i] >= T) { for(int neigh = u-s, w = 1; neigh >= 0 ; neigh -= s, w ++) { if (dis[neigh] > dis[u] + w) { dis[neigh] = dis[u] + w; q.push({dis[neigh], neigh}); } } for(int neigh = u+s, w = 1; neigh < n ; neigh += s, w ++) { if (dis[neigh] > dis[u] + w) { dis[neigh] = dis[u] + w; q.push({dis[neigh], neigh}); } } } else { Y[u][s] = true; for(int neigh = u-s, w = 1; neigh >= 0 && !Y[neigh][s] ; neigh -= s, w ++) { if (dis[neigh] > dis[u] + w) { dis[neigh] = dis[u] + w; q.push({dis[neigh], neigh}); } } for(int neigh = u+s, w = 1; neigh < n && !Y[neigh][s] ; neigh += s, w ++) { if (dis[neigh] > dis[u] + w) { dis[neigh] = dis[u] + w; q.push({dis[neigh], neigh}); } } } } } cout << (dis[b[1]] == n*n+1 ? -1 : dis[b[1]]) << endl; } // check MAXN int32_t main() { fastIO; solve(); return 0; }

Compilation message (stderr)

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i = 0 ; i < D[u].size() ; i ++) {
      |                   ~~^~~~~~~~~~~~~
#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...