|
| 1 | +/** |
| 2 | + * @file 15452.cpp |
| 3 | + * @author Macesuted (i@macesuted.moe) |
| 4 | + * @date 2026-01-22 |
| 5 | + * |
| 6 | + * @copyright Copyright (c) 2026 |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | +#include <bits/stdc++.h> |
| 11 | +using namespace std; |
| 12 | + |
| 13 | +#define endl '\n' |
| 14 | + |
| 15 | +const string names[27] = {"UW", "UJ", "UWR", "MAP", "PW", "AGH", "PG", "NLU", "PUT", "PO", "PWR", "SGGW", "UMCS", "UR", |
| 16 | + "ZUT", "DTP", "GOO", "HUA", "KUL", "PL", "PM", "PS", "UAM", "UG", "UMK", "UO", "WAT"}; |
| 17 | +int cnt[27] = {11, 9, 8, 7, 6, 5, 4, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
| 18 | + |
| 19 | +int a[8][10]; |
| 20 | + |
| 21 | +int _(string s) { |
| 22 | + for (int i = 0; i < 27; i++) |
| 23 | + if (names[i] == s) return i; |
| 24 | + assert(false); |
| 25 | +} |
| 26 | + |
| 27 | +bool dfs(int x, int y) { |
| 28 | + if (x && y && a[x - 1][y - 1] == a[x][y]) return false; |
| 29 | + if (x && a[x - 1][y] == a[x][y]) return false; |
| 30 | + if (x && y < 9 && a[x - 1][y + 1] == a[x][y]) return false; |
| 31 | + if (y && a[x][y - 1] == a[x][y]) return false; |
| 32 | + |
| 33 | + if (x == 7 && y == 9) return true; |
| 34 | + |
| 35 | + vector<int> ids; |
| 36 | + for (int i = 0; i < 27; i++) |
| 37 | + if (cnt[i]) ids.push_back(i); |
| 38 | + sort(ids.begin(), ids.end(), [&](int x, int y) { return cnt[x] > cnt[y]; }); |
| 39 | + |
| 40 | + int nx = x, ny = y + 1; |
| 41 | + if (ny == 10) nx++, ny = 0; |
| 42 | + |
| 43 | + for (auto id : ids) { |
| 44 | + cnt[id]--; |
| 45 | + a[nx][ny] = id; |
| 46 | + if (dfs(nx, ny)) return true; |
| 47 | + cnt[id]++; |
| 48 | + } |
| 49 | + |
| 50 | + return false; |
| 51 | +} |
| 52 | + |
| 53 | +void solve(void) { |
| 54 | + string name; |
| 55 | + cin >> name; |
| 56 | + |
| 57 | + cnt[a[0][0] = _(name)]--; |
| 58 | + assert(dfs(0, 0)); |
| 59 | + |
| 60 | + for (int i = 0; i < 8; i++) |
| 61 | + for (int j = 0; j < 10; j++) |
| 62 | + for (int dx = -1; dx <= +1; dx++) |
| 63 | + for (int dy = -1; dy <= +1; dy++) |
| 64 | + if (dx != 0 || dy != 0) { |
| 65 | + if (i + dx < 0 || i + dx > 7 || j + dy < 0 || j + dy > 9) continue; |
| 66 | + if (a[i][j] == a[i + dx][j + dy]) cerr << i << ' ' << j << ' ' << dx << ' ' << dy << endl; |
| 67 | + } |
| 68 | + |
| 69 | + for (int i = 0; i < 8; i++) { |
| 70 | + for (int j = 0; j < 10; j++) cout << names[a[i][j]] << ' '; |
| 71 | + cout << endl; |
| 72 | + } |
| 73 | + |
| 74 | + return; |
| 75 | +} |
| 76 | + |
| 77 | +int main() { |
| 78 | + ios::sync_with_stdio(false), cin.tie(nullptr); |
| 79 | + |
| 80 | + int _ = 1; |
| 81 | + while (_--) solve(); |
| 82 | + |
| 83 | + return 0; |
| 84 | +} |
0 commit comments