Submission #424045

# Submission time Handle Problem Language Result Execution time Memory
424045 2021-06-11T15:47:35 Z cfalas Ideal city (IOI12_city) C++17
32 / 100
1000 ms 3344 KB
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000000
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

vi a, b;

ii diag[4] = {{0,-1}, {0,1}, {-1,0}, {1,0}};

ll paris(ii x){
	return ((ll)x.F)*(INT_MAX+1ll) + x.S;
}

ii unparis(ll x){
	return {x/(INT_MAX+1ll), x%(INT_MAX+1ll)};
}

int DistanceSum(int n, int *X, int *Y) {
	unordered_map<ll, vector<ll> > adj;
	FOR(i,n){
		FORi(j,i+1,n){
			if(abs(X[i]-X[j])+abs(Y[i]-Y[j])==1){
				adj[paris({X[i], Y[i]})].push_back(paris({X[j], Y[j]}));
				adj[paris({X[j], Y[j]})].push_back(paris({X[i], Y[i]}));
			}
		}
	}
	int ans=0;
	FOR(i,n){
		// bfs from i
		unordered_set<ll> used;
		queue<ll> q;
		q.push(paris({X[i], Y[i]}));
		used.insert(paris({X[i], Y[i]}));
		q.push(-1);
		int d=0;
		//cout<<X[i]<<" "<<Y[i]<<": "<<endl;
		while(q.size()>1){
			ll t = q.front();
			q.pop();
			if(t==-1){
				d++;
				q.push(-1);
				continue;
			}
			//cout<<t.F<<" "<<t.S<<" "<<d<<endl;
			ans+=d;
			ans%=MOD;

			FOA(x, adj[t]){
				if(!used.count(x)){
					q.push(x);
					used.insert(x);
				}
			}
		}
	}
	return ans/2;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 9 ms 204 KB Output is correct
7 Correct 13 ms 204 KB Output is correct
8 Correct 10 ms 324 KB Output is correct
9 Correct 10 ms 328 KB Output is correct
10 Correct 11 ms 204 KB Output is correct
11 Correct 13 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 444 KB Output is correct
2 Correct 224 ms 432 KB Output is correct
3 Correct 498 ms 524 KB Output is correct
4 Correct 510 ms 536 KB Output is correct
5 Correct 853 ms 708 KB Output is correct
6 Correct 942 ms 628 KB Output is correct
7 Correct 854 ms 616 KB Output is correct
8 Correct 987 ms 616 KB Output is correct
9 Correct 957 ms 620 KB Output is correct
10 Correct 992 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 3344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 3132 KB Time limit exceeded
2 Halted 0 ms 0 KB -