Submission #45448

#TimeUsernameProblemLanguageResultExecution timeMemory
45448RayaBurong25_1Jakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
555 ms121124 KiB
#include <stdio.h> #include <vector> #include <queue> #include <algorithm> #define INF 1000000007 int B[30005], P[30005]; int abs(int a) { return (a < 0)?-a:a; } long long Vis[30005][505]; typedef struct node node; struct node { int u, j, t; }; std::vector<int> J[30005]; std::queue<node> Q; int main() { int N, M; scanf("%d %d", &N, &M); int i; node p; for (i = 0; i < M; i++) { scanf("%d %d", &B[i], &P[i]); if (i == 0) p = {B[i], P[i], 0}; else J[B[i]].push_back(P[i]); } Vis[B[0]][P[i]/60] |= (1LL << (P[i]%60)); Q.push(p); int w; while (!Q.empty()) { p = Q.front(); Q.pop(); // printf("pop %d %d %d\n", p.u, p.j, p.t); if (p.u == B[1]) { printf("%d", p.t); return 0; } if (p.u + p.j < N && (Vis[p.u + p.j][p.j/60]&(1LL << (p.j%60))) == 0) { Vis[p.u + p.j][p.j/60] |= (1LL << (p.j%60)); Q.push({p.u + p.j, p.j, p.t + 1}); } if (p.u - p.j >= 0 && (Vis[p.u - p.j][p.j/60]&(1LL << (p.j%60))) == 0) { Vis[p.u - p.j][p.j/60] |= (1LL << (p.j%60)); Q.push({p.u - p.j, p.j, p.t + 1}); } for (i = 0; i < J[p.u].size(); i++) { w = J[p.u][i]; if (p.u + w < N && (Vis[p.u + w][w/60]&(1LL << (w%60))) == 0) { Vis[p.u + w][w/60] |= (1LL << (w%60)); Q.push({p.u + w, w, p.t + 1}); } if (p.u - w >= 0 && (Vis[p.u - w][w/60]&(1LL << (w%60))) == 0) { Vis[p.u - w][w/60] |= (1LL << (w%60)); Q.push({p.u - w, w, p.t + 1}); } } } printf("-1"); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:57:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < J[p.u].size(); i++)
                     ~~^~~~~~~~~~~~~~~
skyscraper.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &B[i], &P[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...