답안 #64132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64132 2018-08-03T11:52:11 Z Vahan 이상적인 도시 (IOI12_city) C++17
100 / 100
451 ms 230424 KB
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
vector<pair<long long,long long> > g[3000000];
vector<long long> tx[3000000],ty[3000000];
long long sx[3000000],sy[3000000],xq[3000000],yq[3000000],n,u[3000000],xh,yh,xg[3000000],yg[3000000];
queue<long long> q;
long long pa=0;
long long mod=1000000000;
long long kax(long long x,long long y)
{
    for(long long i=0;i<tx[x].size();i++)
    {
        long long to=tx[x][i];
        if(to==y)
            return 0;
    }
    return 1;
}
long long kay(long long x,long long y)
{
    for(long long i=0;i<ty[x].size();i++)
    {
        long long to=ty[x][i];
        if(to==y)
            return 0;
    }
    return 1;
}
long long ka(long long x,long long y)
{
    long long in=-1;
    for(long long i=0;i<g[x].size();i++)
    {
        long long to=g[x][i].first;
        long long ind=g[x][i].second;
        if(to==y)
        {
            in=ind;
            break;
        }
    }
    return in;
}
void dfsx(long long v,long long p)
{
    sx[v]=xq[v];
    long long r=0,l=0;
    for(long long i=0;i<tx[v].size();i++)
    {
        long long to=tx[v][i];
        if(to==p)
            continue;
        dfsx(to,v);
        sx[v]+=sx[to];
        pa+=(sx[to]*(n-sx[to]))%mod;
        pa%=mod;
    }
}
void dfsy(long long v,long long p)
{
    sy[v]=yq[v];
    for(long long i=0;i<ty[v].size();i++)
    {
        long long to=ty[v][i];
        if(to==p)
            continue;
        dfsy(to,v);
        sy[v]+=sy[to];
        pa+=(sy[to]*(n-sy[to]))%mod;
        pa%=mod;
    }
}
long long DistanceSum(int N, int *X, int *Y)
{
    n=N;
    for(long long i=0;i<n;i++)
        g[X[i]].push_back(make_pair(Y[i],i));
    for(long long i=0;i<n;i++)
    {
        if(u[i]==0)
        {
            long long x=X[i],y=Y[i];
            xg[i]=xh;
            xq[xh]++;
            long long t=1;
            while(1)
            {
                long long 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)
            {
                long long 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(long long i=0;i<n;i++)
        u[i]=0;
    for(long long i=0;i<n;i++)
    {
        if(u[i]==0)
        {
            long long x=X[i],y=Y[i];
            yg[i]=yh;
            yq[yh]++;
            long long t=1;
            while(1)
            {
                long long aa=ka(x,y+t);
                if(aa==-1)
                    break;
                yg[aa]=yh;
                yq[yh]++;
                u[aa]=1;
                t++;
            }
            t=1;
            while(1)
            {
                long long aa=ka(x,y-t);
                if(aa==-1)
                    break;
                yg[aa]=yh;
                yq[yh]++;
                u[aa]=1;
                t++;
            }
            yh++;
        }
    }
    for(long long i=0;i<n;i++)
    {
        long long x=X[i],y=Y[i];
        long long 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 'long long int kax(long long int, long long int)':
city.cpp:13:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<tx[x].size();i++)
                       ~^~~~~~~~~~~~~
city.cpp: In function 'long long int kay(long long int, long long int)':
city.cpp:23:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<ty[x].size();i++)
                       ~^~~~~~~~~~~~~
city.cpp: In function 'long long int ka(long long int, long long int)':
city.cpp:34:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<g[x].size();i++)
                       ~^~~~~~~~~~~~
city.cpp: In function 'void dfsx(long long int, long long int)':
city.cpp:50:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<tx[v].size();i++)
                       ~^~~~~~~~~~~~~
city.cpp:49:15: warning: unused variable 'r' [-Wunused-variable]
     long long r=0,l=0;
               ^
city.cpp:49:19: warning: unused variable 'l' [-Wunused-variable]
     long long r=0,l=0;
                   ^
city.cpp: In function 'void dfsy(long long int, long long int)':
city.cpp:64:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(long long i=0;i<ty[v].size();i++)
                       ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 211788 KB Output is correct
2 Correct 199 ms 211788 KB Output is correct
3 Correct 219 ms 211824 KB Output is correct
4 Correct 203 ms 211824 KB Output is correct
5 Correct 205 ms 211840 KB Output is correct
6 Correct 196 ms 211896 KB Output is correct
7 Correct 205 ms 211896 KB Output is correct
8 Correct 192 ms 212020 KB Output is correct
9 Correct 188 ms 212020 KB Output is correct
10 Correct 183 ms 212020 KB Output is correct
11 Correct 210 ms 212020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 212080 KB Output is correct
2 Correct 228 ms 212080 KB Output is correct
3 Correct 240 ms 212220 KB Output is correct
4 Correct 192 ms 212220 KB Output is correct
5 Correct 219 ms 212220 KB Output is correct
6 Correct 207 ms 212264 KB Output is correct
7 Correct 202 ms 212264 KB Output is correct
8 Correct 197 ms 212264 KB Output is correct
9 Correct 182 ms 212264 KB Output is correct
10 Correct 180 ms 212264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 213148 KB Output is correct
2 Correct 206 ms 213324 KB Output is correct
3 Correct 245 ms 215424 KB Output is correct
4 Correct 233 ms 215728 KB Output is correct
5 Correct 335 ms 219832 KB Output is correct
6 Correct 367 ms 220236 KB Output is correct
7 Correct 327 ms 221108 KB Output is correct
8 Correct 354 ms 221960 KB Output is correct
9 Correct 249 ms 222024 KB Output is correct
10 Correct 303 ms 225468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 225468 KB Output is correct
2 Correct 261 ms 225468 KB Output is correct
3 Correct 343 ms 225468 KB Output is correct
4 Correct 304 ms 225468 KB Output is correct
5 Correct 378 ms 228768 KB Output is correct
6 Correct 451 ms 228768 KB Output is correct
7 Correct 432 ms 230424 KB Output is correct
8 Correct 432 ms 230424 KB Output is correct
9 Correct 440 ms 230424 KB Output is correct
10 Correct 371 ms 230424 KB Output is correct