Submission #390637

# Submission time Handle Problem Language Result Execution time Memory
390637 2021-04-16T12:33:13 Z maomao90 OBELISK (NOI14_obelisk) C++14
25 / 25
34 ms 1844 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[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;
}

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);
      |              ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 300 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 2 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
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1352 KB Output is correct
2 Correct 31 ms 1328 KB Output is correct
3 Correct 24 ms 1368 KB Output is correct
4 Correct 27 ms 1348 KB Output is correct
5 Correct 23 ms 1328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1612 KB Output is correct
2 Correct 29 ms 1680 KB Output is correct
3 Correct 30 ms 1844 KB Output is correct
4 Correct 32 ms 1624 KB Output is correct
5 Correct 28 ms 1612 KB Output is correct