
Nihao! Hello to all fans of competitive programming and Codeforces enjoyers!
On behalf of Tsinghua University’s Zhili College, we — your proud and slightly sleep-deprived Class of 2029 Information and Computational Science students — are happy to invite you to participate in Codeforces Round 1097 (Div. 1, Based on Zhili Cup 2026) and Codeforces Round 1097 (Div. 2, Based on Zhili Cup 2026), which will take place on May/06/2026 09:05 (Moscow time). Note the unusual start time of the round. You’ll have 2.5 hours to tackle 6 problems for both division 1 and division 2, the round will be rated for all participants.
The score distribution will be announced later.
This round’s problems are brought to you by the incredible AC-Automation, graphcity, erduolong, Ge_QingHui, rsrsr, yangyuxi, schrodingerstom, unputdownable, lyreqwq, wangzhifang, aleph1022 and LinRui. Special thank you to thebighead and CharlieV who also prepared problems that were ultimately not used in this round.
A massive THANK YOU to the following legends who made this event possible:
The one and only KAN for his invaluable support in hosting the round.
Our chad coordinator, SSerxhs for coordinating this round, finding testers, and providing moral and technical support.
Our brilliant testers: XiaoXia, Liang_SYEA, fr200110217102, Nanani, Boboge, CReatiQ, triple__a, tarjen, permutation, SATSKY_2025target_LGM, fallleaves01, tiger2005 and turmax for testing and providing invaluable feedback.
Our fantastic organisers: schrodingerstom, lyreqwq, LitDarkness and kevinliu251831 for the smooth operation of the contest.
Our advisors Ruidong Wan, Yaqi Zhou, Yike Cao and Xi Wang from Zhili College for supporting our efforts and ensuring school approval.
Special thanks to Tsinghua University’s Association of Algorithmic Competitions for their support and help.
MikeMirzayanov and geranazavr555 for enabling this event through the amazing Codeforces platform.
Zhili Cup itself is an annual event hosted by Tsinghua University’s Zhili College along with its freshmen of ICS. We are delighted to meet you on Codeforces this year.
Good luck, and may your code be bug-free and your coffee cup never empty.
See you at the round!
UPD1: Score distribution
- Div. 1: 500−750−1500−2500−3500−4500
- Div. 2: 500−750−1000−1250−2250−3500
UPD2: The editorial has been published.








"Hope it doesn't become unrated" comments incoming
gl to anyone participating!!!
Hope it doesn't become unrated
Hope, I reach Expert :(
Reverse Jinx + Rating Is Useless Now
rating has always been useless
Just a number.
love your cameo in the prelast smiling friends episode, big fan!
Smoooooth Operator!!!!
I'm at school when this contest start, so I will
truantnot be able to participate sadly.one of the worst timing for me
i will be in school when it starts
Conducting contest on unusual time is better suited if contest is on weekend.
I’m very sorry that I won’t be able to participate in my first Div. 1 round after becoming Master because I have to take a flight.
As a PKUer, I sincerely hope that this contest hosted by Tsinghua University will be a great success.
As you know, I’ve always been a huge fan of Tsinghua University.
GL&HF to everyone!
why the unusual time :(
Another day time contest for chinese codeforcers,don't be unrated please
I actually hope some more events will be held at 14:05UTC+8.
22:35UTC+8 is not too Asia friendly.
i thought 14:05UTC+8 would be the time for school/ daytime of many Asia countries, but I didn't do any researches cuz i'm lazy so if I'm wrong please forgive me :D
Excited for Codeforces Round 1097
Big thanks to the organizers and problem setters for this amazing contest!
Ready to test my skills, learn new tricks, and hopefully keep my code bug-free. See you all in the round!
this timing is very unusual..i suggest unusual timing is on weekend is good not week day..also i am not excited tbh.
i won't be able to participate in this contest due to school :((
Bad timing.
btw, Tsinghua round again :(
Oh, Wednesday, I have to go to school :(
bro its at 2 am what
where are you from, for the contest to be at 2am in the morning?
USA
have you considered migration?
considered it but im lowkirkually broke
lollllll
Good luck, and may your code be bug-free and your coffee cup never empty.
The perfect time. I want all the rounds to be in this time :))
plz no problem leak thx
Codeforces said; unusual timing+weekday+rated
we said: sleep is optional T_T.
Good Luck everyone...
The Zhili Cup offline contest is held in Beijing exactly one day before APIO.
As an APIO 2026 contestant, I originally planned to go to Beijing for APIO and take part in the offline Zhili Cup at the same time.
However, the organizers recently revoked the eligibility of all middle school students to participate in the Zhili Cup, so I’ve ended up with an extra Div.1 contest before APIO instead :)
edit:

Have lost my chance to participate offline
Me too. They said I could go before, but now they've changed their mind.
And hope the problems won't be leak.
As a tester, wish you all perform at your best and enjoy the contest.
Thank you!
idk...
I hope to become purple this round pls.
TETOOOOOO GOOD LUCK
Goodluck! But I have to remind you last time Zhili Cup got a *2500 for D1B. It is crazy.
gl teto!
qp
May 6 is my only day(from May 1 to May 12) when I must go to school!!! (which means I can't participate in this contest)
Will be at college at the given time. cant skip because exams are goin on :(
What a Chinese Round but not Chinese-friendly time!
The perfect time. I want all the rounds to be in this time :))
I hope it goes well.
Hope it won't be unrated
Bro rlly has the nuts to disrespect a "Headquarters" member
1250 D and 2250 E in Div.2, interesting:)
Hopefully i don't get cooked this time!
gll!
May green elo find me please :)
As a tester, good luck to cute MaxBlazeIceInk and all other participants!
As a tester, I wish everyone satisfactory results!
Is it rated?
looking at the score distribution, ig i can do 3 to 4 problems fs
I hope to become specialist again :)
Is it still rated?
Until an announcement is published about this.
Small font for stories should become an industry standard!
Fortunately, I don't have school today.
dirtforces
Implementationforces.
Shorter statements -> Harder problems?
Fuck problem Div.2D,I optimized my code's time complexity it hit memory after that I optimized time and it hit time. I've tried ordered_multiset,segtree with compression,Dynamic segtree but none of them passed
Check out my submissions
sort + binary search is always quicker than data structs
another option is Fenwick tree
Why is the TL for problem div1-C so strict?
Agreed. I was stuck on TLE on pretest 18 for a while. Passed pretest after implementing offline processing(sorting queries by m), the constant factor without it is just too huge.
so that (n+q)sqrtn doesn't pass
Do we need to use CRT for congruences?
I didn't use it because $$$m$$$ is known
Only manage to come up $$$O(N^3)$$$ sol to D:(
this is when you lean data structure
no this is where you learn to use binary search
u don't need them in D
this round was total bs, every time tsinghua sets the contest either the problems are way too hard or some unrated mess happens, this time the anti-ai statements got completely messed up in codeforces better's translation (like that hidden html text got translated) and that's why i got 6 extra wrong submissions on a and b, plus problem d was insane, so disappointing and frustrating :(
feel the same bro, but not total bs enm, but wa 6 times really sucks XDDDDD
div2-D is supposed to be fenwick tree counting + compression right? My solution is like $$$O(N^2 * log(4e6))$$$. Should it be some kind of squeezing like global declaration to avoid overhead on allocating big vector?
you can do it with sort + binary search
Mb help if instead of
m[A[i] * B[j]], precalculate this tom[i][j]so get compress cord be $$$O(1)$$$.btw, it's also $$$ln$$$ in Fenwik
upd: yes, it's help
Ahh, again BIT >> ordered_set. Why I read once about ordered_set....
You can just use sort and binary search , I don't think Problem D with only 1250 points can use data structures.
wish time limits where less strict, got screwed by constant optimization on both B and C
Agreed :))
in div2D, my (n^2) * log(n^2) sol using pbds ordered-set TLEd (6seconds),
very sad.
rewrote with merge sort
why didn't you just put everything in an array and then did binary search on it??
It seems our approach is different, I like your approach.
Great round, thanks to authors!
speedforces
How to do problem E? :(
guessforces
Submission
The above submission passed all pretests, but outputs the incorrect answer for the testcase generated by:
Obtained answer: -36131418 Correct answer: 962112935
Isn't it too obvious for an expert to ask?
Yeah, did that in contest, was just pointing out that the tests could've been stronger.
Try Div2E and Div2F then :((
sorry for the wrong words. :(
Ok I don't know what is codeforces' policy on this but i resubmitted my TLE code for C after the contest and it got accepted. Is it possible to get a rejudge? This would greatly impact my rating.
During contest: https://mirror.codeforces.com/contest/2223/submission/373691965
After contest: https://mirror.codeforces.com/contest/2223/submission/373695945
The time limit for D1C is incredibly tight. My $$$O(n \log \log V + q \log^2 n)$$$ solution failed to pass (373689679), yet an optimized brute-force approach managed to get through (373668849). :(
I literally failed solving C(Div 1). Pure DFS works fantastic instead went with the binary lifting and other stuff damn ! I should have solved C. My bad !
Problem Div1 C. Zhily and Signpost technically violates input format. Problem statement says "The second line contains ...", whereas in test 2 apparently every test case has two empty lines between its "first" and "second" lines. I'm not suggesting any particular action, but SSerxhs, I'd like to ask whether this is considered acceptable on codeforces and hence something a participant should be prepared for.
Actually the test 2 is indeed respecting problem statement. If you check it, those lines are empty because
n=1in those cases and the second and third lines contain only values respective to indexes from 2 to N, which in this case, are none.You're right, thanks!
It was a bit of a mistake on my part. I asked writers to remove the $$$n=1$$$ case but forgot to verify if the update was made.
In my view, this doesn't strictly contradict the problem statement (i.e., the second line containing $$$n-1=0$$$ integers), but it's definitely a case we should try to avoid.
$$$n = 1$$$ is indeed presented in tests in the only correct format, my mistake. Personally now I don't think there's anything wrong with the problem, just an edge case. Sorry!
I found a very strange issue in problem C(div 1.).
In my original submission, I defined the function like this:
and called it in the DFS:
This version got TLE on test 18.
However, after only renaming the function from
lcmtoLCM/get_lcm, without changing the algorithm or any other logic:the code passed.
I guess this may be related to the standard library
std::lcm, because I used:So the name
lcmmay cause worse overload resolution / inlining decisions, especially since this function is called many times in a tight loop.Has anyone else encountered this? Why does naming the function
lcmcause TLE, whileLCMgets accepted?Update: fallleaves01 found the real reason.
It was not just a naming / inlining issue. The problem was overload resolution.
My own function was:
But I called it like this:
So the argument types were:
Because I had:
std::lcmwas also visible. Then overload resolution preferredstd::lcm<long long, int>over mylcm(long long, long long), becausestd::lcmmatches both arguments directly, while my function needs to convert the second argument frominttolong long.As a result, my overflow-limited
lcmfunction was not called. Instead,std::lcmwas called, so my intendedreturn -1behavior on overflow was lost. This caused the pruning logic to fail and eventually led to TLE.Renaming the function to
LCM/get_lcm, or castingsztolong long, fixes it:So the real bug was caused by the combination of
using namespace std, a function namedlcm, and passingszas anint.Thank you
After countless TLE submissions I finally got AC by renaming
lcmD<B<C(
I spent the entire contest thinking about Problem B. I really wanted to move on to the later problems, but I just kept hoping I could get Problem B accepted. In the end, I only managed to pass Problem A.
My score for Problem B is -15.It's absolutely terrible.
Hey, considering you're fairly new here, it's fine. It wasn't that obvious to be quite honest with you, you just need a bit more experience to solve those things. Not only in competitive programming, but also in math and other logic-involved areas.
Either way, you got +280 rating for your performance, which is definitely not terrible. My advice: try participating more in the Div. 3 / Div. 4 rounds until you start feeling comfortable there, tasks in Div. 2 are often hard for newbies.
I also took a glance at your last submission (373691388) for problem B. The immediate issue's here:
When a new
a[i]causes a gap (e.g.a[i]=2withlast=0), you correctly set the flag, but forget to addawa(the current MEX level, if I understood correcly) to the answer for that prefix and add only the MAX. Every later prefix that hits a duplicate correctly addsawa + a[n], but the transition one loses it's contribution. The fix is basically a single line:Also, for future reference:
unordered_map<int,bool> mp;is a risky move,vector<bool> mp(n+2);would be definitely safer while it still fulfills the original purpose. Doesn't affect this exact problem, but may in the future.Thank you. I just removed id=i; based on your revised code, and it passed (AC).
I can't speak on the intended approach on D but its quite unfortunate that the TL was tight enough that 373690993 the ordered_multiset approach of the same didn't pass but equivalent approach using Fenwick tree did.373699175
There is way to do it without any such data structure.
You can refer to this code : 373682811
It uses just the standard merge sort algorithm to count the number of inversions in an array in O(NlogN) time
I myself had 2 submissions with TLE on test case 3 with one of them using ordered sets.
A bad round!
Skill issue?
PLEASE SKIP XVIIIs SUBMISSIONSSS
How to do D2E / D1C. i can't think of any solution.
Suppose we go from the root with some value of $$$m$$$. Denote by $$$sz_v$$$ the number of sons of $$$v$$$. Suppose we are now at vertex $$$u$$$ and $$$L$$$ is the lcm of all the $$$sz_w$$$ for $$$w$$$ on the path from the root to $$$u$$$ except $$$u$$$. There are some interesting cases:
If $$$L \gt 10^{18}$$$ (we will call such $$$u$$$ as good nodes) then there exists the only possible value of $$$m$$$ which can lead us to this vertex and this value is the current value of $$$m$$$. So if we will visit the node $$$u$$$ again in the future we can immediately output the answer which will be calculated only once. Denote by $$$to_u$$$ the answer for $$$u$$$
If $$$L$$$ is divisible by $$$sz_u$$$(we will also call such $$$u$$$ good) then we know that for every possible value of $$$m$$$ which can lead us to this vertex there exists the only way do descend to the son of $$$u$$$. Denote by $$$to_u$$$ the first non-good vertex on the path from $$$u$$$ to the leaf.
Otherwise if $$$L$$$ is not too big and is not divisible by $$$sz_u$$$ then we just descend to the corresponing son. But this situation can only appear at most $$$\log{10^{18}}$$$ times
So the algorithm is the following(precompute $$$lcm-s$$$ on paths or if it $$$ \gt 10^{18}$$$ and the distances to vertices from the root):
It works in $$$O(q \cdot \log{m})$$$.
When reaching $$$u$$$, $$$v\in son_u$$$ is the next if and only if m satisfies a congruence equation corresponding to v, denoted as $$$P_v$$$. And you can use exCRT to merge multiple $$$P$$$s. Next, you can calculate every $$$Q_v=\text{merge}_{u\in anc_v}P_u$$$. For those $$$P_v$$$ whose modulus is a factor of $$$P_{fa_v}$$$, whether go to $$$v$$$ or not after $$$u$$$ is fixed. You can merge u and v or delete subtree $$$v$$$. So the modulus will at least double each step, achieving $$$O(n\log n+q\log V)$$$.
Also, for each heavy chain, a prefix of $$$P$$$ can be applied and further binary split to achieve $$$O(n\log n+q\log^2n)$$$
Salam! How to solve div2 D?
I solved it by counting for each pair of indices the number of permutations that results in an inversion at that pair.
The expected sum is then the sum of the probabilities of each pair being inverted.
code here: 373685119
I created video editorial for D. Zhily and Barknights
i think theres a lot of ways but u basically have to count for given i,j and a[i] a[j] how many pairs (ratios basically) from b give an inversion using a simple bs, and for each of them count how many permutations u can make from the remaining elements, and divide it by the total number of possible permutations. or u can use expectation linearity and probability of each pair gives the same exprsn finally
When will the editorial be released?
In fact, I think the problems set by Tsinghua in this round are really well-designed. Unfortunately, I didn't have enough time to finish coding Div2E (Div1C). What a pity.
how do E? the editorial wont open
Process all m offline by passing groups down the tree; each group maintains a modulus and a remainder, using this congruence state to characterize and distinguish its future propagation path.
Can anyone explain D1D? It seems quite interesting.
hello codeforces you have given that my solution of this round is match with Baishakh2/373663971 with this account and submission. but the both account is mine..i was late so i did contest with my 2nd account and after solvin i copied the code and submit same thing... so this Baishakh2 account is also mine..so please dont mind...i was not cheating just copied my own code..thats it. thank you @system / @codeforces check my comment please
Codeforces never supports a contestant using multiple accounts to participate in the same contest, let alone you directly copying.
can anyone tell the ratings of first 3 questions in div 1 and div 2
Appeal regarding plagiarism flag on Problem 2224D
I am writing to formally appeal the plagiarism flag regarding my solution for problem 2224D. While my code coincides with hs222 and sakuun, I can provide conclusive evidence that this is a false positive caused by the use of my long-standing personal documentation and algorithmic library.
Proof of Prior Ownership (Common Source Rule): The coincidence primarily involves my standard modular arithmetic functions and the Frac structure. These are part of a 2000+ line personal library I have curated for over a year.
Competitive Credibility: I am an active competitor in the Moroccan circuit. I secured 5th place (Silver Medal) in the 2025 Moroccan Collegiate Programming Contest (MCPC) Link to my certificate . My level of performance is consistent with the problem's difficulty, and I have historically used these exact templates in various rated and unrated rounds.
Context of Similarity: I serve as a lead instructor for the AppsClub at ENSA Agadir. I frequently share these templates with my students and teammates for training. While the flagged user may not be from my country, the algorithmic components used (Modular Inverse and standard Fraction structs) were partially curated using LLMs during my 2025 training phase. Per the 2024-09-14 AI Rule Revision, using AI to generate boilerplate/logic for training and library-building is permitted. The similarity likely stems from a shared "Common Source" generated by these standard models or shared training materials.
I am prepared to share my full library of files privately with the coordinators to verify that the flagged code is a direct subset of my pre-existing documentation.
Appeal regarding plagiarism flag on 2223B - Zhily and Barknights
I am writing to formally appeal the plagiarism flag regarding my solution for problem 2223B - Zhily and Barknights. While my code coincides with yuanyiguo , I can provide conclusive evidence that my submission is entirely my own original work and that this is a false positive caused by my code being copied by the other party.
Chronological Evidence and Coding Style Discrepancy: The coincidence is the result of the other user lifting my code, not the other way around.
Irrefutable Proof of Authenticity (Screen Recording): To ensure complete transparency and fair play, I recorded my screen during the contest. I have a full, uncut video recording of my entire session, which unequivocally documents my genuine thought process, typing, and debugging of the solution for 2223B - Zhily and Barknights from scratch.
Competitor Credibility and Track Record: I maintain a clean record of fair play. Conversely, the flagged user has a well-documented history of academic dishonesty in competitive programming. Their AtCoder account has been permanently banned previously (likely on multiple occasions) due to similar rule violations.
I am fully prepared to cooperate with the coordinators and provide any further details required to verify that my code is genuine. I kindly request that the administration review the video evidence and timestamps to overturn my penalty and clear my name. I have no idea how he obtained my code (he is definitely not my alternate account). However, given his blatant cheating behavior and past record, I strongly urge you to change his verdict to "Skipped" and consider issuing a direct ban to his account.
I'm stupid, I didn't go to DIV. 2
Seems like you both are using the same LLM model. Being caught by the cf plagiarism checker is a sign of great stupidity. Congratulations!
That's because I've been intensively training in competitive programming for two years. I performed poorly at the beginning because my original account (aaa_Pigeon) was banned as a suspected smurf account after doing too well in a Div. 3 contest (fun fact: cheating only gets your results skipped, not an account ban).
For reference, here is my AtCoder account registered a year ago: https://atcoder.jp/users/aaa_Pigeon
By the way, I submitted a complete screen recording as proof. What makes you think I used an LLM?
Are you just jealous that I reached IGM so fast?
Hey i just checked your submissions on problem https://mirror.codeforces.com/contest/2211/problem/E. This problem is interesting because it was hard problem for llm. And i compared your 6 submissions:
after each submission i see heavy editing(so you didnt have time to think on other approach) . but 5-th submission is completely new code you wrote it in 4 minutes.
That proves that you are cheater using llm. Thats explain why you instantly start to write a code after reading it. You just prompt it on another device and rewrite solution.
So your strength is not igm. You can cope and cry in comments. But now all your friends know your real face. Thats why you results in offline competitions are low. You are not him broski sorry.
Vladosiya
In fact, you'll find that these code implementations are equivalent; all I need to do is perform some mechanical constant optimization.
And the 5th code submission was actually the first one I wrote, but I already knew it was wrong before I submitted it. I only sent this one in because I couldn't figure out why my previous approach wasn't passing, and I thought, "What if this one works by some miracle?"
Actually the 5th submission is short.
I have seen his coding speed at offline, and it is not difficult for him to write such code in 9 minutes.
Edit: Sorry that I I accidentally took the submission time as his submission time during the competition.
In addition, he solved the problem "ascend" in the APIO2026 China region, which is a problem with a difficulty level of at least *3000. Why do you think he performed poorly in the offline exam?
I cannot understand why virtualjduge needs me to be greenname to submint my code.......
I think D2C is an original problem, and the solution to this problem can be exactly the same as that of the problem at https://qoj.ac/problem/10971.