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

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

We will hold Toyota Programming Contest 2025(AtCoder Beginner Contest 389).

We are looking forward to your participation!

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

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I'm happy to attend it and slove $$$5$$$ problems!

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hoping to do 5 problems

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It's my first time to join this contest seriously.Good luck to me

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

I just solved 4 problems and gave up. It is too hard for me.

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

man , i dont know why my c dont is correct , aaaaa

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

after contest someone explain solution for D.

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

After contest, anyone explain approach for D and F, getting stuck in TLE :(

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

    You can go at max r distance from the center in any direction.So, Move across the x-axis from [-r to r] and find the corresponding max y above[0,r]and lowest y below [-r,0] with binary search. 61834784

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

      Can also use the equation of a circle. Fix values of x like 0.5,1.5,.... and just calculate the y . Since its a circle its symmetrical so you can just multiply by 2

      • »
        »
        »
        »
        22 месяца назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится
        void solve()
        {
        	ll r;
        	cin >> r;
        
        	ll n1 = sqrt(1.0 * r * r - 0.5 * 0.5) - 0.5;
        	ll n2 = (1.0 * r) / sqrt( 2.0) - 0.5;
        
        	cout << 4 * (n1 + n2) + 1 << nl;
        }
        

        What's wrong with this solution ?

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

          I dont get what you are trying to do mate.

          I used the equation (x*x+y*y=r*r) for circles, we know r , if we iterate over x from 0.5 we can find the maximum y for which this is valid. I start from the second square , go till the end , multiply this by 2 and then finally add the middle column once.

          Code
          • »
            »
            »
            »
            »
            »
            22 месяца назад, скрыть # ^ |
             
            Проголосовать: нравится 0 Проголосовать: не нравится

            I'm trying to get the maximum count of squares above the root square. With symmetry , we can get the count for the 4 directions , similar logic for diagonal squares .

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

              Oh ok , well im also doing the same thing i just caluclate apart from the base line as it only occurs once so what i do is calculate from above multipy it by 2 then add. After this i multiply this value by 2 for the whole circle then i manually add the center line which would have occured only once

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I loved problem E,gave D an hour and still can't do it,i'm really bad at geometry.

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Looking at the number of ACs on Problem D, it was really disappointing that I couldn’t come up with the solution. Can anyone explain the solution to Problem D?

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

E was a bit painful

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

My thought process on $$$F$$$.

  1. Bla
  2. Bla
  3. Bla
  4. Implement a segment tree with operations $$$X$$$.

"Maybe I can avoid it? Let's try another idea."

  1. Blo
  2. Blo
  3. Blo
  4. Implement a segment tree with operations $$$Y$$$.

"Try again."

  1. Blu
  2. Blu
  3. Blu
  4. Implement a segment tree with operations $$$Z$$$.
»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Has anyone solved problem E using Lagrange multipliers?

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится
D Major Spoilers
»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Solving F by performing binary search on segment tree. Narrowly pass with 800+ms. When calculating the complexity during contest, always worrying about TLE

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how e

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

With Problem E

I change the value of inf in following code from 1e18+1 to 2e18+1 will result in different answer. Why this happend

#include <bits/stdc++.h>
using namespace std;
typedef __uint128_t ll;
// typedef long long ll;
unsigned long long n, m;
vector<unsigned long long> a;
const long double inf = 1e18+1;
ll calcnt(ll p, ll limit)
{
    return (limit / p + 1) / 2;
}
ll calcost(ll limit)
{
    ll ans = 0;
    for (auto x : a)
    {
        ll cnt = calcnt(x, limit);
        if (x * cnt * cnt > inf)
            return inf;
        ans += cnt * cnt * x;
        if (ans > inf)
            return inf;
    }
    return ans;
}
unsigned long long cal(ll limit)
{
    ll ans = 0;
    for (auto x : a)
    {
        ll cnt = calcnt(x, limit);
        ans += cnt;
    }
    return ans;
}
int main()
{
    cin >> n >> m;
    a.resize(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    ll l = 0, r = 1e18;
    while (l < r)
    {
        ll mid = (l + r) / 2;
        if (calcost(mid) > m)
            r = mid;
        else
            l = mid + 1;
    }
    unsigned long long ans = cal(l - 1);
    m -= (unsigned long long)calcost(l - 1);
    cout << ans + m / (unsigned long long)l << endl;
}
»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain the logic for E ? How is binary search applicable ?

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

    it's pretty common trick: You need to pack the backpack with some items. And your task is to put the maximum number of items there. So logically, you'll put the cheapest items. So you perform the BS over the price of last item you can put there.

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

E > F ?

But I still solve E :)

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Problem E can be ACed using the Cauchy–Schwarz inequality with real numbers, followed by removing sub-optimal buys using a heap.

https://atcoder.jp/contests/abc389/submissions/61842706

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi, I solved 5th question, this is my code, can someone point out what is my mistake?

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    int s=0,e=1^18;
    int ans=-1;
    int pnt=0;
    int ss=0;
    while(s<=e){
        int mid=(e-s)/2+s;
        int sum=0;
        int cnt=0;
        for(int i=0; i<n; i++){
            int k=floor(sqrt(double(mid)/double(a[i])));
            sum+=(k*k*a[i]);
            cnt+=k;
        }
        if(sum<=m){
            ans=mid;
            ss=sum;
            pnt=cnt;
            s=mid+1;
        }
        else{
            e=mid-1;
        }
    }
    // cout<<pnt<<endl;
    // cout<<ans<<endl;
    //  cout<<m<<' '<<ss<<' '<<endl;
    pnt+=(m-ss)/(ans+1);
    cout<<pnt<<endl;

}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Can someone please find mistake.

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

    k*k*a[i] is the total price of k products, the price of the kth product should be (2*k-1)*a[i].

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

      I am stuck in same doubt , I dont understand why calculating using sqrt is wrong. for checking how many k satisfy k^2*p[i] <= x .Why is this incorrect

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

        For each i, check how many k_i satisfy (2*k_i-1)*a[i]<=x, and the sum of k_i^2*a[i] should be <= m.

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

          I was trying to bruteforce with a heap , I do understand that the price of each product would be (2*k_i-1)*a[i] but i dont really understand why is the above comment incorrect it doesnt feel trivial/intituitive to me . Can you explain maybe why the search space for total price wouldnt be monotonic or whats the flaw here

          • »
            »
            »
            »
            »
            »
            22 месяца назад, скрыть # ^ |
            ← Rev. 2  
            Проголосовать: нравится 0 Проголосовать: не нравится

            It seems that you don't understand the meaning of x here. x is the upper limit of the purchase price of each product. For product i, the purchase quantity k must satisfy (2*k_i-1)*a[i]<=x.

            Our goal is to find the largest x so that m is enough to buy all products with a price not exceeding x, and the remaining money can be used to buy products with a price of x+1. This x can be found by binary search x and checking the total price sum(k_i^2*a[i])<=m

»
22 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Give clarity on this please.

In problem E. It calculated a price x(using binary search) for which we can by all items with price <=x. Such that total cost is <=M but there will be some remaining money. why is this remaining money used to buy as many items as possible of price x+1. (remaining_money)/(x+1). How we know if item priced x+1 will exist with surety and we can buy as many as possible.