This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define pb push_back
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define int long long
#define pii pair<int, int>
#define inf 1e9
#define mod 1000000007
#define F first
#define S second
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
#define de(x) cout << #x << " = " << x << ' '
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
const int mxN = 2009 + 5;
int n, m, b[mxN], p[mxN];
bitset<mxN> vis[mxN];
vector<int> v[mxN];
signed main() {
IO;
cin >> n >> m;
for(int i = 0; i < m; i++) cin >> b[i] >> p[i], v[b[i]].pb(p[i]);
queue<array<int, 3>> q;
q.push({b[0], p[0], 0});
while(!q.empty()) {
auto now = q.front(); q.pop();
vis[now[0]][now[1]] = 1;
if(now[0] == b[1]) {
cout << now[2] << '\n';
return 0;
}
for(int i : v[now[0]]) {
if(now[0] + i < n and vis[(now[0] + i)][i] == 0)
q.push({now[0] + i, i, now[2] + 1});
if(now[0] - i > 0 and vis[(now[0] - i)][i] == 0)
q.push({now[0] - i, i, now[2] + 1});
}
if(now[0] + now[1] < n and vis[(now[0] + now[1])][now[1]] == 0)
q.push({now[0] + now[1], now[1], now[2] + 1});
if(now[0] - now[1] >= 0 and vis[(now[0] - now[1])][ now[1]] == 0)
q.push({now[0] - now[1], now[1], now[2] + 1});
}
cout << -1 << '\n';
}
Compilation message (stderr)
skyscraper.cpp:3: warning: ignoring #pragma loop [-Wunknown-pragmas]
3 | #pragma loop-opt(on)
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |