Submission #62550671
Source Code Expand
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define Fast1 ios_base::sync_with_stdio(false)
#define Fast2 cin.tie(NULL)
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define inf 1000000000000000000
using namespace std;
const int N = 100000+7;
const ll mod = 998244353;
string S = "abcdefghijklmnopqrstuvwxyz";
ll lcm(ll a, ll b){ return (a*b/__gcd(a,b)); }
// PBDS - Ordered Set -----------------------------------------------------------------------------
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//--------------------------------------------------------------------------------------------------
// Seive, Prime Factors,Divisors ----------------------------------------------------------------------------
bool isPrime[N+1];
ll lowestPrime[N+1], highestPrime[N+1];
map<ll,ll> primeFactors;
vector<ll> divisors[100007];
void Seive(){ memset(isPrime, 1, sizeof isPrime); memset(lowestPrime, 0, sizeof lowestPrime); memset(highestPrime, 0, sizeof highestPrime);
isPrime[0] = isPrime[1] = 0; for(ll i=2;i<=N;i++){ if(isPrime[i]){ lowestPrime[i] = highestPrime[i] = i; for(ll j=2*i;j<=N;j+=i){
isPrime[j] = false; highestPrime[j] = i; if(lowestPrime[j] == 0) lowestPrime[j] = i;}}}}
void getPrimeFactors(ll num){ while(num > 1){ ll primeFactor = highestPrime[num]; while(num % primeFactor == 0){ num /= primeFactor; primeFactors[primeFactor]++;}}}
void getDivisors(){for(ll i=2;i<=100007;i++){for(ll j=i;j<=100007;j+=i){divisors[j].pb(i);}}}
// -------------------------------------------------------------------------------------------------
/*----------------------------Notes----------------------------------------------------//
1. All the perfect square numbers have odd number of divisors and
rest all numbers always have even number of divisors.
2. The sum of two numbers is INT_MAX if their xor is also INT_MAX.
3. For a number d to be divisor of any other number p, d <= floor(p)
4. given a number y >= 2*x, the x^y val will always be greater than x,
as there will be an extra set bit in y >= 2*x.
*/
class DisjointSetUnion{
public:
vector<ll> parent, size;
ll components;
DisjointSetUnion(ll n){
parent.resize(n+1);
iota(all(parent), 0);
size.assign(n+1, 1);
components = n;
}
ll findParent(ll x){
if(parent[x] == x) return x;
return parent[x] = findParent(parent[x]);
}
void unite(ll x, ll y){
x = findParent(x);
y = findParent(y);
if(x == y) return;
if(size[x] < size[y]) swap(x,y);
parent[y] = x;
size[x] += size[y];
components--;
}
};
void solve(){
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
ll n; cin >> n;
vector<map<ll,ll>> num_freq(n+1);
vector<ll> sizes(n+1);
for(int i=1;i<=n;i++){
ll k; cin >> k;
sizes[i] = k;
map<ll,ll> mp;
for(int j=0;j<k;j++){
ll x; cin >> x;
mp[x]++;
}
num_freq[i] = mp;
}
// for(int i=1;i<=n;i++){
// for(auto it : num_freq[i]){
// cout << it.first<< " " << it.second << endl;
// }
// }
ld ans = 0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
auto &mp1 = num_freq[i];
auto &mp2 = num_freq[j];
// for(auto it : mp1){
// cout << it.first << " " << it.second << endl;
// }
// cout << endl;
// for(auto it : mp2){
// cout << it.first << " " << it.second << endl;
// }
// cout << endl;
ll totalPoss = sizes[i] * sizes[j];
// cout << totalPoss << endl;
ll favourableOut = 0;
if(mp1.size() <= mp2.size()){
for(auto f : mp1){
if(mp2.find(f.first) != mp2.end()){
favourableOut += f.second * mp2[f.first];
}
}
}
else{
for(auto f : mp2){
if(mp1.find(f.first) != mp1.end()){
favourableOut += f.second * mp1[f.first];
}
}
}
// cout << favourableOut << endl;
// cout << setprecision(18) << (ld)favourableOut/totalPoss << endl;
ans = max(ans, (ld)(1.0*favourableOut/totalPoss));
}
}
cout << setprecision(15) << ans << endl;
}
int main(){
Fast1;
Fast2;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// Seive();
// int t;
// cin >> t;
// for(int i =1;i<=t;i++){
// // cout << "Case #" << i << ": " ;
// solve();
// }
solve();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Doubles |
| User |
Pandemania |
| Language |
C++ 20 (gcc 12.2) |
| Score |
400 |
| Code Size |
5592 Byte |
| Status |
AC |
| Exec Time |
545 ms |
| Memory |
13168 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt |
| All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| random_01.txt |
AC |
7 ms |
3736 KiB |
| random_02.txt |
AC |
7 ms |
3800 KiB |
| random_03.txt |
AC |
40 ms |
10756 KiB |
| random_04.txt |
AC |
51 ms |
10352 KiB |
| random_05.txt |
AC |
7 ms |
3860 KiB |
| random_06.txt |
AC |
7 ms |
3828 KiB |
| random_07.txt |
AC |
42 ms |
10480 KiB |
| random_08.txt |
AC |
47 ms |
10520 KiB |
| random_09.txt |
AC |
7 ms |
3808 KiB |
| random_10.txt |
AC |
7 ms |
3840 KiB |
| random_11.txt |
AC |
37 ms |
10948 KiB |
| random_12.txt |
AC |
45 ms |
10432 KiB |
| random_13.txt |
AC |
5 ms |
3860 KiB |
| random_14.txt |
AC |
34 ms |
11116 KiB |
| random_15.txt |
AC |
5 ms |
3744 KiB |
| random_16.txt |
AC |
30 ms |
11624 KiB |
| random_17.txt |
AC |
1 ms |
3692 KiB |
| random_18.txt |
AC |
5 ms |
3740 KiB |
| random_19.txt |
AC |
321 ms |
10144 KiB |
| random_20.txt |
AC |
81 ms |
10180 KiB |
| random_21.txt |
AC |
26 ms |
13168 KiB |
| random_22.txt |
AC |
5 ms |
3800 KiB |
| random_23.txt |
AC |
545 ms |
10148 KiB |
| random_24.txt |
AC |
542 ms |
10208 KiB |
| sample_01.txt |
AC |
1 ms |
3736 KiB |
| sample_02.txt |
AC |
1 ms |
3704 KiB |