CarViz's blog

By CarViz, history, 8 months ago, In English

bro i couldnt solve p3 bc i used python i wanted to promote in contest q*k^2 tle last 6 cases. p2 took me like 2 hours and p1 was horrendous casework to get an o(1) solution but lowkey we gotta love it because USACO is our brother as forcers. idk folk how did you guys do i dont really feel like i won even though i gonna promote because i got fried regardless.

  • Vote: I like it
  • -23
  • Vote: I do not like it

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

How did you solve problem 2

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

    copy-pasting from a message of mine:

    The solution to p2 was beautiful. I can prove ans is always <= 2 when possible.

    Since an odd n would make it impossible, we know we are working with an even n. We can split up the cows in two sections, the first half and second. Notice how since it always gives cycles of cow, there's only 3 variations, COW, OWC, WCO. When you pair any two of these together, you always can obtain a substring of length 2 in common. So after taking this substring we are left with one letter for each cow, equivalent on both the first and second half because the cows are made of the same letters, resulting in a square string. The only setup needed is to check if the string is already square (ans = 1).

    Took me 2 hours, first approach was to remove each letter one by one resulting in ans <= 3, doesn't work.

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

Wait how did you solve p2 but not 3 because p1 and p3 were trivial Ngl

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

    My p2 solution is above. I still took around an hour on p1 because I did casework (o1 complexity) but it was much easier than p2. I couldn't solve p3 because (you may correct me if im wrong) q*k^2 wouldn't pass in python, despite it passing in c++ and java. I got 12/18 test cases, so 10/16 partial or ~873 total points, but I'm pretty upset because I would have promoted in contest had I used a different language with my last 30 minutes to resubmit something for p3.

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

      can you please just paste the solution here? I passed q1 and q3 with full test cases, and i only got two correct for q2.

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

        also my solution to q3 is here:

        //this is code ~~~~~~~~~~~~~~~~~

        include

        include

        include

        using namespace std;

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

        int N, K;
        cin >> N >> K;
        
        int Q;
        cin >> Q;
        
        vector<vector<long long>> grid(N + 1, vector<long long>(N + 1, 0));
        vector<vector<long long>> row_prefix(N + 1, vector<long long>(N + 1, 0));
        long long max_attractiveness = 0;
        
        for(int q = 0; q < Q; q++) {
            int r, c;
            long long v;
            cin >> r >> c >> v;
        
            grid[r][c] = v;
        
        
            for(int j = 1; j <= N; j++) {
                row_prefix[r][j] = row_prefix[r][j-1] + grid[r][j];
            }
        
        
            int i_min = max(1, r - K + 1);
            int i_max = min(N - K + 1, r);
            int j_min = max(1, c - K + 1);
            int j_max = min(N - K + 1, c);
        
            for(int i = i_min; i <= i_max; i++) {
                for(int j = j_min; j <= j_max; j++) {
        
                    long long sum = 0;
                    for(int di = 0; di < K; di++) {
                        int row = i + di;
                        sum += row_prefix[row][j + K - 1] - row_prefix[row][j - 1];
                    }
                    max_attractiveness = max(max_attractiveness, sum);
                }
            }
        
            cout << max_attractiveness << '\n';
        }
        
        return 0;

        }

        ~~~~~~~~~~

        also, sorry about the messy formatting, i have no idea how to fix them, the three giant include is actually hashtag include iostream, vector, and algorithm. they are seperate, like write the include three times.

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

          your solution also seems q*k^2 complexity, which doesn't pass in python unfortunately (it passed up to test case 12, giving me enough partial to promote)

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

        yeah that makes sense because its always possible in <= 2 steps so you will fail k = 0 if your solution is <= 3 steps

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

          so uh, mind if you just give me the solution for p2?

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

            scroll up to the first comment i left it in a reply to that

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

              im sorry but i don't see it, can you please just paste it here? i won't mind the formatting

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

                The solution to p2 was beautiful. I can prove ans is always <= 2 when possible.

                Since an odd n would make it impossible, we know we are working with an even n. We can split up the cows in two sections, the first half and second. Notice how since it always gives cycles of cow, there's only 3 variations, COW, OWC, WCO. When you pair any two of these together, you always can obtain a substring of length 2 in common. So after taking this substring we are left with one letter for each cow, equivalent on both the first and second half because the cows are made of the same letters, resulting in a square string. The only setup needed is to check if the string is already square (ans = 1).

                Took me 2 hours, first approach was to remove each letter one by one resulting in ans <= 3, doesn't work.

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

Curious, what were the bronze statements if you have them?

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

I also use python, but after I got TLE I changed my code to C++(I only know the basic grammer about C++ but that's enough for bronze).

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

    yeah i wish i did that i know enough java from ap csa to solve p3 in it couldve gotten to participate in silver