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

Автор atcoder_official, история, 6 дней назад, По-английски

We will hold Toyota Programming Contest 2024#12(AtCoder Beginner Contest 384).

We are looking forward to your participation!

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

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

i am just a chill guy who participates in every atcoder contest

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

    WE GOT MORE UPVOTED COMMENT THAN BLOG BEFORE GTA VI

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

How to do F :( ?

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

Anyone, How to do F??

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

$$$\mathcal O(n^2)$$$ solution passed problem G lol. 60727006.

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

Can someone explain why the two pointers method doesn't work for task D?

My code

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

Did anyone solve F using FFT ??

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

can someone suggest any testcase for which this code fails?

60750107

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

Hi all,

Problem : E

Kindly assists, I was unable to figure out why the code is not passing the if (s[nx][ny] < now/r) condition in the first test case. Furthermore, after reviewing the editorial I made changes in the if condition as if(s[nx][ny] < (now+r-1)/r) doesn't seems to pass the below test case:

3 3 2
2 2
14 6 9
4 9 20
17 15 7
Expected: 28
My result: 13

Here is the code:

#include<bits/stdc++.h>
using namespace std;
using ll = long double;
#define rep(i, x) for(int i = 0; i < int(x); i++)
#define all(x) (x).begin(), (x).end()

template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b;return 1;}return 0;}

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w; double r;
    int p, q;
    cin >> h >> w >> r >> p >> q;
    p--, q--;
    vector<vector<ll>> s(h, vector<ll>(w));
    rep(i, h) rep(j, w) {
        cin >> s[i][j];
    }

    vector seen(h, vector(w, false));
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> Q;

    Q.emplace(s[p][q], p*w + q);
    seen[p][q] = true;
    ll ret = s[p][q];

    while (!Q.empty()) {
        auto [now, idx] = Q.top();
        Q.pop();
        int x = idx/w, y = idx%w;
        rep(di, 4) {
            int nx = x + dx[di], ny = y + dy[di];

            if (nx >= 0 && ny >= 0 && nx < h && ny < w && !seen[nx][ny]) {
                // cout << "O " << nx << " " << ny << endl;
                if (s[nx][ny] * r <= now) {
                    // cout << "I " << nx << " " << ny << endl;
                    chmax(ret, now + s[nx][ny]);
                    seen[nx][ny] = true;
                    Q.emplace(now + s[nx][ny], nx*w + ny);
                }
            }
        }
    }
 
    cout << ret << endl;
    return 0;
}

Thanks in advance.

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

Can anyone explain solution to problem F its a nice problem

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

    Initialize ans to sum of sums without applying function (ans = (n+1)*sum(a)). Then for about the first 27 powers of 2, let p be the current power of 2. Get the sum s of all the sums that are multiple of p. Remove s/p from ans.

    This works because for example if a sum s is divisible by 16 but not by 32 you get s-s/2-s/4-s/8-s/16 = s/16.

    You'll need a dictionary/map indexed by a[i]%p to keep data about number of elems and their sums for each modulo. You also need to distinguish the case when the modulo of the sum elements that equal 0 (mod p) are equal (like (0,0), (2,2) for p=4) or unequal ((1,3) for p=4) because their contribution is computed differently.

    https://atcoder.jp/contests/abc384/submissions/60784930

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

      sorry but i didn't get it can you elaborate on intution and logic

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

        For each sum (s = a[i]+a[j]) you need to add s/p to the answer where p is the largest power of 2 that divides s. This is the problem statement. The idea is to compute s1 the sum of all those s, then s2 the sum of the s divisible by 2, then s4 the sum of the s divisible by 4, s8, s16, s32 and so on for a large enough power of 2.

        The answer is s1-s2/2-s4/4-s8/8-s16/16... (26 terms is enough).

        Edit: It works because the contribution of say a sum s divisible by 16 but not 32 is going to be s-s/2-s/4-s/8-s/16 = s/16 which is what we need (that s won't appear in terms higher than s16).

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

How to E??

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

can any one find runtime bug in my code please it helpful for me.. problem E: https://atcoder.jp/contests/abc384/submissions/60778905

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

I found the data for question D to be weak, for example, in the example below, the answer should be yes, but in some code the answer is no, and AC is obtained 3 7 1 7 2

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

    So in that case, does atcoder rerun the submissions on newly added test cases?

    Here's a problem https://atcoder.jp/contests/abc381/submissions/60100542

    After the contest, somebody pointed out that people who have submitted brute force got an AC but brute force should have given TLE. So, you see at the bottom after contest test cases added and when submitting any brute force solution, only those fail. I don't if the solutions were re-judged after these test cases.

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

      If this is the case, I think it is possible to add new test cases, but it will not be judged that the answer is wrong for the code submitted at the time of the competition

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

ok problems are good and I respect physics0523 a lot as he was my co-ordinator in TheForces round 26.That's why I won't be over expressive but honestly statement writing wasn't good , statements weren't made clear.In problem $$$E$$$ it really wasn't good especially the part of newly adjacent cells, like no where in the statement it was mentioned old adjacent cells persist , I had to understand by reading sample explanation, but why??The main idea of what the problem wants should be in statement not in sample explanation right?

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

    Ok, I just read the samples of E right now after reading your comment cause I normally don't go to samples. That makes the problem so much easier, I thought we lose adjacency to previous adjacent cells. Maybe I don't understand what slime means.

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

    My solution for E is giving WA even though I'm performing BFS with int64 everywhere, and its always the last 2 out of the 65 test cases. my submission:60833551

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

I wrote a solution using plain BFS, with taking the smallest neighbour and breaking if the smallest neighbour is larger than the criteria. I got WA many times, then read editorial and people's suggestions here and saw that overflow might be happening. I used 128 int type as well, but still getting WA. Is the issue with my logic?

#include <iostream>
#include <vector>
#include <set>
#include <cmath>

using namespace std;

#define ll unsigned long long
#define ppi pair<int, pair<int, int>>
#define vll vector<ll>
#define vvll vector<vll>

void solve() {
    int n, m, k;
    cin >> n >> m >> k;

    int p, q;
    cin >> p >> q;
    p--, q--; // zero-based indexing

    vvll arr(n, vll(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> arr[i][j];
        }
    }

    vvll vis(n, vll(m, 0)); // Initialize visited array

    set<ppi> st;
    st.insert({arr[p][q], {p, q}});
    vis[p][q] = 1;

    ll ans = 0;
    bool is_first = true;

    while (!st.empty()) {
        ppi current = *st.begin();
        st.erase(st.begin());

        __int128_t potential_ans = (__int128_t)current.first * (__int128_t)k;
        __int128_t current_ans = (__int128_t)ans;

        if (is_first || current_ans > potential_ans) {
            ans += current.first;
            is_first = false;
        } else {
            break;
        }

        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (abs(i) + abs(j) != 1) continue;

                int x = current.second.first + i;
                int y = current.second.second + j;

                if (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y]) {
                    st.insert({arr[x][y], {x, y}});
                    vis[x][y] = 1;
                }
            }
        }
    }

    cout << ans;
}

int main() {
    solve();
    return 0;
}

Would be grateful if somebody can help with this one. I am trying to get it AC for the past 1 hr.

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

    Your set<ppi> must be set<pair<long long, pair<int, int>> to store the value.

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

      Yeah I have done it with ll itself. Just asking chat gpt to clean code and make it readable, that caused this int issue. My actual submission had

      #define ppi pair<ll, pair<int, int>>
      

      actual solution: https://atcoder.jp/contests/abc384/submissions/60781738

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

        That's strange because I only changed that line in your posted code and got AC. Maybe something else is different from your original code lol.

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

          ohh. if that's the case then i will look into it more. But thanks for taking the effort really.

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

          I got the issue. In my first submission of using double for division and not using any 128 int, I had used

          if(x>=0 && x<n && y>=0 && y<n && !vis[x][y]){
          

          instead of y<m

          Chatgpt fixed it but even after asking it multiple times, it didn't point it out. Thanks for your help really.

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

Finally easier G.

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

why rating is not updated?

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

I had a nice solution forProblem D, simply run a loop from 0 to 2n, taking the sum of array elements and check if the remainder = (s%(totalsum)) occurs in this course, Implementation: https://pastebin.com/nYJd9DEG

Why this works?
  • »
    »
    5 дней назад, # ^ |
    Rev. 6   Проголосовать: нравится 0 Проголосовать: не нравится

    I think we have the same idea but different implementations.

    I changed the equation to: some_suffix_sum + whole_array * some_multiple + some_prefix_sum.

    Consider the array as [1, 2, 3]:

    Case 1: If S = sum(arr), the answer is "Yes."

    Case 2: If S < sum(arr), I used a sliding window to find this, as all elements are positive.But this case will also be handled in the case 3.

    Case 3: If S > sum(arr), for example, S = 10, then the answer would be [3, 1, 2, 3, 1]. Here, I took some_prefix_sum = 1. Now, our sequence is [1]. We still need 9 to reach S. We can repeat the array to cover this 9. This can be found by calculating 9 / 6 = 1 (where 6 is the total sum of the array). So, the sequence becomes [1, 2, 3, 1].

    Now, I still need 10 — 7 = 3. To check if this 3 can be formed as a suffix, we can calculate total_sum — current_remaining.

    For example, here, current_remaining = 3, and total_sum = 6. We check if 6 — 3 = 3 matches any prefix of the array. If it does, there is an answer.

    my code:https://atcoder.jp/contests/abc384/submissions/60772223

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

Can anyone share their idea for F

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

Can anyone explain why this is giving TLE for problem F?

Submission

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

There's also a funny solution for problem F:

Our goal is to find a sum $$$ T = \sum_{i=1}^N \sum_{j=i}^N \frac{A_i + A_j}{2^{k_{ij}}} $$$, where $$$ k_{ij} $$$ is largest s.t. $$$ 2^{k_{ij}} $$$ divides $$$ A_i + A_j $$$.

Let's firstly calculate sum $$$S = \sum_{i=1}^N \sum_{j=i}^N \sum_{t=0}^{k_{ij}} \frac{A_i + A_j}{2^{t}} $$$ (can be done in $$$O(n \ log(C))$$$, where $$$ C = 2 * max(A_1, ..., A_N)$$$).

Now, let's fix pair $$$(i,j)$$$. It's occurence into $$$S$$$ would be:

$$$ \sum_{t=0}^{k_{ij}} \frac{A_i + A_j}{2^{t}} = (A_i + A_j) * ( \sum_{t=0}^{k_{ij}} 2^{-t} ) = (A_i + A_j) * (\frac{\sum_{t=0}^{k_{ij}} 2^{t} }{2^{k_{ij}}} ) = (A_i + A_j) * ( \frac{2^{k_{ij}+1} - 1}{2^{k_{ij}}} ) = (A_i + A_j) * ( 2 - \frac{1}{2^{k_{ij}}} ) $$$.

Thus, $$$S = \sum_{i=1}^N \sum_{j=i}^N \sum_{t=0}^{k_{ij}} \frac{A_i + A_j}{2^{t}} = \sum_{i=1}^N \sum_{j=i}^N (A_i + A_j) * ( 2 - \frac{1}{2^{k_{ij}}} ) = ( \sum_{i=1}^N \sum_{j=i}^N 2 * (A_i + A_j) ) - T = 2 * ( \sum_{i=1}^N A_i * (N + 1) ) - T $$$.

Thus, $$$ T = 2 * ( \sum_{i=1}^N A_i * (N + 1) ) - S $$$. Total complexity — $$$O(n \ log(C))$$$. My solution: 60808479.

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

Can anyone help me please, my solution for E is giving wrong even though I'm performing BFS with int64 everywhere, and its always the last 2 out of the 65 test cases 60833551