Submission #965194

# Submission time Handle Problem Language Result Execution time Memory
965194 2024-04-18T08:10:46 Z phoenix0423 Cell Automaton (JOI23_cell) C++17
24 / 100
606 ms 255860 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){
    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(int i = 0; i < q; i++){
        int t;
        cin>>t;
        cout<<ans[t]<<"\n";
    }
    return;
}

signed main(void){
    fastio;
    cin>>n>>q;
    int mx = 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});
    }
    if(mx <= 1000){
        sol1(e);
        return 0;
    }
    sort(e.begin(), e.end());
    vector<int> dist;
    for(int i = 1; i < n; i++) dist.pb(e[i].f - e[i - 1].f);
    sort(dist.begin(), dist.end());
    int id = 0;
    int comp = n, face = n * 4, ans = n;
    int prv = 0;
    vector<pll> op;
    for(auto x : dist) op.pb({x, -1}), op.pb({x, 2});
    for(int i = 0; i < q; i++){
        int x;
        cin>>x;
        op.pb({x, 1});
    }
    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";
    }


}

Compilation message

cell.cpp: In function 'int main()':
cell.cpp:70:9: warning: unused variable 'id' [-Wunused-variable]
   70 |     int id = 0;
      |         ^~
cell.cpp:71:9: warning: unused variable 'comp' [-Wunused-variable]
   71 |     int comp = n, face = n * 4, ans = n;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 556 ms 126192 KB Output is correct
2 Correct 469 ms 126032 KB Output is correct
3 Correct 503 ms 126196 KB Output is correct
4 Correct 494 ms 126376 KB Output is correct
5 Correct 523 ms 126440 KB Output is correct
6 Correct 484 ms 126192 KB Output is correct
7 Correct 508 ms 126288 KB Output is correct
8 Correct 497 ms 126628 KB Output is correct
9 Correct 495 ms 126380 KB Output is correct
10 Correct 509 ms 126196 KB Output is correct
11 Correct 503 ms 126192 KB Output is correct
12 Correct 507 ms 126596 KB Output is correct
13 Correct 551 ms 126336 KB Output is correct
14 Correct 472 ms 126232 KB Output is correct
15 Correct 485 ms 126428 KB Output is correct
16 Correct 503 ms 126032 KB Output is correct
17 Correct 500 ms 126096 KB Output is correct
18 Correct 501 ms 126360 KB Output is correct
19 Correct 486 ms 126192 KB Output is correct
20 Correct 496 ms 126112 KB Output is correct
21 Correct 522 ms 126288 KB Output is correct
22 Correct 536 ms 126192 KB Output is correct
23 Correct 499 ms 126116 KB Output is correct
24 Correct 506 ms 126200 KB Output is correct
25 Correct 525 ms 126108 KB Output is correct
26 Correct 511 ms 125996 KB Output is correct
27 Correct 497 ms 126192 KB Output is correct
28 Correct 513 ms 126192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 556 ms 126192 KB Output is correct
2 Correct 469 ms 126032 KB Output is correct
3 Correct 503 ms 126196 KB Output is correct
4 Correct 494 ms 126376 KB Output is correct
5 Correct 523 ms 126440 KB Output is correct
6 Correct 484 ms 126192 KB Output is correct
7 Correct 508 ms 126288 KB Output is correct
8 Correct 497 ms 126628 KB Output is correct
9 Correct 495 ms 126380 KB Output is correct
10 Correct 509 ms 126196 KB Output is correct
11 Correct 503 ms 126192 KB Output is correct
12 Correct 507 ms 126596 KB Output is correct
13 Correct 551 ms 126336 KB Output is correct
14 Correct 472 ms 126232 KB Output is correct
15 Correct 485 ms 126428 KB Output is correct
16 Correct 503 ms 126032 KB Output is correct
17 Correct 500 ms 126096 KB Output is correct
18 Correct 501 ms 126360 KB Output is correct
19 Correct 486 ms 126192 KB Output is correct
20 Correct 496 ms 126112 KB Output is correct
21 Correct 522 ms 126288 KB Output is correct
22 Correct 536 ms 126192 KB Output is correct
23 Correct 499 ms 126116 KB Output is correct
24 Correct 506 ms 126200 KB Output is correct
25 Correct 525 ms 126108 KB Output is correct
26 Correct 511 ms 125996 KB Output is correct
27 Correct 497 ms 126192 KB Output is correct
28 Correct 513 ms 126192 KB Output is correct
29 Correct 518 ms 126392 KB Output is correct
30 Correct 474 ms 126028 KB Output is correct
31 Correct 517 ms 126200 KB Output is correct
32 Correct 536 ms 135048 KB Output is correct
33 Correct 485 ms 126180 KB Output is correct
34 Correct 478 ms 125984 KB Output is correct
35 Correct 459 ms 126404 KB Output is correct
36 Correct 508 ms 126288 KB Output is correct
37 Correct 511 ms 126188 KB Output is correct
38 Correct 487 ms 126732 KB Output is correct
39 Correct 518 ms 128652 KB Output is correct
40 Correct 530 ms 135924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 11972 KB Output is correct
2 Correct 50 ms 11384 KB Output is correct
3 Correct 47 ms 11752 KB Output is correct
4 Correct 42 ms 11732 KB Output is correct
5 Correct 46 ms 10960 KB Output is correct
6 Correct 46 ms 11476 KB Output is correct
7 Correct 49 ms 10988 KB Output is correct
8 Correct 482 ms 126184 KB Output is correct
9 Correct 512 ms 126032 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 40 ms 12296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 11972 KB Output is correct
2 Correct 50 ms 11384 KB Output is correct
3 Correct 47 ms 11752 KB Output is correct
4 Correct 42 ms 11732 KB Output is correct
5 Correct 46 ms 10960 KB Output is correct
6 Correct 46 ms 11476 KB Output is correct
7 Correct 49 ms 10988 KB Output is correct
8 Correct 482 ms 126184 KB Output is correct
9 Correct 512 ms 126032 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 40 ms 12296 KB Output is correct
12 Correct 131 ms 27812 KB Output is correct
13 Correct 138 ms 27648 KB Output is correct
14 Correct 131 ms 27832 KB Output is correct
15 Correct 132 ms 27816 KB Output is correct
16 Runtime error 606 ms 255860 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 556 ms 126192 KB Output is correct
2 Correct 469 ms 126032 KB Output is correct
3 Correct 503 ms 126196 KB Output is correct
4 Correct 494 ms 126376 KB Output is correct
5 Correct 523 ms 126440 KB Output is correct
6 Correct 484 ms 126192 KB Output is correct
7 Correct 508 ms 126288 KB Output is correct
8 Correct 497 ms 126628 KB Output is correct
9 Correct 495 ms 126380 KB Output is correct
10 Correct 509 ms 126196 KB Output is correct
11 Correct 503 ms 126192 KB Output is correct
12 Correct 507 ms 126596 KB Output is correct
13 Correct 551 ms 126336 KB Output is correct
14 Correct 472 ms 126232 KB Output is correct
15 Correct 485 ms 126428 KB Output is correct
16 Correct 503 ms 126032 KB Output is correct
17 Correct 500 ms 126096 KB Output is correct
18 Correct 501 ms 126360 KB Output is correct
19 Correct 486 ms 126192 KB Output is correct
20 Correct 496 ms 126112 KB Output is correct
21 Correct 522 ms 126288 KB Output is correct
22 Correct 536 ms 126192 KB Output is correct
23 Correct 499 ms 126116 KB Output is correct
24 Correct 506 ms 126200 KB Output is correct
25 Correct 525 ms 126108 KB Output is correct
26 Correct 511 ms 125996 KB Output is correct
27 Correct 497 ms 126192 KB Output is correct
28 Correct 513 ms 126192 KB Output is correct
29 Correct 518 ms 126392 KB Output is correct
30 Correct 474 ms 126028 KB Output is correct
31 Correct 517 ms 126200 KB Output is correct
32 Correct 536 ms 135048 KB Output is correct
33 Correct 485 ms 126180 KB Output is correct
34 Correct 478 ms 125984 KB Output is correct
35 Correct 459 ms 126404 KB Output is correct
36 Correct 508 ms 126288 KB Output is correct
37 Correct 511 ms 126188 KB Output is correct
38 Correct 487 ms 126732 KB Output is correct
39 Correct 518 ms 128652 KB Output is correct
40 Correct 530 ms 135924 KB Output is correct
41 Correct 50 ms 11972 KB Output is correct
42 Correct 50 ms 11384 KB Output is correct
43 Correct 47 ms 11752 KB Output is correct
44 Correct 42 ms 11732 KB Output is correct
45 Correct 46 ms 10960 KB Output is correct
46 Correct 46 ms 11476 KB Output is correct
47 Correct 49 ms 10988 KB Output is correct
48 Correct 482 ms 126184 KB Output is correct
49 Correct 512 ms 126032 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 40 ms 12296 KB Output is correct
52 Correct 131 ms 27812 KB Output is correct
53 Correct 138 ms 27648 KB Output is correct
54 Correct 131 ms 27832 KB Output is correct
55 Correct 132 ms 27816 KB Output is correct
56 Runtime error 606 ms 255860 KB Execution killed with signal 11
57 Halted 0 ms 0 KB -