Submission #390448

# Submission time Handle Problem Language Result Execution time Memory
390448 2021-04-16T05:46:05 Z maomao90 OBELISK (NOI14_obelisk) C++14
0 / 25
39 ms 23912 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];

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);
				ll shortx = dx % m, longx = dx / m * 2,
				   shorty = dy % m, longy = dy / m * 2;
				if (shortx != 0 && longx == 0) longx += 2;
				if (shorty != 0 && longy == 0) longy += 2;
				d[i][u][v] = shortx + longx + shorty + longy;
				//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:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |  scanf("%d%d", &k, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
obelisk.cpp:38:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |  int sx, sy, ex, ey; scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
obelisk.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |   scanf("%d", &h[i]);
      |   ~~~~~^~~~~~~~~~~~~
obelisk.cpp:45:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |    int x, y; scanf("%d%d", &x, &y);
      |              ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 22908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 23912 KB Output isn't correct
2 Halted 0 ms 0 KB -