We will hold AtCoder Beginner Contest 399.
- Contest URL: https://atcoder.jp/contests/abc399
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250329T2100&p1=248
- Duration: 100 minutes
- Writer: Nyaan, yuto1115, ynymxiaolongbao
- Tester: MtSaka, sounansya
- Rated range: ~ 1999
- The point values: 100-200-350-400-500-550-675
We are looking forward to your participation!








Hello AtCoder,
I think AtCoder needs development, Please stop blocking kenkoooo thanks. Or please add pages like My Submissions or Friends' Submissions on AtCoder. Thank you!
Besides, hope this round will be good. Last ABC is totally a speed round.
============================================
Update :
Not good, too :(
Problem E is well well-known and this is the link :(
And the problems' gap is too large for ABC :(
Debug & speed round :(
https://atcoder.jp/contests/abc399/submissions/64375281
can u explain the solution in short , because i am not able to figure out whats wrong i am getting WA in 4 cases
Edit : found my error
Man, try to debug by yourself because you can find the data here.
yeah sorry i got frustrated, finally got AC
Hi Atcoder,
Please stop unblock kenkoooo thanks.
hope I can slove $$$5$$$ problems!
hope I can slay 5 problems!
E has so many edge cases,also E<<F.
ikr, I got E in the last 30 seconds and 4 WAs.
How did u solve E? I converted it to a graph problem but kept getting 48/87 test cases
I also got that same count for a while. Convert this to a functional graph, then the idea is the answer is initially just the number of edges. However, consider some "pure cycle", wherein there is nothing coming off of the cycle. In this case, we require 1 additional operation to break the cycle by using some additional letter outside the cycle. Of course, to have this "intermediary" letter available, we also need to ensure beforehand that not all letters are on a cycle. Using these ideas and just carefully implementing is enough.
Damn, I got it right but missed the edge cases probably
I hope the authors will learn from the dissatisfactory experience they provided today.
origin of E
origin of F
Shit E playing joke on edge cases huh?
lmao same. I still dont understand what are those edge cases. Isnt it just finding number of cycles? or my logic is wrong for E
Not exactly. First, it's impossible if every node is on a cycle. Second, if for some cycle, there are ingoing edges into the cycle, then it's possible to solve this cycle without any extra operations. For example, if you have d->a->b->c->a, then you can do the operations: c -> d, b -> c, a -> b, d -> a, so you only need 4 and not 5 operations here.
mb thx for the explanation:)
Nice, this is the edge case I couldn't come up with.
I dont know, whats wrong with my approach i am getting 81/87.
My approach is to count number of pure cycles, if there is any pure cycle and all 26 characters are present in string s(ie all characters have outdegree==1) then answer is -1.
Other wise i report ans = (count of such character x that s[i] = x and t[i]!=x) + (number of pure cycles)
E
F
Just a cool observation. Also, F is too classical so I think AI can solve it. wtf
shit problem E. so many edge cases....
Hi, please help with problem E. Here is my Code
My logic:
1) Create a graph from s[i] to t[i] and if more than 1 outgoing edge then print -1
2) Count the number of cycles
3) Decrease the cycle count for each self loop
4) Answer = cycle_count + (number of non self loop edges)
5) If there is a cycle but no unused character in t, then print -1
F has an easier solution with prefix sums and Newtons binomial
I have a solution for F with O(NK). Here is my code
And its derivation is
A genious solution! So, we should first find the prefix sum of array-A, and then find the prefix sum of "this prefix sum", and also the power of 0,1,2,..k. Really wonderful idea, and thank you so much for sharing your solution.
Interesting E.
for Problem D: why am i getting WA ??? ~~~~~ void solve() { int n; cin >> n; vector v(2*n);
f(i, 0, 2*n - 1) cin >> v[i]; vector<vector<int>> pos(n + 1); f(i, 0, 2*n - 1) { pos[v[i]].pb(i); } // pr(pos); int cnt = 0; f(i, 0, 2*n - 2) { int a = v[i], b = v[i + 1]; int diffa = pos[a][1] - pos[a][0]; int diffb = pos[b][1] - pos[b][0]; if(diffa == 1 or diffb == 1) continue; vector<int> temp; temp = {pos[a][0], pos[a][1], pos[b][0], pos[b][1]}; sort(all(temp)); if(temp[0] + 1 == temp[1] and temp[2] + 1 == temp[3]) cnt++; } cout << cnt / 2 << endl;} ~~~~~
Your code is failing for testcase: (array of 8) : 1 2 1 2 3 4 3 4 Ans should be 2, but, your code gives output as 3.
Actually for case, 1 2 1 2, ans should be 2, but, you are reporting as 3.
why this gives WA in D?
This gives answer of 2. Correct answer should be 1:
What's the issue in my code for problem E
My submission for E