답안 #872039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872039 2023-11-12T07:30:45 Z Matjaz 이상적인 도시 (IOI12_city) C++14
55 / 100
103 ms 2132 KB
#include<algorithm>
#include <vector>
#include <stdlib.h>
#include <iostream>
#include <queue>

using namespace std;



int DistanceSum(int N, int *X, int *Y) {
    
    if (N <= 2000){
        vector<vector<int> > s(N, vector<int>());
        
        for (int i=0;i<N;i++){
            for (int j=i+1;j<N;j++){
                if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) <= 1){
                    s[i].push_back(j);
                    s[j].push_back(i);
                }
            }
        }
        
        
        long long M = 1000000000;
        
        long long sum = 0;
        
        for (int i=0;i<N;i++){
            vector<int> d(N, N + 1);
            d[i] = 0;
            queue<int> Q;
            Q.push(i);
            while (!Q.empty()){
                int x = Q.front(); Q.pop();
                for (int i=0;i<s[x].size();i++){
                    if (d[s[x][i]] > d[x] + 1){
                        d[s[x][i]] = d[x] + 1;
                        Q.push(s[x][i]);
                    }
                }
            }

            for (int j=i+1;j<N;j++) sum = (sum + d[j]) % M;
        }
        
        return sum;
        
    } else {
        
        long long sum = 0;
        long long M = 1000000000;
        sort(X, X + N);
        sort(Y, Y + N);
        
        long long total = 0;
        for (int i=N-1;i>=0;i--){
            sum = (sum + total - (long long)(N - 1 - i) * X[i]) % M;
            total += X[i];
        }
        
        total = 0;
        for (int i=N-1;i>=0;i--){
            sum = (sum + total - (long long)(N - 1 - i) * Y[i]) % M;
            total += Y[i];
        }
        
        return sum;
    }
    
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:37:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                 for (int i=0;i<s[x].size();i++){
      |                              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 348 KB Output is correct
2 Correct 25 ms 344 KB Output is correct
3 Correct 51 ms 348 KB Output is correct
4 Correct 54 ms 348 KB Output is correct
5 Correct 91 ms 348 KB Output is correct
6 Correct 95 ms 556 KB Output is correct
7 Correct 92 ms 556 KB Output is correct
8 Correct 103 ms 344 KB Output is correct
9 Correct 95 ms 348 KB Output is correct
10 Correct 91 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 11 ms 1076 KB Output is correct
4 Correct 14 ms 1332 KB Output is correct
5 Correct 21 ms 1840 KB Output is correct
6 Correct 26 ms 1880 KB Output is correct
7 Correct 22 ms 2132 KB Output is correct
8 Correct 21 ms 1884 KB Output is correct
9 Correct 21 ms 1884 KB Output is correct
10 Correct 21 ms 1804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -