Submission #863965

# Submission time Handle Problem Language Result Execution time Memory
863965 2023-10-21T15:05:26 Z Danilo21 Cell Automaton (JOI23_cell) C++17
0 / 100
839 ms 451160 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 4e18;
const int mxN = 1e6+10, A = 5e3+10, INF = 2e9;
ll n, m;
array<int, 2> a[mxN];

ll dist[A][A], cnt[2*A];
bool vis[A][A];
array<int, 2> dxdy[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

bool Valid(int i, int j){ return i >= 0 && i < A && j >= 0 && j < A && !vis[i][j]; }

void BF(){

    queue<array<int, 2> > q;
    for (int i = 0; i < n; i++){
        auto [x, y] = a[i];
        x += A/2; y += A/2;
        q.push({x, y});
        vis[x][y] = 1;
        cnt[0]++;
    }
    while (q.size()){
        auto [i, j] = q.front(); q.pop();
        for (auto [dx, dy] : dxdy){
            int x = i+dx, y = j+dy;
            if (Valid(x, y)){
                vis[x][y] = 1;
                dist[x][y] = dist[i][j] + 1;
                cnt[dist[x][y]]++;
                q.push({x, y});
            }
        }
    }
    while (m--){
        ri(t);
        cout << cnt[t] << en;
    }
}

ll b[mxN];
vector<ll> mrg;

void Solve1(){

    for (int i = 0; i < n; i++)
        b[i] = a[i][0];
    sort(b, b+n);
    for (int i = 0; i < n-1; i++)
        mrg.pb(b[i+1] - b[i]);
    sort(all(mrg));
    int k = 0;
    ll N = n, E = 0;
    while (m--){
        rl(t);
        ll cnt = 0;
        while (mrg[k] <= t){
            E += mrg[k]-1;
            N--;
            if (mrg[k] == t)
                cnt++;
            k++;
        }

        if (t) cout << 2LL*(n*(t+1) - (n-N)*t + E) + (2LL*N + cnt)*(t-1) << en;
        else cout << n << en;
    }
}

void Solve(){

    cin >> n >> m;
    bool f = 1;
    for (int i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1];
        if (a[i][0] != a[i][1]) f = 0;
    }
    if (f) Solve1();
    else BF();
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 730 ms 222552 KB Output is correct
2 Correct 702 ms 222944 KB Output is correct
3 Correct 686 ms 222724 KB Output is correct
4 Correct 712 ms 222708 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 730 ms 222552 KB Output is correct
2 Correct 702 ms 222944 KB Output is correct
3 Correct 686 ms 222724 KB Output is correct
4 Correct 712 ms 222708 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 7132 KB Output is correct
2 Correct 29 ms 6960 KB Output is correct
3 Correct 29 ms 7120 KB Output is correct
4 Correct 35 ms 7184 KB Output is correct
5 Correct 31 ms 8004 KB Output is correct
6 Correct 30 ms 7892 KB Output is correct
7 Correct 29 ms 7780 KB Output is correct
8 Runtime error 7 ms 4700 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 7132 KB Output is correct
2 Correct 29 ms 6960 KB Output is correct
3 Correct 29 ms 7120 KB Output is correct
4 Correct 35 ms 7184 KB Output is correct
5 Correct 31 ms 8004 KB Output is correct
6 Correct 30 ms 7892 KB Output is correct
7 Correct 29 ms 7780 KB Output is correct
8 Runtime error 7 ms 4700 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 839 ms 451160 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 839 ms 451160 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 730 ms 222552 KB Output is correct
2 Correct 702 ms 222944 KB Output is correct
3 Correct 686 ms 222724 KB Output is correct
4 Correct 712 ms 222708 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -