Submission #363060

# Submission time Handle Problem Language Result Execution time Memory
363060 2021-02-05T03:59:53 Z fhvirus Ideal city (IOI12_city) C++14
11 / 100
1000 ms 262148 KB
//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
int DistanceSum(int N, int *X, int *Y);
const int N = 1e5 + 225;
int x[N], y[N];
int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n; cin >> n;
	FOR(i,n) cin >> x[i] >> y[i];
	cout << DistanceSum(n, x, y) << endl;
	return 0;
}
#endif
const int M = 1000000000;
int DistanceSum(int n, int *x, int *y){
	const int dx[4] = {1, -1, 0, 0};
	const int dy[4] = {0, 0, 1, -1};
	vector<vector<int>> dp(n, vector<int>(n, M));
	for(int i = 0; i < n; ++i) dp[i][i] = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i + 1; j < n; ++j){
			for(int d = 0; d < 4; ++d){
				if(x[i] + dx[d] == x[j] and y[i] + dy[d] == y[j])
					dp[i][j] = dp[j][i] = 1;
			}
		}
	}
	for(int k = 0; k < n; ++k){
		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				if(dp[i][k] != M and dp[k][j] != M)
					chmin(dp[i][j], dp[i][k] + dp[k][j]);
				
	}
	ll ans = 0;
	for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j)
			ans += dp[i][j];
	return ans % M;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 268 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 492 KB Output is correct
7 Correct 12 ms 544 KB Output is correct
8 Correct 10 ms 492 KB Output is correct
9 Correct 11 ms 492 KB Output is correct
10 Correct 12 ms 492 KB Output is correct
11 Correct 12 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 4460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 170 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 153 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -