QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700293#5254. DifferenceskjhhjkiTL 0ms0kbC++201.5kb2024-11-02 12:39:382024-11-02 12:39:41

Judging History

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

  • [2024-11-02 12:39:41]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-02 12:39:38]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve()
{
    int n, m, k;
    std::cin >> n >> m >> k;
    std::vector<std::string> s(n + 1);
    std::vector<int> cnt(n + 1);
    for(int i = 1; i <= n; ++i) {
        std::cin >> s[i];
    }
    auto check = [&](int i) {
        for(int j = 1; j <= n; ++j) {
            int t = 0;
            if(i == j) {
                continue;
            }
            for(int l = 0; l < m; ++l) {
                if(s[i][l] != s[j][l]) {
                    ++t;
                }
            }
            if(t != k) {
                return false;
            }
        }
        return true;
    };
    if(1ll * n * n * m <= 2e8) {
        for(int i = 1; i <= n; ++i) {
            if(check(i)) {
                std::cout << i << '\n';
                return;
            }
        }
    }
    for(int j = 0; j < m; ++j) {
        std::array<std::vector<int>, 4> pos;
        for(int i = 1; i <= n; ++i) {
            pos[s[i][j] - 'A'].push_back(i);
        }
        for(int p = 0; p < 4; ++p) {
            int dif = n - pos[p].size();
            for(auto i: pos[p]) {
                cnt[i] += dif;
            }
        }
    }
    for(int i = 1; i <= n; ++i) {
        if(cnt[i] == (n - 1) * k && check(i)) {
            std::cout << i << '\n';
            return;
        }
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    // std::cin >> T;
    while(T --) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3585 4096 2048
ABBBBBBAABAAAAAAAAAAAAABAABABBBABABAAAAABABAAAABAABAABBABBAABAABABBABAABBABBABABABBAAAABBABAABBBBABBBAABBBBBABAABAAABAAABBBBAAAABAABAABABABABBBBBABAAABAAABBAABABBABAABBAABBAABABBBBAABAAAABAABBABAAABBAAAAAABAABBABBABAABABBBAABABBABABBBAAAAABBBABABABBAABAAAABBBBABABAABBBABABABBAABBBABAB...

output:


result: