답안 #390485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390485 2021-04-16T07:10:20 Z maomao90 오벨리스크 (NOI14_obelisk) C++14
5 / 25
60 ms 23432 KB
#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[MAXK][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) {
		REP (u, 0, h[i]) {
			REP (v, 0, h[i + 1]) {
				ll dx = abs(holes[i][u].FI - holes[i + 1][v].FI),
				   dy = abs(holes[i][u].SE - holes[i + 1][v].SE);
				if (m == 2) {
					d[i][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;
				dx = abs(dx - m);
				dy = abs(dy - m);
				ll tsx, tlx; tie(tsx, tlx) = get(dx);
				ll tsy, tly; tie(tsy, tly) = get(dy);
				tlx += 2; tly += 2;
				ll x = min(sx + lx, tsx + tlx), y = min(sy + ly, tsy + tly);
				d[i][u][v] = x + y;

				//printf("%d %d %d: %lld\n", i, u, v, d[i][u][v]);
			}
		}
	}
	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]) {
				mnto(dp[i][v], dp[i - 1][u] + d[i - 1][u][v]);
			}
		}
	}
	printf("%lld\n", dp[k][0]);
	return 0;
}

Compilation message

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);
      |              ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Incorrect 2 ms 800 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 22804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 23432 KB Output isn't correct
2 Halted 0 ms 0 KB -