åé¡ã解ãããæ¹åãï¼ãã¿ãã¬ãå«ã¿ã¾ãã
1åéã空ãã¦ãã¾ãã¾ãããåå ãã¦ãã¾ãããä»åã¯æéå ã«è§£ããªãã£ãã®ã§ãããåé¡çã«ããã°ã©ãã³ã°ããã«è§£ããããããªããã¨ããæ°ãããã®ã§ã»ã¨ãã©ããã°ã©ãã³ã°ããã«è§£ããçµæã®writeupããå±ããã¾ãã
æ®éã«è§£ããããããªã
ãã«ãã¼ã¡ã½ããçãªã®ããã®ã¾ã¾æ®ã£ã¦ãããã£ã¦ããã©ããã®ç¢ºèªé¨åãå ¨é¨ã³ã¡ã³ãã¢ã¦ãã«ãªã£ã¦ãããã¨ããã¨ããã¯ç®ãã¤ã¶ãã¨ãã¦â¦
- ã¾ãã¯æå®ãããç¶æ³ã¾ã§ç¤é¢ãä½ã(solveã®å帰ãapply)
- ã§ããç¤é¢ãå·¦ä¸ããé ã«ç½ãæ¢ããé£ç¶ããç½ãå¡ã£ã¦æ°ãä¸ãã¦ãã(paint_board)
- paint_boardãå帰ã§æ¸ãã¦ãããã©ããã¨ããããstack size exceededã¨è¨ãããã®ã§queueãç¨ãã¦æ¸ãç´ãã
â¦ã¨ããã®ããã£ã¦ãä¸èº«ã
ããããæ°å¦ã®åé¡ã¨ãã¦ã解ããã¨ãã§ããã®ã§ã¯ï¼
ç¾å ´ã§ãæã£ã¦çµå±éã«åããªãã£ãã®ã§ãããããç¶æ ã«å¯¾ãã¦æä½ãé©ç¨ãã¦æ°ããç¶æ ãä½ããã¨ããéç¨ã§ãã®ç¶æ ã®ä¸ã®ç¹å¾´çãªå¤ãè¨ç®ãããã¨ããã®ã§ããã°ãæçµçãªç¤é¢ãä½ã£ã¦æ°ãä¸ãããã¨ãããã¨ãããã¨ãé©åãªã¢ããªã³ã°ãããã°æ¼¸åå¼ã§è§£ããã¨ãã§ããã®ã§ã¯ï¼ã¨æã£ã¦ã解æ£å¾ãããã®æ¹éã§è§£çãæºåãã¾ããã
Oã®é£ç¶ã®ã±ã¼ã¹
ã¾ãã¯ãOã®é£ç¶æ°ãnã¨ãã¦ãã§ããé åæ°ãnãç¨ãã¦è¡¨ããã¨ããå°åé¡ã解ãã¾ãã
詳細ãªè¨¼æã¯çç¥ãã¾ããã以ä¸ã®è¦é ã§ç½ã®é åãæ°ãä¸ãã¾ãï¼
- 対è§ç·ã§æ£æ¹å½¢ãåå²ãããã®ãã¡ã®1ã¤ã®ä¸è§å½¢ã®ç¶æ ãn=1ã®ç¶æ (1åã®ç©ºç½ã®ããç¶æ )ã«å¯¾å¿ã¥ããã
- n=2ã®ç¶æ ã¨ãã¦ããã®ä¸è§å½¢ããå³ã®ããã«å°ããä¸è§å½¢ã2ã¤ä½ã£ãç¶æ ã¨ããã
- n=3以éã§ã¯ãåã®ç¶æ ã®æãå°ããä¸è§å½¢ããããã«2ã¤ã®å°ããä¸è§å½¢ãä½ãã
ããã«ãã£ã¦ãOã®é£ç¶ã®ã¨ã㯠2n+3 - 4 åã®é åãã§ãã¾ãã
Xã®é£ç¶ã®ã±ã¼ã¹
ããããå°ã åä»ã§ããXã®é£ç¶æ°ãnã¨ããã¨ããn=1ã®ã¨ãã¨n=2以ä¸ã®ã¨ãã¨ã§è¨ç®æ¹æ³ãå¤ããã¾ããn=1ã®ã¨ãã¯è¦ãã¾ãã¾ã§é åæ°5ã§ãã
Xã¨ããæä½ã¯ä»¥ä¸ã®ãããªæ§è³ªãæã¡ã¾ãï¼
- é£æ¥ããé»ã®ãã¹ãä½ããªãã(ããã¯Oã«ã¤ãã¦ãåæ§ãªã®ã§ãä»»æã®åæ°Oã¨Xãç¹°ãè¿ããã¨ãé£æ¥ããé»ã®ãã¹ã¯çããªãï¼
- [[0,1],[1,0]]ã®ãããªå½¢ã§é»ã¨ç½ã並ãã§ããã¨ãï¼0ãé»ã§ã1ãé»ã§ãã©ã¡ãã§ãããï¼ãããã«Xãé©ç¨ããã¨åã®ç¶æ ã§ã¯å¥ã®é åã¨ãã¦æ°ãããã¦ããç½å°ã¯é©ç¨å¾ã«ã¯1ã¤ã®ç½å°ã«ãªãã(ãããn=2以ä¸ã§å ´ååããå¿ è¦ãªçç±)
- ä¸è¨ã®æ§è³ªãããn=2以ä¸ã®ã¨ãn=1æã«åå¨ããä¸å¤®ã®ç½å°ã¨è§ã®ç½å°ã¯å ¨é¨ãã£ã¤ãã
- n=2以ä¸ã§ãé»ã®ãã¹ã«Xãé©ç¨ããã¨éã«æ°è¦ã«1ã¤ã®ç½å°ãã§ããã
æå¾ã®æ§è³ªãããnåXãé©ç¨ããã¨ãã®ç½å°ã®æ°ã¯(åã®é»ã®ãã¹ã®æ°) + 1ã¨ãªãã
- é»ã®ãã¹ã®æ°ã¯n=1ã§4
- Xã1åé©ç¨ãããã¨ã«4å
以ä¸ãããn >= 2 㧠4n-1 + 1 åã®ç½å°ãåå¨ãããã¨ã«ãªãã¾ãã
Oã¨Xã®æ··åã±ã¼ã¹
Xã§çµããå ´å
Xã§çµããå ´åãXã®ã¿ã®ã±ã¼ã¹ã¨åæ§ãåã®é»ã®ãã¹ã®æ°ãç¨ãã¦è¨ç®ã§ããã®ã§ã
- Xã¯é»ã®ãã¹ã4åãã
- Oã¯é»ã®ãã¹ã5åãã
ãã¨ãããXã®æ°ãnãYã®æ°ãmã¨ãã¦ã4n-1 * 5m + 1 åãã¨è¨ç®ã§ãã¾ãã ããããXã1åã®å ´åï¼Oã®é£ç¶ã®ãã¨ã«Xãæ¥ãå ´åï¼ã¯ä¾å¤ãããããOã®ã¿ã®é£ç¶ã®å ´åã¯è§ã¯é»ããXãåãã¦æ¥ãã¨è§ã«ç½ãã§ãããâ¦ã¨ãããã¨ã§è§ã®4ã¤ã®ç½å°ãæ°ãã¦ãããªãã¦ã¯ãããªããªãããã®ã¨ã㯠41-1 * 5m + 1 + 4ãã¤ã¾ã 5m + 5ãæ±ããé åæ°ã«ãªãã¾ãã
Oã§çµããå ´å
Oã¨ããæä½ã®æ§è³ªã¨ãã¦ã
- æä½åã«åå¨ããç½å°ã®æ°ã¯ä¿åããã
- ãã®ä¸ã§ã辺ãããã¯è§ã«æ¥ããé»ãæ°è¦ã®ç½å°ãä½ãã辺ã«æ¥ããé»ãã¹1ã¤ã1ã¤ãè§ã®é»ãã¹ã2ã¤ã®ç½å°ãæ°è¦ã«ä½ã
- ãã®ã¨ãããOã¨Xãæ··åããã¤ãOã§çµãããã®ã§ãè§ã¯å¿ ãç½ãã§ãããã¨ã«æ³¨æ
ã¨ããæ§è³ªãããã¾ãï¼è¨¼æã¯ã¡ããã¨ããã®æ¸ããæ°ãããªãã®ã§çç¥ããããããé£æ¥ããé»ã¯åå¨ããªããã¨ããæ§è³ªã¨ã»ããã§æ±ãã¨ãç½å°ãæ¸ããªããã¯è¨¼æã§ãããï¼ã
以ä¸ãããåã®ç¶æ ã®ç½å°ã®æ° + æ°è¦ã«ã§ããç½å°ã®æ°ãã§è¨ç®ã§ãããã¨ã«ãªãã¾ãã
æ°è¦ã«ã§ããç½å°ã®æ°ã¯è¾ºã«æ¥ããé»ãã¹ã®æ°ã«çãããããã¯
- Xã¯è¾ºã«æ¥ããé»ãå¢ãããªã
- Yã¯è¾ºã«æ¥ããé»ã2åãã
- åæå¤ã¯4
â¦ãªã®ã§ãçµæã¨ã㦠åã®ç¶æ ã®ç½å°ã®æ° + 2m+1 *1ã§ä¸ãããã¾ãã
ç´æ¥è¨ç®ããã³ã¼ã
以ä¸ã®çµæãç¨ããã®ããã¡ãã«ãªãã¾ããâ¦çµå±ããã°ã©ã 使ã£ã¦æ¤è¨¼ãã¦ããããã£ã¦ã®ã¯ãã·ã§ï¼
ãã£ã¨ãã·ãªæ¸ãæ¹ãã§ããããããã¾ããããããªã¨ããã§ãããâ¦ããã¨Oã¨Xã®æ··åã±ã¼ã¹ãããããå帰ããã«ãã£ã¨ç°¡æ½ã«æ¸ãæ¹æ³ããããããããªãã
ææ³
æéå ã§æ°å¦ã®åé¡ã¨ãã¦è§£ã解æ³ã«ãã©ãçãã人ãããã¿ããã ããæ°å¦ãå¾æãªäººãªãæ°å¦ã§è§£ã解æ³ãããã§ãªã人ã¯ããã°ãã°1æé以å ã«ããã°ã©ãã³ã°ã§ãããã¨ããæå³ã§é常ã«ãã©ã³ã¹ã®åããåé¡ã ã£ãã®ã§ã¯ãã¨ããå°è±¡ããªãç§ã¯è§£ãã¾ããã§ããã1æåãã¤é©ç¨ãããªãå帰ã§è§£ããããã¨ãªã£ã¦multi-body functionãã»ããããElixirã§æ¸ãåºãããã®ã®ãå¤æ¬¡å é åããã¾ãæ±ãæ¹æ³ãç¥ããè¦æ¦ãçµæã¨ãã¦æéåãããã®å¾ã¯è«¦ãã¦Rubyã§æ¸ããã次ããå¤æ¬¡å é å使ã£ããvector使ã£ããããåé¡ã¯Dè¨èªã¨ãã§è§£ããâ¦ã