QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#504470 | #5499. Aliases | ucup-team1525# | AC ✓ | 26394ms | 42840kb | C++20 | 1.8kb | 2024-08-04 13:21:20 | 2024-08-04 13:21:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int n;
string a[N], b[N];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
int ans = 10, ans_x, ans_y, ans_z;
for (int x = 0; x <= 6; x++)
for (int y = 0; x + y <= 6; y++) {
for (int z = 0; x + y + z <= 6; z++) {
if (x + y + z == 0)
continue;
set<string> s;
map<string, int> ss;
bool flag = true;
for (int k = 1; k <= n; k++) {
string now;
now += a[k].substr(0, min(x, (int)a[k].size()));
now += b[k].substr(0, min(y, (int)b[k].size()));
if (now.empty()) now = "!";
if (z > 0) {
int cnt = ss[now];
if (to_string(cnt).size() > z){
flag = false;
break;
}
ss[now]++;
now += to_string(cnt);
}
if (s.find(now) == s.end())
s.insert(now);
else {
flag = false;
break;
}
}
if (flag) {
if (x + y + z < ans) {
ans = x + y + z;
ans_x = x, ans_y = y, ans_z = z;
}
}
}
}
cout << ans_x << " " << ans_y << " " << ans_z << "\n";
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int z;
cin >> z;
while (z--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 16008kb
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: 363ms
memory: 18360kb
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: 0
Accepted
time: 1904ms
memory: 20620kb
input:
6 5000 dpbcebnavonpwlkermqftinonhckqynyxfwsybsalgmpqmedykqeunbolxhtcnrvbiqrjgziptkqgbsxrprapfzjxefiioecsacujyuhvsapywqohliffaqsbupnocesbgqutaanduiztwwqulwvrx dyearafwtdkifljtvcryeyfzgqghjwhuycusqkxngmanxxjhyqaethbfoqaigbbjuutwzzazsgcguaasrrrzsapcuhvzzjllatjqtxzrotdpcrrdogfwoonxjwisdwhqntlhqpflxvcido...
output:
0 0 4 0 1 3 1 1 2 2 0 2 1 2 1 3 0 1
result:
ok correct! (6 test cases)
Test #4:
score: 0
Accepted
time: 26394ms
memory: 33832kb
input:
6 113503 hxihfx mrqehftb oqmcc bwrbqomg dokyjc kuaiu hhfubp aleme xcnbe shxaqrf kzmqym geclklta jnxjq nppjx xeloxixa owsxnnj pzlvbyuk leioq xipez hoxgsml esujubw cwwzpei fekvoee vbxlts xjhcrkx qicmbmen rskvnrcx mpzpvvye lkkmkstn wlptoh wqgvr qbryq cqxydbr fzdxdrv wzofngxt keqwwhdl fkomzb sckpev geqe...
output:
4 0 1 2 2 1 1 3 1 3 0 2 1 2 2 1 1 3
result:
ok correct! (6 test cases)
Test #5:
score: 0
Accepted
time: 10634ms
memory: 42840kb
input:
6 1331 hidkxivneczxfctnobbqpxsgneaivgbodiejoqgbdthwsdsfzkxcdtzumcfdoawihskkwkehjdezgazzphrnkgncimntusqjqwimwbsztbzceqnwmnzzezwzazakknfwvdsyglpplwgnhwcgpriuwdmbvvlxaoruuuugamntnuqlvslsgvehhegjqpkcskonosndngfkokjcrqewtzzmypimrsoqqffwwzgzwhgfrrxmtptzfnretnoqjprpgqdhxcrccphsdmouuuidojxcyiknpfrrygjgwgwkb...
output:
1 2 0 3 1 0 4 1 0 2 3 0 0 5 0 0 0 6
result:
ok correct! (6 test cases)