QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322758#6549. Two Missing NumbersSkyan0 0ms0kbC++232.6kb2024-02-07 17:05:082024-02-07 17:05:08

Judging History

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

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

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[y][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';
    }
}

详细

Test #1:

score: 0
Stage 1: Program answer Memory Limit Exceeded

First Run Input

1 5
5 1 4 4 5

First Run Output







Second Run Input


Second Run Output


result: