Submission #961306

# Submission time Handle Problem Language Result Execution time Memory
961306 2024-04-11T19:51:07 Z mgch Genetics (BOI18_genetics) C++14
0 / 100
2000 ms 8808 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 4107, L = 26, K = 66, MOD = 1000000007;

char s[N][N];

int main() {
  //  freopen("input.txt", "r", stdin);
  //    ios::sync_with_stdio(false); cin.tie(0);
  int n, m, k;
  scanf("%d%d%d\n", &n, &m, &k);
  vector <int> ord(n), rnk(n, 0);
  iota(ord.begin(), ord.end(), 0);
  for (int i = 0; i < n; ++i) {
    scanf("%s\n", s[i]);
  }
  auto diff = [&](int x, int y) {
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      ans += s[x][i] != s[y][i];
    }
    return ans;
  };
  for (int it = 0; it < 3; ++it) {
    for (int i = 0; i + 1 < (int)ord.size(); ++i) {
      if (diff(ord[i], ord[i + 1]) != k) {
        ++i;
        continue;
      }
      rnk[ord[i]] = 1;
      rnk[ord[i + 1]] = 1;
    }
    sort(ord.begin(), ord.end(), [&](int x, int y) { return rnk[x] > rnk[y]; });
    while (ord.size() > 1 && rnk[ord.back()] == 0) ord.pop_back();
    for (auto it : ord) rnk[it] = 0;
    random_shuffle(ord.begin(), ord.end());
  }
  for (int j = 0; j < (int)ord.size(); ++j) {
    int x = ord[j];
    bool ok = true;
    for (int i = 0; i < n && ok; ++i) {
      if (i == x) continue;
      if (diff(x, i) != k) ok = false;
    }
    if (ok) { cout << x + 1 << '\n'; break; }
  }
  return 0;
}

Compilation message

genetics.cpp: In function 'int main()':
genetics.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d%d%d\n", &n, &m, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%s\n", s[i]);
      |     ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1639 ms 6760 KB Output is correct
2 Correct 1649 ms 8808 KB Output is correct
3 Execution timed out 2007 ms 8796 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1639 ms 6760 KB Output is correct
2 Correct 1649 ms 8808 KB Output is correct
3 Execution timed out 2007 ms 8796 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -