Блог пользователя Imakf

Автор Imakf, история, 3 года назад, По-английски

The jury solutions will be updated later.

The jury solution is updated now.

1496A - Split it!

Idea: waaitg

Tutorial is loading...
Solution (Imakf)

1496B - Max and Mex

Idea: waaitg

Tutorial is loading...
Solution (waaitg)

1495A - Diamond Miner

Idea: smg23333

Tutorial is loading...
Solution (smg23333)

1495B - Let's Go Hiking

Idea: waaitg

Tutorial is loading...
Solution (waaitg)

1495C - Garden of the Sun

Idea: Imakf

Tutorial is loading...
Solution (Imakf)

1495D - BFS Trees

Idea: waaitg, Daniel_yuan, isaf27

Tutorial is loading...
Solution (Daniel_yuan)

1495E - Qingshan and Daniel

Idea: Imakf

Tutorial is loading...
Solution (Imakf)

1495F - Squares

Idea: waaitg

Tutorial is loading...
Solution (waaitg)
Разбор задач Codeforces Round 706 (Div. 1)
Разбор задач Codeforces Round 706 (Div. 2)
  • Проголосовать: нравится
  • +160
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +82 Проголосовать: не нравится

Speedforces.

»
3 года назад, # |
  Проголосовать: нравится -12 Проголосовать: не нравится

Such a fast editorial! That's great! :)

»
3 года назад, # |
  Проголосовать: нравится -45 Проголосовать: не нравится

Second comment:)

»
3 года назад, # |
  Проголосовать: нравится +37 Проголосовать: не нравится

Task C have one max test???? My random solution got AC. So weak...

»
3 года назад, # |
Rev. 2   Проголосовать: нравится -19 Проголосовать: не нравится

Am I the only one who read

$$$p_{x'}<p_x,p_{y'}<p_y$$$

instead of

$$$p_{x'}<p_x, p_{y'}>p_y$$$

(Div2D/Div1B)

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

    Same here, That means I had read the wrong question and still my code passed the pretests... :) Very weak pretest for div2 D :(

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    same with me bro.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Me too, got 4 times WA for this.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Hey, if you don't mind, can you explain what is meant by longest monotone segment? I can't find the explanation of the term anywhere on google.

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится +8 Проголосовать: не нравится

        Longest monotone segment means the longest segment in which all the elements in the segment are increasing or decreasing. but not both. For example:

        • [3, 5, 6, 10] is a monotone because the elements are increasing.
        • [20, 10, 9, 8, 5] is a monotone because the elements are decreasing.
        • [1, 2, 4, 3, 5] is not monotone because the some element are increasing and some are decreasing.

        So the longest monotone segment is the longest of such segment. I don't know if any neighboring element can be the same, but that doesn't matter for the problem since all the elements are guaranteed to be distinct.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    But solutions will be exact same except the l%2 condition in the last

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    me too bro

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Same :(

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Oh,a sad story.

»
3 года назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

Interesting as problem 1C is, 1B is really a bad problem. But I do hope the next competition can be better.

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

losing sleep due to bricking problem a. quite literally

»
3 года назад, # |
  Проголосовать: нравится +45 Проголосовать: не нравится

It will be better if the data of div2D/div1B are multi-tests.

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

    Why would it have been better? Is it because that would have allowed to fit more cases in pretests?

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +11 Проголосовать: не нравится

      Yes. 11 pretests on a YES/NO problem with a lot of casework is very obviously a bad idea but for some reason the authors didn't use multitest.

»
3 года назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

I felt sad that I ignored the description "Magically, any two empty cells have no common points (neither edges nor corners)." in div1 C.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yes, now I read the editorial and came to know about that. Can it be solved for sharing corner points? Or even for sharing edges? (initially assuming it is not forming a cycle?)

»
3 года назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

I got TLE in C just for taking inputs as double in my code. The same code when I just changed the input type from double to long long it got AC. Help!! Thanks in advance. Links to the TLE and AC code is given below and changes are also specified by comment.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Same thing happened to me too. But I couldn't fix it during the contest.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Same. I just got 6 TLE with correct algorithm just for that and lost the points for C.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +12 Проголосовать: не нравится

    It takes more time to take input as Double in C++ and even it takes more time to sort it.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I am not sure, but afaik, although both "long long" and "double" are 8 bytes, the processes on double are way slower, and the reason is the precision problem. I don't think you got TLE because of input, but because of the operations. You use "double" typed vectors, you add elements to them, then sort, multiply them, take the square root. These operations may have overwhelmed the computer(server).

    • »
      »
      »
      3 года назад, # ^ |
      Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

      I don't know why, but Kotlin doesn't care what to store and what to operate with (Long or Double). That's fun btw, cause c++ working slower with doubles.

»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

With many participants happened this: one of the solutions got TLE, the other one got OK, but they have the same logic (problem Div.2-C).

Why??

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

can anyone explain to me why the answer in D is only 1 or 0?

  • »
    »
    3 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

    The key is that Qingshan has two ways to win. The first is that Qingshan can't move for the both sides of it are greater.In this way, the length of monotone subsequence is important. The second is that Qingshan meets Daniel.It means that Daniel can block Qingshan's way and meet in the middle of a monotone subsequence. Understand that and you will solve it. :)

    • »
      »
      »
      3 года назад, # ^ |
      Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

      Can you elaborate more? Why longest monotone is important here?

      • »
        »
        »
        »
        3 года назад, # ^ |
        Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

        If there are two longest monotone and they have the same position, the position whose value is greatest in the monotone is available when the length of the longest monotone is odd(Try to imagine when the two meet). Otherwise, Daniel can always choose the position whose value is least in the other longest monotone (If it isn't exist, Daniel will choose the position near by Qingshan chosen to make Qingshan can't move to the longest monotone), and Qingshan will always lose.

»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

I mis read the question 1495B.

Thanks for the contest

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    We assume that both player plays optimally it includes well choosing the start, if 4 is the number on which is Q, D goes on 3 and no move is possible for Q.\ if 4 is the index D goes on index 1 and either Q move to 3 D move to 2 and Q is stuck either Q goes on the other side and D can walk 3 moves Q too, and Q is stuck, so Q loose if D choose well where it starts

»
3 года назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

In Div_2_C

109615476 : This solution was accepted. 109601607 : This one got me TLE. Can someone please help me understand why did I get tle?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    turns out inputting a double is slow as hell in cpp. as the values were integer, you should have input them as integers in a first time.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What happened with the solution of 'BFS Trees'?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What is longest monotone segments?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    subarray which is either strictly increasing or strictly decreasing .For example take array 2 4 6 5 3 8 7 4 3 . Here 2 4 6 , 8 7 4 3 are some of the monotone segments . 8 7 4 3 is longest monotone segment.

»
3 года назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

Can Any One Help Mi That Why I Get TLE On Today's Problem C

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ld long double


void solve();

int main()
{
    int tc=1;
    cin >> tc;
    while(tc--)
    {
        solve();
    }
}

void solve()
{
    int n,t1=0,t2=0;
    cin >> n;
    vector<ld> x(n),y(n);
    ld a,b;
    ld sum=0;
    for(int i=0;i<2*n;i++)
    {
        cin >> a >> b;
        if(a==0)
        {
            y[t1++]=abs(b);
        }
        else
        {
            x[t2++]=abs(a);
        }
    }
    // ld sum=0;
    //why tle
    sort(x.begin(),x.end());
    sort(y.begin(), y.end());
    for(int i=0;i<n;i++)
    {
        sum+=sqrtl(x[i]*x[i]+y[i]*y[i]);
    }
    cout << fixed << setprecision(15) << sum << endl;
}

Here Is My Submission.109634972

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    use long long int instead of double for a and b and x and y, double (and long double) are slow to read and to sort

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      now it's accepted. thank's a lot i learn new thing and i will never forget it

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      Could you please tell me that why double is slower than int(as sort).

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      Thanks a lot,even I got to learn a new thing , this thing costed me 3 submissions during the contest as I wasn't aware of this fact

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I cant see solution for div1 a (smg2333) not enough rights

»
3 года назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Can anyone explain problem Div 2 D? The editorial is kind of overwhelming for me. Thank You in Advance!

  • »
    »
    3 года назад, # ^ |
    Rev. 5   Проголосовать: нравится +5 Проголосовать: не нравится

    Think of the permutation as hills and valleys. Notice that the first player always has to start at the top of a hill, as only top of hills will have both adjacent points smaller than it, otherwise player 2 would pick the smaller adjacent side forcing player 1 to pick larger side, hence losing. Now the first player would want to descend, so he will pick the mountain which has the longest (and equal) descent on both side out of all mountains( if he doesn't, then player 2 can pick a longer ascent, and player 1 will run out of moves before player 2).Also there should only exist one unique mountain with the longest sides, otherwise player 2 can ascend the other mountain and since player 1 plays first, he will be the first one to exhaust all his moves. Both sides should be equal so that player 2 can't intercept us at one side(if only one side is longest, player 2 would be able to choose in way so that player 1 loses). Now the length of this descent should be odd, since whatever side player 2 chooses, we can go in the same direction, and he will be the one running out of moves first. This is the only case player 1 wins Edit: logic was wrong initially

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

As fast as flash.

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

It seems that the submission of F is not visible.

»
3 года назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

Another suggestion: Use name Alice for first player and Bob for second player. This time Quishisomething and Daniel where not so bad, but still I had to read severeal times before being able to memoize who is first, who is second. Later one of the player is referred to as "she"...what might be hard to understand depending on cultural background.

Alice and Bob is simply less confusing.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
Then, let's consider the contributions of other vertexes i. In the bfs-trees of both x and y, there must be and only be a edge linking i and j, which j satisfies dist(x,i)=dist(x,j)+1∧dist(y,i)=dist(y,j)+1.

Can someone explain this?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    Author's English skill still has space for improvement.

    j is the parent node of i in the required tree. It must satisfy the condition given because required tree is a BFS tree of both x and y. Such j might not exists for some i.

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

I am still struggling to understand Div2F's statement, can any one please explain what does "Given a graph, we define f(x,y) to be the number of spanning trees of that graph that are BFS trees rooted at vertices x and y at the same time." mean?

PS. got it

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For 1495E.

Why this graph has at least 2 simple paths between 2 empty cells.

....X..X..X....
XXXXXXXXXXXXXXX
.X......X......
.X..X.........X
XXXXXXXXXXXXXXX
.X............X
.X.X..X.....X..
XXXXXXXXXXXXXXX
X...X.X........
X.......X...X..
XXXXXXXXXXXXXXX
X.......X......
X............X.
XXXXXXXXXXXXXXX
X.X....X.....X.
»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

What is the difficulty of Div2 C as your opinion?

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

For Div2 D /Div 1 B Why This Testcase giving ans=0 while ans should be 1

N= 11

5 6 9 8 1 2 3 11 10 7 4

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    ans=0 is right. why it should be 1 ? explain. there is no index where we can win.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      For index =7 (0 based ) When value is 11

      • »
        »
        »
        »
        3 года назад, # ^ |
        Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

        If first player will start at index 7 then second player will start from either index 4 or index 10. then first player can't win. from index 7 if first player choose to go 6 then second player will move 4 to 5.and then first player can't move further.

        or if first player move in the right (first player move, second player move) (7->8,4->5) (8->9,5->6) (9->10,6->7) and now first player can't move. So in both situation player first can't win.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

In Div.2C, why can we turn any point (x, y) to (|x|, |y|) without changing the answer?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

when i am taking input in long double is giving tle https://codeforces.com/contest/1496/submission/109591967

while long long int gets accepted https://codeforces.com/contest/1496/submission/109594626

is long double making such a huge difference in time? and why it is not getting memory limit exceeded instead of time limit exceeded?

»
3 года назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

I tried algebra bash for div2 C

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I tried implementing DFS for E which failed on some edge cases and now I am wondering, is there actually a solution with DFS?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

A problem in Div1A when I use 'printf("%.10Lf", ...)' to print a long double, it seems something wrong with it on the platform, but it does work correctly on my com. So could someone help me on how can I use 'printf' to print a long double ? thx for your help !

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For TASK 3 div 2, i wrote a solution with double as my vector type seems and it gives TLE on TC:- 4 but if i change double type to int it passes with time 124ms can anyone one tell me why it is happening

109668126 Code using double

109668230 Code using int

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It takes more time to take input as Double in C++ and even it takes more time to sort it.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I suffered from the same issue due to my carelessness. Float operations are (10-20 times) slow than their integer counterparts. For this problem, the hotspot of time usage is clearly the sorting, which invokes the comparision for O(n log n) times.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thank you for turning me green again ;)

»
3 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

The pretest for div2.D is too weak!

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain the sequence of moves in the following test case for Qingshan to win? Thanks!

5
1 2 5 4 3
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится

    If Player 1 is at index 1 -> Player 2 can be at index 2
    If Player 1 is at index 2 -> Player 2 can be at index 1
    If Player 1 is at index 3 -> Any position of player 2 will be loosing position or him. i.e if
    1) player 2 decides to be at index 4
    player 1 -> index 2
    player 2 -> index 3
    Player 1 -> index 1
    Player 2 cant make move.
    2) Player 2 decides to be at index 5
    player 1 -> index 4
    player 2 cant make move
    3) Same in case of index 1 and 2.
    If Player 1 is at index 4 -> Player 2 can be at index 5
    If Player 1 is at index 5 -> Player 2 can be at index 4

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Div2 C. Why my submission 109604661 109606220 failed with setprecision(11) and setprecision(16) with double. This infrustrates me to the no end and finally passed with setprecision(15)..

Does anyone have an explanation for this? I thought a setprecision(11) could meet the requirement.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It's because that for the input array you used std::vector<int> instead of std::vector<long long> in the previous submissions, nothing to do with precision. More accurately:

    ll tp=a[i]*a[i]+b[i]*b[i];
    

    This will cause an integer overflow, and the result might be a negative number, which you soon called sqrt() on. And this will return nan, as shown on the judger.

»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

Okay , so here is thing, I misread Problem div2(D)/div1(B) and solved some different problem and later realized that I screwed up the problem statement. I thought that whichever index the player steps on becomes his territory. Meaning, the other player can never approach this index ever. Even though, the original problem is different from the one I assume it was, I consider this alternate problem is also fun to solve.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For div1D, consider f(x, y), what if there are multiple shortest paths between x and y? Tutorial skipped this.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    In this case, answer is always 0?

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Yeah,because if there are multiple shortest paths between x and y, there must be an point i,which doesn't satisfy the condition in the tutorial.

      However,you can just consider the situation that an edge in the shortest path is contained in a circle.I think it's better to understand.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Could someone help me with the problem 1C/2E? I get WA on test 3, but I don't know where goes wrong...Thanks in advance. my code

»
3 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Someone kindly elaborate Div2F please!

»
3 года назад, # |
Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

Can someone tell Div1C / Div2E : Will answer always exist regardless whether initial empty cells share a corner or edge or not? I feel this is true, but cannot prove it. And any ideas on how to solve in that case? Using Disjoint Data structure?

Edit: In general I guess there may or may not exist solution but I cant find example, and in general we may have to use backtracking if constraint in question was not given

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    No. Consider a chessboard-like input grid.

    • »
      »
      »
      3 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      I think it works for this big chess, does it fail for higher ? Or maybe a different $$$n\times m$$$ grid ?

      Wrong image here, refer followup reply
      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        The edges between points (1,1),(1,9),(9,9) and (9,1) in your diagram form a loop, so there may be more than one simple path between two points.

        • »
          »
          »
          »
          »
          3 года назад, # ^ |
          Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

          ok if we let (1,1) with the flower, that is not empty the (1,1) cell?

          Like this:

          Image
          • »
            »
            »
            »
            »
            »
            3 года назад, # ^ |
            Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
            .X.
            XX.
            X.X
            .X.
            

            PS. nvm

          • »
            »
            »
            »
            »
            »
            3 года назад, # ^ |
              Проголосовать: нравится +21 Проголосовать: не нравится

            You can have a look at the following picture, it is unable to find out the legal solution, I proved it by counterevidence, but the process is more complicated, so I will not write it in detail, you can also have a try ~

            • »
              »
              »
              »
              »
              »
              »
              3 года назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

              This is nice I was also feeling it might fail for smaller chessboard!

»
3 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone expain, why in Div.2 Problem D,

testcase -->

5

1 2 4 3 5

answer is 0.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    If first chose position x(x\neq 1), then second chose position x-1. If first chose 1, second can chose any.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How is it obvious that the distance between $$$x$$$ and $$$y$$$ in the tree is $$$dist(x , y)$$$, since $$$dist(x,y)$$$ is number of vertices in the shortest path in the graph(there could be multiple paths)

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    To make it clear, "the tree" here means "a tree that is both a BFS tree rooted at x and y at the same time". So by definition, the length of the (one and only) path from x to y on that tree must be equal to the length of the shortest path from x to y in the original graph.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone tell why this solution 109616067 is exceeding the time limit?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What will be the answer of Div2 D for 1 3 2 input. I think it should be 1.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It's 0 instead. Suppose Qingshan start at x = 2 (He can't start at x = 1 or x = 3 because he wouldn't be able to make the first move),Then no matter which y Daniel chooses, Qingshan is definetely going to lose.

»
3 года назад, # |
Rev. 11   Проголосовать: нравится 0 Проголосовать: не нравится

Just a public personal note that Div1D / Div2F was real "fun" to solve in non-C++, heh.

109775962 is my passing submission. Notes:

  • approximately halved runtime by using $$$f(i, j) = f(j, i)$$$ symmetry
  • flattened all arrays. This is overall the most productive optimization; it won't pass with regular 2D arrays for D (distance) or ans, or with an array of adjacency lists for the graph. (instead, edges are stored in U and V, sorted by U and using the auxiliary array P to point to the subarrays corresponding to each vertex)
  • "back to basics" code style; even the BFS doesn't use a deque, but an array and two pointers, although it can probably still pass with the deque, as the BFS isn't the bottleneck.
  • avoided a * b % MOD and uses addition and shifts instead, saves about 150ms over an equivalent solution with multiplication.

I have an even faster submission: 109763945, but it relies on skipping modular multiplication for factors $$$0$$$ and $$$1$$$, and therefore optimizing on this relies on the fact that factors $$$2$$$ and above are limited in number, which is a heuristic that I couldn't prove.

Upd: even faster: 109780486. Modular addition (no multiplication or %). Shortcuts if it finds a $$$0$$$ factor, again, I'm unsure whether there is a way to defeat this optimization and make it run like 109775962.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Neither edges nor corners need a better explanation.

»
3 года назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

Em...i think the Div1.E's description has a small problem. On the 4th line of INPUT, it says $$$p_{j-1}<p_j(2\leq j \leq n)$$$ but the truth is $$$(2 \leq j \leq m)$$$.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Taking input as a double is slow in c++ (my learning from Div1 A).

»
12 месяцев назад, # |
Rev. 6   Проголосовать: нравится 0 Проголосовать: не нравится

deleted