paizaã§æ°ãããªã³ã©ã¤ã³ããã«ã½ã³ãåºé¡ããã¦ããã®ã§ææ¦ãã¦ã¿ã¾ãã
マンガ版「エンジニアでも恋がしたい!」〜転職初日にぶつかった女の子が同僚だった件〜|paizaオンラインハッカソン4 Lite
ä»åã¯ç°¡åãªæãã ã£ãã®ã§ãæè¿ä»¥ä¸ã®ã¹ã©ã¤ããèªãã§ããæ©ä¼ã ã£ãã®ã§Pythonã®ã¯ã³ã©ã¤ãã¼ã§è§£ãã®ã«ææ¦ãã¦ã¿ã¾ãã
Pythonã¯ã³ã©ã¤ãã¼ã®æ³¨æç¹
ã¾ã£ããå®ç¨çã§ã¯ãªãã®ã§æ³¨æ
以ä¸ã®è¨äºãããããããã£ãã§ã
闇Pythonista入門(Pythonワンライナーのテクニック集) - Qiita
ã¯ã³ã©ã¤ãã¼ã§ã¯å
¨é¨ã®ããã°ã©ã ã1è¡ã§æ¸ãã®ã§ãæ¹è¡ã¨ã¤ã³ãã³ããå¿
è¦ãªif, for, whileãªã©ã¯æ¸ããã¨ãã§ããªã(ãã®ä»ã¯æ¹è¡ã®ä»£ããã«;ãç½®ãã°ã ãããæ¸ãã)
ä½ãã§ããªãã¦ã代ããã«ã©ãããã以ä¸ã«åæãã
é¢æ°å®ç¾©
defããå§ã¾ãé¢æ°å®ç¾©ã¯æ¹è¡ã¨ã¤ã³ãã³ããå¿
è¦ã«ãªãã®ã§ãã¡ãã使ããªã
代ããã«ã©ã ãå¼ã使ãã¾ã
ã©ã ãå¼ã®ä¸ã«ã¯å¼ããå
¥ããããªãã®ã§ã代å
¥æãprintæãªã©ãããããã¨ãã§ãã¾ããã
代ããã«é¢æ°ãå¼ã¶ãã¨ãã§ããã®ã§ãã°ãã¼ãã«å¤æ°ã®è¾æ¸ãè¿ãglobals()ã使ã£ãglobals().update({key:value})ããsys.stdout.writeãªã©ãå¼ã¶å¿
è¦ãããã¾ã
ã¾ãè¤æ°ã®å¼ãå
¥ããå ´åã«ãã¿ãã«ããªã¹ãã§å
¥ãããªã©ã®å·¥å¤«ãå¿
è¦ã§ã
æ¡ä»¶åå²
è¤æ°è¡ã®ifã使ããªãã®ã§ãä¸é æ¼ç®åA if condition else Bããè«çæ¼ç®åA and BãA or Bããæ¼ç®çµæã§ãªã¹ããªã©ã®åç §å ãå¤ãããªã©ã®ãã¯ããã¯ãå¿ è¦ã«ãªãã¾ã
ã«ã¼ã
mapãå
å
表è¨ãªã©ã使ããã¨æ¸ããããã§ã
ä»ã«ãitertoolsã®ä¾¿å©ãªé¢æ°ããã©ã ãå¼ã®å帰ãªã©ã使ãã¾ã
ãã ãå帰åæ°ã®ä¸éã¯ããã©ã«ãã§1000ãªã®ã§sys.setrecursionlimitã§ä¸éãå¤ããªãã¨ãããªãããããã¾ãã
åç´ã«å
å
表è¨ã®å
¨è¦ç´ ã«å¯¾ãã¦ã«ã¼ããããã¨ããªããmaxãminã®å¼æ°ã«ä¸ããã ãã§ãããã§ã
1åç®
1è¡ç®ã«è¦ç´ æ°ããã®å¾ã®åè¡ã«æ°å¤ãä¸ããããã®ã§ç·åãçãã
å ¥åã¯æ¨æºå ¥åã«ã¦ä»¥ä¸ã®ãã©ã¼ãããã§ä¸ãããã¾ãã N S_1 S_2 ã» ã» S_N ãã¹ã¦ã®ãã¹ãã±ã¼ã¹ã«ããã¦ã以ä¸ã®æ¡ä»¶ãã¿ããã¾ãã 1 ⦠N ⦠100 0 ⦠S_i ⦠100
解ç
1è¡ã§è¡¨ç¤ºããã¨èªããªããªãã®ã§ã;ãã¨ã«æ¹è¡ãã¦ããã¾ã
import sys; print sum(map(int, sys.stdin.read().splitlines()[1:]))
2åç®
ç¾å¨ã®å¨åº«æ°\(S\)ãå¿
è¦ãªå¨åº«æ°\(T\)以ä¸ã®ãã®ããã£ããä¸ã¤ã«ã¤ãä¾¡æ ¼\(P\)ã§è£å
ãã
å
¨é¨ã®ååã«ã¤ãã¦è£å
ããæã®åè¨éé¡ãçãã
å ¥åã¯æ¨æºå ¥åã«ã¦ä»¥ä¸ã®ãã©ã¼ãããã§ä¸ãããã¾ãã N T_1 S_1 P_1 T_2 S_2 P_2 ã» ã» ã» T_N S_N P_N ãã¹ã¦ã®ãã¹ãã±ã¼ã¹ã«ããã¦ã以ä¸ã®æ¡ä»¶ãã¿ããã¾ãã 1 ⦠N ⦠100 1 ⦠T_i ⦠100 0 ⦠S_i ⦠100 1 ⦠P_i ⦠10,000
解ç
import sys; print sum(map(lambda x: (lambda y: max(y[0] - y[1], 0) * y[2])(map(int, x.split())), sys.stdin.read().splitlines()[1:]))
3åç®
\(n\)åã®æ°åãä¸ããããã®ã§ãé£ç¶ãã\(t\)åã®æ°åã®ç·åã®ãã¡æ大ã®ãã®ãçãã
å ¥åã¯æ¨æºå ¥åã«ã¦ä»¥ä¸ã®ãã©ã¼ãããã§ä¸ãããã¾ãã t n m_1 m_2 m_3 ... m_n ãã¹ã¦ã®ãã¹ãã±ã¼ã¹ã«ããã¦ã以ä¸ã®æ¡ä»¶ãã¿ããã¾ãã 1 ⦠t ⦠n ⦠300,000 0 ⦠m_i ⦠10,000
解ç
tåã®ç·åã«1åãã¤è¦ç´ ã足ãå¼ããã¦åæç¹ã§ã®ç·åãè¨ç®ãã¦ããã¾ã
ã«ã¼ãã®æ¸ãæ¹ãããããããªãã¦è¦æ¦ãã¾ãã
import sys, itertools; set_global = lambda x, y: globals().update({x: y}); lines = sys.stdin.read().splitlines(); t, n = map(int, lines[0].split()); num = map(int, lines[1:]); set_global('sum', sum(num[:t])); print max(sum, t < n and max((((set_global('sum', sum + num[i] - num[i - t]), sum)[1] for i in xrange(t, n)))));
Python 3.3以éã ã¨itertools.accumulateãããã®ã§ããã¡ãã£ã¨çãããã¾ãã
import sys, itertools; lines = sys.stdin.read().splitlines(); t, n = map(int, lines[0].split()); acc = list(itertools.accumulate(map(int, lines[1:]))); print(max([acc[i] - acc[i - t] for i in range(t, n)] + [acc[t - 1]]))
ã¾ã¨ã
Pythonã¯ã³ã©ã¤ãã¼åå¿è
ãªã®ã§ãããºã«ã¨ãã¦ã¯çµæ§ãããããã¦æ¥½ããã£ãã§ã
ãã ããããäºåº¦ã¨ãããããªããããªæ°ããã¾ã