Submission #55813732
Source Code Expand
/*
Author: rnishiura
Date: 24-06-15
Description: template
*/
#define ATCODER_
#include <bits/stdc++.h>
#ifdef ATCODER_
#include <atcoder/all>
#endif
#define _GLIBCXX_DEBUG
#define rep(x, n) for(ll x=0; x<n; x++)
#define repi(x, a, b) for(ll x=a; x<b; x++)
#define rrep(x, n) for(ll x=n-1; x>=0; x--)
#define rrepi(x, a, b) for(ll x=b-1; x>=a; x--)
#define SQ(z) ((z)*(z))
#define contains(x, a) ((a).find(x) != (a).end())
#define all(a) (a).begin(), (a).end()
#define sum(a) (accumulate(all(a), 0LL))
#define mini(a) (min_element(all(a)) - (a).begin())
#define maxi(a) (max_element(all(a)) - (a).begin())
#define mine(a) (*min_element(all(a)))
#define maxe(a) (*max_element(all(a)))
#define lowb(x, a) (lower_bound(all(a), (x)) - (a).begin())
#define uppb(x, a) (upper_bound(all(a), (x)) - (a).begin())
#define divl(n, m) ((n+m)/(m))
#define divle(n, m) ((n+m-1)/(m))
#define divse(n, m) ((n)/(m))
#define divs(n, m) ((n-1)/(m))
#define bstoi(s) stoi((s), nullptr, 2)
#define MOD 998244353
#define PI 3.14159265358979323846
#define inf (1LL << 61)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define POS fi
#define COST se
#define endl '\n'
#define unordered_multiset multiset
#define print(z) { cout << (z) << endl; }
#define print2(y, z) { cout << (y) << ' '; print(z); }
#define print3(x, y, z) { cout << (x) << ' '; print2(y, z); }
#define debug(z) { if(DEBUG) print(z); }
#define debug2(y, z) { if(DEBUG) print2(y, z); }
#define debug3(x, y, z) { if(DEBUG) print3(x, y, z); }
#ifdef ATCODER_
using namespace atcoder;
using mint = modint998244353;
#endif
using namespace std;
using ll = long long;
using v = vector<ll>;
using vv = vector<v>;
using vp = vector<pair<ll, ll>>;
using vvp = vector<vp>;
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U> p){os << p.first << ' ' << p.second; return os;}
template<typename T> vector<T>& operator-- (vector<T> &v){for (auto& i : v) --i; return v;}
template<typename T> vector<T>& operator++ (vector<T> &v){for (auto& i : v) ++i; return v;}
template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;}
template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;}
template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> pair<T,T> operator*(pair<T,T> a, U b){return mp(a.first*b , a.second*b);}
template<typename T, typename U> pair<T,T> operator/(pair<T,T> a, U b){return mp(a.first/b , a.second/b);}
template<typename T, typename U> pair<T,T> operator%(pair<T,T> a, U b){return mp(a.first%b , a.second%b);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}
void build_sea(vv &s) {
ll w = s[0].size();
v t(w+2, 0);
for(auto& ss: s) { ss.insert(ss.begin(), 0); ss.pb(0); }
s.insert(s.begin(), t);
s.pb(t);
}
// const int DEBUG = 1;
const int DEBUG = 0;
void solve() {
ll h, w, y; cin >> h >> w >> y;
vv a(h, v(w)); cin >> a;
vvp ha(100001);
rep(i, h) {
rep(j, w) {
ha[a[i][j]].pb({i+1, j+1});
}
}
build_sea(a);
ll ans = h*w;
vector<vector<bool>> sea(h+2, vector<bool>(w+2, false));
rep(i, h+2) sea[i][0] = true, sea[i][w+1] = true;
rep(i, w+2) sea[0][i] = true, sea[h+1][i] = true;
// for(auto e: sea) print(e);
// for(auto e: sea) {
// for(auto f: e) {
// cout << int(f) << " ";
// }
// print("");
// }
vp dir = {{1,0},{0,1},{-1,0},{0,-1}};
repi(i, 1, y+1) {
vp from = ha[i];
while(true) {
// print2(i, from.size());
if(!from.size()) break;
vp to;
for(auto f: from) {
if(
sea[f.fi+1][f.se] ||
sea[f.fi][f.se+1] ||
sea[f.fi-1][f.se] ||
sea[f.fi][f.se-1]
) {
if(!sea[f.fi][f.se]) ans--;
sea[f.fi][f.se] = true;
}
if(!sea[f.fi][f.se]) continue;
for(auto d: dir) {
// if(f.fi+d.fi == 3 & f.se+d.fi)
if(a[f.fi+d.fi][f.se+d.se] <= i && !sea[f.fi+d.fi][f.se+d.se]) {
to.pb({f.fi+d.fi, f.se+d.se});
sea[f.fi+d.fi][f.se+d.se] = true;
ans--;
}
}
}
from = vp(all(to));
// print(to);
}
print(ans);
// print(i);
// for(auto e: sea) {
// for(auto f: e) {
// cout << int(f) << " ";
// }
// print("");
// }
}
}
int main(void) {
debug("DEBUG MODE IS ON");
cin.tie(nullptr); ios::sync_with_stdio(false);
ll t = 1; // cin >> t;
rep(i, t) solve();
debug("DEBUG MODE IS ON");
}
Submission Info
| Submission Time |
|
| Task |
E - Sinking Land |
| User |
rnishiura |
| Language |
C++ 23 (gcc 12.2) |
| Score |
450 |
| Code Size |
5622 Byte |
| Status |
AC |
| Exec Time |
180 ms |
| Memory |
82104 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
450 / 450 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt, example_01.txt |
| All |
example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
2 ms |
5456 KiB |
| example_01.txt |
AC |
2 ms |
5424 KiB |
| hand_00.txt |
AC |
119 ms |
64808 KiB |
| hand_01.txt |
AC |
119 ms |
64828 KiB |
| hand_02.txt |
AC |
84 ms |
59004 KiB |
| hand_03.txt |
AC |
6 ms |
5764 KiB |
| hand_04.txt |
AC |
5 ms |
5472 KiB |
| hand_05.txt |
AC |
5 ms |
5424 KiB |
| hand_06.txt |
AC |
124 ms |
45584 KiB |
| hand_07.txt |
AC |
100 ms |
82104 KiB |
| hand_08.txt |
AC |
64 ms |
34924 KiB |
| hand_09.txt |
AC |
155 ms |
45852 KiB |
| hand_10.txt |
AC |
97 ms |
81980 KiB |
| hand_11.txt |
AC |
2 ms |
5452 KiB |
| hand_12.txt |
AC |
54 ms |
34900 KiB |
| hand_13.txt |
AC |
2 ms |
5396 KiB |
| random_00.txt |
AC |
177 ms |
44744 KiB |
| random_01.txt |
AC |
180 ms |
44836 KiB |
| random_02.txt |
AC |
179 ms |
45288 KiB |
| random_03.txt |
AC |
178 ms |
44892 KiB |
| random_04.txt |
AC |
177 ms |
44840 KiB |
| random_05.txt |
AC |
149 ms |
46444 KiB |
| random_06.txt |
AC |
148 ms |
46108 KiB |
| random_07.txt |
AC |
148 ms |
45872 KiB |
| random_08.txt |
AC |
150 ms |
45588 KiB |
| random_09.txt |
AC |
148 ms |
45836 KiB |
| random_10.txt |
AC |
139 ms |
44656 KiB |
| random_11.txt |
AC |
142 ms |
45508 KiB |
| random_12.txt |
AC |
144 ms |
44708 KiB |
| random_13.txt |
AC |
142 ms |
44520 KiB |
| random_14.txt |
AC |
141 ms |
44716 KiB |
| random_15.txt |
AC |
134 ms |
45420 KiB |
| random_16.txt |
AC |
132 ms |
45160 KiB |
| random_17.txt |
AC |
134 ms |
46000 KiB |
| random_18.txt |
AC |
133 ms |
45544 KiB |
| random_19.txt |
AC |
128 ms |
45448 KiB |
| random_20.txt |
AC |
176 ms |
45536 KiB |
| random_21.txt |
AC |
173 ms |
45612 KiB |
| random_22.txt |
AC |
178 ms |
45852 KiB |
| random_23.txt |
AC |
175 ms |
45852 KiB |
| random_24.txt |
AC |
173 ms |
45808 KiB |
| random_25.txt |
AC |
147 ms |
42152 KiB |
| random_26.txt |
AC |
136 ms |
42416 KiB |
| random_27.txt |
AC |
138 ms |
42300 KiB |
| random_28.txt |
AC |
132 ms |
42256 KiB |
| random_29.txt |
AC |
137 ms |
42484 KiB |