Submission #898982

# Submission time Handle Problem Language Result Execution time Memory
898982 2024-01-05T10:30:31 Z vjudge1 "The Lyuboyn" code (IZhO19_lyuboyn) C++17
3 / 100
620 ms 1524 KB
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

const int Z = 100;

mt19937 rng(time(nullptr));

int n, k, t, s;
string ss;

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> k >> t >> ss;
  if (k%2 == 0) {
    cout << "-1\n";
    return 0;
  }
  
  s = 0;
  while (ss.size() < n) ss = "0"+ss;
  for (int i = 0; i < n; i++) {
    s += (1 << (n-i-1)) * (ss[i] == '1');
  }

  for (int zz = 0; zz < Z; zz++) {
    vector<int> ans(1 << n);
    for (int i = 0; i < (1 << n); i++) {
      ans[i] = i;
      if (i == s) swap(ans[0], ans[i]);
    }

    
    bool ok = 0;
    shuffle(ans.begin()+1, ans.end(), rng);
    for (int z = 0; z < Z; z++) {
      int x = -1;
      for (int i = 0; i+1 < (1 << n); i++) {
        if (__builtin_popcount(ans[i] ^ ans[i+1]) != k) {
          x = i;
          break;
        }
      }

      if (x == -1) {
        ok = 1;
        break;
      }

      int y = -1;
      for (int i = x+2; i+1 < (1 << n); i++) {
        if (__builtin_popcount(ans[i] ^ ans[i+1]) != k && 
        __builtin_popcount(ans[x] ^ ans[i]) == k && 
        __builtin_popcount(ans[x+1] ^ ans[i+1]) == k) {
          y = i;
          break;
        }
      }

      if (y == -1) break;

      reverse(ans.begin()+x+1, ans.begin()+y+1);
    }
    
    if (!ok) continue;
    else {
      cout << (1 << n) << "\n";
      for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
          if ((ans[i] >> (n-j-1)) & 1) ss[j] = '1';
          else ss[j] = '0';
        }
        cout << ss << "\n";
      }
    }
    return 0;
  }
  cout << "-1\n";
}

Compilation message

lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:23:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |   while (ss.size() < n) ss = "0"+ss;
      |          ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Not a cycle!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 1 ms 344 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Incorrect 620 ms 1524 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 508 ms 1456 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 620 ms 1524 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 312 ms 856 KB Output -1 while solution exists
2 Halted 0 ms 0 KB -