답안 #64126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64126 2018-08-03T11:43:52 Z Vahan 이상적인 도시 (IOI12_city) C++17
32 / 100
232 ms 213520 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;
                if(xg[0]==6)
                cout<<"000000"<<x<<" "<<y<<endl;
                xq[xh]++;
                u[aa]=1;
                t++;
            }
            t=1;
            while(1)
            {
                int aa=ka(x-t,y);
                if(aa==-1)
                    break;
                xg[aa]=xh;
                if(xg[0]==6)
                cout<<"0000"<<x<<" "<<y<<endl;
                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 185 ms 211732 KB Output is correct
2 Correct 209 ms 211816 KB Output is correct
3 Correct 186 ms 211892 KB Output is correct
4 Correct 219 ms 212048 KB Output is correct
5 Correct 232 ms 212048 KB Output is correct
6 Correct 199 ms 212068 KB Output is correct
7 Correct 188 ms 212104 KB Output is correct
8 Correct 187 ms 212104 KB Output is correct
9 Correct 186 ms 212104 KB Output is correct
10 Correct 217 ms 212104 KB Output is correct
11 Correct 205 ms 212248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 212248 KB Output is correct
2 Correct 205 ms 212248 KB Output is correct
3 Correct 189 ms 212256 KB Output is correct
4 Correct 216 ms 212272 KB Output is correct
5 Correct 184 ms 212272 KB Output is correct
6 Correct 184 ms 212288 KB Output is correct
7 Correct 201 ms 212452 KB Output is correct
8 Correct 225 ms 212452 KB Output is correct
9 Correct 189 ms 212452 KB Output is correct
10 Correct 204 ms 212452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 211 ms 212932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 211 ms 213520 KB Output isn't correct
2 Halted 0 ms 0 KB -