#include <bits/stdc++.h>
using namespace std;
bool alg;
const int SIZE = 10;
int column_order[SIZE];
int row_order[SIZE];
int row_ones[SIZE];
string rows[SIZE];
int actual[SIZE][SIZE];
void decode() {
string row;
for (int i = 0; i < SIZE; i++) {
cin >> row;
rows[i] = row;
row_ones[i] = count(row.begin(), row.end(), '1');
}
for (int i = 0; i < SIZE; i++) {
row_order[i] = -1;
column_order[i] = -1;
}
for (int r = 0; r < SIZE; r++) {
int next_row;
for (int i = 0; i < SIZE; i++) {
if (row_order[i] == -1 && row_ones[i] == 1) {
next_row = i;
}
}
//cout << next_row << endl;
row_order[next_row] = r;
int next_column;
for (int i = 0; i < SIZE; i++) {
//cout << "Considering column " << i << "\n";
//cout << "Order: " << column_order[i] << "\n";
//cout << "Value of next row: " << rows[next_row][i] << "\n";
if (column_order[i] == -1 && rows[next_row][i] == '1') {
next_column = i;
}
}
//cout << next_column << endl;
column_order[next_column] = r;
for (int i = 0; i < SIZE; i++) {
if (rows[i][next_column] == '1') {
row_ones[i]--;
}
}
}
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
for (int r = 0; r < SIZE; r++) {
for (int q = 0; q < SIZE; q++) {
if (row_order[r] == i && column_order[q] == j) {
//cout << rows[r][q];
if (rows[r][q] == '0') {
actual[i][j] = 0;
}
else {
actual[i][j] = 1;
}
}
}
}
}
//cout << "\n";
}
long long res = 0;
for (int y = 2; y < SIZE; y++) {
for (int x = 0; x + 2 <= y; x++) {
res *= 2;
res += actual[y][x];
}
}
cout << res << "\n";
cout.flush();
// Find min row
// Gives us max column
// Decrease ones in other rows
// Repeat
}
char to_send[SIZE][SIZE];
void encode() {
long long v;
cin >> v;
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
to_send[i][j] = 0;
}
}
for (int y = SIZE - 1; y >= 2; y--) {
for (int x = y - 2; x >= 0; x--) {
to_send[y][x] = v % 2;
v /= 2;
}
}
for (int y = 0; y < SIZE; y++) {
for (int x = y; x >= 0 && x >= y - 1; x--) {
to_send[y][x] = 1;
}
}
for (int y = 0; y < SIZE; y++) {
for (int x = 0; x < SIZE; x++) {
cout << (char)('0' + to_send[SIZE - y - 1][SIZE - x - 1]);
}
cout << "\n";
}
cout.flush();
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string name;
cin >> name;
int t;
long long n;
cin >> n >> t;
alg = name[0] == 'A';
for (int i = 0; i < t; i++) {
if (alg) {
encode();
}
else {
decode();
}
}
}
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #include <bits/stdc++.h> using namespace std; bool alg; const int SIZE = 10; int column_order[SIZE]; int row_order[SIZE]; int row_ones[SIZE]; string rows[SIZE]; int actual[SIZE][SIZE]; void decode() { string row; for (int i = 0; i < SIZE; i++) { cin >> row; rows[i] = row; row_ones[i] = count(row.begin(), row.end(), '1'); } for (int i = 0; i < SIZE; i++) { row_order[i] = -1; column_order[i] = -1; } for (int r = 0; r < SIZE; r++) { int next_row; for (int i = 0; i < SIZE; i++) { if (row_order[i] == -1 && row_ones[i] == 1) { next_row = i; } } //cout << next_row << endl; row_order[next_row] = r; int next_column; for (int i = 0; i < SIZE; i++) { //cout << "Considering column " << i << "\n"; //cout << "Order: " << column_order[i] << "\n"; //cout << "Value of next row: " << rows[next_row][i] << "\n"; if (column_order[i] == -1 && rows[next_row][i] == '1') { next_column = i; } } //cout << next_column << endl; column_order[next_column] = r; for (int i = 0; i < SIZE; i++) { if (rows[i][next_column] == '1') { row_ones[i]--; } } } for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { for (int r = 0; r < SIZE; r++) { for (int q = 0; q < SIZE; q++) { if (row_order[r] == i && column_order[q] == j) { //cout << rows[r][q]; if (rows[r][q] == '0') { actual[i][j] = 0; } else { actual[i][j] = 1; } } } } } //cout << "\n"; } long long res = 0; for (int y = 2; y < SIZE; y++) { for (int x = 0; x + 2 <= y; x++) { res *= 2; res += actual[y][x]; } } cout << res << "\n"; cout.flush(); // Find min row // Gives us max column // Decrease ones in other rows // Repeat } char to_send[SIZE][SIZE]; void encode() { long long v; cin >> v; for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { to_send[i][j] = 0; } } for (int y = SIZE - 1; y >= 2; y--) { for (int x = y - 2; x >= 0; x--) { to_send[y][x] = v % 2; v /= 2; } } for (int y = 0; y < SIZE; y++) { for (int x = y; x >= 0 && x >= y - 1; x--) { to_send[y][x] = 1; } } for (int y = 0; y < SIZE; y++) { for (int x = 0; x < SIZE; x++) { cout << (char)('0' + to_send[SIZE - y - 1][SIZE - x - 1]); } cout << "\n"; } cout.flush(); } int main() { std::ios_base::sync_with_stdio(false); cin.tie(nullptr); string name; cin >> name; int t; long long n; cin >> n >> t; alg = name[0] == 'A'; for (int i = 0; i < t; i++) { if (alg) { encode(); } else { decode(); } } } |
English