Submission #5878

#TimeUsernameProblemLanguageResultExecution timeMemory
5878kriii새로운 달력 (GCJ12KOR_calendar)C++98
25 / 25
0 ms1088 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...