Добро пожаловать на 2016-2017 CT S03E01: Codeforces Trainings Season 3 Episode 1 - 2010 Benelux Algorithm Programming Contest (BAPC 10). Продолжительность тренировки — 4 часа 30 минут. Тренировка открыта как для команд, так и для индивидуальных участников. После ее окончания вы можете дорешивать задачи тренировки или поучаствовать в ней виртуально, если не смогли принять участие одновременно со всеми. Пожалуйста, участвуйте в тренировке честно.
Так как это тренировка, то возможно набор задач будет расширен, если для значительного количества участников он окажется простым.
Условия задач будут на английском языке, ведь мы же готовимся к ACM-ICPC!
Удачи!
idleness limit excedded on dynamic ip/op problem F !! any flushing needs to be done for java ??
How can I find the time limit for each problem?
On the contest dashboard.
Can someone please explain the solution for the first test case for the "Collatz" problem?
Only after the contest.
for 12 backward ropes to be cut are coming from 24,22,...,14. forward ropes to be cut are originating from 5,7,...,11 so total ropes to be cut are 10.
А можно посмотреть на авторское/какое-нибудь AC решение по задаче H ?
Если все еще актуально — в тренерском режиме можно посмотреть
Тут наверное что то можно найти, если не ошибаюсь.
In the Gene Shuffle problem shouldn't the output for the first seq pair be: 2-2 4-7 8-8 9-10 instead of: 1-3 4-7 8-8 9-10 ? seqs: [1 2 3 6 4 7 5 8 9 10] [3 2 1 4 5 6 7 8 10 9] 1-3 cannot be a minimal common segment as it contains 2-2
Please advice, Thanks,
Actually you have misunderstood the problem statement ! By minimal segment it means that i.....j can not be further divided into i...k and k....j
In your eg 1-3 has been turned into 2-2 but 1 and 3 have not been considered. But the problem statement expects CONTINUOUS segments of similar elements with different permutations.
So final answer shoould always be of form 1...k1,k2....k3,k...k,kn.....n.
A more clear problem statement would have helped
Can someone please tell me how to solve problem C? I think it is DP?
First calculate mm[i] for each subset i of 9 cells where mm[i] denotes the number of perfect matching for this subset. This can be calculated via DP/brute-force easily.
then let dp[i][j] denote the height i and topmost floor has subset j matched to i+1 then answer for any N = dp[N][0]. All values can be calculated in O(3^9*N) as follows:
Sorry... What exactly is the meaning of mm[i]? What is the value of mm[511]?
mm[i] denotes that if for the grid of 3*3(cells renumbered from 0..8) i denotes the subset which is non-empty then in how many ways they can be perfectly matched:
mm[511] = 0 since 9 is odd: no perfect matching
mm[510] = 4 : if you work on paper with only one corner cell empty there are 4 ways in which you can match all non-empty cells with their neighbours.
Let me check if I got the meaning of the DP function correctly...
f(i,j) = number of matchings considering floors 1 to i such that floor i's rooms in subset j are matched to their equals in floor i+1
Is that it?
Yes. So when j=0, you get answer for N as dp[N][0].
could you tell me the complexity of finding all subsets of x? THX
I have solved it
Can you post your complete soln ?? How did u calculate mm ?
Here is my complete solution: http://ideone.com/UT395f — though I calculated mm tediously using DP(I knew how to calculate number of perfect matchings using DP), this can be calculated using brute-force as well since there are only 9 cells.
Ain't that O(N*2^9*2^9)? Because x can have as many as 2^9 subsets if x=511
It will be for each subset sum of sizes of subset since the for(k=x..) loop runs only on the subsets of a set. And sum(each subset size of a set of size k) = sum((k choose i)*2^i) = 3^k.
Hence (3^9)*N.
I'm confused. It's obvious that
equal to
Also this 511 ^ (j | k) = j. Could you confirm or simplify this?
is not equal to
It means that we make a 'x' mask of elements which are not in 'j'.
This we can replace with
511 to binary equal 111111111 and j always less then 512, therefore 511^j = j. Am I right?
It took me a good amount of time to understand what the for loop for(int k = x; ; k = (k — 1)&x) does. Well done actually! sumit16 Does this algorithm has a well known name (for generating combinations of set bits of the set bits of an integer)?
I came up with a different approach from sumit16's DP. My DP also has O(N39) complexity and works as follows.
Let f(i, m1, m2) be the number of pairings considering floors 1 to i such that floor i's rooms in bitmask m1 still need to be paired and rooms in bitmask m2 are currently paired with the floor below, which is i - 1.
Then the answer is f(N, 511, 0): consider floors 1 to N, all 9 rooms in floor N still must be paired and no room in floor i is currently paired with the floor below, which is N - 1.
I'll use set notation for bitmasks when convenient.
Base cases:
$latexbug$
General transition (i ≥ 1, m1 > 0):
Let be any unpaired room (the smallest will do fine). Then:
$morelatexbug$
where V(j) denotes the set of neighbour rooms of j which are present in m1.
You're probably thinking: "this is a 4-state per element bitmask, so it runs in O(N49)!". Yes! But you can supress one of the 4 states. If , then j is already paired and cannot also be in m1. So you can translate a tuple (i, m1, m2) to an array indexing [i][x1][x2]...[x9], where xj = 2 if , xj = 1 if and , and xj = 0 otherwise. And you should store 2-byte integers, so MLE won't be a problem.
Full code: http://ideone.com/2dxXNW
Similiar DP approach, but (maybe) faster:
dp[layer][level][now_consider]: The first two dimension is the same as the dp mentioned above, while the third dimension is the cell we are considering. For a particular cell, we can either
ignore it (and match with the upper level one)
pair with the cell on the right
pair with the cell on the bottom
(To avoid duplicate, we don't consider pairing with cell on top or left).
The transitions are: if k == the bottom-right cell, we cannot pair it anyway, therefore we consider next level, i.e. (i + 1, j, 1) += (i, j xor 511, k) else, (i, j, k + 1) += (i, j, k)
pair with right: (i, j + bit(k) + bit(k+1), k + 1) += (i, j, k) if k is not the rightmost cells and the bitset in j allows
pair with right: (i, j + bit(k) + bit(k+3), k + 1) += (i, j, k) if k is not the bottommost cells and the bitset in j allows
As the transition is now O(1), the overall complexity is O(N * 2K * K), where $K$=9 is the number of cells
code: http://codeforces.me/gym/101078/submission/20441012
I have done something quite similar. But, I am getting WA if I consider pairin other than (right and bottom) ,such as(left,top).
Here's my code which uses (right and bottom) pairing: http://codeforces.me/gym/101078/submission/32757763
But it gives WA when I change the pairing to (left and top). Can you please explain this
You are not supposed to leave any cell empty, but let's say you start with the upper-left cell, then you cannot pair it with either left or top, which makes 0 possible solution afterwards.
I think my solution handles this.
can someone explain how to solve B??
the normal DP solution works: dp[i] = min time for first i songs:
dp[i] = dp[j]+(sum(j+1..i)>m?(sum(S_j+1..S_i)-m)*a:(m-sum(S_j+1..S_i))*b)
j varies from i-60*m..i by the condition that atleast one second for each song — this will give TLE
j varies from i-2*m..i — AC cause the min point will occur <=2*m.
O(n*m)
Dynamic Programming.
Let's define a cost function for which a block has to handle T seconds of songs. Since the penalty is the same for all songs, we should only worry about the total time we are trying to fit in each block. If you are trying to fit T seconds in a block, then depending on whether you need to cut or waste time, you should add the penalty.
Each block can fit a maximum of 60 * M songs. So we should only attempt filling at most these songs.( So you can assign each song a second).
For each block try giving j songs to earlier blocks, and fill i — j for the current one. ( Think of it as a standard N^2 DP). Obviously you should only loop till j < (60*M) so you can satisfy the above condition. This is too much however, the optimal point will always occur earlier, there are many tricks to do this, you can just plug in a value that fits the time limit, or as long as the sum of items is <= M. ( or till 2 * M).
Plz explain how you got both the j ranges !!
--
Could you please explain how do you limit the range to i - 2 * m
I think the tests are weak in problem A. I got it accepted, but my solution get TLE with test
Can someone please tell me how to solve problem J?
make a bipartite graph with H vertices on left, V on right. For each horizontal word i that conflicts with a vertical word j, edge between i-j. Answer = H + V — bipartite_matching(graph) cause min_cut is the minimum number of edges needed to be cut :D
the image is something so great :D
Help me please. How to solve problem I?
Use a doubly linked list and simulate the operations(list in c++).
Hey,, can u please check my code ,, i used list in c++ ,, n still my solution got TLE on test 2
Edit: you are doing some things differently which can be done simpler, see my code below. Also, maybe use fast IO.
i did not get ,, so if string is b<> ,, then i am moving my iterator for < and also for > ,, whats wrong in it ? your code?
http://ideone.com/9xwotO
The announcement was posted 6 hours ago, and the contest is already finished! What happened to making announcements at least one day in advance?
What about the 9th case in the last problem?
In this test case your solution does not give the minimum penalty.
Как решать Е(геом)?
Бинпоиск по ответу. Как проверять:
1. Сжать поле с 0, 0, w, h до r, r, w — r, h — r
2. Увеличить радиус всех существующих окружностей на r
3. Можно вставить окружность с радиусом r если есть точка, которую не покрывает ни одна из окружностей, и она находится в прямоугольнике(r, r, w — r, h — r -- координаты диагонали прямоугольника). Это по-идее можно проверять сканлайном, но я сделал функцию f(x1, y1, x2, y2) — находится ли хотя бы одна точка прямоугольника (x1, y1, x2, y2) вне всех окружностей. Если ни одна из точек не находится то я делю этот прямоугольник на 4 и ищу рекурсивно. Если в какой-то момент прямоугольник полностью лежит в какой-нибудь окружности то я вылетаю.
Editorials, solutions and everything is here!
UPvotes to you sir :))
Can anyone find whats wrong with my MAze Recognition solution ?? I just did dfs using the dynamic inputs to find final room . If no moves possible it comes back to previous room . Used stack to store reverse moves and kept updating ans if goal room found. http://codeforces.me/gym/101078/submission/20451114
EDIt: GOT it nvm
Can someone explain why my solution for A will get TLE on Test Case #2? I think it is still O(N)...
http://codeforces.me/gym/101078/submission/20452670
Use scanf and printf :)
Accepted! Never knew it makes that much difference...
Can anyone explain their detailed approach to C? I can't understand the editorial.
Consider mm[1<<9] array which stores the no. of correct pairing possible
mm[0] = 1;
for i=1 to (1<<9)-1 1. Choose a filled room say k ( whose bit is set to 1 in i ) 2. Its pairing will be above/below/left/right 3.mm[i] = mm[i-k-left] + mm[i-k-right] + mm[i-k-up] + mm[i-k-below];
Coming to dp part refer the dp soln in comment : http://codeforces.me/blog/entry/46993?#comment-313759
let dp[i][j] be no. of correct pairings such that floor 1 to i have been filled and set(j) rooms of floor i are to be paired with corresponding set(j) rooms of floor i+1
in the dp soln in comment, i stands for curr floor, j for set of rooms from i-1 floor which have to be paired with curr floor . Also see that the set(j) rooms have to be compulsarilty paired with set(j) rooms of curr floor. From the remaining (x in soln) 511 — set(j) rooms we have two choices : 1. Pair them on the same floor 2. Or else pair them with upper floor.
So k stands for set of rooms to be paired with upper floor. Hence dp[i][k] = dp[i-1][j] * mm[rooms to be paired on curr floor] = dp[i-1][j] * mm[511 — j — k ) since j and k rooms dont pair on curr floor.
Also pairings of curr floor have been calculated in mm. Note that k will always be a subset of 511 — j. Also final ans will be dp[N][0]
Thanks for the help! :)
How to solve K? Is that related to LP or flow? (Well flow can be done via LP anyway)
good luck to all
Hi I think my code 20456300 for problem A is wrong but I got accept with this code
here is a test case that I think my code answers wrong:
1
1 2 3 4 5 6 7 8 9 10
10 9 8 4 5 6 7 1 2 3
for this test case my code answers 1-10 but I think answer is 4-6 am I right?
see this comment http://codeforces.me/blog/entry/46993?#comment-313836
U misunderstood the problem statement
could u plz tell me problem G's data?
http://2010.bapc.eu/problems.html
Problem A.
Before add "ios::sync_with_stdio(0)" I got TLE, after then I got AC instead :(
Can someone please tell me how to solve problem E?
Please Someone say the output of this input for the problem B
1
29 15
3 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1
99
But Problem Says "At least one second of every single must be played" . Please Explain How 99 ?
Edit : Got it :)
How to solve problem K?
I tried with simplex but it throws Memory Limit Exceeded, any other idea?
can anyone give me some test cases for 'L' problem... i am stuck at test case 9...
Did you try to generate random test cases and use a model solution to check if your solution is printing right answer? It is usually in off, except for border cases.
iam trying to solve C with do but time complexity is 2^9 * 2^9 * 5000 this is done before the testcases and then every test at o(1) can anyone help me to reduce the time this is my code : Your text to link here...
What is idleness limit exceeded?