QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139538 | #5499. Aliases | ammardab3an# | WA | 196ms | 6336kb | C++17 | 1.3kb | 2023-08-13 20:19:22 | 2023-08-13 20:19:23 |
Judging History
answer
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;
int solve() {
int n; cin >> n;
vector<pair<string, string>>v(n);
int mx = 0, mx1 = 0;
for (auto& x : v)cin >> x.first >> x.second, mx = max(mx, (int)x.first.size()), mx1 = max(mx1, (int)x.second.size());
int nn = n;
int cnt = 0;
while (nn) {
nn /= 10;
cnt++;
}
unordered_map<string, ll>mp;
ll res1 = 0, res2 = 0, res3 = cnt, res = cnt;
for (int a = 0; a <= min(cnt, mx); a++) {
for (int b = 0; b <= min(cnt, mx1); b++) {
string ss = "";
mp.clear();
int mx = 0;
for (auto& x : v) {
ss = x.first.substr(0, min(a, (int)x.first.size())) + x.second.substr(0, min(b, (int)x.second.size()));
mp[ss]++;
mx = max(mx, (int)mp[ss]);
}
int sum = a + b;
while (mx) {
mx /= 10;
sum++;
}
if (sum <= res) {
res1 = a, res2 = b, res3 = sum - a - b;
res = sum;
}
}
}
cout << res1 << " " << res2 << " " << res3 << '\n';
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
int i = 1;
while (t--) {
//cout << "case " << i << ": ";
solve();
}
return 0;
}
/*
204
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3468kb
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:
1 0 1
result:
ok correct! (1 test case)
Test #2:
score: 0
Accepted
time: 17ms
memory: 5212kb
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 2 2 1 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: 196ms
memory: 6336kb
input:
6 5000 dpbcebnavonpwlkermqftinonhckqynyxfwsybsalgmpqmedykqeunbolxhtcnrvbiqrjgziptkqgbsxrprapfzjxefiioecsacujyuhvsapywqohliffaqsbupnocesbgqutaanduiztwwqulwvrx dyearafwtdkifljtvcryeyfzgqghjwhuycusqkxngmanxxjhyqaethbfoqaigbbjuutwzzazsgcguaasrrrzsapcuhvzzjllatjqtxzrotdpcrrdogfwoonxjwisdwhqntlhqpflxvcido...
output:
3 0 1 0 1 3 1 1 2 2 0 2 1 2 1 4 0 1
result:
wrong answer Rozwiazanie nieoptymalne! (test case 6)