QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416764#5254. Differencesgalen_colin#TL 1990ms16552kbC++172.2kb2024-05-22 06:50:482024-05-22 06:50:49

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 06:50:49]
  • 评测
  • 测评结果:TL
  • 用时:1990ms
  • 内存:16552kb
  • [2024-05-22 06:50:48]
  • 提交

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);

    vector<pl> lv;

    const ll K = 50;

    while (s > 1) {
        // cout << s << " " << a.size() << endl;
        ll x = -1, y = -1;
        if (!lv.size()) {
            x = rng() % a.size();
            while (bad[a[x]]) x = rng() % a.size();
            x = a[x];
            y = rng() % n;
            while (x == y) y = rng() % n;
        } else {
            y = lv.back().f;
            x = rng() % a.size();
            while (bad[a[x]] || a[x] == y) x = rng() % a.size();
            x = a[x];
        }

        if (!cmp(x, y)) {
            if (!bad[x]) {
                lv.push_back({x, K});
                --s;
            }
            if (!bad[y]) {
                --s;
                lv.push_back({y, K});
            }
            if (lv.size() && y == lv.back().f) lv.back().s = K;
            bad[x] = bad[y] = 1;
        } else {
            if (lv.size() && y == lv.back().f) {
                if (--lv.back().s == 0) lv.pop_back();
            }
        }

        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';
}

詳細信息

Test #1:

score: 100
Accepted
time: 1924ms
memory: 15260kb

input:

3585 4096 2048
ABBBBBBAABAAAAAAAAAAAAABAABABBBABABAAAAABABAAAABAABAABBABBAABAABABBABAABBABBABABABBAAAABBABAABBBBABBBAABBBBBABAABAAABAAABBBBAAAABAABAABABABABBBBBABAAABAAABBAABABBABAABBAABBAABABBBBAABAAAABAABBABAAABBAAAAAABAABBABBABAABABBBAABABBABABBBAAAAABBBABABABBAABAAAABBBBABABAABBBABABABBAABBBABAB...

output:

1397

result:

ok single line: '1397'

Test #2:

score: 0
Accepted
time: 1984ms
memory: 16536kb

input:

4099 4100 2
ABABBAAABBBABBBAABAAAAABABBBBBAAAAABBABBBBABBAAABBAABAAAAAAAAABBABAABAABBAAABAAAABBAABBBBABAAABAABABBAAABBBBBABABBBBBABBABBAABBBABAAABBABBBBAAAABAABBAABAABABABAAABAAAAABAABABBBAAAABBBBBBBABBBAABABBABABBBABAAAAABBBBABAAABABBBAABBAABBBABBABBBABBAABABBABBBBABBBABAABBBAAABAABAABBABAAABABABAB...

output:

2964

result:

ok single line: '2964'

Test #3:

score: 0
Accepted
time: 68ms
memory: 16552kb

input:

4002 4096 2048
ABBBAAABAABBBABBBBABBBBBBBAABBABBBAABABBABBABBABBAABABBBBBAAAAABBBBBBAAAAAABAAAABBBABABAABBBABABAAAABBAABAABABBBABBBBABAAAABBBBBBABBBAAABABBABABAABBABAAABABBABABABAAAAAABABAABABAABBAAAABAAAAABBABAABBAAAAAAABBAAAAABABBABABAAAAABBABBBBBABABAABABBBAABBAAABBBBAAAAABBBBBBBABBBAABBAABBAABBB...

output:

3926

result:

ok single line: '3926'

Test #4:

score: 0
Accepted
time: 1990ms
memory: 16172kb

input:

3892 4096 3072
CCBACBACABCBBCDBDBBDDABDADCDCCAABAAADADDCBABABACAACCADDDAAACBCDACCBDBCCCACACBBBCADBBDBABDACAABADBBBADADADBAADBCCDBDAADCCBDCBDBAACAABDABDAADBBCDDCADDBBDBDBDDBBDACCCCACBACCBADDCCDCDCCACBCDDCDCCCADCDDAADBBDABAADBDDDACBDBDDDBACDAABBBDDABACAACDAADBBBCDCCCAAAADDCBDBBCBDDADCAACCAABBCCBDBABCB...

output:

2870

result:

ok single line: '2870'

Test #5:

score: -100
Time Limit Exceeded

input:

4099 4100 2
CCCDDBDBBCADADBBACDCDDBACCDABADCDDDDBCDDABABDBCCCBCCCDDDCBAABADABDBCABDBDDDCBBCABCCBBDCDBCDCBCCCBABCCBABCDBBAABADCAACBBDDABBBDDBCBDDCCDCADDDBCBBDABCBDBCCCACCADBBDDDCBDCDACCCBCBBDADAAACDADCDDCAACADDCDBDDBBBBCDAADDAADDDDADDCCDCBDDBAACABDADCACAABCCAAACACBCDCBBAABCAACCCDABBDBCDABBDBCCCADBCAA...

output:

2128

result: