Submission #209260

# Submission time Handle Problem Language Result Execution time Memory
209260 2020-03-13T14:09:57 Z kostia244 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
7 ms 2684 KB
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,fma,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 1e5 + 5;
ll n, dp[maxn][3];
map<int, vi> t;
vector<pi> a;
ll dist(pi a, pi b) {
	return abs(a.first - b.first) + abs(a.second - b.second);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int x, y, i = 0; i < 2*n; i++) cin >> x >> y, t[x].pb(y);
	for(auto i : t) {
		int l = 0, r = i.second.size(), q = 0;
		while(l<r) {
			if(q) a.pb({i.first, i.second[l++]});
			else a.pb({i.first, i.second[--r]});
			q ^= 1;
		}
	}
	memset(dp, 0x3f, sizeof dp);
	dp[0][0] = 0;
	for(int i = 0; i < 2*n; i++) {
		dp[1 + (i/2)][0] = min(dp[1 + (i/2)][0], dp[i/2][2] + dist(a[i], {1 + (i/2), 1}));
		dp[1 + (i/2)][0] = min(dp[1 + (i/2)][0], dp[i/2][1] + dist(a[i], {1 + (i/2), 2}));
		dp[i/2][1] = min(dp[i/2][1], dp[i/2][0] + dist(a[i], {1 + (i/2), 1}));
		dp[i/2][2] = min(dp[i/2][2], dp[i/2][0] + dist(a[i], {1 + (i/2), 2}));
	}
	cout << dp[n][0];
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2684 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Incorrect 6 ms 2684 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2684 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Incorrect 6 ms 2684 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Correct 6 ms 2680 KB Output is correct
3 Correct 6 ms 2680 KB Output is correct
4 Correct 6 ms 2684 KB Output is correct
5 Correct 6 ms 2680 KB Output is correct
6 Incorrect 6 ms 2684 KB Output isn't correct
7 Halted 0 ms 0 KB -