QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#180876 | #5259. Skills in Pills | ucup-team1209# | WA | 1ms | 3704kb | C++20 | 1.6kb | 2023-09-16 13:57:36 | 2023-09-16 13:57:37 |
Judging History
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'