이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define pb push_back
#define sc second
#define fr first
#define int long long
#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
//mesanu
int mp[30005][175];
vector<vector<pair<int, int>>> adj;
void cnn(int first, int second)
{
vector<pair<int, int>> a;
mp[first][second] = adj.size();
adj.pb(a);
}
int dijkstra(int s, int e)
{
int n = adj.size();
vector<int> d(n, MXL);
d[s] = 0;
set<pair<int, int>> q;
q.insert({0, s});
while (!q.empty()) {
int v = q.begin()->second;
q.erase(q.begin());
for (auto edge : adj[v]) {
int to = edge.first;
int len = edge.second;
if (d[v] + len < d[to]) {
q.erase({d[to], to});
d[to] = d[v] + len;
q.insert({d[to], to});
}
}
}
return d[e];
}
void solve()
{
int n, m;
cin >> n >> m;
int start = 0;
int end = 0;
int th = sqrt(n);
vector<pair<int, int>> ph;
adj.pb(ph);
for(int i = 0; i < n; i++)
{
cnn(i, 0);
}
for(int sky = 0; sky < n; sky++)
{
for(int power = 1; power <= th; power++)
{
cnn(sky, power);
}
}
for(int sky = 0; sky < n; sky++)
{
for(int power = 1; power <= th; power++)
{
adj[mp[sky][power]].pb({mp[sky][0], 0});
if(sky-power >= 0)
{
adj[mp[sky][power]].pb({mp[sky-power][power], 1});
}
if(sky+power < n)
{
adj[mp[sky][power]].pb({mp[sky+power][power], 1});
}
}
}
for(int i = 0; i < m; i++)
{
int sky, power;
cin >> sky >> power;
if(i == 0)
{
start = sky;
}
if(i == 1)
{
end = sky;
}
if(power <= th)
{
adj[mp[sky][0]].pb({mp[sky][power], 0});
}
else
{
for(int j = sky%power; j < n; j+=power)
{
adj[mp[sky][0]].pb({mp[j][0], abs(sky-j)/power});
}
}
}
cout << "bruh" << endl;
return;
int dist = dijkstra(mp[start][0], mp[end][0]);
if(dist == MXL)
{
cout << -1 << endl;
}
else
{
cout << dist << endl;
}
}
int32_t main(){
startt
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
/*
5 3
0 2
1 1
4 1
*/
# | 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... |