QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76921 | #5499. Aliases | CrazyMurky# | WA | 440ms | 6136kb | C++20 | 1.3kb | 2023-02-12 17:50:34 | 2023-02-12 17:50:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct User {
string name, surname;
};
void solve() {
int n; cin >> n;
vector<User> users(n);
for(auto& x: users) {
cin >> x.name >> x.surname;
}
if (n == 1) {
cout << "0 0 1\n";
return;
}
auto check = [&](size_t a, size_t b) -> array<size_t, 3> {
map<string, int> cnt;
for (const auto& [name, surname] : users) {
cnt[name.substr(0, min(a, name.size())) + surname.substr(0, min(b, surname.size()))]++;
}
int max_cnt = 0;
for (const auto& [_, c] : cnt) {
max_cnt = max(max_cnt, c);
}
return {a, b, max_cnt > 1 ? to_string(max_cnt).size() : 0};
};
array<size_t, 3> ans{};
size_t best = 1000;
for (size_t a = 0; a <= 6; ++a) {
for (size_t b = 0; a + b <= 6; ++b) {
auto cur_ans = check(a, b);
auto cur_size = cur_ans[0] + cur_ans[1] + cur_ans[2];
if (cur_size < best) {
ans = cur_ans;
best = cur_size;
}
}
}
for (int i = 0; i < 3; ++i) cout << ans[i] << " \n"[i == 2];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3308kb
input:
1 11 sven eriksson erik svensson sven svensson erik eriksson bjorn eriksson bjorn svensson bjorn bjornsson erik bjornsson sven bjornsson thor odinsson odin thorsson
output:
0 0 2
result:
ok correct! (1 test case)
Test #2:
score: 0
Accepted
time: 78ms
memory: 5080kb
input:
6 1 g u 14643 gj ek hc bi hi ke ab ij hk cj ha bi ag fe eb ej hd ei bf gj ke dd ib jd id jb gd ei cj bi bi hg ic dh ke gk af eg fg dd fe fa be ge hf kj ih ci gg jf ed dd eh gi cc kd ka fd af gb ka fe ja ed bc hi eg cf gg ff kf gf ii ch hh ec ei ec cd gc bh hb dd id ce bk ib ic bf kk gh cd hb he if g...
output:
0 0 1 0 0 5 0 1 1 1 0 2 1 1 1 2 0 1
result:
ok correct! (6 test cases)
Test #3:
score: -100
Wrong Answer
time: 440ms
memory: 6136kb
input:
6 5000 dpbcebnavonpwlkermqftinonhckqynyxfwsybsalgmpqmedykqeunbolxhtcnrvbiqrjgziptkqgbsxrprapfzjxefiioecsacujyuhvsapywqohliffaqsbupnocesbgqutaanduiztwwqulwvrx dyearafwtdkifljtvcryeyfzgqghjwhuycusqkxngmanxxjhyqaethbfoqaigbbjuutwzzazsgcguaasrrrzsapcuhvzzjllatjqtxzrotdpcrrdogfwoonxjwisdwhqntlhqpflxvcido...
output:
0 0 4 0 1 3 1 1 2 2 0 2 1 2 1 0 0 5
result:
wrong answer Rozwiazanie nieoptymalne! (test case 6)