Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cassert>
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <map>
- #include <set>
- #include <string>
- #include <utility>
- #include <vector>
- using namespace std;
- #define pb push_back
- #define st first
- #define nd second
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef pair<int, int> ii;
- typedef vector<ii> vii;
- char c;
- int T, B;
- void solve_lte_10() {
- vector<char> v(B+1);
- for (int i = 1; i <= B; ++i) {
- cout << i << endl;
- cin >> v[i];
- }
- string s = "";
- for (int i = 1; i <= B; ++i) {
- s += v[i];
- }
- cout << s << endl;
- cin >> c;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin >> T >> B;
- for (int t = 1; t <= T; ++t) {
- if (B <= 10) {
- solve_lte_10();
- continue;
- }
- vector<int> v(B+1);
- int idx_eq = -1, idx_dif = -1;
- // First 5 pairs
- int i = 1, j = B;
- for (; i <= 5; ++i, --j) {
- int xi, xj;
- cout << i << endl;
- cin >> xi;
- cout << j << endl;
- cin >> xj;
- v[i] = xi;
- v[j] = xj;
- if (idx_eq == -1 && xi == xj) idx_eq = i;
- if (idx_dif == -1 && xi != xj) idx_dif = j;
- }
- assert(i <= j);
- while (i <= j) {
- // inicio rodada
- int iini = i, jini = j;
- int xeq, xdif;
- if (idx_eq != -1) {
- cout << idx_eq << endl;
- cin >> xeq;
- cout << idx_eq << endl;
- cin >> xeq;
- }
- if (idx_dif != -1) {
- cout << idx_dif << endl;
- cin >> xdif;
- cout << idx_dif << endl;
- cin >> xdif;
- }
- if (idx_dif == -1 || idx_eq == -1) { // tudo igual ou tudo diferente
- if ((idx_eq != -1 && xeq == v[idx_eq]) || (idx_dif != -1 && xdif == v[idx_dif])) { // continuou igual
- // faz nada
- } else {
- // not de todos os anteriores
- for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
- v[aux_i] = 1-v[aux_i];
- v[aux_j] = 1-v[aux_j];
- }
- }
- } else { // tem ambos iguais e diferentes
- if (xeq == v[idx_eq] && xdif == v[idx_dif]) { // continuou igual
- // faz nada
- } else if (xeq != v[idx_eq] && xdif != v[idx_dif]) { // ambos mudaram
- // not de todos os anteriores
- for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
- v[aux_i] = 1-v[aux_i];
- v[aux_j] = 1-v[aux_j];
- }
- } else if (xeq == v[idx_eq] && xdif != v[idx_dif]) { // par igual continuou e par diferente mudou
- for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
- swap(v[aux_i], v[aux_j]);
- }
- } else { // par igual mudou e par diferente continuou
- for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
- v[aux_i] = 1-v[aux_i];
- v[aux_j] = 1-v[aux_j];
- swap(v[aux_i], v[aux_j]);
- }
- }
- }
- for (int k = 0; i <= j && k < 4; ++k, ++i, --j) {
- int xi, xj;
- cout << i << endl;
- cin >> xi;
- cout << j << endl;
- cin >> xj;
- v[i] = xi;
- v[j] = xj;
- if (idx_eq == -1 && xi == xj) idx_eq = i;
- if (idx_dif == -1 && xi != xj) idx_dif = j;
- }
- // final rodada
- }
- string s = "";
- for (int i = 1; i <= B; ++i)
- s += ((char)(v[i])+'0');
- cout << s << endl;
- cin >> c;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement