Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // clang-format off
- #include<bits/stdc++.h>
- using namespace std;
- #ifdef LOCAL
- #include "deb/debug.h"
- #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
- #else
- #define debug(...) 42
- #endif
- #define int long long
- typedef unsigned long long ull;
- typedef long double ld;
- #define ff first
- #define ss second
- const int K = 5e4;
- const int MODR = 1e5;
- mt19937 rnd(time(0));
- int func(int n, int m, vector< vector<int> > &v) {
- int cnt = 0;
- for (int x1 = 0; x1 < n; x1++) {
- for (int x2 = x1 + 1; x2 < n; x2++) {
- for (int y1 = 0; y1 < m; y1++) {
- for (int y2 = y1 + 1; y2 < m; y2++) {
- if (v[x1][y1] == v[x2][y1] && v[x1][y1] == v[x1][y2] && v[x1][y1] == v[x2][y2])
- cnt++;
- }
- }
- }
- }
- return cnt;
- }
- ld prob() {
- int x = rnd() % MODR;
- return (ld)x / (ld)MODR;
- }
- void solve() {
- int n, m, c;
- cin >> n >> m >> c;
- vector< vector<int> > v(n, vector<int>(m));
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- v[i][j] = rnd() % c + 1;
- }
- }
- if (c == 3) {
- vector< vector<int> > tr(10, vector<int>(10));
- tr[0] = {1, 2, 2, 3, 2, 1, 1, 3, 3, 3};
- tr[1] = {3, 1, 2, 2, 1, 3, 1, 1, 3, 2};
- tr[2] = {2, 2, 1, 1, 3, 1, 3, 1, 3, 2};
- tr[3] = {2, 3, 2, 1, 3, 2, 1, 3, 2, 1};
- tr[4] = {1, 2, 3, 2, 3, 2, 2, 1, 1, 3};
- tr[5] = {1, 2, 1, 3, 1, 3, 3, 2, 2, 1};
- tr[6] = {3, 1, 2, 3, 3, 1, 2, 2, 1, 1};
- tr[7] = {3, 3, 3, 1, 1, 2, 3, 2, 1, 2};
- tr[8] = {2, 3, 1, 2, 2, 3, 1, 2, 1, 3};
- tr[9] = {1, 1, 3, 1, 2, 3, 2, 3, 2, 2};
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cout << tr[i][j] << " \n"[j == m - 1];
- }
- }
- return;
- }
- int ans = func(n, m, v);
- ld t = 1;
- for (int i = 0; i < K && ans; i++) {
- t *= 0.99;
- if (t < 0.001)
- t = 1;
- vector< vector<int> > u = v;
- int x = rnd() % n;
- int y = rnd() % m;
- int p = rnd() % c + 1;
- while (p == u[x][y])
- p = rnd() % c + 1;
- u[x][y] = p;
- int cur = func(n, m, u);
- if (cur < ans) {
- ans = cur;
- v.swap(u);
- } else if (prob() < exp((ans - cur) / t)) {
- ans = cur;
- v.swap(u);
- }
- }
- debug(func(n, m, v));
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cout << v[i][j] << ' ';
- }
- cout << '\n';
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int _ = 1;
- // cin >> _;
- for (;_; --_) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement