이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Need to git gud and reach 1900+
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define prev prev123
#define next next123
#define pow pow123
#define left left123
#define right right123
const int N = 30007;
const int INF = 1e9 + 7;
int a[N], b[N], d[N];
int m, n;
map < pi, int > mp;
vector < pi > g[N];
main(){ // If you don't know what to do, check the text box at the bottom
cin >> m >> n;
for (int i = 1; i <= n; i++){
scanf("%d%d", &a[i], &b[i]);
a[i]++;
if (mp[{a[i], b[i]}])
b[i] = 0;
mp[{a[i], b[i]}] = 1;
}
for (int i = 1; i <= n; i++){
if (!b[i])
continue;
int pos = a[i], pw = b[i], c = 0;
while (pos + pw <= m){
pos += pw; c++;
g[a[i]].pb(mk(pos, c));
if (mp[{pos, pw}])
break;
}
pos = a[i], pw = b[i], c = 0;
while (pos - pw > 0){
pos -= pw; c++;
g[a[i]].pb(mk(pos, c));
if (mp[{pos, pw}])
break;
}
}
priority_queue < pi > pq;
pq.push(mk(0, a[1]));
memset(d, 0x3f3f3f3f, sizeof(d));
d[a[1]] = 0;
while (!pq.empty()){
int w = -pq.top().fr, v = pq.top().sc;
pq.pop();
if (d[v] < w)
continue;
for (pi to : g[v]){
if (d[to.fr] > d[v] + to.sc){
d[to.fr] = d[v] + to.sc;
pq.push(mk(-d[to.fr], to.fr));
}
}
}
printf("%d", d[a[2]]);
}
/*
Totally not inspired by BenQ's template
Things you should do:
1. Look for stupid typos in code e.g 1 instead of -1 etc
2. Check if there is no infinite loops
3. "Measure twice, cut once"
4. Stay focused
*/
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){ // If you don't know what to do, check the text box at the bottom
^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |