shorya1835's blog

By shorya1835, history, 8 months ago, In English

2140A - Shift Sort

Idea: shorya1835 Preparation: wakanda-forever

Solution
Code

2140B - Another Divisibility Problem

Idea: wakanda-forever Preparation: wakanda-forever

Solution
Code

2140C - Ultimate Value

Idea: shorya1835 Preparation: wakanda-forever

Solution
Code

2140D - A Cruel Segment's Thesis

Idea: shorya1835 Preparation: shorya1835

Solution
Code

2140E1 - Prime Gaming (Easy Version)

Idea: Divine_Spark Preparation: shorya1835

Solution
Code

2140E2 - Prime Gaming (Hard Version)

Idea: Divine_Spark Preparation:wakanda-forever, shorya1835

Solution
Code
Bonus

2140F - Sum Minimisation

Idea: shorya1835 Preparation: wakanda-forever, shorya1835

Solution
Code

Thanks to satyam343 for his help throughout the round.

  • Vote: I like it
  • +216
  • Vote: I do not like it

»
8 months ago, hide # |
 
Vote: I like it +37 Vote: I do not like it

noooo I want yesterday's rating please this one killed me:(

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

i did same for a but it give me wrong aaaaahhh

btw great tutorial like what i am thinking thanks

»
8 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

A was very tricky for me to prove that such strategy gives minimum moves.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Questions were really good.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For the case 110100, we can take i = 1, j = 3, k = 4 and the string will become 111000 which is sorted but the answer given in test case is 2 steps

»
8 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it
E2 bonus
  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    That's for non distinct piles, bonus asks for distinct.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
      I'm pretty sure that
      • »
        »
        »
        »
        8 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it 0 Vote: I do not like it

        It's not that complicated, you can derive something closed form combined with the dp

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it +47 Vote: I do not like it

          My principle if that if I don't need to think I don't think.

          • »
            »
            »
            »
            »
            »
            8 months ago, hide # ^ |
             
            Vote: I like it +5 Vote: I do not like it

            bruh

            • »
              »
              »
              »
              »
              »
              »
              8 months ago, hide # ^ |
               
              Vote: I like it +19 Vote: I do not like it
              OK
»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Got clapped but round was nice, thanks !

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hey can anyone tell me what is wrong in my approach. And please while pointing out my mistake, tell me how to think in the way to get to the approach mentioned in the editorial. It would be of great help to me. 337853452

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    Check it for this tc

    1
    4
    5 5 5 5
    

    Answer should be 3 (swap first and last element), but your code is giving 2 on this tc

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Thanks for pointing that out. I faced this testcase during the contest only. I want to know how to build intuition for the solution as given in the editorial for C.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What's case 1 in editorial for F? Doesn't [3, 0, 1] fall into case 1, but allow only 1 single operation?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

337862621

any clue why my code keeps wrong? give me hint plz

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    If you look at the failing 26th test case, it says:

    3 2 2 1

    You can see where your logic has fault. Hint: If you do mx-mn then you are also doing index(mx) — index(mn). This will be correct when mx lies to the right of mn, but that's not the case here.

»
8 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

For B , I just saw the consistent occurances of 12/3 , 102/3 , 1002/3 , then i realized that 3 would always divide the numbers having sum of digits factors of 3 , so therefore 2.x is the best solution here

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I solved B by observing the pattern and got y = 10^9 - 1 - x always works, can anyone prove this

  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Yes! let we have chosen y ...d=(length of y****)+1,,and mod=x+y. Then (x#y) = x*(10^d)+y.Then x#y is divisable by x+y;it will hold iff (x*(10^d)+y)%mod=0 i.e (x*(10^d)%mod+y%mod=0 as mod>x then y%mod=y so (x*(10^d))%mod must be x to hold the criteria of (x#y)%mod=0; we already know mod>x and mod>y; so if we can make 10^d %mod==1 we can fillup the criteria....so it will become 1 when mid=10^d-1 i.e x+y=10^d-1;.....thus it is ovbious for every d<i<=9; max value of d=9,,,,we can choose choose y=999999999-x everytime and it will pass every testcase!**____**

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    We want

    $$$(x \cdot 10^{k} + y) \bmod (x+y) = 0.$$$

    We know

    $$$y \bmod (x+y) = y.$$$

    Hence for the above to be zero, we need

    $$$x \cdot 10^{k} \bmod (x+y) = x.$$$

    We also know

    $$$x \bmod (x+y) = x.$$$

    Therefore

    $$$10^{k} \bmod (x+y) = 1.$$$

    A number of the form 10^k - 1 will always give remainder 1.

    As we want y to have the same number of digits as k, we take the largest possible k, which is $9$.

»
8 months ago, hide # |
Rev. 2  
Vote: I like it -6 Vote: I do not like it

2140B - Another Divisibility Problem can be solved with other values of $$$y$$$ as well, for example $$$y = 999... - x$$$ depending on $$$x$$$. Because,

$$$x \text{#} y = x \cdot 10^d + y = x \cdot (10^d − 1) + (x + y)$$$

So, to make the $$$10^d - 1$$$, which is basically $$$9999...$$$ for $$$d$$$ times, to be divisible by $$$x + y$$$, we can make $$$x + y$$$ itself be of this shape. For $$$x$$$ to be any $$$k$$$-digit number, $$$x + y$$$ can be of shape with any $$$k$$$ or more digits of $$$9$$$ s. Since the constraints state that $$$x \lt 10^8$$$ and $$$y \lt 10^9$$$, we can set $$$x + y$$$ to be $$$999,999,999$$$ i.e. $$$y = 10^9 - 1 - x$$$.

Also, obviously, $$$y = 8 \cdot x$$$ works for the same reason as tutorial.

Upd: can anybody explain why the downvotes? Cause I'm pretty sure there's nothing wrong in terms of logic cause I literally got AC with this approach. 337798106

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +11 Vote: I do not like it
E2 Bonus Solution:
Spoiler
»
8 months ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it
another way to look at D
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What's wrong with my code ? 337868493

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Love the reference to my favorite song — "A Cruel Angel's Thesis" by Yoko Takahashi ‧ 1995

OP
»
8 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

My solution to Problem D works as follows: the original problem is equivalent to finding a matching among the intervals $$$1, \cdots, n$$$ that maximizes the value

$$$ \displaystyle\sum_{(j,k) \text{ are matched}} \max(r_j - l_k, r_k - l_j). $$$

Using the identity $$$\max(A, B) = \frac{A + B}{2} + \frac{|A - B|}{2}$$$, this expression can be rewritten as

$$$ \displaystyle\sum_{(j,k)} \max(r_j - l_k, r_k - l_j) = \sum_{(j,k)} \frac{(r_j - l_j) + (r_k - l_k)}{2} + \sum_{(j,k)} \frac{|(r_j + l_j) - (r_k + l_k)|}{2} \quad (\star). $$$

For even $$$n$$$, the first term is constant (equal to half the total sum of the lengths of the intervals), and the second term is maximized by partitioning the array $$$a[j] = r_j + l_j$$$ into two halves and subtracting the sum of the smaller half from the sum of the larger half. This can be computed efficiently using prefix sums in $$$\mathcal{O}(1)$$$ time per query after preprocessing.

For odd $$$n$$$, one interval (say $$$i$$$) remains unmatched. We enumerate each $$$i = 1, \cdots, n$$$ as the unmatched interval, and the value in equation $$$(\star)$$$ can be easily evaluated in $$$\mathcal{O}(1)$$$ time using a similar prefix sum approach with minor modifications, resulting to an $$$\mathcal{O}(n)$$$ solution.

This method is basically identical to the one in the editorial, but more clear to me.

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

the second problem was a humbling experience for me

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone explain this part This can be solved by maintain prefix minimum over odd and even indexes.

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +17 Vote: I do not like it

for problem E, dp[i][mask][1] is actually the same as dp[i][~mask][0]; you can just maintain one

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can someone help me understand, why this code of mine for problem C is giving wrong answer, I am not able to understand.

//this is the code

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> ind[2];
    map<ll, vector<ll>> mp0,mp1;
    ll cost = 0;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ind[i % 2].push_back(a[i]);
        if (i % 2 == 0){
            cost += a[i];
            mp0[a[i]].push_back(i);
        }
        else{
            cost -= a[i];
            mp1[a[i]].push_back(i);
        }
    }

    sort(ind[0].begin(), ind[0].end()); // even paratiy
    sort(ind[1].begin(), ind[1].end()); // odd pararity

    ll temp_cost = 0;
    if (n % 2 == 0) temp_cost = n - 2;
    else temp_cost = n - 1;

    if (ind[0].empty() || ind[1].empty()) {
        cout << cost << "\n";
        return;
    }

    ll num1 = ind[1].back();   
    ll num2 = ind[0][0];       

    ll temp_cost2 = 0;
    if (!mp1[num1].empty() && !mp0[num2].empty()) {
        temp_cost2 = num1 - num2 +
            max(abs(mp1[num1][0] - mp0[num2].back()),
                abs(mp0[num2][0] - mp1[num1].back()));
    }
    ll cost2=cost;
    if (temp_cost2 >= temp_cost) {
        cost2 = cost2 + num1 - num2;
        cost2 += temp_cost2;
        //cout << cost << "\n";
    }

    cout<<max(temp_cost+cost,cost2) << "\n"; 
}
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem C, I used a DP approach. Surprisingly, when I implemented it with a regular array (initialized using memset), it resulted in TLE. However, switching to a map for memoization led to an AC. Could someone explain why this happens?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You initialize the whole DP table with $$$8 \cdot 10^5$$$ elements for every test case. Since there are $$$10^4$$$ test cases at most, you're overwriting $$$8 \cdot 10^9$$$ elements in sum, which is too slow.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Oh, I see now. This means my array-based solution ends up doing about $$$2 \cdot 10^5$$$ operations for each test case, which ignores the fact that "the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$". In contrast, the map-based solution only stores and processes the states that are actually needed, so its complexity is closer to $$$O(n)$$$ overall. Is that correct?

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        You're correct. You don't need the whole DP array for a test case with smaller $$$n$$$. If you are given $$$n$$$ for a test case, make sure you only touch $$$O(n)$$$ elements; then your solution won't time out.

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I see, thanks!

          • »
            »
            »
            »
            »
            »
            8 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            I have faced so many WAs over the years for this reason that I always take extra care when clearing/initializing arrays. Always clear only n+5 (or 2n + 5) elements, don't touch higher indices since you don't need them.

            You'll get used to it haha. Good luck!

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    Hello Osama, i want to show you a trick you can use when you come across dp problems that involve test cases, as someone previously replied clearing your dp each case is too slow, but also the map memo isn't the best practice when it comes to this sort of problems.

    There are two main ways to to this better, first is to give each test case an id, and to distinguish if you have been in this state before in the same test case you check if vis[state] equals the current id. 338980284

    Another way is to clear exactly the size you need for this test case, after taking input n, loop and set it to the value you want.

    338981249

    Hope this helps.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Thanks a lot, Adham — that was really helpful. I like how these approaches let us stick with arrays instead of maps and still avoid TLE. There’s just one thing I’m not fully clear on: in the first solution, the vis array isn’t initialized. Is it safe to compare its values like that? If not, then initializing it once like int vis[(int)(2e5 + 5)][2][2]{}; should be enough, right?

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Welcome , glad to help.

        When an array is declared globally it’s initialized with zeros, same for integers.

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Oh, that’s new to me — I thought it would be initialized with garbage like local arrays. Appreciate the clarification, bro :)

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

where balanced paranthesis come from in d editorial??? (*cry emoji)

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

How can u directly find out left out segment in O(1) in D editorial ??

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Oh WOW, that's a fast editorial.

Loved the problems, and I FINALLY became a specialist.

I got the idea of C, but for those who didn't, I think the change in the statement of C gave it away. B was a little hard tho

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

2140B extended The editorial was prepared together with my coach, after he tried during the contest to brute-force all divisors of $$$10^k-1$$$ and $$$x$$$ and ran into TLE. Submission.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I like how noone mentioned that question 2140D was just an evangelion reference

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

bro I didn't got yesterday's contest's rating

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is what I got for B and it got accepted lol. If anyone could lmk why this works that would be cool. I was basing this off the fact that both these numbers will be divisible by 3 as both their digit sums would be divisible by 3 and just kinda tested from there and it worked:

#include <bits/stdc++.h>
#define PB push_back
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<long long, long long> > vpll;

const ll INF = 4e18;

void solve() {
  ll x;
  cin >> x; 
  string s = to_string(x);
  bool flag = false;
  if (s[0] == '9') flag = true;
  string y;
  if (flag) y.push_back('9');

  for (int i = 0; i < s.length(); i++) {
    y += to_string('9'-s[i]);
  }

  cout << y << '\n';
} 

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  //cin.ignore(numeric_limits<streamsize>::max(), '\n');
  while(t--) {
    solve();
  }
}
»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

What is wrong in this solution for D:

First we initially compute the sum of all segments , Initial_sum = $$$S = \sum_{i=1}^{n} y_i - x_i$$$ then we want to compute the additional segments length formed by marking these segments, if we sort the $$$l_i$$$'s and $$$r_i$$$'s and then take the sum of (highest $$$r_i$$$ — least $$$l_i$$$) + (2nd highest $$$r_i$$$ — 2nd least $$$l_i$$$) + ..... and add this sum to the Initial_sum

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You probably mean the highest r_i — least l_j for distinct i and j. The problem arises in the case when a segment with the largest r_i contains all other segments. In that case we have a choice between r_i of largest segment — second highest l_i and second highest r_i — l_i of largest segment.

    Consider these segments: [1, 100], [5, 90], [98, 99]. You select the first two, but the optimal way is to take the first and the third segments.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone please explain the solution of E2 after calculating the dp values. How is it calculating the original answer from binary(0, 1)?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    For a configuration where alice wins in easy version with the bits that are 1 here are values that are >= k (for some k we are looping through) and other(0) values are < k then Alice can Force Bob into making the final Answer >=k as it forced Bob into making the final value 1 for the corresponding 0-1 mask. so we just need to count for every k the sum of masks * no of ways to generate this mask (1 filled by >=k value and 0 filled by <k values)

    • »
      »
      »
      8 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      (k−1)^n−r⋅(m−k+1)^r⋅cnt[r]

      isn't this line just the number of ways to create a mask with (n-r) places with < k and r places with >=k, cnt[r] times. So then how how are we accounting for the sum of the actual values left at last? What am i missing here?

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        it is clever way of doing things, it is basically >=1 + >=2 + >= 3 ... which can be re written as 1*(==1) + 2*(==2) + 3*(==3)... which what we are required to find.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

You can think of this approach : let's choose y=k*x; Now you can so this :

// you can use all values generated below. you can change 1000 to your number // for 1000 these are valid : 2 8 26 36 100 302 908 // basicaaly formula is to count = 10k/k+1 should be divisible. here 10k is concatination of 10 and k // but here y has limit that can atmost 10*x so we can use only 2 and 8 in this code.

// void solve(){ // ll num=10; // for(ll i=1;i<=1000;i++){ // if(i/num>0) num=num*10; // ll x=num*10+i; // if(x%(i+1)==0){ // cout << i << " "; // } // } // cout << endl; // } ~~~~~ Your code here... ~~~~~

»
8 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

For problem D, a very "neat" way of reaching the greedy conclusion is by expanding the formula of the chosen segments' sum. Let's name the of chosen segments $$$C$$$ and the rest be $$$R$$$.

Our formula is :

$$$ \sum_{i \in C} r_i - \sum_{j \in R} l_j $$$

If we manage to eliminate contribution of group $$$R$$$ from this equation it will be easy to select group $$$C$$$ to maximize this expression. To do so we can expand the second term, based on this substitution :

$$$\sum_{j \in R} l_j = \sum_{i=1}^n l_i - \sum_{k \in C} l_k $$$

Where $$$n$$$ is the input size, by substitution our formula becomes :

$$$ \sum_{i \in C} r_i - (\sum_{i=1}^n l_i - \sum_{i \in C} l_i )$$$
$$$ \sum_{i \in C} r_i + \sum_{i \in C} l_i - \sum_{i=1}^n l_i $$$
$$$ \sum_{i \in C} (r_i + l_i ) - \sum_{i=1}^n l_i $$$

Now it's clear to see that maximizing this expression is equivalent to maximizing sum of right and left of a segment, since summation of all lefts is constant.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone explain what they mean in the solution for problem C when it says

Spoiler

This is very confusing to me.

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

"In Problem D editorial it says you can directly find the left out segment in O(1) — can someone explain how to actually do that part?"

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    When I write something/2, I mean smaller one (etc. 7/2=3), I do not know how to write that type of brackets in comment.
    Well, when n is odd, from the first sum (with all r) you need to take away one r and n/2 l+r. So, you have n choices for taking away r. Lets sort aray by l+r. Now, find a sum of all r minus sum of first n/2 l+r, I called that difference tmp. If that choice is NOT in first n/2 elements, you should just take away r. You find a minimum the same way you would normally do in an array, just with mathematical expression tmp-r.
    Now, when you search in first n/2 elements, first you take away l+r from tmp (before taking away r). But now, you substracted n/2-1 l+r's. That means you have to substract l[n/2]+r[n/2] too.
    Thats it — you can count the sum for some i in O(1) because you precalculated some "part" of the sum in tmp. You just have to be careful when examining if element is in first n/2 elements or not. For this I used two for loops because ifs looked messy.
    Hope I made it clear. :) Here is the code that worked.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    Spoiler
»
8 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Here's a brainf*ck solution of 2140B - Another Divisibility Problem for no reason

(Assuming all cells are 32-bit instead of 8-bit as normal, if someone can implement an 8-bit solution I'm more than excited to see it)

[-]>[-]+[[-]>[-],[+[-----------[>[-]++++++[<------>-]<--<<[->>++++++++++<<]>>[-<<+>>]<+>]]]<]<
// Inputs the number of testcases
[>
[-]>[-]+[[-]>[-],[+[-----------[>[-]++++++[<------>-]<--<<[->>++++++++++<<]>>[-<<+>>]<+>]]]<]<
// Inputs n
[->++<]>
// Calculate 2*n
>[-]>[-]+>[-]+<[>[-<-<<[->+>+<<]>[-<+>]>>]++++++++++>[-]+>[-]>[-]>[-]<<<<<
[->-[>+>>]>[[-<+>]+>+>>]<<<<<]>>-[-<<+>>]<[-]++++++++[-<++++++>]>>[-<<+>>]<<]
<[.[-]<]<
// Output 2*n
[-]++++++++++.[-]
// Output newline character
<<-
// Decrement testcase number
]
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't understand the complexity in E1, isn't is supposed to be $$$O(n^2 \cdot 2^n)$$$, because of the for loop over "good" vector?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

taskkill /f /im libmain.exe && taskkill /f /im xhost.exe

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, My account was recently flagged for cheating in this round. I would like to clarify my situation.

I did not share my code with anyone, nor did I copy from others. I usually keep my solutions locked, but I understand now that similarity in code can happen naturally since many problems have standard approaches. This might have caused suspicion.

I respect Codeforces and its rules, and I never intended to violate them. If my actions caused unintentional leakage or misunderstanding, I sincerely apologize. I will be more careful in the future to avoid such issues.

I kindly request the admins to review my case. Thank you for your time and understanding.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Similar problem for B from Project Euler. Editorial

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In the editorial for problem D, I dont understand:

this part of editorial

My question being

the question

Thanks a lot in advance!

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I am not sure, what your question is, can you elaborate?

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I understand that part of the editorial

      as follows.

      Sorry if I misunderstood the editorial. And please excuse my English as well.

      • »
        »
        »
        »
        8 months ago, hide # ^ |
        Rev. 3  
        Vote: I like it 0 Vote: I do not like it
        Spoiler
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem C: I'm not quite sure how you're meant to use prefix sums. Can anyone explain?

I instead (338651248) used an approach along the lines of "for each + element, what's the best — element to swap it with?". Explaining exactly how I did it is difficult, but essentially it works by considering how the distances (i.e. abs(l-r)) between + elements and — elements change as you iterate over the + elements.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem F, is y taken to be the absolute value of x — floor(x/k)*k? I'm not sure if it's ever possible to get infinitely decreasing sum otherwise.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for problem "another divisibility problem" doesnt x#x % x = 0? so returning x always works, nowhere in the problem can I find something that forbids you from doing that. it can be mathematically proven that x#x % x = 0:

let x be = 42 for example

4242 % 42 = (42 *10^2 + 42) % 42

42(10^2+1) % 42

this equals to zero since 10^2 +1 is an integer, that number multiplied by 42 is divisible by 42. this works for all numbers as long as 2 is substituted by the number of digits x has.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think there's a slight logical error in Case 2 in the editorial for F. The editorial asserts that if any operation can be performed on the last n-1 elements of the array, then performing that operation will take us to Case 1. This is not true when the operation only modifies one element and that element is equal to the minimum of the array. For example, consider the array [1, 1, 3, 3]. We can perform an operation on the three larger elements, which makes the array [0, 1, 3, 3], which does not fall under Case 1.

The reason the model solution still works is that if this happens, then we can perform the same operation again, replacing the element that was decreased with the original minimum element of the array. At this point, we have two occurrences of the original minimum — 1, so we have an element other than $$$a_1$$$ with the opposite parity of the elements of the original array, putting us into Case 1.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    Yes, i am aware of that case, in my rough editorial i had written sometime ago, operation wasn't singular but plural. I had mistakenly changed it, when formalizing it. Thanks for pointing it out.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      When receiving the following input, the given code for problem F outputs -1, but I cannot figure out a way to achieve a sum of less than $$$12$$$. Maybe there's still some special cases when $$$n=3$$$?

      1
      3
      2 2 10
      
      • »
        »
        »
        »
        7 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it +3 Vote: I do not like it

        Do operation on whole array to get a=[1,1,10], after that you can repeat the operation 1st, 3rd element and 1st,2nd elements infinitely.

        • »
          »
          »
          »
          »
          7 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Sorry, it seems that I misunderstood the problem. I thought it was "decrease the y-th element", haha. Thank you for helping out!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't understand this :

for (int r = 1; r <= n; r++)
{   
    for(int k=1;k<=m;k++){
        finans += (((binpow(k-1,n-r)*binpow(m-k+1,r))%MOD) * (cnt[pl][n][r]))%MOD;
    }
}
cout << finans%MOD << endl;

Why is the result calculated this way?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

what is wrong with this approach for C-

import sys
input = sys.stdin.readline
MOD = 1_000_000_007

def ans():
  n = int(input())
  l = list(map(int, input().split()))
  s = x = y = 0
  m = 1_000_000_007
  ma = -1_000_000_007

  for j in range(n):
    if j % 2 == 0:
      s += l[j]
      if (2*l[j] + j) < m:
        m, y = (2*l[j] + j), j
    else:
      s -= l[j]
      if (2*l[j] + j) > ma:
        ma, x = (2*l[j] + j), j

  xa = ya = 0
  mr = 1_000_000_007
  maa = -1_000_000_007

  for j in range(1, n+1):
    if (n - j) % 2 == 0:
      if (2*l[-j] + j - 1) < mr:
        mr, ya = (2*l[-j] + j - 1), n - j
    else:
      if (2*l[-j] + j - 1) > maa:
        maa, xa = (2*l[-j] + j - 1), n - j

  u1 = ma - m
  u2 = maa - mr  
  u = max(u1, u2)
  return s + max(u, (n - 1 - (n + 1) % 2))

for _ in range(int(input())):
  print(ans())