Submission #123927

#TimeUsernameProblemLanguageResultExecution timeMemory
123927AyaBenSaadJakarta Skyscrapers (APIO15_skyscraper)C++14
22 / 100
276 ms238712 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 3; //number of skyscrapers const int M = 3e4 + 4; //number of doges; const int inf = 1e9; int n, m, b[M], p[M], ok; vector <int> dgin[N]; int dp[M][N]; int solve (int doge, int sk) { if (doge == 1) {ok = 1; return 0;} if (sk < 0 || sk >= n) return inf; int &ret = dp[doge][sk]; if (ret != -1) return ret; ret = solve(doge, sk+p[doge]) + 1; ret = min(ret, solve(doge, sk-p[doge]) + 1); for (int i : dgin[sk]) { if (i != doge) ret = min (ret, min(solve(i, sk-p[i])+1, solve(i, sk+p[i])+1)); } return ret; } int main () { scanf ("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &b[i], &p[i]); dgin[b[i]].push_back (i); } memset (dp, -1, sizeof dp); int x = solve(0, b[0]); if(ok) printf("%d\n", x-1); else puts("-1"); }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &n, &m);
     ~~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:28: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...