Submission #36602494


Source Code Expand

const long long MOD = 998244353;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef complex<double> cd;

#define forn(i, n) for (int i = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << " fine, thanks" << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No\n", "Yes\n"};
string YES[2] = {"NO\n", "YES\n"};
string Possible[2] = {"Impossible\n", "Possible\n"};
string POSSIBLE[2] = {"IMPOSSIBLE\n", "POSSIBLE\n"};

#define ok(x, n) (0 <= (x) && (x) < (n))
#define withBit(mask, i) ((mask & (1 << i)) > 0)

ll binpow(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = binpow(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

#define inq binpow

ll rev(ll x)
{
    return binpow(x, MOD - 2);
}

int _comb_precomputed_combinatorics = 0;
vector<ll> _comb_fact, _comb_ufact, _comb_rev;

inline void _comb_precompute_combinatorics(int _comb_n)
{
    if (_comb_n < 2) _comb_n = 2;
    if (_comb_precomputed_combinatorics >= _comb_n)
        return;
    _comb_fact.resize(_comb_n);
    _comb_ufact.resize(_comb_n);
    _comb_rev.resize(_comb_n);
    _comb_rev[1] = 1;
    for (int i = max(2, _comb_precomputed_combinatorics); i < _comb_n; i++)
        _comb_rev[i] = MOD - _comb_rev[MOD % i] * (MOD / i) % MOD;
    _comb_fact[0] = 1, _comb_ufact[0] = 1;
    for (int i = max(1, _comb_precomputed_combinatorics); i < _comb_n; i++)
        _comb_fact[i] = _comb_fact[i - 1] * i % MOD, _comb_ufact[i] = _comb_ufact[i - 1] * _comb_rev[i] % MOD;
    _comb_precomputed_combinatorics = _comb_n;
}

ll fact(int x)
{
    if (_comb_precomputed_combinatorics <= x)
        _comb_precompute_combinatorics(x + 1);
    return _comb_fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n)
        return 0;
    if (_comb_precomputed_combinatorics <= n)
        _comb_precompute_combinatorics(n + 1);
    return _comb_fact[n] * _comb_ufact[n - k] % MOD * _comb_ufact[k] % MOD;
}

template<typename T> istream& operator>>(istream& in, vector<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        in >> a[i];
    return in;
}

template<typename T> ostream& operator<<(ostream& out, const vector<T>& a)
{
    for (auto e : a)
    {
        out << e << " ";
        if (typeid(T) != typeid(int) && typeid(T) != typeid(ll))
            out << "\n";
    }
    return out;
}

void solve()
{
    int n, m, k, h, w;
    cin >> n >> m >> k >> h >> w;
    vvi a(n, vi(m));
    cin >> a;

    vi L(k, INF), R(k, -INF), U(k, INF), D(k, -INF);
    forn(i, n) forn(j, m)
    {
        a[i][j]--;
        L[a[i][j]] = min(L[a[i][j]], i);
        R[a[i][j]] = max(R[a[i][j]], i);
        U[a[i][j]] = min(U[a[i][j]], j);
        D[a[i][j]] = max(D[a[i][j]], j);
    }
    for (int i = 0; i <= n - h; i++)
    {
        for (int j = 0; j <= m - w; j++)
        {
            int x = 0;
            for (int y = 0; y < k; y++)
            {
                if (L[y] < i || R[y] >= i + h || U[y] < j || D[y] >= j + w)
                    x++;
            }
            cout << x << " ";
        }
        cout << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    #ifdef tests
    cin >> t;
    #endif // tests
    while (t--)
    {
        solve();
    }
}

Submission Info

Submission Time
Task E - Grid Filling
User IgorI
Language C++ (GCC 9.2.1)
Score 500
Code Size 4060 Byte
Status AC
Exec Time 80 ms
Memory 3744 KiB

Compile Error

./Main.cpp: In instantiation of ‘std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = std::vector<int>; std::istream = std::basic_istream<char>]’:
./Main.cpp:120:12:   required from here
./Main.cpp:99:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::vector<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   99 |     for (int i = 0; i < a.size(); i++)
./Main.cpp: In instantiation of ‘std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = int; std::istream = std::basic_istream<char>]’:
./Main.cpp:100:12:   required from ‘std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = std::vector<int>; std::istream = std::basic_istream<char>]’
./Main.cpp:120:12:   required from here
./Main.cpp:99:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 03_max_12.txt, 03_max_13.txt, 03_max_14.txt, 03_max_15.txt, 04_edge_16.txt, 04_edge_17.txt, 04_edge_18.txt, 04_edge_19.txt, 04_edge_20.txt, 04_edge_21.txt, 04_edge_22.txt, 04_edge_23.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 7 ms 3560 KiB
00_sample_01.txt AC 2 ms 3588 KiB
00_sample_02.txt AC 2 ms 3444 KiB
01_small_03.txt AC 2 ms 3564 KiB
01_small_04.txt AC 2 ms 3488 KiB
01_small_05.txt AC 2 ms 3572 KiB
02_random_06.txt AC 2 ms 3504 KiB
02_random_07.txt AC 29 ms 3608 KiB
02_random_08.txt AC 3 ms 3568 KiB
02_random_09.txt AC 2 ms 3568 KiB
02_random_10.txt AC 2 ms 3500 KiB
02_random_11.txt AC 2 ms 3580 KiB
03_max_12.txt AC 26 ms 3680 KiB
03_max_13.txt AC 36 ms 3720 KiB
03_max_14.txt AC 41 ms 3744 KiB
03_max_15.txt AC 14 ms 3692 KiB
04_edge_16.txt AC 40 ms 3700 KiB
04_edge_17.txt AC 22 ms 3636 KiB
04_edge_18.txt AC 15 ms 3680 KiB
04_edge_19.txt AC 11 ms 3512 KiB
04_edge_20.txt AC 80 ms 3588 KiB
04_edge_21.txt AC 32 ms 3624 KiB
04_edge_22.txt AC 15 ms 3712 KiB
04_edge_23.txt AC 17 ms 3680 KiB