PROBLEM LINK:
Author:Tiancheng Lou
Tester:Shiplu Hawlader and Mahbubul Hasan
DIFFICULTY:
HARD
EXPLANATION(as written by ACRush):
Step 1 :
Reduce to : given a list of numbers 1, 2, ... p-1, split the list into as many as sub-list(s), such that the sum within each list is a multiple of p.
Proof :
Suppose the array is Ai, where 1<=i<=n. Denote A0 = An+1=0, and Bj = Aj - Aj-1 where 1<=j<=n+1.
*) Ai are all zero if and only if Bi are all zero.
Given a list of operations, we construct a graph of n+1 nodes. Such that, for each operation (s, t, k), we add one edge between s and t+1. So,
*) the sum of Bi within each connected component is a multiple of p.
*) for each component consists of c nodes, we can use c-1 OPs to zero it.
*) the answer is n+1 - max number of components whose sum is a multiple of p.
Step 2 :
Use p=10 as example, we always use 19, 28, 37, 46, 55 if possible. Since there must be one solution with the same number of moves but more 2-digits moves.
Step 3 :
If p is odd, and the number of p/2 is also odd, try all possible subset containing 5.
Step 4 :
There are only 4 digits left. ##IMPORTANT : the number of possible subsets is very limited. Even if p = 10, the number of subsets is ~30. Then, we need to formalize the problem into a Integer Linear programming problem.
There are many different ways to handle ILP problem.
*) mugurelionut@ and kutengine@ are using simplex for ILP, which required int128 and "branch and bound" algorithm. Though I'm not sure their solutions are 100% correct, hard to generate corner cases for them.
*) aawisong@ and the standard algorithm : precompute all simplex points, and use gauss equations to solve the rest of them.
AUTHOR'S AND TESTER'S SOLUTIONS:
To be updated soon.