Submission #46217081


Source Code Expand

// LUOGU_RID: 127623306
#include<bits/stdc++.h>
#define il inline
using namespace std;
#define int long long
il int read()
{
    int xr=0,F=1; char cr=getchar();
    while(cr<'0'||cr>'9') {if(cr=='-') F=-1;cr=getchar();}
    while(cr>='0'&&cr<='9')
        xr=(xr<<3)+(xr<<1)+(cr^48),cr=getchar();
    return xr*F;
}
const int N=55,inf=1e18;
int rk,S,d;
int f[N];
il int count(int x)
{
    int res=0;
    for(int i=0;i<d;i++) if(f[i]<=x) res+=(x-f[i])/d+1;
    return res-1;
}
il int find(int rk)
{
    int ct=count((S-1)/2);
    if(ct>=rk)
    {
        int l=1,r=(S-1)/2;
        while(l<r)
        {
            int mid=(l+r)>>1;
            if(count(mid)>=rk) r=mid;
            else l=mid+1;
        }
        return l;
    }
    int l=(S-1)/2+1,r=S;
    while(l<r)
    {
        int mid=(l+r)>>1;
        int cnt=(S-1)/2-(S-1-mid-count(S-1-mid));
        // cout<<"check "<<mid<<" "<<cnt<<" "<<count(S-1-mid)<<endl;
        if(cnt>=rk) r=mid;
        else l=mid+1;
    }
    return l;
}
int solve()
{
    if(rk>(S-1)/2) return -1;
    d=1; while(S%d==0) d++;
    for(int i=1;i<d;i++) f[i]=inf; f[0]=0;
    while("qwq")
    {
        int mv=inf;
        for(int x=1;x<d;x++)
        {
            int v=0;
            for(int i=1;i<d;i++) v=max(v,(S-f[((S-x*i)%d+d)%d])/i+1);
            while(v%d!=x) v++;
            if(v>=f[x]) continue;
            mv=min(mv,v);
        }
        if(mv>(S-1)/2) break;
        f[mv%d]=mv;
        for(int i=0,gd=__gcd(mv,d);i<gd;i++)
        {
            for(int t=i,c=0;c<2;c+=(t==i))
            {
                int nxt=(t+mv)%d;
                f[nxt]=min(f[nxt],f[t]+mv),t=nxt;
            }
        }
        // cerr<<mv<<" ";
    }
    return find(rk);
}
signed main()
{
    int T=read();
    while(T--)
    {
        S=read(),rk=read();
        printf("%lld\n",solve());
    }
    return 0;
}
/*
1
84 22
*/

Submission Info

Submission Time
Task D - Sum Avoidance
User yingxue
Language C++ 20 (gcc 12.2)
Score 1100
Code Size 1948 Byte
Status AC
Exec Time 111 ms
Memory 3864 KiB

Compile Error

Main.cpp: In function ‘long long int solve()’:
Main.cpp:52:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   52 |     for(int i=1;i<d;i++) f[i]=inf; f[0]=0;
      |     ^~~
Main.cpp:52:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   52 |     for(int i=1;i<d;i++) f[i]=inf; f[0]=0;
      |                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1100 / 1100
Status
AC × 1
AC × 31
Set Name Test Cases
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 04_rand_2_06.txt, 04_rand_2_07.txt, 04_rand_2_08.txt, 04_rand_2_09.txt, 04_rand_2_10.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 05_rand_3_06.txt, 05_rand_3_07.txt, 05_rand_3_08.txt, 05_rand_3_09.txt, 05_rand_3_10.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3792 KiB
02_small_01.txt AC 1 ms 3600 KiB
02_small_02.txt AC 1 ms 3616 KiB
02_small_03.txt AC 1 ms 3668 KiB
02_small_04.txt AC 1 ms 3796 KiB
02_small_05.txt AC 1 ms 3796 KiB
03_rand_1_01.txt AC 1 ms 3788 KiB
03_rand_1_02.txt AC 2 ms 3792 KiB
03_rand_1_03.txt AC 1 ms 3808 KiB
03_rand_1_04.txt AC 1 ms 3644 KiB
03_rand_1_05.txt AC 2 ms 3720 KiB
04_rand_2_01.txt AC 32 ms 3668 KiB
04_rand_2_02.txt AC 32 ms 3632 KiB
04_rand_2_03.txt AC 32 ms 3864 KiB
04_rand_2_04.txt AC 32 ms 3864 KiB
04_rand_2_05.txt AC 33 ms 3856 KiB
04_rand_2_06.txt AC 32 ms 3772 KiB
04_rand_2_07.txt AC 31 ms 3800 KiB
04_rand_2_08.txt AC 33 ms 3792 KiB
04_rand_2_09.txt AC 35 ms 3856 KiB
04_rand_2_10.txt AC 33 ms 3792 KiB
05_rand_3_01.txt AC 111 ms 3668 KiB
05_rand_3_02.txt AC 111 ms 3864 KiB
05_rand_3_03.txt AC 111 ms 3804 KiB
05_rand_3_04.txt AC 111 ms 3672 KiB
05_rand_3_05.txt AC 111 ms 3720 KiB
05_rand_3_06.txt AC 111 ms 3600 KiB
05_rand_3_07.txt AC 111 ms 3632 KiB
05_rand_3_08.txt AC 110 ms 3656 KiB
05_rand_3_09.txt AC 111 ms 3656 KiB
05_rand_3_10.txt AC 111 ms 3724 KiB