Submission #562574

# Submission time Handle Problem Language Result Execution time Memory
562574 2022-05-14T16:33:31 Z Leo121 Ideal city (IOI12_city) C++14
0 / 100
1000 ms 1748 KB
#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, int> mapa;
queue<pii> q;
int mod = 1e9;
int res = 0;
void bfs(){
    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])] == -1){
                    mapa[mp(act.fi + mx[i], act.se + my[i])] = mapa[mp(act.fi, act.se)] + 1;
                    res += mapa[mp(act.fi + mx[i], act.se + my[i])];
                    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])] = 0;
        forn(j, i + 1, N - 1){
            mapa[mp(X[j], Y[j])] = -1;
        }
        q.push(mp(X[i], Y[i]));
        bfs();
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 1748 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 1748 KB Time limit exceeded
2 Halted 0 ms 0 KB -