Report

HKOI 2014 Senior Pharmaceutical Company Problem Prepared by : Gary Wong Problem • Find the maximum number of capsules they can produce • Find the earliest possible time for the workers to finish the synthesis process in such case Solution 1 • Write a function to achieve this – given the time the workers finished the synthesis work, find the number of capsules they can produce • Exhaust the finishing time for X workers, from 1 to T • Complexity = O( T * ( X + Y ) ) • Score = 50 Observation 1 • If the synthesis process is too long, the Y workers cannot finish the capsuling process • If the synthesis process is too short, the number of capsules will not be maximized • There must be a critical time slot (s – t), such that – More than t units of time, the capsuling process cannot be finished – Less than s units of time, the number of capsules will not be optimal Possible Idea 1 • One might use binary search to locate one terminal of that time slot t • Is t units of time the answer? Tricky Part • In that time slot, the number of capsules can be produce might be identical • Recalled from the problem statement – “If there are multiple solutions that can maximize the number of capsules, output the earliest time for the shift” • Obviously finding t is not good enough • What should we do to find s? Possible Idea 2 • After the binary search, we’ve already known the optimal number of pills we can make • Studying the property of s – Using less than s units of time, the number of pills apparently is not maximum – Using time from s to t, the number of pills is identical • In other words, s is another critical point Solution 2 • Write a function to achieve this – given the time the workers finished the synthesis work, find the number of capsules they can produce • • • • Use binary search to locate t from 1 to T Use binary search to locate s from 1 to t Complexity = O((X + Y) ln T) Score = 100 Observation 2 • Using two binary search is not convenient enough • For example, – X = 1, he need 3 units of time to produce a pill – Giving him 3, 4, 5 units of time, the number of pill he could produce is same • Once we locate the time of t • Find x = min(t mod Ta[i]) • The optimal time is actually t - x Solution 3 • Write a function to achieve this – given the time the workers finished the synthesis work, find the number of capsules they can produce • • • • • Use binary search to locate t from 1 to T Find the minimum modulus Output t – x and the pills can be made Complexity = O((X + Y) * ln T) Score = 100% Tricky Case • If the time is only enough to produce 0 pill, what should we output? – (0, 0)? • No! • As the boss is very mean, X workers need to prepare and clean up before Y workers arrive • END