#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 (k < n-1 && 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 |
697 ms |
222800 KB |
Output is correct |
2 |
Correct |
666 ms |
222900 KB |
Output is correct |
3 |
Correct |
663 ms |
222552 KB |
Output is correct |
4 |
Correct |
639 ms |
222900 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
655 ms |
222904 KB |
Output is correct |
9 |
Correct |
652 ms |
222768 KB |
Output is correct |
10 |
Correct |
637 ms |
223056 KB |
Output is correct |
11 |
Correct |
654 ms |
222800 KB |
Output is correct |
12 |
Correct |
656 ms |
222544 KB |
Output is correct |
13 |
Correct |
682 ms |
222960 KB |
Output is correct |
14 |
Correct |
661 ms |
222644 KB |
Output is correct |
15 |
Correct |
685 ms |
223056 KB |
Output is correct |
16 |
Correct |
635 ms |
222704 KB |
Output is correct |
17 |
Correct |
636 ms |
222692 KB |
Output is correct |
18 |
Correct |
668 ms |
222544 KB |
Output is correct |
19 |
Correct |
652 ms |
222680 KB |
Output is correct |
20 |
Correct |
673 ms |
222544 KB |
Output is correct |
21 |
Correct |
661 ms |
222708 KB |
Output is correct |
22 |
Correct |
606 ms |
222540 KB |
Output is correct |
23 |
Correct |
675 ms |
222708 KB |
Output is correct |
24 |
Correct |
656 ms |
222588 KB |
Output is correct |
25 |
Correct |
667 ms |
222856 KB |
Output is correct |
26 |
Correct |
640 ms |
222708 KB |
Output is correct |
27 |
Correct |
674 ms |
222492 KB |
Output is correct |
28 |
Correct |
720 ms |
222780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
697 ms |
222800 KB |
Output is correct |
2 |
Correct |
666 ms |
222900 KB |
Output is correct |
3 |
Correct |
663 ms |
222552 KB |
Output is correct |
4 |
Correct |
639 ms |
222900 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
655 ms |
222904 KB |
Output is correct |
9 |
Correct |
652 ms |
222768 KB |
Output is correct |
10 |
Correct |
637 ms |
223056 KB |
Output is correct |
11 |
Correct |
654 ms |
222800 KB |
Output is correct |
12 |
Correct |
656 ms |
222544 KB |
Output is correct |
13 |
Correct |
682 ms |
222960 KB |
Output is correct |
14 |
Correct |
661 ms |
222644 KB |
Output is correct |
15 |
Correct |
685 ms |
223056 KB |
Output is correct |
16 |
Correct |
635 ms |
222704 KB |
Output is correct |
17 |
Correct |
636 ms |
222692 KB |
Output is correct |
18 |
Correct |
668 ms |
222544 KB |
Output is correct |
19 |
Correct |
652 ms |
222680 KB |
Output is correct |
20 |
Correct |
673 ms |
222544 KB |
Output is correct |
21 |
Correct |
661 ms |
222708 KB |
Output is correct |
22 |
Correct |
606 ms |
222540 KB |
Output is correct |
23 |
Correct |
675 ms |
222708 KB |
Output is correct |
24 |
Correct |
656 ms |
222588 KB |
Output is correct |
25 |
Correct |
667 ms |
222856 KB |
Output is correct |
26 |
Correct |
640 ms |
222708 KB |
Output is correct |
27 |
Correct |
674 ms |
222492 KB |
Output is correct |
28 |
Correct |
720 ms |
222780 KB |
Output is correct |
29 |
Correct |
697 ms |
222996 KB |
Output is correct |
30 |
Correct |
644 ms |
222804 KB |
Output is correct |
31 |
Correct |
641 ms |
222812 KB |
Output is correct |
32 |
Correct |
698 ms |
225732 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2384 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
700 ms |
222708 KB |
Output is correct |
37 |
Correct |
670 ms |
222532 KB |
Output is correct |
38 |
Correct |
676 ms |
222800 KB |
Output is correct |
39 |
Correct |
708 ms |
223520 KB |
Output is correct |
40 |
Correct |
714 ms |
226404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5844 KB |
Output is correct |
2 |
Correct |
28 ms |
5840 KB |
Output is correct |
3 |
Correct |
28 ms |
5840 KB |
Output is correct |
4 |
Correct |
32 ms |
5900 KB |
Output is correct |
5 |
Correct |
28 ms |
5848 KB |
Output is correct |
6 |
Correct |
28 ms |
5852 KB |
Output is correct |
7 |
Correct |
29 ms |
5852 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
29 ms |
7896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5844 KB |
Output is correct |
2 |
Correct |
28 ms |
5840 KB |
Output is correct |
3 |
Correct |
28 ms |
5840 KB |
Output is correct |
4 |
Correct |
32 ms |
5900 KB |
Output is correct |
5 |
Correct |
28 ms |
5848 KB |
Output is correct |
6 |
Correct |
28 ms |
5852 KB |
Output is correct |
7 |
Correct |
29 ms |
5852 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2516 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
29 ms |
7896 KB |
Output is correct |
12 |
Correct |
118 ms |
17660 KB |
Output is correct |
13 |
Correct |
103 ms |
17700 KB |
Output is correct |
14 |
Correct |
104 ms |
17672 KB |
Output is correct |
15 |
Correct |
103 ms |
17608 KB |
Output is correct |
16 |
Correct |
65 ms |
9564 KB |
Output is correct |
17 |
Correct |
64 ms |
9464 KB |
Output is correct |
18 |
Correct |
85 ms |
12716 KB |
Output is correct |
19 |
Correct |
108 ms |
17936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
780 ms |
451364 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
780 ms |
451364 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
697 ms |
222800 KB |
Output is correct |
2 |
Correct |
666 ms |
222900 KB |
Output is correct |
3 |
Correct |
663 ms |
222552 KB |
Output is correct |
4 |
Correct |
639 ms |
222900 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
655 ms |
222904 KB |
Output is correct |
9 |
Correct |
652 ms |
222768 KB |
Output is correct |
10 |
Correct |
637 ms |
223056 KB |
Output is correct |
11 |
Correct |
654 ms |
222800 KB |
Output is correct |
12 |
Correct |
656 ms |
222544 KB |
Output is correct |
13 |
Correct |
682 ms |
222960 KB |
Output is correct |
14 |
Correct |
661 ms |
222644 KB |
Output is correct |
15 |
Correct |
685 ms |
223056 KB |
Output is correct |
16 |
Correct |
635 ms |
222704 KB |
Output is correct |
17 |
Correct |
636 ms |
222692 KB |
Output is correct |
18 |
Correct |
668 ms |
222544 KB |
Output is correct |
19 |
Correct |
652 ms |
222680 KB |
Output is correct |
20 |
Correct |
673 ms |
222544 KB |
Output is correct |
21 |
Correct |
661 ms |
222708 KB |
Output is correct |
22 |
Correct |
606 ms |
222540 KB |
Output is correct |
23 |
Correct |
675 ms |
222708 KB |
Output is correct |
24 |
Correct |
656 ms |
222588 KB |
Output is correct |
25 |
Correct |
667 ms |
222856 KB |
Output is correct |
26 |
Correct |
640 ms |
222708 KB |
Output is correct |
27 |
Correct |
674 ms |
222492 KB |
Output is correct |
28 |
Correct |
720 ms |
222780 KB |
Output is correct |
29 |
Correct |
697 ms |
222996 KB |
Output is correct |
30 |
Correct |
644 ms |
222804 KB |
Output is correct |
31 |
Correct |
641 ms |
222812 KB |
Output is correct |
32 |
Correct |
698 ms |
225732 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2384 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
700 ms |
222708 KB |
Output is correct |
37 |
Correct |
670 ms |
222532 KB |
Output is correct |
38 |
Correct |
676 ms |
222800 KB |
Output is correct |
39 |
Correct |
708 ms |
223520 KB |
Output is correct |
40 |
Correct |
714 ms |
226404 KB |
Output is correct |
41 |
Correct |
28 ms |
5844 KB |
Output is correct |
42 |
Correct |
28 ms |
5840 KB |
Output is correct |
43 |
Correct |
28 ms |
5840 KB |
Output is correct |
44 |
Correct |
32 ms |
5900 KB |
Output is correct |
45 |
Correct |
28 ms |
5848 KB |
Output is correct |
46 |
Correct |
28 ms |
5852 KB |
Output is correct |
47 |
Correct |
29 ms |
5852 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
0 ms |
2516 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
29 ms |
7896 KB |
Output is correct |
52 |
Correct |
118 ms |
17660 KB |
Output is correct |
53 |
Correct |
103 ms |
17700 KB |
Output is correct |
54 |
Correct |
104 ms |
17672 KB |
Output is correct |
55 |
Correct |
103 ms |
17608 KB |
Output is correct |
56 |
Correct |
65 ms |
9564 KB |
Output is correct |
57 |
Correct |
64 ms |
9464 KB |
Output is correct |
58 |
Correct |
85 ms |
12716 KB |
Output is correct |
59 |
Correct |
108 ms |
17936 KB |
Output is correct |
60 |
Runtime error |
780 ms |
451364 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |