QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#476992#9114. Black or White 2ucup-team3926#AC ✓192ms36956kbC++207.4kb2024-07-13 22:15:422024-07-13 22:15:43

Judging History

你现在查看的是最新测评结果

  • [2024-07-13 22:15:43]
  • 评测
  • 测评结果:AC
  • 用时:192ms
  • 内存:36956kb
  • [2024-07-13 22:15:42]
  • 提交

answer

/*
    author:  Maksim1744
    created: 13.07.2024 17:04:45
*/

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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> 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, 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> 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;}

#ifdef HOME
#define SHOW_COLORS
#include "/mnt/c/Libs/tools/print.cpp"
#else
#define show(...) void(0)
#define debugf(fun)   fun
#define debugv(var)   var
#define mclock    void(0)
#define shows     void(0)
#define debug  if (false)
#define OSTREAM(...)    ;
#define OSTREAM0(...)   ;
#endif

namespace grid_iterator_ns {
const array<pair<int, int>, 8> dirs = {{{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}};
struct GridIterator {
    int n, m;
    GridIterator(int n, int m) : n(n), m(m) {}

    template<size_t N>
    struct NeighbourIteratorContainer {
        int i, j, n, m;
        NeighbourIteratorContainer(int i, int j, int n, int m) : i(i), j(j), n(n), m(m) {}

        struct NeighbourIterator {
            int cur;
            int i, j, n, m;
            NeighbourIterator(int cur, int i, int j, int n, int m) : cur(cur), i(i), j(j), n(n), m(m) {
                skip_to_first_allowed();
            }

            void skip_to_first_allowed() {
                while (cur < N &&
                    (i + dirs[cur].first  < 0 || i + dirs[cur].first  >= n ||
                     j + dirs[cur].second < 0 || j + dirs[cur].second >= m)) {
                    ++cur;
                }
            }

            NeighbourIterator& operator ++ () {
                ++cur;
                skip_to_first_allowed();
                return *this;
            }

            pair<int, int> operator * () const { return {i + dirs[cur].first, j + dirs[cur].second}; }

            bool operator == (const NeighbourIterator& other) const { return cur == other.cur; }
        };

        auto begin() const { return NeighbourIterator(0, i, j, n, m); }
        auto end()   const { return NeighbourIterator(N, i, j, n, m); }

        auto collect() const {
            vector<pair<int, int>> result;
            for (auto it = begin(); it != end(); ++it) result.push_back(*it);
            return result;
        }
    };

    template<size_t N>
    auto iterate(int i, int j) const {
        static_assert(N == 4 || N == 8, "you can remove this, but make sure you understand what you are doing");
        return NeighbourIteratorContainer<N>(i, j, n, m);
    }
};
}
using grid_iterator_ns::GridIterator;

void test_case(int test) {
    int n, m, kk;
    cin >> n >> m >> kk;
    if (n == 2 && m == 2 && kk == 2) {
        cout << "10\n01\n";
        return;
    }
    // for (int n = 2; n <= 20; ++n)
    // for (int m = 2; m <= 20; ++m)
    // for (int kk = 0; kk <= n * m; ++kk)

    {
        int k = kk;
        int white = 0;
        int black = 1;
        if (k * 2 > n * m) {
            swap(white, black);
            k = n * m - k;
        }
        vector<vector<int>> v(n, vector<int>(m, white));
        vector<vector<pair<int, int>>> byd(n + m - 1);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                byd[i + j].eb(i, j);
            }
        }
        int fr = 0;
        for (int i = 0; i < byd.size(); ++i) {
            if (byd[i].size() <= k) {
                for (auto [x, y] : byd[i]) {
                    v[x][y] = black;
                    --k;
                }
                fr = i;
            } else {
                break;
            }
        }
        for (int i = (int)byd.size() - 1; i > fr + 2; --i) {
            if (byd[i].size() <= k) {
                for (auto [x, y] : byd[i]) {
                    v[x][y] = black;
                    --k;
                }
            } else {
                break;
            }
        }

        GridIterator gi(n, m);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (v[i][j] == black) continue;
                if (k == 0) break;
                bool ok = true;
                for (auto [x, y] : gi.iterate<8>(i, j)) {
                    if (v[x][y] == black) {
                        ok = false;
                    }
                }
                if (ok) {
                    --k;
                    v[i][j] = black;
                }
            }
        }

        if (n == 4 && m == 4 && kk == 8) {
            k = kk;
            vector<string> temp = {
                "1101",
                "1000",
                "0010",
                "0111",
            };
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    v[i][j] = temp[i][j] - '0';
                    k -= v[i][j];
                }
            }
            assert(k == 0);
        }

        // if (k != 0) {
        //     cerr << n << ' ' << m << ' ' << kk << endl;
        // }

        for (const auto& l : v) {
            for (int x : l)
                cout << x;
            cout << '\n';
        }
        cout << '\n';
        // for (int i = 0; i < n - 1; ++i) {
        //     for (int j = 0; j < m - 1; ++j) {
        //         assert(v[i][j] + v[i][j + 1] + v[i + 1][j] + v[i + 1][j + 1] != 2);
        //     }
        // }
    }
    // exit(0);
}

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

    int T;
    cin >> T;
    for (int test = 1; test <= T; ++test) {
        test_case(test);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

2
2 2 2
2 3 0

output:

10
01
000
000


result:

ok Output is valid. OK.

Test #2:

score: 0
Accepted
time: 160ms
memory: 3636kb

input:

27520
2 2 0
2 2 1
2 2 2
2 2 3
2 2 4
2 3 0
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
3 2 0
3 2 1
3 2 2
3 2 3
3 2 4
3 2 5
3 2 6
3 3 0
3 3 1
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
3 3 8
3 3 9
2 4 0
2 4 1
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
2 4 7
2 4 8
3 4 0
3 4 1
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10...

output:

00
00

10
00

10
01
01
11

11
11

000
000

100
000

100
001

110
100

011
110

011
111

111
111

00
00
00

10
00
00

10
00
01

11
10
00

01
11
10

01
11
11

11
11
11

000
000
000

100
000
000

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

011
111
111

111
111
111

000...

result:

ok Output is valid. OK.

Test #3:

score: 0
Accepted
time: 109ms
memory: 26228kb

input:

162
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #4:

score: 0
Accepted
time: 110ms
memory: 19900kb

input:

163
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #5:

score: 0
Accepted
time: 115ms
memory: 19016kb

input:

165
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #6:

score: 0
Accepted
time: 160ms
memory: 4012kb

input:

1020
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #7:

score: 0
Accepted
time: 164ms
memory: 4296kb

input:

1012
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #8:

score: 0
Accepted
time: 172ms
memory: 4088kb

input:

1033
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #9:

score: 0
Accepted
time: 192ms
memory: 3628kb

input:

100000
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #10:

score: 0
Accepted
time: 81ms
memory: 3756kb

input:

100000
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #11:

score: 0
Accepted
time: 85ms
memory: 3488kb

input:

100000
2 2 2
2 3 2
2 3 3
2 3 4
3 2 2
3 2 3
3 2 4
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10
4 2 2
4 2 3
4 2 4
4 2 5
4 2 6
4 3 2
4 3 3
4 3 4
4 3 5
4 3 6
4 3 7
4 3 8
4 3 9
4 3 10
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4...

output:

10
01
100
001

110
100

011
110

10
00
01

11
10
00

01
11
10

100
000
001

110
100
000

110
100
001

001
011
110

001
011
111

011
111
110

1000
0001

1100
1000

1100
1001

0011
0111

0111
1110

1000
0000
0001

1100
1000
0000

1100
1000
0001

1101
1000
0001

1110
1100
1000

0010
0111
1110

0011
011...

result:

ok Output is valid. OK.

Test #12:

score: 0
Accepted
time: 112ms
memory: 36548kb

input:

3
1500 1500 2250000
1322 1322 1747684
1158 2 2316

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok Output is valid. OK.

Test #13:

score: 0
Accepted
time: 113ms
memory: 36956kb

input:

3
1500 1500 1125000
1322 1322 873842
1158 2 1158

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok Output is valid. OK.

Extra Test:

score: 0
Extra Test Passed