#include <bits/stdc++.h>
#define forn(i, a, b) for(int i = int (a); i <= int(b); ++ i)
#define fora(i, a, b) for(int i = int (a); i >= int(b); -- i)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
int mx[4] = {0, 0, 1, -1};
int my[4] = {1, -1, 0, 0};
map<pii, pii> mapa;
queue<pii> q;
int mod = 1e9;
int res = 0;
void bfs(int ind){
pii act;
while(!q.empty()){
act = q.front();
q.pop();
forn(i, 0, 3){
if(mapa.count(mp(act.fi + mx[i], act.se + my[i]))){
if(mapa[mp(act.fi + mx[i], act.se + my[i])].fi == -1){
mapa[mp(act.fi + mx[i], act.se + my[i])].fi = mapa[mp(act.fi, act.se)].fi + 1;
if(mapa[mp(act.fi + mx[i], act.se + my[i])].se > ind){
res += mapa[mp(act.fi + mx[i], act.se + my[i])].fi;
res %= mod;
}
q.push(mp(act.fi + mx[i], act.se + my[i]));
}
}
}
}
}
int DistanceSum(int N, int *X, int *Y) {
forn(i, 0, N - 1){
mapa[mp(X[i], Y[i])] = mp(0, i);
forn(j, 0, N - 1){
if(j != i){
mapa[mp(X[j], Y[j])] = mp(-1, j);
}
}
q.push(mp(X[i], Y[i]));
bfs(i);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
20 ms |
212 KB |
Output is correct |
7 |
Correct |
20 ms |
316 KB |
Output is correct |
8 |
Correct |
21 ms |
212 KB |
Output is correct |
9 |
Correct |
21 ms |
212 KB |
Output is correct |
10 |
Correct |
22 ms |
212 KB |
Output is correct |
11 |
Correct |
21 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
758 ms |
368 KB |
Output is correct |
2 |
Correct |
739 ms |
360 KB |
Output is correct |
3 |
Execution timed out |
1098 ms |
340 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
1704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1097 ms |
1748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |