Skip to content

Commit fbad970

Browse files
committed
The 4th Universal Cup. Stage 8: Grand Prix of Poland
1 parent 36abb73 commit fbad970

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

‎QOJ/15448.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @file 15448.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 int pw10[5] = {1, 10, 100, 1000, 10000};
16+
17+
int dist[100000], cnt[25];
18+
19+
void solve(void) {
20+
int n;
21+
cin >> n;
22+
23+
for (int i = 0; i < 100000; i++) cnt[dist[i] = 25]++;
24+
25+
auto upd = [&](int p, int d) -> void {
26+
cnt[dist[p]]--;
27+
cnt[dist[p] = d]++;
28+
return;
29+
};
30+
31+
int ans = 25;
32+
for (int i = 1; i <= n; i++) {
33+
string s;
34+
cin >> s;
35+
36+
int x = stoi(s);
37+
if (dist[x] == 0) continue;
38+
39+
queue<int> que;
40+
upd(x, 0), que.push(x);
41+
while (!que.empty()) {
42+
int p = que.front();
43+
que.pop();
44+
45+
for (int t = 0; t < 5; t++)
46+
for (int delt : {-1, 1}) {
47+
int pb = p / pw10[t] % 10, qb = (pb + 10 + delt) % 10;
48+
int q = p + (qb - pb) * pw10[t];
49+
if (dist[q] > dist[p] + 1) upd(q, dist[p] + 1), que.push(q);
50+
}
51+
}
52+
53+
while (!cnt[ans]) ans--;
54+
55+
cout << ans << ' ' << cnt[ans] << endl;
56+
}
57+
}
58+
59+
int main() {
60+
ios::sync_with_stdio(false), cin.tie(nullptr);
61+
62+
int _ = 1;
63+
while (_--) solve();
64+
65+
return 0;
66+
}

‎QOJ/15452.cpp‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)