QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#180876#5259. Skills in Pillsucup-team1209#WA 1ms3704kbC++201.6kb2023-09-16 13:57:362023-09-16 13:57:37

Judging History

你现在查看的是最新测评结果

  • [2023-09-16 13:57:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3704kb
  • [2023-09-16 13:57:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define templ template<typename T>
templ bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
    #ifdef zqj
    freopen("a.in","r",stdin);
    #endif
}
typedef long long ll;

int work(int n,int k,int j) {
    ll lcm=1ll*k/__gcd(k,j)*j;
    if (lcm>n) return n/j+n/k;
    int res=lcm/j+lcm/k;
    if (__gcd(j,k)!=1) return res+(n-lcm)/j+(n-lcm+1)/k;
    int inv=1;
    while (1ll*k*inv%j!=1) inv++;
    ll len=1ll*k*inv-1;
    int cnt=inv+len/j;
    int t=(n-lcm)/len;
    res+=t*cnt,n-=t*len;
    return res+(n-lcm)/j+(n-lcm+1)/k;
}

int main() {
    file();
    int n,k,j; cin>>k>>j>>n;
    int ans=n;
    chkmin(ans,work(n,k,j)),chkmin(ans,work(n,j,k));
    if (__gcd(k,j)!=1||1ll*k*j>n) return cout<<ans<<'\n',0;
    n-=j*k,n+=2;
    int invk=1;
    while (1ll*k*invk%j!=1) invk++;
    int invj=1;
    while (1ll*j*invj%k!=1) invj++;
    ll len1=1ll*k*invk-1,len2=1ll*j*invj-1;
    ll c1=invk+len1/j,c2=invj+len2/k;
    rep(t1,0,n/len1) {
        int t2=(n-t1*len1)/len2;
        int res=j+k-2+c1*t1+c2*t2;
        int nn=n-t1*len1-t2*len2;
        if (nn<=2) chkmin(ans,res);
        else {
            nn-=2; res+=2;
            chkmin(ans,res+nn/k+(nn+1)/j);
            if (nn+2<=len1) chkmin(ans,res+nn/j+(nn+1)/k);
        }
    }
    cout<<ans<<'\n';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3564kb

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3704kb

input:

2 5 15

output:

9

result:

wrong answer 1st lines differ - expected: '10', found: '9'