이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Coded by thegamercoder
Happy Competition and Hacking
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define FILER 0
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ll MAX = 401;
const ll MODD = 998244353;
const ll BL = 1;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto i : a)
#define FORAE(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout<<(s?"YES":"NO")<<endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;
ll n, m, p;
V<ll> d, b;
V<V<ll>> fr;
void solve()
{
cin >> n >> m;
fr.resize(n); d.resize(n, INFL); b.resize(m);
FOR(ll, i, 0, m, 1)cin >> b[i] >> p, fr[b[i]].push_back(p);
PQ<pll, V<pll>, greater<pll>> pq;
d[b[0]] = 0;
pq.push({ 0,b[0] });
WH(!pq.empty())
{
auto [du, u] = pq.top(); pq.pop();
if (du != d[u])continue;
FORAE(fr[u], p)
{
ll dist = 1;
for (ll v = u + p; v < n; v += p, dist++)
if (d[v] > d[u] + dist)d[v] = d[u] + dist, pq.push({ d[v],v });
dist = 1;
for (ll v = u - p; v >= 0; v -= p, dist++)
if (d[v] > d[u] + dist)d[v] = d[u] + dist, pq.push({ d[v],v });
}
}
cout << (d[b[1]] == INFL ? -1 : d[b[1]]) << endl;
}
void init()
{
if (FILER)
{
freopen("pump.in", "r", stdin);
freopen("pump.out", "w", stdout);
}
}
void handle()
{
init();
ll t = 1;
if (TYP)cin >> t;
WHI(t)solve();
}
int main()
{
IOF
handle();
RET 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:64:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
64 | auto [du, u] = pq.top(); pq.pop();
| ^
skyscraper.cpp: In function 'void init()':
skyscraper.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen("pump.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen("pump.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |