Hello, Codeforces!
We are pleased to announce the resumption of the Global Rounds. Thanks to XTX Markets for supporting the initiative! In 2024, we will hold 4 such rounds. The series results will take into account the best 3 participations out of 4.
On Oct/27/2024 17:35 (Moscow time) we will host Codeforces Global Round 27.
Codeforces Global Round 27 marks the third round in the 2024 series of Codeforces Global Rounds. These rounds are open and rated for everyone.
The prizes for this round are as follows:
- The top 30 participants will receive a t-shirt.
- 20 t-shirts will be randomly distributed among participants ranked between 31 and 500, inclusive.
The prizes for the 4-round series in 2024:
- In each round, the top-100 participants get points according to the table.
- A participant's final score will be the sum of the points they earned in their 3 highest-placing rounds.
- The top 20 participants across the series will receive sweatshirts and placement certificates.
We extend our gratitude to XTX Markets for supporting the global rounds initiative in 2024!
The 8 problems were authored by our 8 authors: Benq, lunchbox, oursaco, sum, willy108, Hori, turtletortles, and last but not least ChatGPT.
We would also like to thank:
- Our coordinatorz Sugar_fan (first time) and errorgorn (almost last time)
- Our testers jqdai0815, SSerxhs, RDDCCD, wygzgyw, fallleaves01, triple__a, tarjen, omeganot, Yam, InternetPerson10, EmeraldBlock, Cai_Guang, Tobo, jay_jayjay, Nanani, ezraft, myst-6, Mr.Pie, AbduSaber, A_Nafees, Timosh, redpanda, newb_programmer, Jasonwei08, koolkid403, ShineChang318, khluo
- Alexdat2000 for translating the statements to Russian
- the one and only KAN
- MikeMirzayanov for creating the Codeforces platform
Round Information:
- Duration: 180 minutes
- Number of problems: 8 problems with 1 subtask
- Score distribution: 250 — 500 — 1000 — 1500 — 2000 — 2250 — (2250 — 2000) — 4500
We look forward to your participation!
UPD: Congrats to the winners
UPD2: First solves
A: dXqwq
B: hos.lyric
C: dorijanlendvaj
D: riantkb
E: turmax
F: taeyeon_ss
G1: taeyeon_ss
G2: Kevin114514
H: orz (only in contest solve!)
UPD3: Editorial
As a setter, I was unable to get a picture of myself eating [] before this blog was posted.
As a tester, I am glad willy108 was unable to eat [] before this blog was posted.
As a tester, love the contest, love the problems!
and orz willy108
No wonder you love it because I'm about to get -1000 delta on it...
based
actually, now i can tell you that i love it because sammyuri will make top 20
As a setter, I can confirm this contest is one of the contests of all time.
orz
I love newbies just as much as I love ChatGPT
im a newbie, could u plz help me getting z best benefit of this "codeforces" , i am really confused with it ..
i have some questions i just need u to awenser it for me :) 1- where and how to find problems to solve Gradually? 2- when i will be ready to enroll one of these contests that is published on here? 3- how much time should i spend here a day? thanks in advance :)
First of all you are not a newbie :)
i am very excited
Admin, He slunged in Bangla here. Please look into it
joy bangla!!!
lol
BENQ ROUND ORZ
TAKE THIS ROUND
As a tester who has not tested yet, the problems are very good and you should take the contest!
orz
If you hasn't tested, said that it's good, but in fact it will be bad, I'll find you.
Hope to see tourist register for this contest.
orz
keys is gonna cook
Orz
orz Sugar_fan
Chatgpt authored a problem!??
non-negative votes for comments, blog.
Benq round orz
Funny time is comiing
How can ChatGPT be an Author? :). How can I make questions using ChatGPT?
as a tester...
As a tester, I want to orz willy108 for also playing Arknights.
Is there a rating?
Would unrated registration will ever be available on div.1s? It seems like this is the 4-th div.1 that could have unrated registration enabled.
qp
Hoping to become purple after this contest!
Same here
lesgo
wanna see tourist vs jiangly today
Hoping to see jiangly reach tourist!
Maybe in the next div1 contest
Hope to reach expert today!
Excited to see jiangly reaching 4000 & the new name for 4000<=.
Well it's not possible today.. Two more contests needed
It was wriiten the problems are made by ChatGPT.Is this a person or literally ChatGPT ???
tourist has registered for this contest. His rating is gonna change today. I hope he will cross $$$4100$$$
That's not possible cuz he will get at max +70 as rating increase is very slow at that level
Ohh yeah, But he will cross $$$4050$$$ at least I hope.
He is in a position where if he didn't get the first position among RED coder's he will get mines(-)...
As a tester, I really hope yall enjoy this round!
omg ChatGPT has the rating better than me :penguin:
will this be rated
no
So you are saying ChatGPT is an expert in codeforces.
Best wishes
it is rated or unrated ??
fifty-fifty
So, ChatGPT is expert?
I was sweating while solving C
Was this rated?
OK..Stuck on D forever with WA on pretest 2.
Guessforces
Nice D have to study about it
I'm really not a fan of B, I honestly don't think I would have solved this problem in a "no internet" contest because who remembers the divisibility properties for 11...
Why do you need it? I almost immediately understood, that the solution is written on the screen.
Note that $$$33\cdot10^n$$$ is divisible by $$$66$$$.
I dont think we need the divisibility properties of 11. We can only use 3 and 6 as digits, and the number is to be divisible by 66, so the number must end with 66.
Then you need to add 33 * pow(10, x) always, and you cannot have 9 as a digit in the resultant number. So, by logic we have answer ->
for n >= 4: concat(333333....(n — 2)times, 66) when n is even and concat(33333...(n — 4)times, 6366) when n is odd.
Then you can handle cases for n < 4.
Neither did I. Fun part: If you divided the solutions in the tests by 11 you'd get something very interesting.
when I looked on "n = 500", I started observing the testcases on the screen and I got it it only about 3s.
Sample just gives the answer. You can also just dp with the remainder, no need of any math.
god D made me so pissed, I was only getting the last number from the last test wrong i changed all the MODS, reviewed all of them and still wrong
u must be using mod somewhere where u shouldn't be using it
yea yea
Nah, I can assure you it is not that easy. Most probably, your algorithm doesn't even work on case #2 in the sample. Just check it.
well I think my answer had some consistency I accumulated the distance from every number from the very least significative Bit to the first Bit, and thats the number of times I could multiply a number by 2. Then I right shifted all the numbers the amount of times they could be shifted, and for every query, I get the preffix sum of all shifted numbers + the max shifted numbers left shifted the amount of times I accumulated b4
rip in piece i got unlucky on D (first try AC but i way overcomplicated it)
Can you verify if this approach is ok I maintain a 2 stacks one with the value and one with the potential
the value is essentially the number that remains after we remove all the 2 from it if the last number is greater the the value of the stack we maintain we remove that and add it's potential to the potential of the current number ,and subtract (last_elem-1) * (2^its_potential) to the ans and at the end we add curr_elem * (2^curr_potentail) to the ans and stack
cache the 2 ^ power into and array
I spent 1 hour + on this still wa on tc 2
There's a case when the power of $$$2$$$ is too big, you need to handle correctly.
I think I did that
I initialized a big array with powers of 2 and applied mod on it
Have to see what that elusive test case is tho!
Maybe the way you use modulo. Take a look at the line 48. When you subtract, you need to add it to modulo instead of just using
%
operator.Just checked my submission , You are right
while multiplting I naively assumed that it will stay in limit but it did not
I did c += (b*d) => overflow occured
instead of c += (b*d)%1000000007;
I feel so dumb, Forever stuck on D, Need to improve on my debugging and analysing skills
Me too
Quite expected when,
Peter
opts to beBond
instead of beingParker
.xD.
Me too :D
Can you please tell us which one chatGPT made?
Too weak for C again... GG
How to solve D?
I used monotonic decreasing Stack, which stores Odd values and powers Of 2.
You can refer to my submission. I have tried using as much as verbose variable names. In case you still have doubts, you can ask me.
https://mirror.codeforces.com/contest/2035/submission/288353463
ObservationForces
That is what CF is supposed to be, yes.
Most of the CM / Experts(including me) tried a lot to pass (bruteforce + ternarySearch) to pass pretests for problem E.
E has some sort of
There are multiple local minimums. How to find the optimal local minimum ?
Use sqrt-decomposition. You can refer to 1954E - Chain Reaction
ohhh, Understood. So for each square-root, block, we need to apply ternary search. Is that right ?
( haven't looked at your solution, Want to solve on my own. Will check your solution, if I can't solve it ).
Thanks for the hint !
you dont "find" the local minimum, you bruteforce!
let A be a chain of k operation 1s and 1 operation 2 (in that order)
optimal answer would be A repeated some amount of times -> op1 some amt (must be <= k) -> op2 some amt
brute force through number of A repeats -> sqrt(z/k)
if k is small (k <= 1e4) -> number of op1s is bruteforceable -> sqrt(z/k)*k = sqrt(zk) but k <= 1e4 so at worst it's 1e6 per case
if k is large then the number of op2s so that number of op1s is >1e4 is also small (i wasnt able to exactly calculate the amt but it should run fast enough)
Okay, I tried something similar, but couldn't pass.
prob some bad implementation (or youre missing some optimizations) cause mine ran in ~200ms
Check my 288346163. I used ternary-300 optimization to pass it. I will write a blog about it soon.
Thanks a lot, waiting !!!!
Is this guaranteed to find the global min? It looks heuristical
Of course it is heuristical. If it wasn't, we could find global minimum of a random function. It works because the function is close to unimodal.
got it. I'm wondering if there's a condition where it will provably find it.
like maybe if f(x) is almost unimodal and there exists some unimodal function g(x) s.t. abs(f(x)-g(x)) < C then it'll find it
What does Authorized by ChatGPT means
how to solve C?
find patterns in sample testcases
Well, I didn't find any pattern. I did simple maths. you only care about last 3 to 5 values last values
if odd then obviously the max you can get is just n, and if not odd, then you can set all bits that are present in the permutation, by doing the same thing as with n-1, but just adding result^(n-1) at the en
so for odd I just have to print 2 1 3 4 5 6 7 8.. but what for even?? tbh I got destroyed by this C :( too tough for me
You print whatever at the beggining and at the end print 1 3 n-2 n-1 (res^n-1). where res is the highest set bit in n times 2 — 1
ahh okay I upsolved it with little different approach that if n is a power of 2 or n is odd then max answer we can get is n and so I printed it like 2 1 and then 3,4,.. else i took the highest power close to n which is less than it call it x I printed 2 1 3 4 till x-2 and then from reverse I printed n to x-1
For even $$$n$$$, the intuition is as follows,
First of all you can show $$$k$$$ can always be $$$2^{\lfloor\log_2 n \rfloor+1} - 1$$$ if $$$n \geq 4$$$ and we are given $$$5 \leq n$$$
Now for explanation, consider n = 10. Let $$$p_n = 2^{\lfloor\log_2 n\rfloor} = 8 = 1000$$$.
We know $$$k = 15 = 1111$$$, so there must be an $$$x_n$$$ such that $$$8 | x_n = 1111$$$. So, $$$x_n=0111$$$ (not $$$1111$$$ as that does not exist in this permutation).
Now, we want $$$p_{n-1} \land x_{n-1} = 0111$$$, thus $$$p_{n-1} = 0111 = 7$$$. Now we can fix $$$p_{n-2} = 6 = 0110$$$ and $$$p_{n-3} = 1 = 0001$$$ as we can observe their OR gives us $$$p_{n-1}$$$.
Finally we just need to ensure that $$$x_{n-3}$$$ is odd so $$$p_{n-3} \land x_{n-3} \neq 0$$$. This we can do by letting all even indices from 1 to $$$n - 4$$$ be odd and odd indices from 1 to $$$n - 4$$$ be even. Thus at each OR step, we would be ORing with an odd number. Since $$$n$$$ is even $$$n-3$$$ is odd. So if we are ORing at $$$n$$$-th step, we are ANDing at $$$n-3$$$th step. But $$$n-4$$$-th step would have an odd number as per our construction so $$$x_{n-3}$$$ would be odd!
Final permutation looks like this: $$$\text{odd}_1,\ \text{even}_2,\ \ldots \ \text{odd}_{n-4},\ 1,\ n-2,\ n-1,\ n$$$
Here
nice problem D need 2 more minutes to submit :(
In problem D, "Since this problem is too easy" killed me.
+1
If there's no elegant solution for B and C then they are not good, since it's casework for odd\even basically. D and E on the other hand are great, thank you.
I thought there must be some proof and did not see the standings assuming it was hard, i fcdkup :)
To be fair, C really just boils down to solving for $$$2 \cdot \lfloor \frac{n}{2} \rfloor$$$ so idk if it is fair to call it casework.
i hate overflow :(
For C, I just got the pattern for $$$n > 4$$$. if $$$n$$$ is odd, a permutation of $$$[2, 1, 3, 4, 5, \dots, n]$$$ always gives the max answer which is $$$n$$$. For even the maximum answer will be $$$2^{p+1}-1$$$, where $$$p$$$ is just the number of the leftmost bit, and it's still the same pattern but $$$2^p-1$$$ should be the last number. but if $$$n$$$ is a power of $$$2$$$ it should be the last number after the $$$2^p-1$$$. I want proof of this.
I solved C by guessing but got stuck on both D and E. I enjoyed the contest though, D is a great problem in my opinion. I think I was missing the case where it was a situation like [4, 4, 11, 2, 3], and the max array would be [1, 1, 176, 1, 6], not [1, 1, 176, 2, 3].
Can anyone Share Idea of problem C ?
Try to get $$$2^{k}-1$$$ for even numbers.
how to get the permutation that fits 2^k -1?
If $$$2^{k-1}<n<2^{k}$$$, the array ends with $$$[2^{k-1}-1, (2^{k-1}-1)\,\text{XOR} \,\text{lowbit}(n),n]$$$. The $$$\text{lowbit}$$$ is to ensure that $$$n$$$ can fill the zero bit that the previous item of $$$n$$$ causes.
If $$$n=2^k$$$, the array ends with $$$[1,3,n-2,n-1,n]$$$. $$$1$$$ is to fill the last bit that $$$n-2$$$ lacks
If $$$n$$$ is odd, note that $$$a\,\text{AND}\,b\le a$$$, so $$$n$$$ itself is the maximum and you can just put $$$n$$$ after your even array to reach the maximum.
Thanks, I got the even/odd observation. But miss the [1,3,n-2,n-1] could be a thing... I was desperate to code a dfs and pray that I have enough luck but I guess I don't
It's always possible. There is always a number
m < n
such thatn|m
gives all ones in binary so last but one should be thatm
which is actually odd. So its now reduced to odd case from here except for edge cases for numbers less than 5Why I found D easier than C :(
IDK why it was happening while doing C my brain not Braining I was not able to focus on the pattern.
Damnnn any ideas ?
How to solve D?
i did dp till index i such that total power of 2s <= 32 and then do greedy aferwards
can't submit during contest, but let see if that's correct or (hopefully) atleast the idea is correct.
For large enough ($$$\geq 8$$$ works) even $$$n$$$, you can just end the permutation with $$${1, 3, maxpow-2, maxpow-1, n}$$$, where $$$maxpow$$$ is the greatest power of $$$2$$$ that's $$$\leq n$$$, which ends up with having all bits that are set in at least one number $$$\leq n$$$ on, so the answer is $$$2*maxpow-1$$$. A greater answer is clearly impossible. And for large enough odd $$$n$$$ ($$$\geq 8$$$ still works), you may note that the result is bounded by the last element of the permutation, and therefore by $$$n$$$. And the result $$$n$$$ is achievable by putting $$$n$$$ at the end of the optimal permutation for $$$n-1$$$. Cases where $$$n<8$$$ can be hardcoded.
I am not able to solve the problems after the contest. I am getting "You can't run practice now or contest does not support practice" error.
You've to wait until system testing ends.
thanks for reply. how long will it take?
Editorial?
Contest ended $$$20$$$ minutes ago. The editorial isn't usually published that early. I'm sure it will eventually appear.
there are cases where they immediately publish an editorial
There are. Not very often, and there are also cases where the editorial is published $$$3$$$ hours after the contest. I think out of the $$$12$$$ contests I participated in, editorial was published immediately twice or something like that.
the fact that you almost once reached master within just 12 contests is WILDDDD, username checks out
I think he is an ALT user. If not then Mad Respect. ORZ.
I'm not an alt user, but I started with competitive programming (olympiads and stuff) about $$$2$$$ years before joining Codeforces, and I've been doing math olympiads even longer (which also helps).
During this contest my mental health dropped to a new record.
hints for F?
minimize something => binary search
Why are global rounds always so hard :sob:
Because they are global rounds :)
Weak systests on E, incorrect "sqrt" decomp (~2e7 ops/tc worst case) passes in 500ms:
https://mirror.codeforces.com/contest/2035/hacks/1094322 (uphack of my own sol)
Didn't think to pick my parameter correctly. Didn't matter.
Even my C $$$maybe$$$ hackable.. for even $$$N$$$.
I like the essential observation part of problem G, nice! However reading a binary search using closed interval ($$$[l, h]$$$ instead of $$$[l, h)$$$) was painful, please go learn X(
I agree wholeheartedly with $$$[l, h]$$$ being painful.
Pressed submit and timer ended 1 second before. Tried submitting after system testing. It was AC. :(
next time u will get ... fosho ! just don't give up.
Why is the amount of wrong submissions for E more than $$$11$$$ times the amount of correct submissions, what was going on
Same mentioned here.
Me who submitted it 15 times: I first ran into a wrong idea that a single ternary search would work. It turned out that it doesn't work because it can have multiple local minimums. It was too late for me to carefully think of a right approach, so instead I could only try to add some extra ranges to search and hope that they are enough. None of them could pass pretests.
bruh, the round was sweaty to be fair. Anyway ,returned ,my expert after a disasterous div2 yestersay.
Loved the contest, thank you! G is cool, F is nice, D is nice, E is OK, and B&C are also OK.
Missed the trivial "remove every test" case in G1 :(
hope to have rate soon
whats wrong with this approach on D? I couldn't even match the sample test cases on this one :(.
Thanks in advance.
Nevermind, overlooked something in the question.
How to solve D?
My final code was edit distance 2 away from AC-ing E...:(
Hint to D:
Let us pick $$$a_i$$$ and $$$a_j$$$ and decompose $$$a_i$$$ into $$$a_i=p_i\cdot2^{q_i}$$$ where $$$p_i$$$ is odd and $$$q_i>0$$$. Performing the operation on $$$a_i$$$ and $$$a_j$$$ is optimal if and only if $$$p_i<a_j$$$.
Liked C a lot:
Maybe a bit harder than a regular D2C, but definitely solvable (and in many approaches, whats not always a case). It's generally hard to create a good problem for position C and today it was just awesome.
Interestingly enough the answer for lower $$$n$$$ is just the identity permutation. I still decided to remove it so people didn't get confused by edge cases.
Bad decision, you should've done everything in reverse: made $$$n \geq 1$$$, made $$$1$$$ multitest in examples with $$$n=1,\ 2,\ 3,\ 4$$$ and printing identity permutations as answers for them. Doing so we would see a lot of noobies sending solutions with just printing identity permutations xD xD xD
ty bro <3
For problem D, I didn't understand how to use the modulo. When I apply it to intermediate results, it gives me the wrong answer. If I only use it at the end, I get a TLE. I believe the numbers are getting too large. Any help?
In my correct submission, I apply it while calculating answer for each index but I store numbers num = x * 2^y as (x, y) , where x is an odd number (Edit: clearly here x and y will always lie in int range as per constraints in the problem). And while comparing I use log2 of the num which is log2(x) + y, which gives correct comparison.
Thank you for the explanation. but, still I didn't get why applying the modulo for every intermediate result cause a wrong answer!
I don't exactly know in which steps you are applying mod, but if you apply mod and then some comparisons on some value on which mod is already applied then you should expect wrong results.
Or else, maybe your solution which gives TLE is also wrong, just that it gives tle before detecting wrong answer in the test cases (maybe). Is there any test case which passes the TLE solution but gives wrong answer verdict on your other solution.
Without applying mod on the count TLE on test 3
Applying mod on the count Wrong answer on test 2
so, If i'm not applying mod it works, but it gives TLE because of applying arthimetic on large number. when I apply the mod it gives wrong answer.
so i realised i was applying modulo correctly but missed the 2s > 30 thing where u dont (2 ^ 2s) with the odd number, how exactly does it help in getting the correct result?
Numbers quite large. So, instead of doing the multiplication, you just need to store the oddNumber, and powerOfTwo everytime you process the value. This will help in managing integer overflows ( although, in python u won't get any ).
In problem D of this round, it has missing test cases. One missing test case that I found, which potentially could give rejected verdict on some submission:
1
3
999999986 2097152 1048576
My last submission 288365525 during contest gives correct answer for it, but my earlier submission during contest gives wrong answer. But still when I resubmitted my earlier submission 288377619 after the contest ended to check if it passes system tests, unfortunately it passed!!
Explanation of mistake in earlier submission:
My approach for above given test case:
given n = 3, and array a = {999999986 2097152 1048576} = {499999993 * 2^1, 1 * 2^21, 1 * 2^20}
for i = 1: f[a1] = a1 (obviously)
for i = 2: f[a1, a2] I first check if I can transfer power of 2 from earlier indices which have power of 2 and increase the total sum.
I check it as if last_element_having_factor_2/(power_of_2_in_it) <= current_element, then transfer the power.
Since, transferring power from a1 to a2, will reduce the total sum, so I don't do it here.
So, f[a1, a2] = (999999986 + 2097152)%1000000007;
for i = 3: f[a1, a2, a3]
last previous index which has power of 2 is a2 which is 1 * 2^21 and since 1 <= current_a3 (1 * 2^20), so I transfer the power from a2 to a3, then a3 becomes 1 * 2^41.
then last element which has power of 2 is a1 which is 499999993 * 2^1 and here is where there is silly mistake in my older submission which still passes the system test cases.
In my correct solution I check if log2(499999993) <= log2(1) + 41 , but in older submission I checked if 499999993 <= 1 * (2^41 % 1000000007), which gives wrong answer as it does satisfy the condition to transfer the power, but it should.
So, correct answer = (499999993 + 1 + 2^42)%1000000007 .
But my other submission (which passes the system tests) gives answer = (999999986 + 1 + 2^41)%1000000007 .
This modular arithmetic mistake could have been done by few (or maybe many) other users also. So Hori, would the test cases be updated and since many others might have done same mistake, would the solutions for problem D be rejudged for the contest or the updated test cases be used for further submissions only. Or test cases won't get updated as contest is over.
Edit: My flawed submission has been uphacked. I didn't know someone can uphack even after contest ends and hacking phase ends.
That's a valid test case that should be in the contest. Problem setters and/or testers should have added such test cases. Nonetheless, they should add it now.
There can be many such test cases, like
1
3
999999998 2097152 1048576
and many more, but unfortunately official test cases didn't have any of them.
hm using the log seems beneficial since no issue of overflow and mod can be used when decrementing/incrementing the sum
I don't think D is a good question about mod.
orz
Too many cheaters again today on D, submission blew up too much in the last one hour
I think, D was little difficult to implement. That's why people took time to fully implement it. Even, so many Red coders submitted D in the last 1 hour of the contest. Does that mean, Red coders also cheated !
Your assumption might be true in other cases, but IMO, today's D was actually time-consuming to implement.
problem D, why my code is WA ~~~~~ import sys
MOD = 1000000007
def Pow(a, b): res = 1 while b > 0: if b % 2 == 1: res = res * a a = a * a b //= 2 return res
def main(): input = sys.stdin.read data = input().split() t = int(data[0]) idx = 1
if name == "__main__": main()
~~~~~
can anyone tell me what is i am doing wrong in my code for 4th question code---
~~~~~~~~~~~~~ #include
include
include
include
using namespace std;
int main() { long long T; cin >> T; while (T--) { long long n; cin >> n; vector nums(n); vector ans; // Store the answer for each test case priority_queue store; long long sum = 0;
}// ~~~~~~~~~~~~~~~~~~
why noone mentions the anime Alya Sometimes Hides Her Feelings in Russian for problem C LOL
After seeing D: It's doable :) After trying D: Oh hell nawwww
https://mirror.codeforces.com/contest/2035/submission/288461359
Could anyone tell me what exactly I’m doing wrong with the modulo operation?
My int is set to long long. The commented lines are direct multiplication and the for loop does *2 step by step.
like global rounds for interesting tasks
is system testing done till this round?