Submission #5878

# Submission time Handle Problem Language Result Execution time Memory
5878 2014-05-20T21:20:00 Z kriii 새로운 달력 (GCJ12KOR_calendar) C++
25 / 25
0 ms 1088 KB
#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
1 Correct 0 ms 1088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1088 KB Output is correct