I want to restart CP after more than 2 years
Can you guys help me,
Things to know before restarting
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
I want to restart CP after more than 2 years
Can you guys help me,
Things to know before restarting
[my code]
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define ff first
#define ss second
#define endl '\n'
using namespace std;
void solve() {
ll n, m; cin >> n >> m;
ll g[n][m];
ll x, y, mx = 0;
queue<pair<ll, ll>>q;
ll vis[n][m];
rep(i, 0, n) {
rep(j, 0, m) {
cin >> g[i][j];
vis[i][j] = 0;
mx = max(mx, g[i][j]);
}
}
rep(i, 0, n) {
rep(j, 0, m) {
if (g[i][j] == mx) { vis[i][j] = 1; q.push({i, j});}
}
}
ll xx[4] = { -1, 0, 1, 0};
ll yy[4] = {0, 1, 0, -1};
ll ans = 0;
while (!q.empty()) {
x = q.front().ff;
y = q.front().ss;
q.pop();
rep(i, 0, 4) {
ll X = x + xx[i];
ll Y = y + yy[i];
if (X < 0 or Y <0 or Y > m - 1 or X > n - 1) continue;
if (!vis[X][Y]) {
if (g[X][Y] == g[x][y]) continue;
else {
if ((g[x][y] - g[X][Y]) == 1) {
q.push({X, Y});
vis[X][Y] = 1;
}
else if ((g[x][y] - g[X][Y]) > 1) {
vis[X][Y] = 1;
ans += (g[x][y] - g[X][Y]) - 1;
g[X][Y] = g[x][y] - 1;
q.push({X, Y});
}
}
}
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
rep(i, 1, t + 1)
{
cout << "Case #" << i << ": ";
solve();
}
return 0;
}
Name |
---|