1877D - Effects of Anti Pimples - CodeForces Solution


combinatorics number theory sortings

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define ll               long long
#define uniq(v)           (v).erase(unique(all(v)),(v).end())

//const long long INF=1e18;
//const int32_t M=1e9+7;
const int32_t MM=998244353;
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
void solve()
{
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++)
	{
		cin>>nums[i];
	}
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		int ma=INT_MIN;
		for(int j=i;j<n;j=j+(i+1))
		{
			ma=max(ma,nums[j]);
		}
		v[i]=ma;

	}


	

	// for(int i=0;i<n;i++)
	// {
	// 	cout<<v[i]<<" ";
	// }
	int ans=0;
	sort(v.begin(),v.end());

	for(int i=0;i<n;i++)
	{
		int t=expo(2,i,MM);
		int g=mod_mul(v[i],t,MM);

		int k=mod_add(g,ans,MM);
		//cout<<t<<" "<<g<<" "<<k<<endl;
		ans=k;
	}
	cout<<ans<<endl;


}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Comments

Submit
0 Comments
More Questions

427C - Checkposts
1159A - A pile of stones
508A - Pasha and Pixels
912A - Tricky Alchemy
1249A - Yet Another Dividing into Teams
1713C - Build Permutation
1699A - The Third Three Number Problem
1617B - GCD Problem
841A - Generous Kefa
1690B - Array Decrements
1692C - Where's the Bishop
104A - Blackjack
1438A - Specific Tastes of Andre
1711C - Color the Picture
1194C - From S To T
110B - Lucky String
1114A - Got Any Grapes
224B - Array
125B - Simple XML
567B - Berland National Library
431B - Shower Line
282C - XOR and OR
1582B - Luntik and Subsequences
609A - Флеш-карты
1207A - There Are Two Types Of Burgers
371C - Hamburgers
343B - Alternating Current
758B - Blown Garland
1681B - Card Trick
1592A - Gamer Hemose