yooz's blog

By yooz, history, 34 hours ago, In English

Exactly the the title says, I currently keep track of the problems I can't solve. However, even though I had done more than 50 1700 rated problems sometimes I still struggle... so should I redo the problems I can't solve or just solve new problems until I'm comfortable with this rating? Thank you!

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By yooz, history, 35 hours ago, In English
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf LLONG_MAX
#define pb push_back
#define deb cout<<"YES"<<endl
#define fi first
#define se second
#define pii pair<int,int>
#define lc 2*pos
#define rc 2*pos+1
    int calc(int n,int a){
        int x= 2*a + n-1; 
        x*=n; 
        x/=2;
        return x;

    }
signed main(){
    vector<int>pul(10); 
    pul[0]=1; 
    for(int i=1;i<=6;i++) pul[i]=pul[i-1]*10; 
    int t;cin>>t;while(t--){
        int a,b,c,k;cin>>a>>b>>c>>k;
        if (a>b) swap(a,b); 
        if (c-b!=1 && c-b!=0){
            cout<<-1<<endl;
            continue; 
        }
        int l=pul[a-1],r=pul[a]-1; 
        bool yes=0;
        while(l<=r){
            int mid=(l+r)/2; 
            int aa=pul[b]-1-max(pul[c-1]-pul[a-1],1ll)+1; 
            int cc=max(0ll,pul[b]-1+pul[a-1]-(pul[c]-1)); 
            aa-=cc;
            int prev=calc(mid-1-pul[a-1]+1,aa); 
            int cur=calc(mid-pul[a-1]+1,aa);
            // cout<<mid<<" "<<prev<<" "<<cur<<" "<<aa<<endl; 
            int dif=k-prev; 
            int tar=max(pul[c-1]-mid-1,0ll)+dif; 
            int mi=tar+mid; 
            if (prev<=k && k<=cur && mi<=pul[c]){
                cout<<mid<<" + "<<tar<<" = "<<mi<<endl; 
                yes=1; 
                break;
            }
            else if (cur<k) l=mid+1; 
            else r=mid-1;
        }
        if (!yes) cout<<-1<<endl; 

    }
}

Hi! So this is the problem: https://codeforces.net/contest/1836/problem/C I think the solution is basically the same but I am using binary search (which is actually not needed but yeah the idea should have been the same) but this is incorrect... does anyone know where is the fault or is it logic fault? thank you so much!

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it