Advertisement
tiom4eg

Good Paintings Solver

Apr 21st, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define pii pair <int, int>
  9. #define pll pair <ll, ll>
  10. #define vi vector <int>
  11. #define mi vector <vector <int> >
  12. // Quick functions
  13. #define endl "\n"
  14. #define F first
  15. #define S second
  16. #define all(a) a.begin(), a.end()
  17. #define sz(a) a.size()
  18. #define pb push_back
  19. #define mp make_pair
  20. // Quick fors
  21. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  22. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  23. // Pragmas
  24. #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
  25. //#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  26. #pragma GCC comment(linker, "/stack:200000000")
  27. // PBDS
  28. #include <ext/pb_ds/assoc_container.hpp>
  29. #include <ext/pb_ds/tree_policy.hpp>
  30. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  31. #define ook order_of_key
  32. #define fbo find_by_order
  33. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  34. using namespace std;
  35. using namespace __gnu_pbds;
  36. mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
  37.  
  38. int randint(int n) {
  39.     return rng() % n + 1;
  40. }
  41. /*
  42.  ██▓     ███▄ ▄███▓ ▄▄▄       ▒█████
  43. ▓██▒    ▓██▒▀█▀ ██▒▒████▄    ▒██▒  ██▒
  44. ▒██░    ▓██    ▓██░▒██  ▀█▄  ▒██░  ██▒
  45. ▒██░    ▒██    ▒██ ░██▄▄▄▄██ ▒██   ██░
  46. ░██████▒▒██▒   ░██▒ ▓█   ▓██▒░ ████▓▒░
  47. ░ ▒░▓  ░░ ▒░   ░  ░ ▒▒   ▓▒█░░ ▒░▒░▒░
  48. ░ ░ ▒  ░░  ░      ░  ▒   ▒▒ ░  ░ ▒ ▒░
  49.   ░ ░   ░      ░     ░   ▒   ░ ░ ░ ▒
  50.     ░  ░       ░         ░  ░    ░ ░
  51. */
  52.  
  53. mi f;
  54. int n, m, c, cur, best;
  55.  
  56. void gen() { FOR(i, 0, n) FOR(j, 0, m) f[i][j] = randint(c); }
  57. int calc(int x, int y) {
  58.     int res = 0;
  59.     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++;
  60.     return res;
  61. }
  62.  
  63. int main(){
  64.     fastIO;
  65.     cin >> n >> m >> c;
  66.     f.assign(n, vi(m));
  67.     FOR(iter, 0, 100) {
  68.         gen();
  69.         cur = 0;
  70.         FOR(i, 0, n) FOR(j, 0, m) cur += calc(i, j);
  71.         cur >>= 2;
  72.         best = cur;
  73.         FOR(att, 0, 5000) {
  74.             int i = randint(n) - 1, j = randint(m) - 1;
  75.             int nw = f[i][j], tmp = f[i][j];
  76.             while (nw == f[i][j]) nw = randint(c);
  77.             cur -= calc(i, j);
  78.             f[i][j] = nw;
  79.             cur += calc(i, j);
  80.             if (cur > best) {
  81.                 cur -= calc(i, j);
  82.                 f[i][j] = tmp;
  83.                 cur += calc(i, j);
  84.             }
  85.             best = min(best, cur);
  86.             if (!cur) {
  87.                 FOR(k, 0, n) {
  88.                     FOR(l, 0, m) cout << f[k][l] << ' ';
  89.                     cout << endl;
  90.                 }
  91.                 exit(0);
  92.             }
  93.         }
  94.     }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement