Submission #55803991


Source Code Expand

#include <bits/stdc++.h>
// #include "prettyprint.hpp"
#define fastio                 \
	ios::sync_with_stdio(false); \
	cin.tie(0)
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x.size())

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<array<ll,2>, null_type, less<array<ll,2>>, rb_tree_tag, tree_order_statistics_node_update>

template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>>
{
	static_assert(D >= 1, "Vector dimension must be greater than zero!");
	template <typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...))
	{
	}
};
template <typename T>
struct Vec<1, T> : public vector<T>
{
	Vec(int n = 0, const T &val = T()) : vector<T>(n, val)
	{
	}
};

// Code begins here

const ll M = 1000000007LL;
const ll INF = 1e18 + 10;

template <typename T>
void maxa(T &v, const T &x)
{
	v = max(v, x);
}

template <typename T>
void mina(T &v, const T &x)
{
	v = min(v, x);
}

template <typename T>
void madd(T &v, const T &x)
{
	v = (v + x);
	v %= M;
}

const int mxn = 1e6 +10;

ll pw(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = (res * a) % M;
		a = (a * a) % M;
		b >>= 1;
	}
	return res;
}

void solve(){
	int h,w,y;
	cin >> h >> w >> y;
	Vec<2, int> a(h, w);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a[i][j];
		}
	}
	set<array<ll,3>> q;
	Vec<2, ll> dist(h, w, INF);
	for (int i=0;i<h;++i){
		for (int j=0;j<w;++j){
			if (i==0 || i==h-1 || j==0 || j==w-1){
				dist[i][j] = a[i][j];
				q.insert({dist[i][j], i, j});
			}
		}
	}
	vector<pair<int,int>> dir = {{-1,0}, {1,0}, {0,-1}, {0,1}};
	while (!q.empty()){
		auto [d, i, j] = *q.begin();
		q.erase(q.begin());
		for (auto [di, dj] : dir){
			int ni2 = i+di;
			int nj2 = j+dj;
			if (ni2<0 || ni2>=h || nj2<0 || nj2>=w) continue;
			ll nd = max(d, (ll)a[ni2][nj2]);
			if (dist[ni2][nj2] > nd){
				q.erase({dist[ni2][nj2], ni2, nj2});
				dist[ni2][nj2] = nd;
				q.insert({dist[ni2][nj2], ni2, nj2});
			}
		}
	}
	vector<ll> b;
	for (int i=0;i<h;++i){
		for (int j=0;j<w;++j){
			b.push_back(dist[i][j]);
		}
	}
	sort(b.begin(), b.end());
	for (int i=1;i<=y;++i){
		int idx = upper_bound(b.begin(), b.end(), i) - b.begin();
		cout << h*w-idx << "\n";
	}
}


int main()
{
	fastio;
	// freopen("in.txt","r",stdin);
	// int t;
	// cin >> t;
	// while (t--)
	solve();
}

Submission Info

Submission Time
Task E - Sinking Land
User decsp
Language C++ 20 (gcc 12.2)
Score 450
Code Size 2653 Byte
Status AC
Exec Time 476 ms
Memory 46688 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 2
AC × 46
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 1 ms 3424 KiB
example_01.txt AC 1 ms 3464 KiB
hand_00.txt AC 220 ms 46572 KiB
hand_01.txt AC 227 ms 46596 KiB
hand_02.txt AC 162 ms 23320 KiB
hand_03.txt AC 6 ms 3660 KiB
hand_04.txt AC 6 ms 3560 KiB
hand_05.txt AC 5 ms 3456 KiB
hand_06.txt AC 175 ms 23544 KiB
hand_07.txt AC 162 ms 23328 KiB
hand_08.txt AC 177 ms 23364 KiB
hand_09.txt AC 403 ms 38956 KiB
hand_10.txt AC 156 ms 23412 KiB
hand_11.txt AC 1 ms 3428 KiB
hand_12.txt AC 167 ms 23464 KiB
hand_13.txt AC 1 ms 3420 KiB
random_00.txt AC 445 ms 43680 KiB
random_01.txt AC 448 ms 43572 KiB
random_02.txt AC 476 ms 43976 KiB
random_03.txt AC 427 ms 43744 KiB
random_04.txt AC 457 ms 43448 KiB
random_05.txt AC 284 ms 33152 KiB
random_06.txt AC 291 ms 33148 KiB
random_07.txt AC 295 ms 32908 KiB
random_08.txt AC 285 ms 33104 KiB
random_09.txt AC 288 ms 33100 KiB
random_10.txt AC 229 ms 28356 KiB
random_11.txt AC 223 ms 28624 KiB
random_12.txt AC 230 ms 28472 KiB
random_13.txt AC 228 ms 28396 KiB
random_14.txt AC 233 ms 28372 KiB
random_15.txt AC 185 ms 24040 KiB
random_16.txt AC 176 ms 23936 KiB
random_17.txt AC 173 ms 24176 KiB
random_18.txt AC 176 ms 24024 KiB
random_19.txt AC 181 ms 23940 KiB
random_20.txt AC 401 ms 31528 KiB
random_21.txt AC 417 ms 31496 KiB
random_22.txt AC 397 ms 31524 KiB
random_23.txt AC 403 ms 31552 KiB
random_24.txt AC 406 ms 31788 KiB
random_25.txt AC 340 ms 46688 KiB
random_26.txt AC 353 ms 46632 KiB
random_27.txt AC 352 ms 46480 KiB
random_28.txt AC 351 ms 46380 KiB
random_29.txt AC 349 ms 46568 KiB