이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005
#define MAXK 505
#define MAXH 105
int k, m;
int h[MAXK];
ii holes[MAXK][MAXH];
ll d[MAXH][MAXH];
ll dp[MAXK][MAXH];
pll get(ll d) {
return MP(d % m, d / m * 2);
}
int main() {
scanf("%d%d", &k, &m);
m++;
int sx, sy, ex, ey; scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
holes[0][0] = MP(sx, sy);
holes[k][0] = MP(ex, ey);
h[0] = h[k] = 1;
REP (i, 1, k) {
scanf("%d", &h[i]);
REP (j, 0, h[i]) {
int x, y; scanf("%d%d", &x, &y);
holes[i][j] = MP(x, y);
}
}
REP (i, 0, k + 1) {
REP (j, 0, h[i]) {
dp[i][j] = LINF;
}
}
dp[0][0] = 0;
REP (i, 1, k + 1) {
REP (u, 0, h[i - 1]) {
REP (v, 0, h[i]) {
ll dx = abs(holes[i - 1][u].FI - holes[i][v].FI),
dy = abs(holes[i - 1][u].SE - holes[i][v].SE);
if (m == 2) {
d[u][v] = dx + dy;
continue;
}
ll sx, lx; tie(sx, lx) = get(dx);
ll sy, ly; tie(sy, ly) = get(dy);
if (ly == 0 && sx != 0) ly += 2;
if (lx == 0 && sy != 0) lx += 2;
ll tsx, tlx; tie(tsx, tlx) = get(dx);
ll tsy, tly; tie(tsy, tly) = get(dy);
tlx += 2; tly += 2;
tsx = m - tsx; tsy = m - tsy;
ll x = min(sx + lx, tsx + tlx), y = min(sy + ly, tsy + tly);
d[u][v] = x + y;
//printf("%d %d %d: %lld\n", i, u, v, d[i][u][v]);
}
}
REP (u, 0, h[i - 1]) {
REP (v, 0, h[i]) {
mnto(dp[i][v], dp[i - 1][u] + d[u][v]);
}
}
}
printf("%lld\n", dp[k][0]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
obelisk.cpp: In function 'int main()':
obelisk.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
40 | scanf("%d%d", &k, &m);
| ~~~~~^~~~~~~~~~~~~~~~
obelisk.cpp:42:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
42 | int sx, sy, ex, ey; scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
obelisk.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
47 | scanf("%d", &h[i]);
| ~~~~~^~~~~~~~~~~~~
obelisk.cpp:49:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
49 | int x, y; scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |