#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
// #define DEBUG
string kto;
long long n, t;
long long nPoK(long long n, long long k) {
long long result = 1;
// cout << "LICZYMY " << n << " PO " << k << endl;
for (long long i = 1; i <= k; i++) {
result *= n - i + 1;
result /= i;
// cout << (n - i + 1) / i << " ";
}
// cout << endl;
return result;
}
vector<long long> combinadicsEncode(long long n) {
vector<long long> result;
long long reminder = n;
for (int i = 6; i >= 1; i--) {
long long N = i;
while (nPoK(N, i) <= reminder) {
//cout << N << " PO " << i << " = " << nPoK(N, i) << " ZA MALE" << endl;
N++;
}
//cout << N-1 << " JEST CACY" << endl;
reminder -= nPoK(N-1, i);
result.push_back(N-1);
}
return result;
}
long long combinadicsDecode(vector<long long> c) {
long long result = 0;
for (int i = 0; i < 6; i++) {
result += nPoK(c[i], 6-i);
}
return result;
}
int main() {
cin >> kto;
cin >> n >> t;
while (t--) {
if (kto == "Algosia") {
cin >> n;
vector<long long> encoded = combinadicsEncode(n);
cout << "0000000111" << endl;
cout << "0001111111" << endl;
cout << "0110011001" << endl;
cout << "0010101010" << endl;
for (int i = 0; i < 6; i++) {
int cnt = 0;
while (encoded[i]) {
cout << encoded[i]%2;
encoded[i] >>= 1;
cnt++;
}
for (int j = cnt; j < 10; j++) {
cout << "0";
}
cout << endl;
cout.flush();
}
} else {
#ifdef DEBUG
cout << "BAJTEK" << endl;
#endif // DEBUG
int T[10][10];
string input;
for (int i = 0; i < 10; i++) {
cin >> input;
for (int j = 0; j < 10; j++) {
T[i][j] = input[j] - '0';
}
}
int best_i, best_j, best_k, best_l;
bool found = false;
int kolumny[10];
int mapaKolumn[15] = {0,-1,1,2,3,4,5,6,-1,-1,-1,-1,7,8,9};
for (int i = 0; i < 10 && !found; i++) {
for (int j = 0; j < 10 && !found; j++) {
if (i == j) continue;
for (int k = 0; k < 10 && !found; k++) {
if (k == i || k == j) continue;
for (int l = 0; l < 10 && !found; l++) {
if (i == l || j == l || k == l) {
continue;
}
set<int> indeksy;
for (int a = 0; a < 10; a++) {
int indeks = T[i][a] * 8 + T[j][a] * 4 + T[k][a] * 2 + T[l][a];
if (indeks >= 15 || mapaKolumn[indeks] == -1 || indeksy.find(indeks) != indeksy.end()) {
break;
}
indeksy.insert(indeks);
kolumny[mapaKolumn[indeks]] = a;
}
found = indeksy.size() == 10;
if (found) {
#ifdef DEBUG
cout << "ZNALEZIONE! " << i << " " << j << " " << k << " " << l << endl;
#endif // DEBUG
best_i = i;
best_j = j;
best_k = k;
best_l = l;
}
}
}
}
}
if (!found) {
#ifdef DEBUG
cout << "DUPA :(" << endl;
#endif // DEBUG
}
vector<long long> wierszeDanych;
for (int x = 0; x < 10; x++) {
if (x == best_i || x == best_j || x == best_k || x == best_l) {
continue;
}
long long dana = 0;
for (int y = 0; y < 10; y++) {
dana += T[x][kolumny[y]] * (1<<y);
}
wierszeDanych.push_back(dana);
}
sort(wierszeDanych.begin(), wierszeDanych.end(), greater<long long>());
cout << combinadicsDecode(wierszeDanych) << endl;
cout.flush();
}
}
}
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 150 151 152 153 154 155 | #include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; // #define DEBUG string kto; long long n, t; long long nPoK(long long n, long long k) { long long result = 1; // cout << "LICZYMY " << n << " PO " << k << endl; for (long long i = 1; i <= k; i++) { result *= n - i + 1; result /= i; // cout << (n - i + 1) / i << " "; } // cout << endl; return result; } vector<long long> combinadicsEncode(long long n) { vector<long long> result; long long reminder = n; for (int i = 6; i >= 1; i--) { long long N = i; while (nPoK(N, i) <= reminder) { //cout << N << " PO " << i << " = " << nPoK(N, i) << " ZA MALE" << endl; N++; } //cout << N-1 << " JEST CACY" << endl; reminder -= nPoK(N-1, i); result.push_back(N-1); } return result; } long long combinadicsDecode(vector<long long> c) { long long result = 0; for (int i = 0; i < 6; i++) { result += nPoK(c[i], 6-i); } return result; } int main() { cin >> kto; cin >> n >> t; while (t--) { if (kto == "Algosia") { cin >> n; vector<long long> encoded = combinadicsEncode(n); cout << "0000000111" << endl; cout << "0001111111" << endl; cout << "0110011001" << endl; cout << "0010101010" << endl; for (int i = 0; i < 6; i++) { int cnt = 0; while (encoded[i]) { cout << encoded[i]%2; encoded[i] >>= 1; cnt++; } for (int j = cnt; j < 10; j++) { cout << "0"; } cout << endl; cout.flush(); } } else { #ifdef DEBUG cout << "BAJTEK" << endl; #endif // DEBUG int T[10][10]; string input; for (int i = 0; i < 10; i++) { cin >> input; for (int j = 0; j < 10; j++) { T[i][j] = input[j] - '0'; } } int best_i, best_j, best_k, best_l; bool found = false; int kolumny[10]; int mapaKolumn[15] = {0,-1,1,2,3,4,5,6,-1,-1,-1,-1,7,8,9}; for (int i = 0; i < 10 && !found; i++) { for (int j = 0; j < 10 && !found; j++) { if (i == j) continue; for (int k = 0; k < 10 && !found; k++) { if (k == i || k == j) continue; for (int l = 0; l < 10 && !found; l++) { if (i == l || j == l || k == l) { continue; } set<int> indeksy; for (int a = 0; a < 10; a++) { int indeks = T[i][a] * 8 + T[j][a] * 4 + T[k][a] * 2 + T[l][a]; if (indeks >= 15 || mapaKolumn[indeks] == -1 || indeksy.find(indeks) != indeksy.end()) { break; } indeksy.insert(indeks); kolumny[mapaKolumn[indeks]] = a; } found = indeksy.size() == 10; if (found) { #ifdef DEBUG cout << "ZNALEZIONE! " << i << " " << j << " " << k << " " << l << endl; #endif // DEBUG best_i = i; best_j = j; best_k = k; best_l = l; } } } } } if (!found) { #ifdef DEBUG cout << "DUPA :(" << endl; #endif // DEBUG } vector<long long> wierszeDanych; for (int x = 0; x < 10; x++) { if (x == best_i || x == best_j || x == best_k || x == best_l) { continue; } long long dana = 0; for (int y = 0; y < 10; y++) { dana += T[x][kolumny[y]] * (1<<y); } wierszeDanych.push_back(dana); } sort(wierszeDanych.begin(), wierszeDanych.end(), greater<long long>()); cout << combinadicsDecode(wierszeDanych) << endl; cout.flush(); } } } |
English