#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string role;
if (!(cin >> role)) return 0;
ull n_limit;
int t;
cin >> n_limit >> t;
if (role == "Algosia") {
while (t--) {
ull val;
cin >> val;
vector<string> M(10, string(10, '0'));
val--;
vector<int> ar_degs = {10, 9, 8, 7};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
M[i][j] = '1';
}
}
vector<int> pat = {15, 14, 13, 12, 10, 8};
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 4; j++) {
if ((pat[i] >> (3 - j)) & 1) {
M[i + 4][j] = '1';
}
}
}
for (int j = 0; j < 6; j++) {
for (int i = 0; i < 4; i++) {
if ((pat[j] >> (3 - i)) & 1) {
M[i][j + 4] = '1';
}
}
}
for (int i = 4; i < 10; i++) {
for (int j = 4; j < 10; j++) {
if (val % 2 == 1) {
M[i][j] = '1';
}
val /= 2;
}
}
for (int i = 0; i < 10; i++) {
cout << M[i] << "\n";
}
cout.flush();
}
} else if (role == "Bajtek") {
while (t--) {
vector<string> M(10);
for (int i = 0; i < 10; i++) {
cin >> M[i];
}
vector<int> row_deg(10, 0), col_deg(10, 0);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (M[i][j] == '1') {
row_deg[i]++;
col_deg[j]++;
}
}
}
vector<int> R, C;
for (int i = 0; i < 10; i++) R.push_back(i);
for (int j = 0; j < 10; j++) C.push_back(j);
sort(R.begin(), R.end(), [&](int a, int b) { return row_deg[a] > row_deg[b]; });
sort(C.begin(), C.end(), [&](int a, int b) { return col_deg[a] > col_deg[b]; });
vector<int> dr(R.begin() + 4, R.end());
vector<int> dc(C.begin() + 4, C.end());
auto get_pat_r = [&](int r) {
int p = 0;
for (int j = 0; j < 4; j++) {
if (M[r][C[j]] == '1') p |= (1 << (3 - j));
}
return p;
};
auto get_pat_c = [&](int c) {
int p = 0;
for (int i = 0; i < 4; i++) {
if (M[R[i]][c] == '1') p |= (1 << (3 - i));
}
return p;
};
sort(dr.begin(), dr.end(), [&](int a, int b) { return get_pat_r(a) > get_pat_r(b); });
sort(dc.begin(), dc.end(), [&](int a, int b) { return get_pat_c(a) > get_pat_c(b); });
ull val = 0;
ull mul = 1;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if (M[dr[i]][dc[j]] == '1') {
val += mul;
}
mul *= 2;
}
}
cout << val + 1 << "\n";
cout.flush();
}
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; typedef unsigned long long ull; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string role; if (!(cin >> role)) return 0; ull n_limit; int t; cin >> n_limit >> t; if (role == "Algosia") { while (t--) { ull val; cin >> val; vector<string> M(10, string(10, '0')); val--; vector<int> ar_degs = {10, 9, 8, 7}; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { M[i][j] = '1'; } } vector<int> pat = {15, 14, 13, 12, 10, 8}; for (int i = 0; i < 6; i++) { for (int j = 0; j < 4; j++) { if ((pat[i] >> (3 - j)) & 1) { M[i + 4][j] = '1'; } } } for (int j = 0; j < 6; j++) { for (int i = 0; i < 4; i++) { if ((pat[j] >> (3 - i)) & 1) { M[i][j + 4] = '1'; } } } for (int i = 4; i < 10; i++) { for (int j = 4; j < 10; j++) { if (val % 2 == 1) { M[i][j] = '1'; } val /= 2; } } for (int i = 0; i < 10; i++) { cout << M[i] << "\n"; } cout.flush(); } } else if (role == "Bajtek") { while (t--) { vector<string> M(10); for (int i = 0; i < 10; i++) { cin >> M[i]; } vector<int> row_deg(10, 0), col_deg(10, 0); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (M[i][j] == '1') { row_deg[i]++; col_deg[j]++; } } } vector<int> R, C; for (int i = 0; i < 10; i++) R.push_back(i); for (int j = 0; j < 10; j++) C.push_back(j); sort(R.begin(), R.end(), [&](int a, int b) { return row_deg[a] > row_deg[b]; }); sort(C.begin(), C.end(), [&](int a, int b) { return col_deg[a] > col_deg[b]; }); vector<int> dr(R.begin() + 4, R.end()); vector<int> dc(C.begin() + 4, C.end()); auto get_pat_r = [&](int r) { int p = 0; for (int j = 0; j < 4; j++) { if (M[r][C[j]] == '1') p |= (1 << (3 - j)); } return p; }; auto get_pat_c = [&](int c) { int p = 0; for (int i = 0; i < 4; i++) { if (M[R[i]][c] == '1') p |= (1 << (3 - i)); } return p; }; sort(dr.begin(), dr.end(), [&](int a, int b) { return get_pat_r(a) > get_pat_r(b); }); sort(dc.begin(), dc.end(), [&](int a, int b) { return get_pat_c(a) > get_pat_c(b); }); ull val = 0; ull mul = 1; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (M[dr[i]][dc[j]] == '1') { val += mul; } mul *= 2; } } cout << val + 1 << "\n"; cout.flush(); } } return 0; } |
English