å¾®å¦ãªé ä½ã§Round1ãééãã
312ä½, 228.26ç¹, +1/-0 challenge
Volatility: ?->255
250: TheNicePair
æ´æ°ã®ãªã¹ããä¸ããããã®ã§ãããããä»»æã®ç¯å²ãé¸ãã æã«ç¯å²å
ã®åå以ä¸ã®æ´æ°ã1以å¤ã®åãæ°ã§å²ãåããæ大ã®ç¯å²ã®é·ãå¼ã1ãçãã
æ¡ä»¶ãæºãããªãå ´åã¯-1ã¨çãã
ãã¹ã¦ã®ç¯å²ã¨ãã¹ã¦ã®æ°ã§å²ãã®ã試ãã¦ãéã«åãã£ã½ã
é·ãã1ã®æã«å¿ ã-1ã¨çããã³ã¼ãã®äººãããã®ã§1æå¢ã§ãã
ä¸è¨ã®ã³ã¼ãã¯æåã«ããããç´ å æ°ã®åæããã¦ãããã£ã¦ã
# -*- coding: utf-8 -*- import math,string,itertools,fractions,heapq,collections,re,array,bisect def prime_factor_table(n): table = [0] * (n + 1) for i in xrange(2, n + 1): if table[i] == 0: for j in xrange(i + i, n + 1, i): table[j] = i return table def prime_factor(n, prime_factor_table): prime_count = collections.Counter() while prime_factor_table[n] != 0: prime_count[prime_factor_table[n]] += 1 n /= prime_factor_table[n] prime_count[n] += 1 return prime_count class TheNicePair: def solve(self, A): L = len(A) P = prime_factor_table(1002) print p = [] for i in xrange(L): p.append(prime_factor(A[i], P)) result = -1 divisor = set() for d in p: for div in d: divisor.add(div) for i in xrange(L): for div in divisor: if div == 1: continue count = 0 length = 0 for j in xrange(i, L): length += 1 if div in p[j]: count += 1 if count * 2 >= length and result < j - i: result = j - i return result
500: TheTips
Nåã®ãã®ãè¦ã¤ãã確ç\(probability\)ãä¸ãããã
ã¾ãiçªç®ã®ãã®ãè¦ã¤ãã£ããå¿
ãããä»ã®è¦ç´ ãè¦ã¤ããé¢ä¿ãå®ç¾©ããã¦ãã¦ããã®ãªã¹ããä¸ãããã
ä½åãè¦ã¤ãããã®æå¾
å¤ãçãã
確çãæ±ãã¦æå¾ å¤ã®ç·å½¢æ§ã§ããã ããã¨æã£ãã2å以ä¸ã®é£éã§è¦ã¤ããå ´åãèæ ®ãã¦ãªãã¦æ¬çªä¸ã«ã¯è§£ããªãã£ã
içªç®ã®ãã®ãé£éãã¦è¦ã¤ããå¯è½æ§ã®ãããã®ãDFSãã¯ã¼ã·ã£ã«ã»ããã¤ãçãªã¢ã«ã´ãªãºã ã§ãããããåæãã¦ãã
ä»ããé£éçã«è¦ã¤ããå ´åãå«ãã¦içªç®ãè¦ã¤ãã確çã¯ã1ãã¤ãã¹içªç®ãè¦ã¤ãããªã確çãªã®ã§ãiçªç®ãé£éãã¦è¦ã¤ããå¯è½æ§ã®ãããã®ã«ã¤ãã¦ããããè¦ã¤ãããªã確çãããã¦ã1ããå¼ãã°ãã
# -*- coding: utf-8 -*- import math,string,itertools,fractions,heapq,collections,re,array,bisect class TheTips: def solve(self, clues, probability): L = len(clues) result = 0.0 probability = list(probability) for i in xrange(L): probability[i] /= 100.0 clues = list(clues) for k in xrange(L): for i in xrange(L): clues[i] = list(clues[i]) for j in xrange(L): if clues[i][k] == clues[k][j] == 'Y': clues[i][j] = 'Y' for i in xrange(L): prob = 1.0 for j in xrange(L): if i == j: prob *= (1 - probability[j]) elif clues[j][i] == 'Y': prob *= (1 - probability[j]) result += (1 - prob) return result