답안 #541441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541441 2022-03-23T15:18:22 Z AmirElarbi 이상적인 도시 (IOI12_city) C++14
32 / 100
1000 ms 4300 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 1e5+5;
int ans = 0;
int mnx = INF,mny = INF, mxx = 0, mxy = 0;
int d[nax];
bool vis[nax];
vi adj[nax];
ve<pair<ii,int>> ed1, ed2;
int DistanceSum(int n, int *x, int *y) {
    for (int i = 0; i < n; ++i)
    {
        mnx = min(mnx,x[i]), mny = min(mny,y[i]);
        mxx = max(mxx,x[i]), mxy = max(mxy, y[i]);
    }
    mxx-=mnx,mxy-=mny;
    mxx++,mxy++;
    for (int i = 0; i < n; ++i)
    {
        x[i]-=mnx,y[i]-=mny;
        ed1.pb({{x[i],y[i]},i});
        ed2.pb({{y[i],x[i]},i});
    }
    sort(ed1.begin(), ed1.end());
    sort(ed2.begin(), ed2.end());
    for (int i = 1; i < n; ++i)
    {
        if(ed1[i].fi.fi == ed1[i-1].fi.fi && ed1[i].fi.se - ed1[i-1].fi.se == 1){
            adj[ed1[i].se].pb(ed1[i-1].se);
            adj[ed1[i-1].se].pb(ed1[i].se);
        }
        if(ed2[i].fi.fi == ed2[i-1].fi.fi&& ed2[i].fi.se - ed2[i-1].fi.se == 1){
            adj[ed2[i].se].pb(ed2[i-1].se);
            adj[ed2[i-1].se].pb(ed2[i].se);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        queue<int> q;
        q.push(i);
        memset(d,0,sizeof d);
        vis[i] = 1;
        while(!q.empty()){
            int cur = q.front();
            q.pop();
            for (auto j : adj[cur])
            {
                if(d[j] ) continue;
                d[j] = d[cur] + 1;
                if(!vis[j])
                    ans += d[j];
                ans %= MOD;
                q.push(j);
            }
        }
    }
    
    return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 3 ms 3028 KB Output is correct
5 Correct 3 ms 3028 KB Output is correct
6 Correct 6 ms 3028 KB Output is correct
7 Correct 5 ms 3028 KB Output is correct
8 Correct 5 ms 3028 KB Output is correct
9 Correct 5 ms 3028 KB Output is correct
10 Correct 4 ms 3028 KB Output is correct
11 Correct 4 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 3028 KB Output is correct
2 Correct 36 ms 3028 KB Output is correct
3 Correct 73 ms 3156 KB Output is correct
4 Correct 73 ms 3156 KB Output is correct
5 Correct 131 ms 3156 KB Output is correct
6 Correct 140 ms 3172 KB Output is correct
7 Correct 141 ms 3156 KB Output is correct
8 Correct 128 ms 3176 KB Output is correct
9 Correct 132 ms 3172 KB Output is correct
10 Correct 145 ms 3176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 4300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 4300 KB Time limit exceeded
2 Halted 0 ms 0 KB -