Submission #106214

# Submission time Handle Problem Language Result Execution time Memory
106214 2019-04-17T12:43:31 Z Noam527 Genetics (BOI18_genetics) C++17
0 / 100
2000 ms 9720 KB
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 1;
const int OOO = 1;
using namespace std;

int n, m, k;
bool check[4101][4101] = {};

struct seq {
	string s;
	int i;
	seq() {}
	seq(const string &t, int ii) {
		s = t;
		i = ii;
	}
};

bool good(const seq &a, const seq &b) {
	if (check[a.i][b.i] || check[b.i][a.i]) return true;
	check[a.i][b.i] = check[b.i][a.i] = 1;
	int cnt = 0;
	for (int i = 0; i < m; i++) {
		if (a.s[i] != b.s[i]) cnt++;
		if (cnt > k || cnt + m - i - 1 < k) return false;
	}
	return true;
}

vector<seq> s;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	s.resize(n);
	for (int i = 0; i < n; i++)
		cin >> s[i].s, s[i].i = i + 1;
	srand(12342345);
	random_shuffle(s.begin(), s.end());
	int nxt = n - 1;
	while (1) {
		int i = 1;
		while (i < n && good(s[0], s[i])) i++;
		if (i == n) finish(s[0].i);
		if (nxt < i) swap(s[0], s[nxt--]);
		else {
			swap(s[0], s[nxt--]);
			swap(s[i], s[nxt--]);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
2 Incorrect 5 ms 760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2064 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2064 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
2 Incorrect 5 ms 760 KB Output isn't correct
3 Halted 0 ms 0 KB -