#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
pii delta[4] ={{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<pii> find_adj(pii pos){
vector<pii> res;
for(int i = 0; i<4; i++){
res.push_back({pos.first+delta[i].first, pos.second + delta[i].second});
}
return res;
}
map<pii, int> next(map<pii, int> cur){
map<pii, int> res;
for(auto e: cur){
if(e.second >0){
res[e.first] =e.second-1;
}
}
for(auto e: cur){
if(e.second ==2){
for(auto ee: find_adj(e.first)){
if(res.find(ee)==res.end()){
res[ee] = 2;
}
}
}
}
return res;
}
const int sz= 10;
void display(map<pii, int>&m){
for(int i = -sz; i<=sz; i++){
for(int j = -sz; j<=sz; j++){
if(m.find({i, j})!=m.end()){
cout<<m[{i, j}];
}
else{
cout<<"0";
}
}
cout<<endl;
}
cout<<endl;
}
signed main(){
int n, q;
cin>>n>>q;
vector<int> pos;
map<pii, int> cur;
bool diag= true;
for(int i = 0; i<n; i++){
int x, y;
cin>>x>>y;
pos.push_back(x);
cur[{x, y}] = 2;
if(x!=y){
diag= false;
}
}
if(diag){
sort(pos.begin(), pos.end());
for(int i = 0; i<q; i++){
int t;
cin>>t;
vector<pii> groups;
if(t==0){
cout<<pos.size()<<endl;
continue;
}
int r= 0;
pii cur_g = {pos[0], pos[0]};
for(int j = 1; j<n; j++){
if(pos[j]-pos[j-1]<=t){
if(pos[j]-pos[j-1]==t){
r+=t-1;
}
cur_g.second= pos[j];
}
else{
groups.push_back(cur_g);
cur_g ={pos[j], pos[j]};
}
}
groups.push_back(cur_g);
for(auto e: groups){
//cout<<e.first<<" "<<e.second<<endl;
r+= 2*(e.second-e.first+t+1);
r+= 2*(t-1);
}
cout<<r<<endl;
}
}
else{
vector<int> ans(1000+1, -1);
int r;
for(int steps= 0; steps<1000+1; steps++){
r=0;
for(auto e: cur){
if(e.second ==2){
r++;
}
}
ans[steps] = r;
cur = next(cur);
}
int max_s= 0;
for(int i = 0; i<q; i++){
int steps= 0;
cin>>steps;
cout<<ans[steps]<<endl;
}
}
}
Compilation message
cell.cpp: In function 'int main()':
cell.cpp:122:13: warning: unused variable 'max_s' [-Wunused-variable]
122 | int max_s= 0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1490 ms |
2856 KB |
Output is correct |
2 |
Correct |
1539 ms |
2704 KB |
Output is correct |
3 |
Correct |
1695 ms |
2712 KB |
Output is correct |
4 |
Correct |
1765 ms |
3140 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1824 ms |
3000 KB |
Output is correct |
9 |
Correct |
1787 ms |
2912 KB |
Output is correct |
10 |
Correct |
1767 ms |
2644 KB |
Output is correct |
11 |
Correct |
1730 ms |
3220 KB |
Output is correct |
12 |
Correct |
1816 ms |
3048 KB |
Output is correct |
13 |
Correct |
1822 ms |
3576 KB |
Output is correct |
14 |
Correct |
1817 ms |
3060 KB |
Output is correct |
15 |
Correct |
1806 ms |
2816 KB |
Output is correct |
16 |
Correct |
1437 ms |
2844 KB |
Output is correct |
17 |
Correct |
1435 ms |
2900 KB |
Output is correct |
18 |
Correct |
1465 ms |
3152 KB |
Output is correct |
19 |
Correct |
1440 ms |
2652 KB |
Output is correct |
20 |
Correct |
1442 ms |
2868 KB |
Output is correct |
21 |
Correct |
1442 ms |
2812 KB |
Output is correct |
22 |
Correct |
1482 ms |
2900 KB |
Output is correct |
23 |
Correct |
1441 ms |
2900 KB |
Output is correct |
24 |
Correct |
1443 ms |
2928 KB |
Output is correct |
25 |
Correct |
1440 ms |
2772 KB |
Output is correct |
26 |
Correct |
1462 ms |
2792 KB |
Output is correct |
27 |
Correct |
1487 ms |
2640 KB |
Output is correct |
28 |
Correct |
1448 ms |
2932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1490 ms |
2856 KB |
Output is correct |
2 |
Correct |
1539 ms |
2704 KB |
Output is correct |
3 |
Correct |
1695 ms |
2712 KB |
Output is correct |
4 |
Correct |
1765 ms |
3140 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1824 ms |
3000 KB |
Output is correct |
9 |
Correct |
1787 ms |
2912 KB |
Output is correct |
10 |
Correct |
1767 ms |
2644 KB |
Output is correct |
11 |
Correct |
1730 ms |
3220 KB |
Output is correct |
12 |
Correct |
1816 ms |
3048 KB |
Output is correct |
13 |
Correct |
1822 ms |
3576 KB |
Output is correct |
14 |
Correct |
1817 ms |
3060 KB |
Output is correct |
15 |
Correct |
1806 ms |
2816 KB |
Output is correct |
16 |
Correct |
1437 ms |
2844 KB |
Output is correct |
17 |
Correct |
1435 ms |
2900 KB |
Output is correct |
18 |
Correct |
1465 ms |
3152 KB |
Output is correct |
19 |
Correct |
1440 ms |
2652 KB |
Output is correct |
20 |
Correct |
1442 ms |
2868 KB |
Output is correct |
21 |
Correct |
1442 ms |
2812 KB |
Output is correct |
22 |
Correct |
1482 ms |
2900 KB |
Output is correct |
23 |
Correct |
1441 ms |
2900 KB |
Output is correct |
24 |
Correct |
1443 ms |
2928 KB |
Output is correct |
25 |
Correct |
1440 ms |
2772 KB |
Output is correct |
26 |
Correct |
1462 ms |
2792 KB |
Output is correct |
27 |
Correct |
1487 ms |
2640 KB |
Output is correct |
28 |
Correct |
1448 ms |
2932 KB |
Output is correct |
29 |
Correct |
1499 ms |
2776 KB |
Output is correct |
30 |
Correct |
2470 ms |
3244 KB |
Output is correct |
31 |
Correct |
3968 ms |
4516 KB |
Output is correct |
32 |
Correct |
7413 ms |
131664 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
464 KB |
Output is correct |
36 |
Correct |
1446 ms |
2712 KB |
Output is correct |
37 |
Correct |
1467 ms |
2660 KB |
Output is correct |
38 |
Correct |
6298 ms |
21796 KB |
Output is correct |
39 |
Correct |
6352 ms |
66184 KB |
Output is correct |
40 |
Correct |
7550 ms |
148672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
9584 KB |
Output is correct |
2 |
Correct |
96 ms |
11588 KB |
Output is correct |
3 |
Correct |
95 ms |
10840 KB |
Output is correct |
4 |
Correct |
93 ms |
10180 KB |
Output is correct |
5 |
Correct |
94 ms |
10948 KB |
Output is correct |
6 |
Correct |
95 ms |
10916 KB |
Output is correct |
7 |
Correct |
99 ms |
11592 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
92 ms |
9508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
9584 KB |
Output is correct |
2 |
Correct |
96 ms |
11588 KB |
Output is correct |
3 |
Correct |
95 ms |
10840 KB |
Output is correct |
4 |
Correct |
93 ms |
10180 KB |
Output is correct |
5 |
Correct |
94 ms |
10948 KB |
Output is correct |
6 |
Correct |
95 ms |
10916 KB |
Output is correct |
7 |
Correct |
99 ms |
11592 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
92 ms |
9508 KB |
Output is correct |
12 |
Execution timed out |
8087 ms |
14104 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
8026 ms |
9252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
8026 ms |
9252 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1490 ms |
2856 KB |
Output is correct |
2 |
Correct |
1539 ms |
2704 KB |
Output is correct |
3 |
Correct |
1695 ms |
2712 KB |
Output is correct |
4 |
Correct |
1765 ms |
3140 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1824 ms |
3000 KB |
Output is correct |
9 |
Correct |
1787 ms |
2912 KB |
Output is correct |
10 |
Correct |
1767 ms |
2644 KB |
Output is correct |
11 |
Correct |
1730 ms |
3220 KB |
Output is correct |
12 |
Correct |
1816 ms |
3048 KB |
Output is correct |
13 |
Correct |
1822 ms |
3576 KB |
Output is correct |
14 |
Correct |
1817 ms |
3060 KB |
Output is correct |
15 |
Correct |
1806 ms |
2816 KB |
Output is correct |
16 |
Correct |
1437 ms |
2844 KB |
Output is correct |
17 |
Correct |
1435 ms |
2900 KB |
Output is correct |
18 |
Correct |
1465 ms |
3152 KB |
Output is correct |
19 |
Correct |
1440 ms |
2652 KB |
Output is correct |
20 |
Correct |
1442 ms |
2868 KB |
Output is correct |
21 |
Correct |
1442 ms |
2812 KB |
Output is correct |
22 |
Correct |
1482 ms |
2900 KB |
Output is correct |
23 |
Correct |
1441 ms |
2900 KB |
Output is correct |
24 |
Correct |
1443 ms |
2928 KB |
Output is correct |
25 |
Correct |
1440 ms |
2772 KB |
Output is correct |
26 |
Correct |
1462 ms |
2792 KB |
Output is correct |
27 |
Correct |
1487 ms |
2640 KB |
Output is correct |
28 |
Correct |
1448 ms |
2932 KB |
Output is correct |
29 |
Correct |
1499 ms |
2776 KB |
Output is correct |
30 |
Correct |
2470 ms |
3244 KB |
Output is correct |
31 |
Correct |
3968 ms |
4516 KB |
Output is correct |
32 |
Correct |
7413 ms |
131664 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
464 KB |
Output is correct |
36 |
Correct |
1446 ms |
2712 KB |
Output is correct |
37 |
Correct |
1467 ms |
2660 KB |
Output is correct |
38 |
Correct |
6298 ms |
21796 KB |
Output is correct |
39 |
Correct |
6352 ms |
66184 KB |
Output is correct |
40 |
Correct |
7550 ms |
148672 KB |
Output is correct |
41 |
Correct |
95 ms |
9584 KB |
Output is correct |
42 |
Correct |
96 ms |
11588 KB |
Output is correct |
43 |
Correct |
95 ms |
10840 KB |
Output is correct |
44 |
Correct |
93 ms |
10180 KB |
Output is correct |
45 |
Correct |
94 ms |
10948 KB |
Output is correct |
46 |
Correct |
95 ms |
10916 KB |
Output is correct |
47 |
Correct |
99 ms |
11592 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
92 ms |
9508 KB |
Output is correct |
52 |
Execution timed out |
8087 ms |
14104 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |