QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225200 | #5499. Aliases | Gawor270 | TL | 1002ms | 3580kb | C++14 | 2.0kb | 2023-10-24 05:13:40 | 2023-10-24 05:13:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << "[" << #x << " " << x << "] ";
#define ar array
#define ll long long
#define ld long double
#define sz(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
typedef pair<int,int> pi;
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
vector<string> firstname;
vector<string> lastname;
int qexp10(int x){
int res = 1;
int a = 10;
while(x){
if(x&1)res *= a;
a *= a;
x >>= 1;
}
return res;
}
bool ispos(int a, int b, int c){
map<string,int> count;
int maxim = 0;
for(int i=0; i<firstname.size(); i++){
int l1 = firstname[i].length();
int l2 = lastname[i].length();
string res = firstname[i].substr(0,min(l1,a)) + lastname[i].substr(0,min(l2,b));
count[res]++;
maxim = max(maxim,count[res]);
}
return maxim <= qexp10(c);
}
void solve() {
int n;
cin >> n;
firstname.resize(n), lastname.resize(n);
int maxf =0, maxl = 0;
for(int i=0; i<n; i++){
cin >> firstname[i] >> lastname[i];
maxf = max((int)firstname[i].length(), maxf);
maxl = max((int)lastname[i].length(), maxl);
}
int minim = 1e9;
int a,b,c;
for(int i=0; i<=maxf; i++){
for(int j=0; j<=maxl; j++){
for(int k=0; k<=20000; k++){
if((i || j || k) && ispos(i,j,k)){
if(i + j + k < minim){
minim = i + j + k;
a = i, b= j, c = k;
}
}
}
}
}
cout << a << " " << b << " " << c;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1002ms
memory: 3580kb
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: -100
Time Limit Exceeded
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...