Cycle_Trikstr's blog

By Cycle_Trikstr, history, 4 months ago, In English

When I first saw this problem, I felt that this problem is somewhat similar to 1068 B. Niko's Tactical Cards in which DP was used , as I haven't studied DP I was unable to solve it .

But After the contest I learn't the basic trick that first we define states , we apply operation in every state and then take min or max as the problem tells and then define the next state for further interations .

Now , I applied the same logic during solving the online mirror of 2025-2026 ICPC, NERC, Northern Eurasia Finals Problem M. Medical Parity which gave me AC 353928464 .

Similarly , I had the same intuition for going for this trick in yesterday's Good Bye 2025 C problem as there were two operations held at position 1 and 2 so I tried to define two states .

1st state — it tried to maximise the outcome of the leftmost operation by taking the best X of 1st state so far , then applying a left operation on it and a right operation on it , then reseting it to the best of the left operation of 1st state and best left operation from the 2nd state .

2nd state — it tried to maximise the outcome of the rightmost operation by taking the best X of 2st state so far , then applying a left operation on it and a right operation on it , then reseting it to the best of the right operation of 1st state and best right operation from the 2nd state .

I did a dry run and it It perfectly worked on pretests 1 but somehow fails on pretests 2 . Is there a flaw in my logic or did someone implemented a similar approach and got AC . Can anyone Help ..

Submission — 355435711

vector<int> a(n) ;
for(int i = 0 ; i < n ; i++)cin >> a[i] ;
  
vector<int> l = {0 , 0 , 1} , r = {0 , 0 , 1} ; //l , r = {best X , cur left pointer , cur right pointer}
vector<int> ll(3) , lr(3) , rl(3) , rr(3) ;

while(l[2] < n)
{
  ll[0] = l[0] + a[l[1]] ; 
  ll[1] = l[2] ;
  ll[2] = l[2] + 1 ;

  lr[0] = l[0] - a[l[2]] ;
  lr[1] = l[1] ;
  lr[2] = l[2] + 1 ;

  rl[0] = r[0] + a[r[1]] ;
  rl[1] = r[2] ;
  rl[2] = r[2] + 1 ;

  rr[0] = r[0] - a[r[2]] ;
  rr[1] = r[1] ;
  rr[2] = r[2] + 1 ;

  if(ll[0] > rl[0])l = ll ;
  else if(ll[0] == rl[0])
  {
    if(a[ll[1]] >= a[rl[1]]) l = ll ;
    else l = rl ;
  }
  else l = rl ;

  if(lr[0] > rr[0])r = lr ;
  else if(lr[0] == rr[0])
  {
    if(a[lr[1]] >= a[rr[1]])r = lr ;
    else r = rr ;
  }
  else r = rr ;
}

  cout << max(l[0] , r[0]) << endl ;

Plus , It's my first blog :D

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

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

Auto comment: topic has been updated by Cycle_Trikstr (previous revision, new revision, compare).

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

You can check this DP implentation.

My states are (idx,zero) -> zero is used to track whether zero is used till now.

355361808

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

When I first saw this problem, I felt that this problem is somewhat similar to 1068 B. Niko's Tactical Cards in which DP was used , as I haven't studied DP I was unable to solve it .

I just did a simple way by having two variables (minAns and maxAns), submission

In Goodbye 2025 C, I used a different approach, which is brute forcing the child not picked in all operations, by precomputing the left and right answer, submission

Also, I found the WA case a=[-2, 1, -3, 5], your code outputs 0 but correct answer is 2, by picking:

  • Pick first (-2), score is -2, array is [1, -3, 5]
  • Pick second (-3), score is 1, array is [1, 5]
  • Pick first (1), score is 2, array is [5]
  • End

Also I am Expert, not Candidate Master (by magic)

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

As soon as I read the problem, my first reaction was prefix and suffix sums.

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

I had the same feeling with it being similar to problem B,but fastly realized that there I need a different approach.