Hamed_Ghaffari's blog

By Hamed_Ghaffari, history, 9 months ago, In English

Hello, Codeforces!

We are proud to invite you to participate in Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2) which will be held on Aug/07/2025 17:35 (Moscow time).

The round will be rated for everyone. You will be given 8 problems, one of which is divided into two subtasks, and 3 hours to solve them. One of the problems will be interactive, so make sure to read the guide for interactive problems before the contest.

The problems are authored and prepared by Ali_BBN, Bahamin, _R00T, eren__, sweetweasel, and me.

We would like to thank:

Special thanks to [MVP] LMydd0225 for his invaluable help during testing!

The scoring distribution is below.

A B C D E F G1 G2 H
$$$500$$$ $$$1000$$$ $$$1500$$$ $$$2000$$$ $$$2500$$$ $$$3000$$$ $$$2750$$$ $$$2750$$$ $$$4000$$$

Now, a few words from our sponsor!

At Atto Trading, we are a science-driven quantitative trading firm where engineers, quants, and researchers combine their efforts to engineer cutting-edge trading systems that execute in nanoseconds, powering decisions at the speed of light in the world’s most competitive market. Many of our team members started their journey on platforms like Codeforces. We are thrilled to announce our own round on Codeforces platform.

Follow the link below and complete the application form to explore career opportunities with us.

Fill Form →

We prepared some exciting rewards for participants in this round.

  • Rank 1: Apple MacBook + backpack + branded T‑shirt + sports bag
  • Ranks 2-3: Apple iPad + backpack + branded T‑shirt + sports bag
  • Ranks 4-5: Apple Watch + backpack + branded T‑shirt + sports bag
  • Ranks 6-20: Backpack + branded T‑shirt + sports bag
  • Ranks 21-100: Branded T‑shirt + sports bag

If we encounter difficulties delivering your gift, we reserve the right to reimburse its value in cryptocurrency

Good luck!


UPD 1: Score distribution was released!

UPD 2: Editorial

UPD 3: Congratulations to the winners!

  1. ksun48

  2. jiangly

  3. turmax

  4. tourist

  5. jiangbowen

  6. zhoukangyang

  7. maspy

  8. ecnerwala

  9. Radewoosh

  10. 244mhq

  • Vote: I like it
  • +239
  • Vote: I do not like it

»
9 months ago, hide # |
Rev. 25  
Vote: I like it -10 Vote: I do not like it

as a tester, i can confirm the problems are "absolute cinema"

»
9 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

As a tester, “googooli” contest

»
9 months ago, hide # |
 
Vote: I like it +53 Vote: I do not like it

Nice problems, recommend to participate

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hoping for a positive $$$\Delta$$$

»
9 months ago, hide # |
Rev. 4  
Vote: I like it +3 Vote: I do not like it

Ayy, massive congratulations to Hamed_Ghaffari and eren__ for snagging silver medals at IOI2025! The GOAT has officially announced his round!

ORZ ORZ ORZ

And a huge shoutout to the entire Iranian National Computer Team for achieving the 7th global rank at IOI2025, with Hamed and Mani being a part of this incredible squad! What an outstanding achievement for all of you and our country!

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a tester, it would be fun for every participants, from gray to Nutella!

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a tester, this is one of the best rounds of the past 2yrs, I actually enjoyed solving the problems and didn't swear at the writers

»
9 months ago, hide # |
 
Vote: I like it +55 Vote: I do not like it

As the "MVP", I want to copy Error_Yuan's words: Nice problems, recommend to participate :)

»
9 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

as a tester, my biggest regret is not being able to participate in this round

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think the problem statements should be short and easy.

»
9 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

"What is the probability of me winning an Apple MacBook?"

»
9 months ago, hide # |
 
Vote: I like it -14 Vote: I do not like it

like this comment if you join this contest in order to miss gf :heartpulse :heartpulse

»
9 months ago, hide # |
 
Vote: I like it -15 Vote: I do not like it

as a tester, this contest is "MAMAMIA MAMACITA COACHELA"!

»
9 months ago, hide # |
 
Vote: I like it +24 Vote: I do not like it

August 7th is my birthday. Although I won't take part in the contest, best regards for everyone.

»
9 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

I'm new to comp. coding and this is my first contest, and I hope to give it my all. I love codeforces and the community so far :)

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why are the competitions held in my sleeping time?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can kevin exceed tourist?

»
8 months ago, hide # |
 
Vote: I like it -16 Vote: I do not like it

as a tester , I wish i could go back in time and choose to participate in this round instead of testing it ! :)

»
8 months ago, hide # |
Rev. 2  
Vote: I like it -28 Vote: I do not like it

.

»
8 months ago, hide # |
 
Vote: I like it -27 Vote: I do not like it

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Wish interactive problem is D.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Rank 1 tourist.

»
8 months ago, hide # |
 
Vote: I like it +71 Vote: I do not like it

It started with 9 rejected problems. It ended like this:

»
8 months ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

I originally planned but now I am unable to participate this round. Anyway, hope it has great problems and may it be cheater free!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Otto Round?

»
8 months ago, hide # |
 
Vote: I like it +15 Vote: I do not like it

Thanks! Hamed_Ghaffari for providing this Information and I'm so much excited to participate in this contest.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It is essential to identify and prevent the use of AI-generated code. Dear author, please consider taking appropriate action regarding this issue.

»
8 months ago, hide # |
 
Vote: I like it -26 Vote: I do not like it

It would be much better if you also gave away prizes for some of the ranks 100-1000. This would increase the competition.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

as it is a round sponsored by quant company i guess this will be a math round

»
8 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

Standings/leaderboard is broken? I can't open it

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    nope

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I can't open it either. Fortunately the rest of the system seems to work. With the dashboard you can see how many people solved a given problem.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it -8 Vote: I do not like it

      true, but what i wanted to know is whether i can safely go sleep without getting -delta

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I HOPE I GOT + Δ

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B>>

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

aaaaaahhhhh !!! got idea of D so quickly .. but the WA -> WA -> WA -> WA -> WA ..... -> WA -> AC

and 1 to 3 is CASEWORKforces

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +5 Vote: I do not like it

    u don`t need casework for C

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      or any of the A-C

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        oh ok .. I solved it that way ...

        for A -> I was thinking mex can be 0,1,2,3 ( but later realized not needed ) for B -> 2 cases ... go left or go right .. and put wall to left or put wall to right for C -> ranges overlap ... don't overlap.

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          feel free to check my submissions, i feel today's A-C I wrote it beautifully

          • »
            »
            »
            »
            »
            »
            8 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            I think you are awesome because you are able to think simple solutions .. my strategy is called PANIC and FREAK OUT

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      oh I did range merging kind of thing .. where I had to handle overlapping and non-overlapping ranges

      but I guess we can say minimum gap which I later figured out.

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Can you explain how you solve D

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it +3 Vote: I do not like it

          so if any cycle ... not possible .. ans = 0.. cycle check can be just m >= n because it is given that all are connected

          because if you have cycle then either edges will cross or it will not be bipartite

          otherwise it will be a tree

          now it has to be like a chain where every node with degree > 1 has to be along a chain ( like a linked list ) .. otherwise edges will cross .. if any node in that tree which has deg > 2 is connected to more than 2 such nodes .. .we return 0

          once you make that chain then it is kind of how many nodes are connected to chain .. product of their factorial ... because chain nodes are fixed but nodes connected to those node can be independently permuted so their factorials get multiplied

          then you can flip across the river so x2

          if length of chain > 1, then you can flip the chain so x2

          • »
            »
            »
            »
            »
            »
            8 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            Thank you, I had the same idea but cannot figure out the implementation.

            https://mirror.codeforces.com/contest/2127/submission/332891533

            • »
              »
              »
              »
              »
              »
              »
              8 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              yeah I also had hard time in this.. just look at my WA submissions .. so many :(

              ... got lucky like 5 min before end

          • »
            »
            »
            »
            »
            »
            8 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            My test case for deg>1 not in single chain also contained a cycle so it didn't catch my nonworking detector. Caught it right after the contest ended :/

            • »
              »
              »
              »
              »
              »
              »
              8 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              sorry !! not clear

              all nodes deg > 1 will be connected in a single chain right ... what do you mean not in single chain

              .. but I understand the frustration.. I also solved like 5min before contest after struggling for hours .. was almost crying LOL

              • »
                »
                »
                »
                »
                »
                »
                »
                8 months ago, hide # ^ |
                 
                Vote: I like it +3 Vote: I do not like it

                If any node is connected to more than 2 nodes with degree>1 then they cannot be put into a chain. My solution skipped already visited nodes so they didn't get counted. All I had to do was change count>2 to count>1 and it would pass lol

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  8 months ago, hide # ^ |
                   
                  Vote: I like it 0 Vote: I do not like it

                  oh no I get it ... lol .. I also wrote some messy code to handle this.

»
8 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

Struggled alot to understand questions :<

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

can anyone please explain how they solved D?

  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    It may not be difficult to implement, but it requires careful analysis of the problem For the problem to have a solution: 1. The graph must not be a circle (it must be a tree) 2. If we root the tree from a leaf, all children except one must be leaves (you can check) Then you have to go and multiply your answer by the following value at each step: (count is the number of leaves) ans *= count! ans %= mod Finally multiply by 4 (horizontal and vertical symmetry) We also have an exception!!! If the graph is star-shaped (all vertices are connected to one vertex) Then the answer is 2 * (n-1)!

    #include <bits/stdc++.h>
    using namespace std;
    
    /* Besme allahe alrahman alrahim */
    
    #define mod 1000000007
    
    struct Node {
        char color='w';
        int h;
        int par;
        bool barg=false;
        vector<int> hamsa;
    };
    vector<Node> nodes;
    int n;
    bool mishe=true;
    bool canzarb=true;
    long long ans=1;
    
    long long fac(int x) {
        long long ani=1;
        for(int i=1; i<=x; i++) {
            ani*= 1ll*i;
            ani%= mod;
        }
        return ani;
    }
    
    void dfs(int x) {
        nodes[x].color='r';
    
        if(nodes[x].hamsa.size()==1) {
            nodes[x].barg=true;
        } if(nodes[x].hamsa.size()==n-1) {
            canzarb=false;
        }
    
        for(int i: nodes[x].hamsa) {
            if(nodes[i].color=='w') {
                nodes[i].h=nodes[x].h+1;
                nodes[i].par=x;
                dfs(i);
            } else {
                if(i!=nodes[x].par) {
                    mishe=false;
                }
            }
        }
    }
    
    void dfs2(int x) {
        nodes[x].color='r';
        int all=(int)nodes[x].hamsa.size();
        int count=0;
    
        for(int i: nodes[x].hamsa) {
            if(nodes[i].barg) {
                count++;
            }
            if(nodes[i].color=='w') {
                dfs2(i);
            }
        }
    
        if(all-1-count>1) {
            mishe=false;
        }
        ans*= fac(count);
        ans%= mod;
    }
    
    
    void solve() {
        int m;
        cin>>n>>m;
    
        for(int i=0; i<n; i++) {
            nodes.push_back(Node());
        }
        for(int i=0; i<m; i++) {
            int a,b; cin>>a>>b; a--; b--;
            nodes[a].hamsa.push_back(b);
            nodes[b].hamsa.push_back(a);
        }
    
        if(n==2) {
            cout<<2<<endl; return;
        }
    
        nodes[0].h=0;
        dfs(0);
    
        if(mishe==false) {
            cout<<0<<endl; return;
        }
        for(int i=0; i<n; i++) {
            nodes[i].color='w';
        }
    
        for(int i=0; i<n; i++) {
            if(nodes[i].barg) {
                dfs2(i);
                break;
            }
        }
        if(mishe==false) {
            cout<<0<<endl; return;
        }
    
        if(canzarb) {
            cout<<(4ll*ans)%mod<<endl;
        } else {
            cout<<(2ll*fac(n-1))%mod<<endl;
        }
    
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    
        int t; cin>>t;
        while(t--) {
            solve();
            nodes.clear();
            mishe=true;
            canzarb=true;
            ans=1;
        }
    
        return 0;
    }
    
  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    First, note that if the graph isn't a tree (or a forest, but statement says it's connected), the answer is $$$0$$$, because there's no way to build a cycle of bridges without a self-intersection or a bridge connecting two houses on the same side. Then, note that assuming the answer is $$$ \gt 0$$$, in the tree, every vertex can have at most $$$2$$$ neighbors which aren't leaves, otherwise there is a non-leaf neighbor fully cut off by remaining bridges from this vertex, a contradiction. Thus, the non-leaf vertices of the tree form a path (assuming a non-leaf vertex exists, but otherwise $$$n=2$$$ and the answer is clearly $$$2$$$)). Then, note that there are either $$$2$$$ or $$$4$$$ "distinct" ways to create the path, depending on whether it's size is at least $$$2$$$ (choices are first riverbank and "direction"), and then for each vertex on the path neighboring $$$d$$$ leaves, they all have to be between the neighbors on the path in any order, so we get $$$d!$$$ options for each. Just multiply everything and we're done.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I was trying this, but only passed the given test case

    1. First assign 0/1 colours to all nodes; two nodes with an edge should have opposite colours. if not possible -> return 0
    2. Second, start with a node having degree 1, traverse all nodes, and only one of these nodes should have a degree > 1 to prevent the crossing

    If both of the above conditions are satisfied, then only we can have an arrangement

    For the total number of arrangements

    1. For every node having degree > 1, find how many nodes are connected with degree 1, because we can permute them. Let's say it is x1, x2, x3 and so on — then total arrangements would be x1! * x2! * x3! * ...
    2. Then we can flip up and down so multiply by 2 ( this is only applicable when there are at least 2 nodes with degree > 1)
    3. Then we can flip right, left, so again multiply by 2

    Not sure what is wrong with this approach. Can someone please point out the mistake

    • »
      »
      »
      8 months ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      Based on what you've written (haven't seen the code), you appear to be incorrectly answering the case when there's only one vertex with degree $$$ \gt 1$$$, and therefore the right-left flip doesn't do anything. EDIT: Checked the code and you did take care of that, so I don't know.

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        no that case is correct when only 1 node with degree > 1 then x1 will be n-1 I do not consider the up-down flip, so skips multiplying by 2 But I am considering a left-right flip, so multiply by 2

        The final answer comes out to be 2 * (n-1)!

        One clarification -> I am considering the right-left flip to be across the river — different from the picture given in the question

        -- I feel like my approach is correct, but I have made it unnecessarily complex, and must've made some implementation error

        Your explanation makes it much easier — thinking in terms of a tree. Thanks, will try to implement that

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          first off labeling nodes with colors isnt needed because the graph must be a tree, and all trees are bipartite graphs so you can check if $$$n = m-1$$$ instead. Second your "one of these nodes should have a degree >1 to prevent the crossing" is either wrong or worded badly. The right condition is that "at most 2 neighbors of any node can have a degree >1". There are only 2 places for a neighbor with degree >1 to fit (right and left) and any middle spot will cause a cross.

          Looking at your code, your counting seems right but you don't make sure the graph has no cycles and your double bfs for degree counting is funky.

»
8 months ago, hide # |
 
Vote: I like it +31 Vote: I do not like it

Was I the only one unable to access standings throughout the whole duration of the contest?

»
8 months ago, hide # |
 
Vote: I like it +38 Vote: I do not like it

Great problems! But sadly problem F is chatgpt-solvable. Proved by BinaryPhoenix10 and other talented participants. Bless them!

  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +7 Vote: I do not like it

    You are right! I couldn't find a solution better than O(nk) then I just search on chatgpt on find number of n-element arrays of sum y such that each element is at most k, and it gives me the closed solution using exclusion-inclusion. Then, I ask to do the same on number of n-element arrays of sum at most y and each element at most k, and it gives me a very clean solution computable in O(k) time (by using some combinatoric magic) which gives us a O(nlogn) solution! Too bad, I only read your comment after the contest!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

OHH MAN B WAS SO TOUGH . IS IT SAME FOR OTHERS?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    istg same

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    literally got me brainstorming with pen and paper for an hour. When I finally got AC, I was so happy.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      HOW DID YOU SOLVE IT CAN YOU PLEASE HELP

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        the formula is

        optimal = min(minCover + canCover, maxCover) + 1

        here minCover is the minimum of leftCovered and rightCovered. maxCover is max of leftCovered, rightCovered. leftCover is the distance between left most index (0) to the closest left side wall from the position of hamid, similarly rightCover is the distance between the right most index(n-1) and the closes right side wall. canCover is the distance between left closest wall and hamid, if leftCover is minCover or it is the distance between right closest wall and hamid if rightCover is minCover. The entire problem is based on which side will Mani put the first wall, once that is found, the problem will naturally be easy. The formula i told is based on which is the most optimal side to place the wall at

»
8 months ago, hide # |
 
Vote: I like it -29 Vote: I do not like it

My code for C Can anybody tell me where I m wrong

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define PB push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;

int gainFromPair(int a1, int a2, int b1, int b2) {
    vector<int> v = {a1, a2, b1, b2};
    int original = abs(a1 - b1) + abs(a2 - b2);
    int maxGain = original;
    sort(v.begin(), v.end());
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (i == j) continue;
            int a_i = v[i];
            int b_i = v[j];
            vector<int> remaining;
            for (int k = 0; k < 4; k++) {
                if (k != i && k != j) remaining.push_back(v[k]);
            }
            int a_j = remaining[0];
            int b_j = remaining[1];
            int val = abs(a_i - b_i) + abs(a_j - b_j);
            maxGain = max(maxGain, val);
        }
    }

    return maxGain - original;
}

void solve(){
    int n, k;
    cin>>n>>k;
    vector<pair<int, int>> a(n + 1), b(n + 1);
    for(int i = 1; i <= n; i++){
        int x;
        cin>>x;
        a[i] = {x, i};
    }
    for(int i = 1; i <= n; i++){
        int x;
        cin>>x;
        b[i] = {x, i};
    }
    
    int mini = 0;
    for(int i = 1; i <= n; i++){
        mini += abs(a[i].first - b[i].first);
    }
    
    vector<pair<int, int>> helpA = a;
    sort(all(a));
    int increase = 1e9;
    
    for(int i = 1; i < n; i++){
        int a1 = a[i].first, a2 = a[i + 1].first;
        int b1 = b[a[i].second].first, b2 = b[a[i + 1].second].first;
        increase = min(increase, gainFromPair(a1, a2, b1, b2));
    }
    
    a = helpA;
    sort(all(b));
    
    for(int i = 1; i < n; i++){
        int b1 = b[i].first, b2 = b[i + 1].first;
        int a1 = a[b[i].second].first, a2 = a[b[i + 1].second].first;
        increase = min(increase, gainFromPair(b1, b2, a1, a2));
    }
    
    cout<<mini + increase<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
»
8 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

I GOT THE BEST RANK I'VE EVER GOTTEN IN CF TODAY. I'M SO HAPPY.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

guys what this error Compilation error this is first time This appears to me

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    your code did not compile on judge compiler,

    if it compiled successfully on your machine then it might be setting difference.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to do C guys? I can't think anymore

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You can take some (i, j) pair over and over again so its basically solve for k = 1 everytime. Then u just need to find (i, j) pair that adds least amount to original answer and just take that all the time. Furthermore if u have a[i], b[i] and a[j], b[j] then this pair only adds extra if max(a[i], b[i]) < min(a[j], b[j]) or vice versa and it adds 2*(min-max). So we sort pairs {min(a[i], b[i]), max(a[i], b[i])} check if there exists any adjacent pairs such that min < max(basically add 0) and if none exist take the minimum of min-max of adj pairs.

  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +5 Vote: I do not like it

    First thing first, only 1 round matters, because Ali can keep choosing the same i and j and only one time Bahamin can gain points. Now, If you have i and j, such that max(ai, bi) >= min(aj, bj), then there will no score gain from this pair and Ali can choose this pair, otherwise try to minimise gain, which you can see here: 332903480

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      thanks for this one! I cannot believe I did everything else apart from this and how close I was to this one...aaaaaah man! Anyways thanks a lot brother, very well written code!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how C?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

too hard -_-

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

B was really easy in retrospect, but I was in off-by-one indexing hell during the contest. Also didn't help that I misread at first and thought you could only move one space at a time :|

C was interesting, it was pretty funny that K didn't matter at all (noticed this <5min lol)

Overall good problems in retrospect and orz to the problemsetters, even if I trolled

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    can you please share you easy idea for B

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      the best way Mani can put a wall is 1 on the right or on the left of Hamid. He chooses the maximum of the two cases. Once the wall is placed, Hamid chooses the minimum of going to the right or to the left, and the best choice is where the first wall is closer to the edge

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Thank you for these problems! I don't remember the last time I enjoyed solving a codeforces round as much as I did today (:

»
8 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

E was nice, proving that adding additional color to a subtree(if the subtree doesn't already have that color) doesn't improve the cost was the key!

»
8 months ago, hide # |
 
Vote: I like it +44 Vote: I do not like it

What's up with H limitations? Is the model solution exponential in $$$n$$$?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it -16 Vote: I do not like it

    Yes. It is about $$$\exp(n/2)$$$. Now we realize that we should change this problem into counting...

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it +44 Vote: I do not like it

      Even counting version can be solved in O(M)...

      • »
        »
        »
        »
        8 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it +27 Vote: I do not like it

        Now we found some really obvious solutions to this problem (like graph matching), but none of them are found during testing. Even worse, the only tester who solved this problem used the same algorithm as MCS.

        We apologize for this bad-setting problem — it shouldn't have occurred in the round. We are very very sorry for the bad experience.

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it +19 Vote: I do not like it

          The problem is fine. Just give $$$n \le 500$$$ or $$$n \le 50000$$$

        • »
          »
          »
          »
          »
          8 months ago, hide # ^ |
           
          Vote: I like it +40 Vote: I do not like it

          I wouldn't say it's bad, just unexpected for me. It's not a big issue when authors don't have the best solution for their own problem.

    • »
      »
      »
      8 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it +8 Vote: I do not like it

      I think most linear-time solutions can also support counting as well (at a cost of being quadratic, possibly)

»
8 months ago, hide # |
 
Vote: I like it +33 Vote: I do not like it

Enjoyed D a lot. Literally the first time to go through an hour of thinking to get to a correct answer, and the trill of seeing the pretests passed is just incomparable!

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +5 Vote: I do not like it

I can't remember a codeforces round where the problems were as enjoyable as today. Thank you!

»
8 months ago, hide # |
 
Vote: I like it +145 Vote: I do not like it

H is the worst problem in the history of cf. Just random shuffle the edges 1e5 times and choose greedily(as the order of the edges) passes. 332898118

»
8 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

I loved this contest, thank you for such great problems.

»
8 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

Amazing contest... thank you very much!

»
8 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

I need 29 rank to become red... And predictor shows +29... Hope

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

rk103… No!!! My tshirt!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

sad/(ㄒoㄒ)/~~

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

C Good problem.

»
8 months ago, hide # |
Rev. 2  
Vote: I like it -27 Vote: I do not like it

I don't understand whats wrong with my code for problem B.

// this is code
int main() {
	long long t;
	cin>>t;
	while(t--){
	    long long n,x,c=0;
	    cin>>n>>x;
	    char a[n];
	    for(long long i=0;i<n;i++){
	        cin>>a[i];
	        if(a[i]=='#') c++;
	    }
	    x--;
	    if(x==0 || x==n-1 || c==0) cout<<"1\n";
	    else if(a[x-1]=='#' || a[x+1]=='#')cout<<min(x+1,n-x)<<'\n';
	    else{
	        long long l=-1,m=n;
	        for(long long i=x;i>=0;i--){
	            if(a[i]=='#'){
	                l=i+2;
	                break;
	            }
	        }
	        for(long long i=x;i<n;i++){
	            if(a[i]=='#'){
	                m=i+1;
	                break;
	            }
	        }
	        if(l==-1) cout<<min(x+1,n-m+2)<<'\n';
	        else if(m==n) cout<<min(l,n-x)<<'\n';
	        else cout<<max(l,n-m+2)<<'\n';
	    }
	}
}

Anyone please explain.

  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it -18 Vote: I do not like it

    I was doing something similar but I can suggest you not to use x--. Anyway, if you count based on the position of x (not x--), the answer is either x or n-x+1, while if you count based on the position p of the wall you place, the answer is either p+1 or n-p+2

    import sys, random, bisect
    from collections import deque, defaultdict
    from heapq import heapify, heappop, heappush
    from itertools import permutations
    from math import gcd, log, sqrt, isqrt
    
    input = lambda: sys.stdin.readline().rstrip()
    
    
    def solve():
        n, x = map(int, input().split())
        a = input()
        c = 0
        for i in range(n):
            if a[i] == "#":
                c += 1
        if c == 0:
            print("1")
            return
        indl = float("+inf")
        indr = float("+inf")
        for i in range(n):
            if i < x - 1 and a[i] == "#":
                indl = i + 1
            elif i > x - 1 and a[i] == "#":
                indr = min(indr, i + 1)
        if x == 1 or x == n:
            print(1)
            return
        if indl == x - 1 or indr == x + 1:
            print(min(x, n - x + 1))
            return
        if indl == float("+inf"):
            print(min(x, n - indr + 2))
            return
        if indr == float("+inf"):
            print(min(indl + 1, n - x + 1))
            return
        res1 = min(n - x + 1, indl + 1)
        res2 = min(x, n - indr + 2)
        print(max(res1, res2))
    
    
    for _ in range(int(input())):
        solve()
    
»
8 months ago, hide # |
 
Vote: I like it -20 Vote: I do not like it
const int maxn = 2e5+100;
int mod = 10e9+7;
ll fact[maxn];
void init() {
    fact[0] = 1;
    for (int i = 1; i < maxn; i++) {
        fact[i] = ((i % mod) * (fact[i - 1] % mod)) % mod;
    }
}

ll mul(ll a, ll b) {
    return (a * b) % mod;
}

struct test {
    vector<vector<int>> adj;
    vector<bool> is_leaf;
    vector<int> deg, leaf, non_leaf;

    void solve() {
        int n, m; cin >> n >> m;
        adj.resize(n);
        deg.assign(n, 0);
        is_leaf.assign(n, false);
        non_leaf.assign(n, 0);
        leaf.assign(n, 0);

        for (int i = 0; i < m; i++) {
            int u, v; cin >> u >> v;
            u--, v--;
            adj[u].pb(v);
            adj[v].pb(u);
            deg[v] += 1;
            deg[u] += 1;
        }

        if (m != n - 1) {
            cout << 0 << endl;
            return;
        }

        for (int i = 0; i < n; i++) {
            is_leaf[i] = deg[i] == 1;
        }

        for (int i = 0; i < n; i++) {
            for (auto ch : adj[i]) {
                leaf[i] += is_leaf[ch];
                non_leaf[i] += !is_leaf[ch];
            }
        }

        ll ans = 1;
        for (int i = 0; i < n; i++) {
            if (non_leaf[i] > 2) {
                cout << 0 << endl;
                return;
            }
            ans = mul(ans, fact[leaf[i]]);
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += !is_leaf[i];
        }

        if (cnt >= 2) {
            ans = mul(ans, 2) % mod;
        }

        cout << mul(ans, 2) % mod << endl;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

   	// file IO
    // freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
    init();
    int tt = 1;
    cin >> tt;
    while (tt--) {
        test().solve();
    }
}

I couldn't figure out where I messed up on D

»
8 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

Successful hacks in A are not put in to main test? There are 6 successful hacks in A during contest but no fst!

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Hacks were added to the main tests before system testing. This problem has ~10 tests now.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it +24 Vote: I do not like it

      I filtered the submissions with more or equal to 5 test cases and sorted them by judging time in desending order, and it seems only codes that are submitted after contest are tested in 10 test cases. And when I open my own A code which submitted during contest, it only has 4 tests.

      pic
    • »
      »
      »
      8 months ago, hide # ^ |
      Rev. 4  
      Vote: I like it 0 Vote: I do not like it

      I was also wondering why there are so few FSTs when people managed to hack 6 submissions just during the contest time (which highly suggests that many, possibly hundreds or even thousands of solutions will fail with the hacks).

      I think this really requires rejudging the solutions of A... Why is rating already udpated before addressing this issue?

»
8 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Great contest, thanks to the authors!

»
8 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

Can my A be judged please? It is still at "pretest passed", and my position in the standings does not include my points on problem A

Hamed_Ghaffari sweetweasel eren__

https://mirror.codeforces.com/contest/2127/submission/332803312

Update: Thanks for the help

»
8 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

I love the round! Thanks...

»
8 months ago, hide # |
Rev. 2  
Vote: I like it -20 Vote: I do not like it

deleted

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I wasted like 1 hour in A and ended up not solving it anyway i guess it happens ???

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yes it does. you atleast tried for 1 hour .. I just get frustrated and give up around 15-20 min mark .. keep up the practice.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I've found the tree cute in the cutie points problem!

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

The questions are quite interesting, especially question C. Thank you to everyone for their contributions! (Please forgive me for commenting using a translation software. My English is not very good QAQ)

»
8 months ago, hide # |
 
Vote: I like it +79 Vote: I do not like it

Excluding the issues on H, I think the round was pretty nice. Thanks to the authors.

»
8 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

Very good round, thanks for brilliant problems

»
8 months ago, hide # |
 
Vote: I like it +66 Vote: I do not like it

Could you give me a +1 in rating after the rollback? Thanks in advance!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What the hell was question D my gawd wasn't able to configure it out at all

»
8 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

D problem was very good

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, My handle is 10_Mahen. I received a warning about solution 332893401 coinciding with others. I did not knowingly share my solution publicly, but a friend (handle: madhurdingalwar123) copied it without me understanding that this was against the rules. I now understand that even unintentional leaks are not allowed, and I take responsibility for being careless. This won’t happen again, and I ask that you please consider this as a first-time mistake. Thank you for your understanding.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I would like to sincerely apologize for violating the Codeforces rules in Round 2127A. I submitted a solution (ID: 332894758) that was copied from my friend, not fully realizing that this constitutes a serious rules violation, including unintentional sharing. I now understand that Codeforces does not allow any form of code sharing or copying during contests, even between friends.

This was my mistake, and I take full responsibility for it. I assure you it won’t happen again in the future. I’ve read the rules and guidelines at http://mirror.codeforces.com/blog/entry/8790 to make sure I understand them clearly now.

Please accept my apology, and I respectfully request leniency this time as I was unaware of the seriousness of this action. I am committed to fair and honest participation going forward.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I(Darsh_01) recieved a mail regarding that my solution of problem 2172B coincides with many others solution but I have not used any third-party apps or shared my code with anyone. I think it is because of those people also thought of the same logic for the problem which is a legitimate case in my opinion. I have not copied my code from anywhere and I give all my contests honestly. If there are any further clarifications needed I am open to give as I have written a genuine code by myself. Thank You

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I just received the prize from Atto Round. It indeed contained some nice gifts, thank you for that.

However, I have one concern. I was asked by the delivery person to pay a tariff and tax in cash then. Although the amount was small this time (around $2), such payment without any prior notice does not seem appropriate to me. I would appreciate it if future shipment situation is improved.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it +12 Vote: I do not like it

    Yeah, that's something I've ran into with prizes before as well.

    Problem is the sender can't afford to make sure everything is ok on your end. Import authorities are rather harsh on prizes/gifts — sometimes they demand an extra fee, sometimes a declaration that you really only received it for free and its value is low enough, etc. It depends on the country and on how an import/export officer woke up that day. The sender can try to pay what they understand as correct for your country, but it's imperfect and they're not going to know if everything went ok unless you tell them since communicating with various imports offices is tough and tracking package status doesn't give that much info.

    It's not on the contest organiser. Your import/export office may be at fault, or otherwise it's just that there are too many rules for these things in the world for a tech company to watch out for. Maybe an intermediary company dedicated to sending the prizes correctly could be found... or there was one here and then it's their fault.

    What are the import rules for material prizes in Japan? They're not free under a certain value limit?

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Then I'm so lucky that I haven't ran into this kind of issues for $$$\ge15$$$ years.

      Thanks for the explanation, sounds true. I even heard that the payment differed for another recipient this time. I don't think these issues are common sense and the "without any prior notice" part in my comment still makes sense.

      What are the import rules for material prizes in Japan? They're not free under a certain value limit?

      I can't say for sure as I'm not a law expert (and Japanese official site for this seems down for some time now...), but my understanding is that there is a tax exempt for <=10000JPY in this case. I received much valuable prize without an issue recently.