QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700280#5254. DifferenceskjhhjkiTL 0ms0kbC++201.6kb2024-11-02 12:36:552024-11-02 12:36:56

Judging History

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

  • [2024-11-02 12:36:56]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-02 12:36:55]
  • 提交

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);
    std::array<std::vector<std::vector<int>>, 4> pos;
    pos.fill(std::vector(m, std::vector<int>{}));
    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 i = 1; i <= n; ++i) {
        for(int j = 0; j < m; ++j) {
            pos[s[i][j] - 'A'][j].push_back(i);
        }
    }
    for(int p = 0; p < 4; ++p) {
        for(int j = 0; j < m; ++j) {
            int dif = n - pos[p][j].size();
            for(auto i: pos[p][j]) {
                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: