QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322759#4828. Four Plus FourSkyan0 863ms96220kbC++232.5kb2024-02-07 17:05:272024-02-07 17:05:27

Judging History

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

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

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]];
            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: 100
Accepted
time: 863ms
memory: 96220kb

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:

paws wops saws 
huic thio ruth 

input:

keys
4
paws wops
ruth thio
saws paws
wops saws
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 abet...

output:

password
couthier
password
password

result:

ok OK

Test #2:

score: 100
Accepted
time: 863ms
memory: 96184kb

input:

password
1
quirkier
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 abetters abet...

output:

keir keir keir 

input:

keys
1
keir keir
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 abetters abettin...

output:

quirkier

result:

ok OK

Test #3:

score: 100
Accepted
time: 849ms
memory: 96072kb

input:

password
3
aardvark
aardwolf
aardvark
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 abet...

output:

arak arak arak 
flaw ward woad 
arak arak arak 

input:

keys
18
arak arak
arak arak
woad flaw
arak arak
arak arak
arak arak
ward woad
flaw ward
arak arak
woad ward
arak arak
flaw woad
arak arak
arak arak
arak arak
ward flaw
arak arak
arak arak
28558
aardvark aardwolf aasvogel abacuses abalones abampere abandons abapical abasedly abashing abatable abatise...

output:

aardvark
aardvark
aardwolf
aardvark
aardvark
aardvark
aardwolf
aardwolf
aardvark
aardwolf
aardvark
aardwolf
aardvark
aardvark
aardvark
aardwolf
aardvark
aardvark

result:

ok OK

Test #4:

score: 0
Stage 2: Program answer Runtime Error

input:

password
10000
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
abetters
abetting
abetto...

output:

arak arak arak 
flaw ward woad 
lags slog sola 
bass case sabs 
anoa nobs bola 
mabe beam bema 
bads ados bans 
lipa lipa lipa 
abys byes abye 
agha bash bani 
blat beta baba 
stab bise east 
bott boat bora 
bias baba babe 
blat blat blat 
babe babe babe 
bide bait bate 
boas bone bend 
ambo maid ia...

input:

keys
60000
gale linn
self self
flit clef
size zigs
deco nice
grog info
tusk kues
dink skit
drab bier
toke fork
ogam amie
mode node
oafs sola
flab fell
bike bisk
duad aunt
clad coal
orcs onus
hist sade
spat pyas
echo echo
lear call
next ired
logs grog
coif fado
free feel
diss dire
fork fork
vain vita...

output:


result: