1279D - Santa's Bot - CodeForces Solution


combinatorics math probabilities *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define all(x) begin(x),end(x)

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> iset;

void solve(){
    const long long MOD=998244353;
    
    long long n;
    cin>>n;
    
    map<int,long long> m;
    vector<vector<long long>> a;
    for(int i=0;i<n;i++){
	int k;
	cin>>k;
	a.push_back(vector<long long>(k));
	while(k--){
	    long long x;
	    cin>>x;
	    m[x]++;
	    a[i][k]=x;
	}
    }

    auto pow=[&](auto&&pow,long long x,long long y)->long long
    {
	if(y==0)return 1;
	long long sol=pow(pow,x,y/2);
	sol*=sol;
	sol%=MOD;
	if(y%2)sol*=x;
	sol%=MOD;
	return sol;
    };

    long long val=0;
    for(auto&as:a){
	for(auto i:as){
	    long long can=1;
	    can*=pow(pow,n,MOD-2);
	    can%=MOD;
	    can*=pow(pow,n,MOD-2);
	    can%=MOD;
	    can*=pow(pow,as.size(),MOD-2);
	    can%=MOD;
	    can*=m[i];
	    can%=MOD;
	    val+=can;
	    val%=MOD;
	}
    }

    long long sol=val;
    sol%=MOD;
    cout<<sol<<'\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int numberOfTests=1;
    //cin>>numberOfTests;
    while(numberOfTests--){
	solve();
    }
}


Comments

Submit
0 Comments
More Questions

1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph
404A - Valera and X
908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64