Submission #255169

#TimeUsernameProblemLanguageResultExecution timeMemory
255169davi_bartIdeal city (IOI12_city)C++14
32 / 100
1081 ms4856 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); map<pair<int,int>,int>k; vector<int> v[100010]; const int mod=1e9; int DistanceSum(int N, int *X, int *Y) { for(int i=0;i<N;i++){ if(k.count({X[i]-1,Y[i]})){ v[i].push_back(k[{X[i]-1,Y[i]}]); v[k[{X[i]-1,Y[i]}]].push_back(i); } if(k.count({X[i]+1,Y[i]})){ v[i].push_back(k[{X[i]+1,Y[i]}]); v[k[{X[i]+1,Y[i]}]].push_back(i); } if(k.count({X[i],Y[i]-1})){ v[i].push_back(k[{X[i],Y[i]-1}]); v[k[{X[i],Y[i]-1}]].push_back(i); } if(k.count({X[i],Y[i]+1})){ v[i].push_back(k[{X[i],Y[i]+1}]); v[k[{X[i],Y[i]+1}]].push_back(i); } k[{X[i],Y[i]}]=i; } ll tot=0; for(int i=0;i<N;i++){ vector<bool> vis(N,0); queue<pair<int,int> >q; q.push({i,0}); while(!q.empty()){ int pos=q.front().first; int d=q.front().second; q.pop(); if(vis[pos])continue; vis[pos]=1; tot+=d; for(int y:v[pos])q.push({y,d+1}); } } return (tot/2)%mod; } /* #define inbuf_len 1 << 16 #define outbuf_len 1 << 16 int DistanceSum(int N, int *X, int *Y); int main() { int tmp; char *inbuf, *outbuf; inbuf = (char*) malloc(inbuf_len * sizeof(char)); outbuf = (char*) malloc(outbuf_len * sizeof(char)); tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len); assert(tmp == 0); tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len); assert(tmp == 0); int N, i; tmp = scanf("%d", &N); assert(tmp == 1); int *sq_x, *sq_y; sq_x = (int*) malloc(N * sizeof(int)); sq_y = (int*) malloc(N * sizeof(int)); for (i = 0; i < N; i++) { tmp = scanf("%d %d", &sq_x[i], &sq_y[i]); assert(tmp == 2); } int ds = DistanceSum(N, sq_x, sq_y); printf("%d\n", ds); return 0; }*/ /* 11 2 5 2 6 3 3 3 6 4 3 4 4 4 5 4 6 5 3 5 4 5 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...