QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#154630 | #5499. Aliases | berarchegas# | WA | 25ms | 17716kb | C++17 | 1.6kb | 2023-08-31 19:49:51 | 2023-08-31 19:49:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
const ll INF = 2e18;
const int maxn = 200010;
int n;
int lg[maxn];
string p[maxn], q[maxn];
int getMinC(int a, int b)
{
int minC = 0;
unordered_map<string,int> freq;
for(int i = 1 ; i <= n ; i++)
{
int sizeFirst = min( a , (int)p[i].size() );
int sizeLast = min( b , (int)q[i].size() );
string alias = p[i].substr( 0 , sizeFirst ) + q[i].substr( 0 , sizeLast );
freq[alias]++;
if( ++freq[alias] > 1 )
minC = max( minC , lg[ freq[alias] ] );
}
return minC;
}
void solve()
{
cin >> n;
for(int i = 1 ; i <= n ; i++)
cin >> p[i] >> q[i];
if( n == 1 )
{
cout << "0 0 1" << endl;
return;
}
int optA = 0, optB = 0, optC = lg[n];
for(int a = 0 ; a < optA + optB + optC ; a++)
{
for(int b = 0 ; a + b < optA + optB + optC ; b++)
{
int c = getMinC( a , b );
int curSum = a + b + c;
if( curSum < optA + optB + optC )
optA = a, optB = b, optC = c;
}
}
cout << optA << " " << optB << " " << optC << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for(int i = 1 ; i < maxn ; i++)
lg[i] = lg[i/10] + 1;
int t;
cin >> t;
while( t-- )
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 16772kb
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
Wrong Answer
time: 25ms
memory: 17716kb
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 0 3 0 0 4 0 0 4 0 0 4
result:
wrong answer Rozwiazanie nieoptymalne! (test case 3)