답안 #64115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64115 2018-08-03T11:24:41 Z Vahan 이상적인 도시 (IOI12_city) C++17
0 / 100
251 ms 213688 KB
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
vector<pair<int,int> > g[3000000];
vector<int> tx[3000000],ty[3000000];
int sx[3000000],sy[3000000],xq[3000000],yq[3000000],n,u[3000000],xh,yh,xg[3000000],yg[3000000];
queue<int> q;
long long pa=0;
int kax(int x,int y)
{
    for(int i=0;i<tx[x].size();i++)
    {
        int to=tx[x][i];
        if(to==y)
            return 0;
    }
    return 1;
}
int kay(int x,int y)
{
    for(int i=0;i<ty[x].size();i++)
    {
        int to=ty[x][i];
        if(to==y)
            return 0;
    }
    return 1;
}
int ka(int x,int y)
{
    int in=-1;
    for(int i=0;i<g[x].size();i++)
    {
        int to=g[x][i].first;
        int ind=g[x][i].second;
        if(to==y)
        {
            in=ind;
            break;
        }
    }
    return in;
}
void dfsx(int v,int p)
{
    sx[v]=xq[v];
    long long r=0,l=0;
    for(int i=0;i<tx[v].size();i++)
    {
        int to=tx[v][i];
        if(to==p)
            continue;
        dfsx(to,v);
        sx[v]+=sx[to];
        pa+=sx[to]*(n-sx[to]);
    }
}
void dfsy(int v,int p)
{
    sy[v]=yq[v];
    for(int i=0;i<ty[v].size();i++)
    {
        int to=ty[v][i];
        if(to==p)
            continue;
        dfsy(to,v);
        sy[v]+=sy[to];
        pa+=sy[to]*(n-sy[to]);
    }
}
int DistanceSum(int N, int *X, int *Y)
{
    n=N;
    for(int i=0;i<n;i++)
        g[X[i]].push_back(make_pair(Y[i],i));
    for(int i=0;i<n;i++)
    {
        if(u[i]==0)
        {
            int x=X[i],y=Y[i];
            xg[i]=xh;
            xq[xh]++;
            int t=1;
            while(1)
            {
                int aa=ka(x+t,y);
                if(aa==-1)
                    break;
                xg[aa]=xh;
                xq[xh]++;
                u[aa]=1;
                t++;
            }
            t=1;
            while(1)
            {
                int aa=ka(x-t,y);
                if(aa==-1)
                    break;
                xg[aa]=xh;
                xq[xh]++;
                u[aa]=1;
                t--;
            }
            xh++;
        }
    }
    for(int i=0;i<n;i++)
        u[i]=0;
    for(int i=0;i<n;i++)
    {
        if(u[i]==0)
        {
            int x=X[i],y=Y[i];
            yg[i]=yh;
            yq[yh]++;
            int t=1;
            while(1)
            {
                int aa=ka(x,y+t);
                if(aa==-1)
                    break;
                yg[aa]=yh;
                yq[yh]++;
                u[aa]=1;
                t++;
            }
            t=1;
            while(1)
            {
                int aa=ka(x,y-t);
                if(aa==-1)
                    break;
                yg[aa]=yh;
                yq[yh]++;
                u[aa]=1;
                t--;
            }
            yh++;
        }
    }
    for(int i=0;i<n;i++)
    {
        int x=X[i],y=Y[i];
        int e=ka(x+1,y);
        if(e!=-1 && kay(yg[i],yg[e]))
            ty[yg[i]].push_back(yg[e]);
        e=ka(x-1,y);
        if(e!=-1 && kay(yg[i],yg[e]))
            ty[yg[i]].push_back(yg[e]);
        e=ka(x,y+1);
        if(e!=-1 && kax(xg[i],xg[e]))
            tx[xg[i]].push_back(xg[e]);
        e=ka(x,y-1);
        if(e!=-1 && kax(xg[i],xg[e]))
            tx[xg[i]].push_back(xg[e]);
    }
    dfsx(0,-1);
    dfsy(0,-1);
    return pa;
}

Compilation message

city.cpp: In function 'int kax(int, int)':
city.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<tx[x].size();i++)
                 ~^~~~~~~~~~~~~
city.cpp: In function 'int kay(int, int)':
city.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ty[x].size();i++)
                 ~^~~~~~~~~~~~~
city.cpp: In function 'int ka(int, int)':
city.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g[x].size();i++)
                 ~^~~~~~~~~~~~
city.cpp: In function 'void dfsx(int, int)':
city.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<tx[v].size();i++)
                 ~^~~~~~~~~~~~~
city.cpp:48:15: warning: unused variable 'r' [-Wunused-variable]
     long long r=0,l=0;
               ^
city.cpp:48:19: warning: unused variable 'l' [-Wunused-variable]
     long long r=0,l=0;
                   ^
city.cpp: In function 'void dfsy(int, int)':
city.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ty[v].size();i++)
                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 211876 KB Output is correct
2 Incorrect 215 ms 211876 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 195 ms 212048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 251 ms 212748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 227 ms 213688 KB Output isn't correct
2 Halted 0 ms 0 KB -