# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872037 | 2023-11-12T07:27:49 Z | Matjaz | Ideal city (IOI12_city) | C++14 | 99 ms | 856 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 - (N - 1 - i) * X[i]) % M; total += X[i]; } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 500 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 | 1 ms | 500 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 348 KB | Output is correct |
2 | Correct | 22 ms | 600 KB | Output is correct |
3 | Correct | 49 ms | 348 KB | Output is correct |
4 | Correct | 54 ms | 348 KB | Output is correct |
5 | Correct | 89 ms | 344 KB | Output is correct |
6 | Correct | 96 ms | 560 KB | Output is correct |
7 | Correct | 93 ms | 556 KB | Output is correct |
8 | Correct | 99 ms | 560 KB | Output is correct |
9 | Correct | 95 ms | 348 KB | Output is correct |
10 | Correct | 92 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 600 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 856 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |