QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322755#4828. Four Plus FourSkyan0 0ms0kbC++232.6kb2024-02-07 17:00:582024-02-07 17:00:59

Judging History

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

  • [2024-02-07 17:00:59]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-02-07 17:00:58]
  • 提交

answer

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
string a[10005], b[10005], s[30005], t[4005];
int c[30005][26], d[4005][26], dd[4005][4005], p[4005];
vector<int> g[30005], res[30005];
map<string, int> m;
bool check(int x, int y) {
    for (int i = 0; i < 26; i++) {
        if (c[x][i] < d[x][i]) {
            return false;
        }
    }
    return true;
}
bool cmp(int x, int y) {
    return p[x] > p[y];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string ss;
    cin >> ss;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (ss == "keys") cin >> b[i];
    }
    int x, y;
    cin >> x;
    for (int i = 1; i <= x; i++) {
        cin >> s[i];
        m[s[i]] = i;
        for (char w : s[i]) {
            c[i][w - 'a']++;
        }
    }
    cin >> y;
    for (int i = 1; i <= y; i++) {
        cin >> t[i];
        m[t[i]] = i;
        for (char w : t[i]) {
            d[i][w - 'a']++;
        }
    }
    vector<pair<int, int>> v;
    for (int i = 1; i <= x; i++) {
        for (int j = 1; j <= y; j++) {
            if (check(i, j) == true) {
                g[i].push_back(j);
                g[i].push_back(j);
                g[i].push_back(j);
            }
        }
        if (g[i].size() >= 9) {
            v.push_back({g[i].size(), i});
        }
    }
    sort(v.begin(), v.end());
    for (auto w : v) {
        sort(g[w.second].begin(), g[w.second].end(), cmp);
        for (int x : g[w.second]) {
            int flag = 0;
            for (int xx : res[w.second]) {
                if (dd[xx][x] != 0) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) res[w.second].push_back(x);
            if (res[w.second].size() == 3) {
                break;
            }
        }
        for (int i = 0; i < 3; i++) {
            for (int j = i + 1; j < 3; j++) {
                dd[res[w.second][i]][res[w.second][j]] = w.second;
                dd[res[w.second][j]][res[w.second][i]] = w.second;
                p[res[w.second][i]]--;
                p[res[w.second][j]]--;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (ss == "password") {
            int h = m[a[i]];
            cout << a[i] << " " << h << " " << res[h].size() << '\n';
            for (auto w : res[h]) {
                cout << t[w] << " ";
            }
        }
        else {
            cout << s[dd[m[a[i]]][m[b[i]]]];
        }
        cout << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer on the first run

input:

password
2
password
couthier
28558
aardvark aardwolf aasvogel abacuses abalones abampere abandons abapical abasedly abashing abatable abatises abattoir abbacies abbatial abbesses abdicate abdomens abdomina abducens abducent abducing abducted abductee abductor abelmosk aberrant abetment abettals abet...

output:

password 17584 0

couthier 5555 0


input:


output:


result:

wrong answer password is not in the royal dictionary