QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718677 | #5499. Aliases | Sakib_Safwan | WA | 2694ms | 52476kb | C++20 | 4.8kb | 2024-11-06 21:08:13 | 2024-11-06 21:08:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
//#define int long long
// Don't Start typing till you complete the idea.
// Check these things for WA and before submitting
// 1. Did you clear all the global arrays
// 2. Did you checked your <= >= < >
// 3. Did you take the input properly. Did you use break or return while taking input?
// 4. Did you divide by 0.
// 5. Check array , vector , etc size
// 6. in the while loop did you miss something that would cause infinite loop?
// 7. Did you save your dp?
// 8. Are you trying to use something after deleting it?
// 9. Did you read the problem statement wrong?
// 10. Did you check the constrains of the problem properly
// 11. Did you checked for smaller cases like 1 , 0 , etc
// 12. Is it something to with overflow?
// 13. Did you initialized all the variables properly?
// 14. Did you use the formulas correctly?
// STRESS TESTING !!!!!! STRESS TESTING !!!!!
// STRESS Testing Not working?
// Stress test for multiple cases?
// Stress test for big inputs?
// Stress test for really small inputs?
// Even then if it doesn't work -> Did you wrote the wrong Brute force code
// Check these things if you are not generating ideas
// 1. Did you try thinking it in reverse?
// 2. Read the problem statement again
// 3. Check the constraints again
// 4. Try smaller cases in notebook and try to expand
// 5. Think about invariants
// 6. Think simpler ideas maybe?
// 7. Think brute force and try to get something out of it.
// 8. Maybe take a deep breath and take a break for few minutes and drink some water? :3
int primes[] = {285897553, 745494041, 693888673, 950758511, 282174533, 847345579, 722520917, 354688703, 963459817, 139793893};
const int MOD1 = 127657753, MOD2 = 987654319;
const int p1 = 137, p2 = 277;
const int N = 2e5 + 9;
pair<int,int> fst[6][N] , lst[6][N];
void GG()
{
int n;
cin >> n;
int mxd = 0;
int temp = 1;
for(int j = 0; ; j++){
if(n <= temp){
mxd = j;
break;
}
temp *= 10;
}
mxd = max(mxd , 1);
vector<pair<string , string>> vs(n);
for(auto &s : vs) cin >> s.first >> s.second;
for(int i = 0; i < n; i++){
fst[0][i] = {0 , 0};
for(int j = 1; j < min(mxd , (int)vs[i].first.size()); j++){
fst[j][i].first = 1LL * fst[j - 1][i].first * p1 % MOD1;
fst[j][i].first = (fst[j][i].first + vs[i].first[j - 1]) % MOD1;
fst[j][i].second = 1LL * fst[j - 1][i].second * p2 % MOD2;
fst[j][i].second = (fst[j][i].second + vs[i].first[j - 1]) % MOD2;
// cout << i << ' ' << j << ' ' << fst[j][i].first << ' ' << fst[j][i].second << endl;
}
for(int j = vs[i].first.size(); j < mxd; j++) fst[j][i] = fst[j - 1][i];
}
for(int i = 0; i < n; i++){
lst[0][i] = {0 , 0};
for(int j = 1; j < min(mxd , (int)vs[i].second.size()); j++){
lst[j][i].first = 1LL * lst[j - 1][i].first * p1 % MOD1;
lst[j][i].first = (lst[j][i].first + vs[i].second[j - 1]) % MOD1;
lst[j][i].second = 1LL * lst[j - 1][i].second * p2 % MOD2;
lst[j][i].second = (lst[j][i].second + vs[i].second[j - 1]) % MOD2;
// cout << i << ' ' << j << ' ' << lst[j][i].first << ' ' << lst[j][i].second << endl;
}
for(int j = vs[i].second.size(); j < mxd; j++) lst[j][i] = lst[j - 1][i];
}
ll ans = mxd;
int hudai[3] = {0 , 0 , mxd};
for(int i = 0; i < mxd; i++){
for(int j = 0; i + j < mxd; j++){
if(i == 0 && j == 0) continue;
map<array<int , 4> , int> woo;
int mxcnt = 0;
for(int k = 0; k < n; k++){
mxcnt = max(mxcnt , ++woo[{fst[i][k].first , fst[i][k].second , lst[j][k].first , lst[j][k].second}]);
}
// cout << i << ' ' << j << ' ' << mxcnt << endl;
int tempo = mxcnt;
mxcnt = 0;
temp = 1;
for(int j = 0; ; j++){
if(tempo <= temp){
mxcnt = j;
break;
}
temp *= 10;
}
if(mxcnt + i + j < ans){
ans = mxcnt + i + j;
hudai[0] = i;
hudai[1] = j;
hudai[2] = mxcnt;
}
}
}
cout << hudai[0] << ' ' << hudai[1] << ' ' << hudai[2] << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int ttc=1;
cin>>ttc;
//int cnt=0;
while(ttc--)
{
//cout<<"Case "<<++cnt<<": ";
GG();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9672kb
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: 10ms
memory: 20540kb
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: 116ms
memory: 20684kb
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: 2694ms
memory: 35320kb
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: -100
Wrong Answer
time: 1379ms
memory: 52476kb
input:
6 1331 hidkxivneczxfctnobbqpxsgneaivgbodiejoqgbdthwsdsfzkxcdtzumcfdoawihskkwkehjdezgazzphrnkgncimntusqjqwimwbsztbzceqnwmnzzezwzazakknfwvdsyglpplwgnhwcgpriuwdmbvvlxaoruuuugamntnuqlvslsgvehhegjqpkcskonosndngfkokjcrqewtzzmypimrsoqqffwwzgzwhgfrrxmtptzfnretnoqjprpgqdhxcrccphsdmouuuidojxcyiknpfrrygjgwgwkb...
output:
1 2 0 0 0 5 0 0 6 0 0 6 0 0 6 0 0 6
result:
wrong answer Rozwiazanie nieoptymalne! (test case 2)