QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416756 | #5254. Differences | galen_colin# | TL | 0ms | 0kb | C++17 | 1.6kb | 2024-05-22 06:39:20 | 2024-05-22 06:39:21 |
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define f first
#define s second
ll n, m, k;
bool bad[100005];
using ul = unsigned long long;
vector<ul> bs[100005];
ll sz;
mt19937 rng(53);
bool cmp(ll a, ll b) {
ll ans = 0;
for (ll i = 0; i < sz; i++) ans += __builtin_popcountll(bs[a][i] ^ bs[b][i]);
// cout << a << " " << b << " " << ans << " " << k << endl;
return ans == k;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
k *= 2;
sz = m / 16 + 2;
for (ll i = 0; i < n; i++) {
string s; cin >> s;
bs[i] = vector<ul>(sz);
for (ll j = 0; j < m; j++) {
ul v = 1 << (s[j] - 'A');
bs[i][j / 16] += v << (4 * (j % 16));
}
}
ll s = n;
vl a(n);
iota(a.begin(), a.end(), 0);
while (s > 1) {
// cout << s << " " << a.size() << endl;
ll x = rng() % a.size();
while (bad[a[x]]) x = rng() % a.size();
x = a[x];
ll y = rng() % n;
while (x == y) y = rng() % n;
if (!cmp(x, y)) {
if (!bad[x]) --s;
if (!bad[y]) --s;
bad[x] = bad[y] = 1;
}
if (s * 2 <= a.size()) {
vl b;
for (ll x: a) if (!bad[x]) b.push_back(x);
a = b;
s = a.size();
}
}
cout << a[0] + 1 << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3585 4096 2048 ABBBBBBAABAAAAAAAAAAAAABAABABBBABABAAAAABABAAAABAABAABBABBAABAABABBABAABBABBABABABBAAAABBABAABBBBABBBAABBBBBABAABAAABAAABBBBAAAABAABAABABABABBBBBABAAABAAABBAABABBABAABBAABBAABABBBBAABAAAABAABBABAAABBAAAAAABAABBABBABAABABBBAABABBABABBBAAAAABBBABABABBAABAAAABBBBABABAABBBABABABBAABBBABAB...
output:
1397