답안 #287230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287230 2020-08-31T14:04:17 Z stoyan_malinin 이상적인 도시 (IOI12_city) C++14
32 / 100
1000 ms 3064 KB
//#include "grader.cpp"

#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int mod = 1e9;

struct Point
{
    long long x, y;

    Point(){}
    Point(long long x, long long y)
    {
        this->x = x;
        this->y = y;
    }
};

int n;
vector <Point> v;

void init()
{
    int ind = 0;
    set <int> s;
    map <int, int> code;

    for(Point p: v) s.insert(p.x);
    for(int x: s) code[x] = ind, ind++;
    for(Point &p: v) p.x = code[p.x];

    //-----------------------

    ind = 0;
    s.clear();
    code.clear();

    for(Point p: v) s.insert(p.y);
    for(int y: s) code[y] = ind, ind++;
    for(Point &p: v) p.y  = code[p.y];
}

namespace Subtask2
{
    const vector <pair <int, int>> jumps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    const int MAXN = 2005;

    bool exists[MAXN][MAXN];
    int dist[MAXN][MAXN];

    void bfs(Point p)
    {
        queue <Point> q;
        for(Point p: v) dist[p.x][p.y] = -1;

        q.push(p);
        dist[p.x][p.y] = 0;

        while(q.empty()==false)
        {
            p = q.front();
            q.pop();

            for(pair <int, int> j: jumps)
            {
                if(p.x+j.first>=0 && p.y+j.second>=0
                   && dist[p.x+j.first][p.y+j.second]==-1
                   && exists[p.x+j.first][p.y+j.second]==true)
                {
                    q.push(Point(p.x+j.first, p.y+j.second));
                    dist[p.x+j.first][p.y+j.second] = dist[p.x][p.y] + 1;
                }
            }
        }
    }

    long long solve()
    {
        for(Point p: v) exists[p.x][p.y] = true;

        long long answer = 0;
        for(Point p: v)
        {
            bfs(p);
            for(Point other: v) answer = (answer + dist[other.x][other.y])%mod;
        }

        return answer;
    }
};

int DistanceSum(int N, int *X, int *Y)
{
    n = N;
    for(int i = 0;i<n;i++) v.push_back(Point(X[i], Y[i]));

    init();
    if(n<=2000) return Subtask2::solve()/2;
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:107:1: warning: control reaches end of non-void function [-Wreturn-type]
  107 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 768 KB Output is correct
2 Correct 35 ms 768 KB Output is correct
3 Correct 80 ms 896 KB Output is correct
4 Correct 74 ms 896 KB Output is correct
5 Correct 146 ms 1024 KB Output is correct
6 Correct 122 ms 896 KB Output is correct
7 Correct 147 ms 1280 KB Output is correct
8 Correct 125 ms 1400 KB Output is correct
9 Correct 121 ms 768 KB Output is correct
10 Correct 119 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1038 ms 2756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 3064 KB Time limit exceeded
2 Halted 0 ms 0 KB -