An annual programmers fair is taking place on the main square of Omsk. You, as the main programmer of Omsk, decided to take part in this wonderful event and went there. At the entrance, a guard decided to check your skills and gave you a problem:
You are given three integers a, b, x. You want to make a and b equal. In order to do so, you can apply the following operations:
Choose one of the integers a or b and add 1 to it.
Choose one of the integers a or b and divide it by x with rounding down.
You need to find the minimum number of operations after which a becomes equal to b. Can you prove your skills, or will you have to go back home?
Dabir and Egor were not satisfied with the fame from the previous episode, so they decided to make another TV show: the guys play their favorite game on an array a with their favorite integer k.
Dabir moves first. On the first move, any element from the array can be chosen and removed. Let the previous chosen element be equal to x. Then on the current move, except the very first one, a player must choose an element y from the array such that 0≤y−x≤k and remove it from the array. The player who cannot make a move loses.
But since this was not just a game, but a real show-match, Arseniy (aka MAKAN) — the main celebrity of Omsk was invited again. As a guest celebrity, Arseniy was given the opportunity to make the first move in this match, that is, to make the very first move in the game instead of Dabir. However, it turns out Arseniy is a fan of Egor, so he wants his first move to guarantee Egor a winning strategy against any response from Dabir.
Determine whether Arseniy can make the first move for Dabir so that, no matter how Dabir plays, Egor wins.
voidsol() { int n,k; cin>>n>>k; vector<int>a(n+1,0); vector<int>tr(n+1); vector<int>ct(n+1,0); vector<int>bt(1,0); int cnt=0; vector<int>dp(n+1,-1);//dp[i]means player del this cell and will win or fail for(int i=1;i<=n;i++)cin>>a[i]; sort(a.begin()+1,a.end()); int lst=0; for(int i=1;i<=n;i++) { if(a[i]!=lst) { lst=a[i]; bt.push_back(a[i]); ct[++cnt]++; } else { ct[cnt]++; } } for(int i=cnt;i>=1;i--) { int j=upper_bound(bt.begin()+1,bt.end(),bt[i]+k)-bt.begin()-1; if(i==j) { if(ct[i]%2) { dp[i]=0; } else { dp[i]=1; add(tr,i); } continue; } if(search(tr,j)-search(tr,i)<j-i)//have P => N pos { dp[i]=1; add(tr,i); } else//not P { if(ct[i]%2)//odd => P { dp[i]=0; } else//even => N { dp[i]=1; add(tr,i); } } } for(int i=1;i<=cnt;i++) { if(dp[i]==1) { cout<<"YES\n"; return; } } cout<<"NO\n"; } //1 2 3 4 //P N N P //if I can move to P => the pos is N //if I cant move to P, //if cnt is odd => the pos is P //if cnt is even => the pos still N //choos y that x<= y <= x+k
E
Arseniy decided to make his friends Dabir and Egor happy. For this, he decided to give each of them an array of numbers of the same length. An array b is called good if its elements can be rearranged so that for all i>1 the condition bi−bi−1=1 holds.
Arseniy wants Dabir and Egor to be able to play with these arrays. For this, the following conditions must be satisfied:
Each of the given arrays is good.
If you write one array after the other (in other words, concatenate them), the resulting array is also good.
Arseniy already has an array a of length n. He plans to cut both arrays from a, that is, to choose two non-overlapping subsegments of the same length. Help Arseniy determine the maximum possible length of the resulting arrays.
This is the easy version of the problem. The only difference is that x=1
On the way home after buying his favorite soda “Zola Cero”, Egor saw that elections for the position of “Best Number” are taking place in Saransk.
There are n people at the polling station. Each person brought a number ai. When the i-th person enters the voting booth, they choose a candidate that is a divisor of the number ai. Let the chosen candidate be pi.
After everyone has voted, we get an array of votes [p1,p2,…,pn].
Egor really likes the number x and considers the voting ideal if x⋅lcm(p1,p2,…,pn)∗ = p1⋅p2⋅…⋅pn. Help him find the number of different† arrays p modulo 109+7 that are ideal.