Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define pii pair <int, int>
- #define pll pair <ll, ll>
- #define vi vector <int>
- #define mi vector <vector <int> >
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) a.size()
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- // Pragmas
- #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
- //#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
- int randint(int n) {
- return rng() % n + 1;
- }
- /*
- ██▓ ███▄ ▄███▓ ▄▄▄ ▒█████
- ▓██▒ ▓██▒▀█▀ ██▒▒████▄ ▒██▒ ██▒
- ▒██░ ▓██ ▓██░▒██ ▀█▄ ▒██░ ██▒
- ▒██░ ▒██ ▒██ ░██▄▄▄▄██ ▒██ ██░
- ░██████▒▒██▒ ░██▒ ▓█ ▓██▒░ ████▓▒░
- ░ ▒░▓ ░░ ▒░ ░ ░ ▒▒ ▓▒█░░ ▒░▒░▒░
- ░ ░ ▒ ░░ ░ ░ ▒ ▒▒ ░ ░ ▒ ▒░
- ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒
- ░ ░ ░ ░ ░ ░ ░
- */
- mi f;
- int n, m, c, cur, best;
- void gen() { FOR(i, 0, n) FOR(j, 0, m) f[i][j] = randint(c); }
- int calc(int x, int y) {
- int res = 0;
- FOR(i, 0, n) FOR(j, 0, m) if (i != x && j != y) if (f[i][j] == f[x][j] && f[x][j] == f[i][y] && f[i][y] == f[x][y]) res++;
- return res;
- }
- int main(){
- fastIO;
- cin >> n >> m >> c;
- f.assign(n, vi(m));
- FOR(iter, 0, 100) {
- gen();
- cur = 0;
- FOR(i, 0, n) FOR(j, 0, m) cur += calc(i, j);
- cur >>= 2;
- best = cur;
- FOR(att, 0, 5000) {
- int i = randint(n) - 1, j = randint(m) - 1;
- int nw = f[i][j], tmp = f[i][j];
- while (nw == f[i][j]) nw = randint(c);
- cur -= calc(i, j);
- f[i][j] = nw;
- cur += calc(i, j);
- if (cur > best) {
- cur -= calc(i, j);
- f[i][j] = tmp;
- cur += calc(i, j);
- }
- best = min(best, cur);
- if (!cur) {
- FOR(k, 0, n) {
- FOR(l, 0, m) cout << f[k][l] << ' ';
- cout << endl;
- }
- exit(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement