Submission #965211

# Submission time Handle Problem Language Result Execution time Memory
965211 2024-04-18T08:19:42 Z phoenix0423 Cell Automaton (JOI23_cell) C++17
32 / 100
559 ms 136072 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 4000 + 5;
const int INF = 1e18;
int dist[maxn][maxn];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, q;

void sol1(vector<pll> e, vector<pll> op){
    queue<pll> qq;
    for(int i = 0; i < maxn; i++) for(int j = 0; j < maxn; j++) dist[i][j] = INF;
    for(auto [x, y] : e){
        x += maxn / 2, y += maxn / 2;
        dist[x][y] = 0;
        qq.push({x, y});
    }
    vector<int> ans(maxn * 2);
    ans[0] = e.size();
    auto inbound = [&](int x, int y) -> bool {
        return x >= 0 && y >= 0 && x < maxn && y < maxn;
    };
    while(!qq.empty()){
        auto [x, y] = qq.front(); qq.pop();
        for(int d = 0; d < 4; d++){
            int xx = x + dx[d], yy = y + dy[d];
            if(!inbound(xx, yy) || dist[xx][yy] < INF) continue;
            dist[xx][yy] = dist[x][y] + 1;
            ans[dist[xx][yy]] += 1;
            qq.push({xx, yy});
        }
    }
    for(auto [t, tmp] : op){
        cout<<ans[t]<<"\n";
    }
    return;
}

vector<pll> op;
signed main(void){
    fastio;
    cin>>n>>q;
    int mx = 0, mxt = 0;
    vector<pll> e;
    for(int i = 0; i < n; i++){
        int x, y;
        cin>>x>>y;
        mx = max(mx, max(abs(x), abs(y)));
        e.pb({x, y});
    }
    for(int i = 0; i < q; i++){
        int x;
        cin>>x;
        mxt = max(mxt, x);
        op.pb({x, 1});
    }
    if(mx <= 1000 && mxt <= 1000){
        sol1(e, op);
        return 0;
    }
    sort(e.begin(), e.end());
    for(int i = 1; i < n; i++){
        int x = e[i].f - e[i - 1].f;
        op.pb({x, 0}), op.pb({x, 2});
    }
    int face = n * 4, ans = n;
    int prv = 0;
    sort(op.begin(), op.end());
    for(auto [t, val] : op){
        ans += face * (t - prv);
        if(prv == 0 && t != 0) ans -= n;
        prv = t;
        if(val != 1){
            ans -= (t + 1);
            if(val == 2) ans += 2;
            face -= 2;
        }
        else cout<<ans<<"\n";
    }


}
# Verdict Execution time Memory Grader output
1 Correct 495 ms 125972 KB Output is correct
2 Correct 509 ms 126036 KB Output is correct
3 Correct 451 ms 126200 KB Output is correct
4 Correct 436 ms 126176 KB Output is correct
5 Correct 448 ms 126356 KB Output is correct
6 Correct 435 ms 126188 KB Output is correct
7 Correct 441 ms 126000 KB Output is correct
8 Correct 455 ms 126620 KB Output is correct
9 Correct 442 ms 126200 KB Output is correct
10 Correct 455 ms 125984 KB Output is correct
11 Correct 458 ms 126196 KB Output is correct
12 Correct 473 ms 126236 KB Output is correct
13 Correct 465 ms 126192 KB Output is correct
14 Correct 475 ms 126236 KB Output is correct
15 Correct 484 ms 126480 KB Output is correct
16 Correct 473 ms 126408 KB Output is correct
17 Correct 479 ms 126192 KB Output is correct
18 Correct 473 ms 126120 KB Output is correct
19 Correct 464 ms 126188 KB Output is correct
20 Correct 439 ms 126160 KB Output is correct
21 Correct 469 ms 126272 KB Output is correct
22 Correct 464 ms 126172 KB Output is correct
23 Correct 523 ms 126372 KB Output is correct
24 Correct 460 ms 126192 KB Output is correct
25 Correct 463 ms 126092 KB Output is correct
26 Correct 528 ms 126420 KB Output is correct
27 Correct 503 ms 126412 KB Output is correct
28 Correct 496 ms 126200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 495 ms 125972 KB Output is correct
2 Correct 509 ms 126036 KB Output is correct
3 Correct 451 ms 126200 KB Output is correct
4 Correct 436 ms 126176 KB Output is correct
5 Correct 448 ms 126356 KB Output is correct
6 Correct 435 ms 126188 KB Output is correct
7 Correct 441 ms 126000 KB Output is correct
8 Correct 455 ms 126620 KB Output is correct
9 Correct 442 ms 126200 KB Output is correct
10 Correct 455 ms 125984 KB Output is correct
11 Correct 458 ms 126196 KB Output is correct
12 Correct 473 ms 126236 KB Output is correct
13 Correct 465 ms 126192 KB Output is correct
14 Correct 475 ms 126236 KB Output is correct
15 Correct 484 ms 126480 KB Output is correct
16 Correct 473 ms 126408 KB Output is correct
17 Correct 479 ms 126192 KB Output is correct
18 Correct 473 ms 126120 KB Output is correct
19 Correct 464 ms 126188 KB Output is correct
20 Correct 439 ms 126160 KB Output is correct
21 Correct 469 ms 126272 KB Output is correct
22 Correct 464 ms 126172 KB Output is correct
23 Correct 523 ms 126372 KB Output is correct
24 Correct 460 ms 126192 KB Output is correct
25 Correct 463 ms 126092 KB Output is correct
26 Correct 528 ms 126420 KB Output is correct
27 Correct 503 ms 126412 KB Output is correct
28 Correct 496 ms 126200 KB Output is correct
29 Correct 524 ms 126320 KB Output is correct
30 Correct 501 ms 126416 KB Output is correct
31 Correct 559 ms 126240 KB Output is correct
32 Correct 465 ms 135108 KB Output is correct
33 Correct 474 ms 126320 KB Output is correct
34 Correct 441 ms 126024 KB Output is correct
35 Correct 468 ms 126316 KB Output is correct
36 Correct 535 ms 126168 KB Output is correct
37 Correct 512 ms 126156 KB Output is correct
38 Correct 462 ms 126776 KB Output is correct
39 Correct 390 ms 128520 KB Output is correct
40 Correct 447 ms 136072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 9720 KB Output is correct
2 Correct 46 ms 9836 KB Output is correct
3 Correct 45 ms 9140 KB Output is correct
4 Correct 44 ms 8676 KB Output is correct
5 Correct 57 ms 9292 KB Output is correct
6 Correct 59 ms 9544 KB Output is correct
7 Correct 44 ms 9700 KB Output is correct
8 Correct 439 ms 126152 KB Output is correct
9 Correct 412 ms 126024 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 56 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 9720 KB Output is correct
2 Correct 46 ms 9836 KB Output is correct
3 Correct 45 ms 9140 KB Output is correct
4 Correct 44 ms 8676 KB Output is correct
5 Correct 57 ms 9292 KB Output is correct
6 Correct 59 ms 9544 KB Output is correct
7 Correct 44 ms 9700 KB Output is correct
8 Correct 439 ms 126152 KB Output is correct
9 Correct 412 ms 126024 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 56 ms 9040 KB Output is correct
12 Correct 142 ms 27016 KB Output is correct
13 Correct 144 ms 25900 KB Output is correct
14 Correct 148 ms 27076 KB Output is correct
15 Correct 149 ms 25980 KB Output is correct
16 Correct 75 ms 15256 KB Output is correct
17 Correct 112 ms 15348 KB Output is correct
18 Correct 115 ms 18624 KB Output is correct
19 Correct 144 ms 26392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 495 ms 125972 KB Output is correct
2 Correct 509 ms 126036 KB Output is correct
3 Correct 451 ms 126200 KB Output is correct
4 Correct 436 ms 126176 KB Output is correct
5 Correct 448 ms 126356 KB Output is correct
6 Correct 435 ms 126188 KB Output is correct
7 Correct 441 ms 126000 KB Output is correct
8 Correct 455 ms 126620 KB Output is correct
9 Correct 442 ms 126200 KB Output is correct
10 Correct 455 ms 125984 KB Output is correct
11 Correct 458 ms 126196 KB Output is correct
12 Correct 473 ms 126236 KB Output is correct
13 Correct 465 ms 126192 KB Output is correct
14 Correct 475 ms 126236 KB Output is correct
15 Correct 484 ms 126480 KB Output is correct
16 Correct 473 ms 126408 KB Output is correct
17 Correct 479 ms 126192 KB Output is correct
18 Correct 473 ms 126120 KB Output is correct
19 Correct 464 ms 126188 KB Output is correct
20 Correct 439 ms 126160 KB Output is correct
21 Correct 469 ms 126272 KB Output is correct
22 Correct 464 ms 126172 KB Output is correct
23 Correct 523 ms 126372 KB Output is correct
24 Correct 460 ms 126192 KB Output is correct
25 Correct 463 ms 126092 KB Output is correct
26 Correct 528 ms 126420 KB Output is correct
27 Correct 503 ms 126412 KB Output is correct
28 Correct 496 ms 126200 KB Output is correct
29 Correct 524 ms 126320 KB Output is correct
30 Correct 501 ms 126416 KB Output is correct
31 Correct 559 ms 126240 KB Output is correct
32 Correct 465 ms 135108 KB Output is correct
33 Correct 474 ms 126320 KB Output is correct
34 Correct 441 ms 126024 KB Output is correct
35 Correct 468 ms 126316 KB Output is correct
36 Correct 535 ms 126168 KB Output is correct
37 Correct 512 ms 126156 KB Output is correct
38 Correct 462 ms 126776 KB Output is correct
39 Correct 390 ms 128520 KB Output is correct
40 Correct 447 ms 136072 KB Output is correct
41 Correct 47 ms 9720 KB Output is correct
42 Correct 46 ms 9836 KB Output is correct
43 Correct 45 ms 9140 KB Output is correct
44 Correct 44 ms 8676 KB Output is correct
45 Correct 57 ms 9292 KB Output is correct
46 Correct 59 ms 9544 KB Output is correct
47 Correct 44 ms 9700 KB Output is correct
48 Correct 439 ms 126152 KB Output is correct
49 Correct 412 ms 126024 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 56 ms 9040 KB Output is correct
52 Correct 142 ms 27016 KB Output is correct
53 Correct 144 ms 25900 KB Output is correct
54 Correct 148 ms 27076 KB Output is correct
55 Correct 149 ms 25980 KB Output is correct
56 Correct 75 ms 15256 KB Output is correct
57 Correct 112 ms 15348 KB Output is correct
58 Correct 115 ms 18624 KB Output is correct
59 Correct 144 ms 26392 KB Output is correct
60 Incorrect 1 ms 600 KB Output isn't correct
61 Halted 0 ms 0 KB -