This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
int T,C,GO[101],DA[101],END[101],LEN,CYC,ST;
long long M,D,W,ANS,S,SUM[101],CYS;
int main()
{
int T; scanf ("%d",&T); for (C=1;C<=T;C++){
scanf ("%lld %lld %lld",&M,&D,&W);
for (int i=0;i<W;i++){
GO[i] = (D + i) % W;
DA[i] = (D + i + W - 1) / W;
END[i] = -1; SUM[i] = 0;
}
S = 0; END[0] = 0; SUM[0] = DA[0];
while (1){
int E = GO[S];
if (END[E] != -1){
LEN = END[E] + 1;
CYC = END[S] - END[E] + 1;
CYS = SUM[S] + DA[E] - SUM[E];
ST = S;
break;
}
SUM[E] = SUM[S] + DA[E];
END[E] = END[S] + 1;
S = E;
}
ANS = 0; S = 0;
while (LEN-- && M--){
ANS += DA[S];
S = GO[S];
}
if (M > 0){
ANS += CYS * (M / CYC);
M %= CYC;
while (M--){
ANS += DA[S];
S = GO[S];
}
}
printf ("Case #%d: %lld\n",C,ANS);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |