2025.1.15——1200
Q1. 1200
简单来说就是给定3个数组,每个数组选择一个数,三者下标不同,问三者和的最大值。
Winter holidays are coming up. They are going to last for \(n\) days.
During the holidays, Monocarp wants to try all of these activities exactly once with his friends:
- go skiing;
- watch a movie in a cinema;
- play board games.
Monocarp knows that, on the \(i\)-th day, exactly \(a_i\) friends will join him for skiing, \(b_i\) friends will join him for a movie and \(c_i\) friends will join him for board games.
Monocarp also knows that he can't try more than one activity in a single day.
Thus, he asks you to help him choose three distinct days \(x, y, z\) in such a way that the total number of friends to join him for the activities (\(a_x + b_y + c_z\)) is maximized.
Input
The first line of each testcase contains a single integer \(n\) (\(3 \le n \le 10^5\)) — the duration of the winter holidays in days.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (\(1 \le a_i \le 10^8\)) — the number of friends that will join Monocarp for skiing on the \(i\)-th day.
The third line contains \(n\) integers \(b_1, b_2, \dots, b_n\) (\(1 \le b_i \le 10^8\)) — the number of friends that will join Monocarp for a movie on the \(i\)-th day.
The fourth line contains \(n\) integers \(c_1, c_2, \dots, c_n\) (\(1 \le c_i \le 10^8\)) — the number of friends that will join Monocarp for board games on the \(i\)-th day.
Q2. 1200
You are given an array \(a_1, a_2, \dots, a_n\) of distinct positive integers. You have to do the following operation exactly once:
- choose a positive integer \(k\);
- for each \(i\) from \(1\) to \(n\), replace \(a_i\) with \(a_i \text{ mod } k^\dagger\).
Find a value of \(k\) such that \(1 \leq k \leq 10^{18}\) and the array \(a_1, a_2, \dots, a_n\) contains exactly \(2\) distinct values at the end of the operation. It can be shown that, under the constraints of the problem, at least one such \(k\) always exists. If there are multiple solutions, you can print any of them.
\(^\dagger\) \(a \text{ mod } b\) denotes the remainder after dividing \(a\) by \(b\). For example:
- \(7 \text{ mod } 3=1\) since \(7 = 3 \cdot 2 + 1\)
- \(15 \text{ mod } 4=3\) since \(15 = 4 \cdot 3 + 3\)
- \(21 \text{ mod } 1=0\) since \(21 = 21 \cdot 1 + 0\)
Input
The first line of each test case contains a single integer \(n\) (\(2 \le n \le 100\)) — the length of the array \(a\).
The second line of each test case contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(1 \le a_i \le 10^{17}\)) — the initial state of the array. It is guaranteed that all the \(a_i\) are distinct.
Q3. 1200
In Cyprus, the weather is pretty hot. Thus, Theofanis saw this as an opportunity to create an ice cream company.
He keeps the ice cream safe from other ice cream producers by locking it inside big storage rooms. However, he forgot the password. Luckily, the lock has a special feature for forgetful people!
It gives you a table \(M\) with \(n\) rows and \(n\) columns of non-negative integers, and to open the lock, you need to find an array \(a\) of \(n\) elements such that:
- \(0 \le a_i < 2^{30}\), and
- \(M_{i,j} = a_i | a_j\) for all \(i \neq j\), where \(|\) denotes the bitwise OR operation.
The lock has a bug, and sometimes it gives tables without any solutions. In that case, the ice cream will remain frozen for the rest of eternity.
Can you find an array to open the lock?
Q4. 1200
Kristina has a matrix of size \(n\) by \(n\), filled with lowercase Latin letters. The value of \(n\) is even.
She wants to change some characters so that her matrix becomes a perfect square. A matrix is called a perfect square if it remains unchanged when rotated \(90^\circ\) clockwise once.
Here is an example of rotating a matrix by \(90^\circ\):
In one operation, Kristina can choose any cell and replace its value with the next character in the alphabet. If the character is equal to "z", its value does not change.
Find the minimum number of operations required to make the matrix a perfect square.
Q5. 1200
Chaneka, a gamer kid, invented a new gaming controller called joyboard. Interestingly, the joyboard she invented can only be used to play one game.
The joyboard has a screen containing \(n+1\) slots numbered from \(1\) to \(n+1\) from left to right. The \(n+1\) slots are going to be filled with an array of non-negative integers \([a_1,a_2,a_3,\ldots,a_{n+1}]\). Chaneka, as the player, must assign \(a_{n+1}\) with an integer between \(0\) and \(m\) inclusive. Then, for each \(i\) from \(n\) to \(1\), the value of \(a_i\) will be equal to the remainder of dividing \(a_{i+1}\) (the adjacent value to the right) by \(i\). In other words, \(a_i = a_{i + 1} \bmod i\).
Chaneka wants it such that after every slot is assigned with an integer, there are exactly \(k\) distinct values in the entire screen (among all \(n+1\) slots). How many valid ways are there for assigning a non-negative integer into slot \(n+1\)?
Input
The only line of each test case contains three integers \(n\), \(m\), and \(k\) (\(1 \leq n \leq 10^9\); \(0 \leq m \leq 10^9\); \(1 \leq k \leq n+1\)) — there are \(n+1\) slots, the integer assigned in slot \(n+1\) must not be bigger than \(m\), and there should be exactly \(k\) distinct values.
------------------------独自思考分割线------------------------
-
发现结论+发现充分性结论/二进制/取模+位运算/神秘题+发现结论/推坐标+数论/模拟结论。前3题被卡了,值得回味。
A1
- 卡了好久在想优化,感觉优化很麻烦。其实方向错了。
- 发现结论:可缩小范围,每个数组选择的范围只有三个数。
- 据说还有dp解法。
A2.
- 充分性:在所有数不相同条件下,在二进制之下,由低位到高位必然会存在两种值。
A3
- 位运算局部到整体:构造每一位,若 \(M\) 为 \(0\), \(a_i\) \(a_j\) 必为 \(0\),否则使 \(a_i\) \(a_j\) 为 \(1\) 。
- 是道神秘题,充分必要性我现在不能证明。
点击链接去洛谷吧
A4
- 发现结论:对应的四个位置绑定,都要变相同取最大值。
- 推出动态坐标即可。
A5
- 数论一下或模拟发现结论。
------------------------代码分割线------------------------
A1
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<int> a(n), b(n), c(n);for (int &x : a)cin >> x;for (int &x : b)cin >> x;for (int &x : c)cin >> x;struct Node{int x, idx;};vector<Node> mx1, mx2, mx3;auto get = [](vector<int> &a, vector<Node> &mx){mx.assign(3, {-1, -1});for (int i = 0; i < a.size(); i++)if (a[i] > mx[0].x)mx[2] = mx[1], mx[1] = mx[0], mx[0] = {a[i], i};else if (a[i] > mx[1].x)mx[2] = mx[1], mx[1] = {a[i], i};else if (a[i] > mx[2].x)mx[2] = {a[i], i};};get(a, mx1);get(b, mx2);get(c, mx3);int res = 0;for (auto [va, ida] : mx1)for (auto [vb, idb] : mx2)for (auto [vc, idc] : mx3)if (ida - idb && ida - idc && idb - idc)res = max(res, va + vb + vc);cout << res << endl;
}
A2
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<int> a(n);for (int &x : a)cin >> x;int bit = 0;auto check = [&](int bit){int two[2] = {};for (auto v : a)two[v >> bit & 1]++;return two[0] && two[1];};for (;; bit++)if (check(bit))break;cout << (1ll << bit + 1) << endl;
}
A3
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<vector<int>> a(n + 1, vector<int>(n + 1));for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)cin >> a[i][j];vector<int> res(n + 1, (1ll << 30) - 1);for (int i = 1; i <= n; i++)for (int j = i + 1; j <= n; j++)res[i] &= a[i][j], res[j] &= a[i][j];bool f = 1;for (int i = 1; i <= n; i++)for (int j = i + 1; j <= n; j++)if ((res[i] | res[j]) - a[i][j])f = 0;cout << (f ? "YES" : "NO") << endl;if (f)for (int i = 1; i <= n; i++)cout << res[i] << ' ';cout << endl;
}
A4
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n;cin >> n;vector<string> a(n + 1);for (int i = 1; i <= n; i++){cin >> a[i];a[i] = " " + a[i];}int res = 0;auto get = [](char a, char b, char c, char d){int ans = 0;char mx = max({a, b, c, d});ans += abs(mx - a) + abs(mx - b) + abs(mx - c) + abs(mx - d);return ans;};for (int i = 1; i <= n >> 1; i++)for (int j = 1; j <= n >> 1; j++)res += get(a[i][j], a[n - i + 1][n - j + 1], a[n - j + 1][i], a[j][n - i + 1]);cout << res << endl;
}
A5
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cout << fixed << setprecision(10);int T = 1;cin >> T;while (T--)_();return 0;
}void _()
{int n, m, k;cin >> n >> m >> k;int res = 0;if (m > n)res = m - n + 1 - m / n;if (k == 1)res = 1;if (k == 2)res = m - res;if (k > 3)res = 0;cout << res << endl;
}