답안 #5878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1088 KB Output is correct