QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105305 | #5499. Aliases | pdstiago# | AC ✓ | 16369ms | 38460kb | C++14 | 1.7kb | 2023-05-13 21:38:00 | 2023-05-13 21:38:02 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define mxn 1e5+5
#define fastio ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define endl '\n'
#define INF 0x3f3f3f3f
typedef long long ll;
int solve(){
int n;
cin >> n;
vector<pair<string, string> > v(n+1);
for(int i=1; i<=n; i++){
cin >> v[i].first >> v[i].second;
}
if(n==1){
cout << "1 0 0" << endl;
return 0;
}
int newn = n;
newn--;
int m=0;
if(newn>0){
string num = to_string(newn);
m = (int)num.size();
}
int resp=m;
int ar = 0, br = 0, cr = 0;
for(int a=0; a<=m; a++){
for(int b=0; b<=m; b++){
map<string, int> mapa;
for(int i=1; i<=n; i++){
string as = v[i].first.substr(0, min(a, (int)v[i].first.size()));
string bs = v[i].second.substr(0, min(b, (int)v[i].second.size()));
mapa[as+bs]++;
}
int maior=0;
for(auto it=mapa.begin(); it!=mapa.end(); it++){
pair<string, int> agr = *it;
maior=max(maior, agr.second);
}
int best=0;
maior--;
if(maior>0){
string agr = to_string(maior);
best = (int)agr.size();
}
if(a+b+best<=resp){
resp=a+b+best;
ar=a, br=b, cr=best;
}
}
}
cout << ar << " " << br << " " << cr << endl;
return 0;
}
int main(){
fastio;
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3372kb
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 1 0
result:
ok correct! (1 test case)
Test #2:
score: 0
Accepted
time: 113ms
memory: 5180kb
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:
1 0 0 2 2 1 0 1 1 1 0 2 1 1 1 2 0 1
result:
ok correct! (6 test cases)
Test #3:
score: 0
Accepted
time: 569ms
memory: 6288kb
input:
6 5000 dpbcebnavonpwlkermqftinonhckqynyxfwsybsalgmpqmedykqeunbolxhtcnrvbiqrjgziptkqgbsxrprapfzjxefiioecsacujyuhvsapywqohliffaqsbupnocesbgqutaanduiztwwqulwvrx dyearafwtdkifljtvcryeyfzgqghjwhuycusqkxngmanxxjhyqaethbfoqaigbbjuutwzzazsgcguaasrrrzsapcuhvzzjllatjqtxzrotdpcrrdogfwoonxjwisdwhqntlhqpflxvcido...
output:
3 0 1 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: 16369ms
memory: 19336kb
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: 13366ms
memory: 38460kb
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)