#include <bits/stdc++.h>
using namespace std;
int len(int x) {
int sz = 0;
while (x > 0) {
x /= 10;
sz++;
}
return sz;
}
int find_digit(int a, int d) {
string s = "";
while (a > 0) {
s += ((a % 10) + '0');
a /= 10;
}
reverse(s.begin(), s.end());
for (int i = 0; i < 4; i++) s += '0';
return s[d - 1] - '0';
}
vector<vector<int>> devise_strategy(int n) {
vector<vector<int>> s(50, vector<int>(n+1));
s[0][0] = 0;
// the first prisoner will write the amount of digits A has
// the second prisoner will compare this with the amount of digits B has
// if they have same no. digits:
/*
the current prisoner will write the current digit of A on the board (form: pd, where p is the position of the digit and d is its value)
the next prisoner will compare with the respective digit of B
if they are equal, he will write which digit of A must be inspected next (added + 4) (so it doesnt conflict with the number written by the first pr.)
max X: 49
*/
for (int i = 1; i <= n; i++) {
s[0][i] = len(i);
}
for (int i = 1; i <= 4; i++) { // read i on the board
s[i][0] = 1; // see B
for (int j = 1; j <= n; j++) {
if (len(j) < i) {
s[i][j] = -2;
}
else if (len(j) > i) {
s[i][j] = -1;
}
else s[i][j] = 1 + 4; // we need to see the first digit of A; add 1 so it doesnt conflict with the no. of digits of A
}
}
for (int i = 5; i <= 8; i++) { // we need to see this digit of A next
s[i][0] = 0;
int need = i - 4;
for (int j = 1; j <= n; j++) {
s[i][j] = need * 10 + find_digit(j, need);
}
}
for (int i = 10; i <= 49; i++) { // we know that the i[0] digit of A is i[1]
s[i][0] = 1;
int v = i % 10;
int d = i / 10;
for (int j = 1; j <= n; j++) {
int rep = find_digit(j, d);
if (rep < v) {
s[i][j] = -2;
}
else if (rep > v) {
s[i][j] = -1;
}
else {
s[i][j] = d + 1 + 4; // we must see the next digit
}
}
}
return s;
}
/*
int main() {
vector<vector<int>> x = devise_strategy(20);
for (auto a: x) {
for (auto b: a) {
cout << b << " ";
}
cout << "\n";
}
return 0;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |