#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;
int n, m;
array<int, 2> a[mxN];
ll dist[A][A], cnt[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;
if (dist[x][y] < A)
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--){
ri(t);
int cnt = 0;
while (mrg[k] <= t){
E += mrg[k]-1;
N--;
if (mrg[k] == t)
cnt++;
k++;
}
if (t) cout << 2*(n*(t+1) - (n-N)*t + E) + (2*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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
706 ms |
222620 KB |
Output is correct |
2 |
Correct |
689 ms |
222668 KB |
Output is correct |
3 |
Correct |
695 ms |
222756 KB |
Output is correct |
4 |
Correct |
706 ms |
222884 KB |
Output is correct |
5 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
706 ms |
222620 KB |
Output is correct |
2 |
Correct |
689 ms |
222668 KB |
Output is correct |
3 |
Correct |
695 ms |
222756 KB |
Output is correct |
4 |
Correct |
706 ms |
222884 KB |
Output is correct |
5 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
5840 KB |
Output is correct |
2 |
Correct |
29 ms |
5852 KB |
Output is correct |
3 |
Correct |
29 ms |
5852 KB |
Output is correct |
4 |
Incorrect |
30 ms |
5852 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
5840 KB |
Output is correct |
2 |
Correct |
29 ms |
5852 KB |
Output is correct |
3 |
Correct |
29 ms |
5852 KB |
Output is correct |
4 |
Incorrect |
30 ms |
5852 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
805 ms |
451212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
805 ms |
451212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
706 ms |
222620 KB |
Output is correct |
2 |
Correct |
689 ms |
222668 KB |
Output is correct |
3 |
Correct |
695 ms |
222756 KB |
Output is correct |
4 |
Correct |
706 ms |
222884 KB |
Output is correct |
5 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |