Submission #896556

#TimeUsernameProblemLanguageResultExecution timeMemory
896556AgentPenginJakarta Skyscrapers (APIO15_skyscraper)C++17
100 / 100
261 ms112720 KiB
/** * author: AgentPengin ( Độc cô cầu bại ) * created: 23.12.2022 10:08:02 * too lazy to update time **/ #include<bits/stdc++.h> #define EL '\n' #define fi first #define se second #define NAME "TASK" #define ll long long #define lcm(a,b) (a/gcd(a,b))*b #define db(val) "["#val" = " << (val) << "] " #define bend(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() #define ex exit(0) #define visit __visit using namespace std; const ll mod = 1e9 + 7; const int inf = 0x1FFFFFFF; const int MAXN = 30005; int n,m,pw[MAXN],pos[MAXN]; vector<int> adj[MAXN]; bitset<MAXN> visit[MAXN]; signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if (ifstream(NAME".inp")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } cin >> n >> m; for (int i = 1;i <= m;i++) { cin >> pos[i] >> pw[i]; adj[pos[i]].push_back(pw[i]); } queue<tuple<int,int,int>> q; q.push({pos[1],pw[1],0}); int ans = -1; while(!q.empty()) { int u,p,d; tie(u,p,d) = q.front(); q.pop(); if (u == pos[2]) { ans = d; break; } if (u - p >= 0 && !visit[u - p][p]) { visit[u - p][p] = 1; q.push({u - p,p, d + 1}); } if (u + p < n && !visit[u + p][p]) { visit[u + p][p] = 1; q.push({u + p,p,d + 1}); } for (int p : adj[u]) { visit[u][p] = 1; if (u - p >= 0 && !visit[u - p][p]) { visit[u - p][p] = 1; q.push({u - p,p,d + 1}); } if (u + p < n && !visit[u + p][p]) { visit[u + p][p] = 1; q.push({u + p,p,d + 1}); } } } cout << ans; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } // agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

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