Submission #810953

# Submission time Handle Problem Language Result Execution time Memory
810953 2023-08-06T18:07:43 Z ma_moutahid Ideal city (IOI12_city) C++17
32 / 100
1000 ms 2968 KB
#include <bits/stdc++.h>
using ll =long long;
//#define int ll
ll LINF=1000000000000000000;
int INF=1000000000;
#define pi pair<int,int>
#define pl pair<ll,ll>
#define endl '\n'
#define vi vector<int>
#define vii vector<vector<int>>
#define vl vector<ll>
#define vll vector<vector<ll>>
//#define int ll
using namespace std;



int DistanceSum(int n,int *X,int *Y){
    map<pi,int>m;
    map<pi,pi>pos;
    int mod=1e9;
    vii g(n);
    for(int i=0;i<n;i++){
        m.insert(make_pair(make_pair(X[i],Y[i]),i));
    }
    for(int i=0;i<n;i++){
        int x=X[i],y=Y[i];
        auto itr=m.find(make_pair(x+1,y));
        if(itr!=m.end()){
            g[i].push_back(itr->second);
        }
        itr=m.find(make_pair(x-1,y));
        if(itr!=m.end()){
            g[i].push_back(itr->second);
        }
        itr=m.find(make_pair(x,y+1));
        if(itr!=m.end()){
            g[i].push_back(itr->second);
        }
        itr=m.find(make_pair(x,y-1));
        if(itr!=m.end()){
            g[i].push_back(itr->second);
        }
    }
    ll result=0;
    for(int i=0;i<n;i++){
        set<pair<ll,int>>s;
        s.insert(make_pair(0ll,i));
        vi checked(n);
        while(!s.empty()){
            ll dist=s.begin()->first;
            dist%=mod;
            int node=s.begin()->second;
            checked[node]= 1;
            result+=dist;
            result%=mod;
            s.erase(s.begin());
            for(int &i:g[node]){
                if(checked[i])continue;
                s.insert(make_pair(dist+1,i));
            }
        }
    }
    return result/2;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 5 ms 212 KB Output is correct
7 Correct 6 ms 212 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 6 ms 212 KB Output is correct
11 Correct 6 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 340 KB Output is correct
2 Correct 131 ms 460 KB Output is correct
3 Correct 280 ms 468 KB Output is correct
4 Correct 280 ms 468 KB Output is correct
5 Correct 529 ms 564 KB Output is correct
6 Correct 542 ms 468 KB Output is correct
7 Correct 417 ms 572 KB Output is correct
8 Correct 529 ms 560 KB Output is correct
9 Correct 706 ms 584 KB Output is correct
10 Correct 694 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 2968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 2900 KB Time limit exceeded
2 Halted 0 ms 0 KB -