Hatena::Grouptopcoder

hama_DU@TopCoderへの道

2012-03-20SRM368, SRM369 (Practice)

SRM 369 BeautifulString

|  SRM 369 BeautifulString - hama_DU@TopCoderへの道 を含むブックマーク はてなブックマーク -  SRM 369 BeautifulString - hama_DU@TopCoderへの道

http://www.topcoder.com/stat?c=problem_statement&pm=8193

  • これはダメだ、分からん
    • 適当にやるだけっぽいが明らかにサンプルが弱い
    • 先に500を見よう
public class BeautifulString {
	public int maximumLength(int countA, int countB, int maxA, int maxB) {
		if (maxA == 0 && maxB == 0) {
			return 0;
		}
		if (maxA == 0) {
			return Math.min(countB, maxB);
		}
		if (maxB == 0) {
			return Math.min(countA, maxA);
		}
		
		int max = -1;
		int aparts = (countA + maxA - 1) / maxA;
		if (countB < aparts - 1) {
			return countB + (countB + 1) * maxA;
		}

		int bparts = (countB + maxB - 1) / maxB;
		if (countA < bparts - 1) {
			return countA + (countA + 1) * maxB;
		}
		return countA + countB;
	}
}