2024-05-01ãã1ã¶æéã®è¨äºä¸è¦§
ãã®æ代㯠Greedy ãå¤ãã£ããããã¦ãå®ã¯ãããåç´ãªãã¨ã«æ°ãã¤ããã©ãããåãããåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ°ç´ç·ä¸ (æ±è¥¿æ¹å) ã« åã®çºããããããããã®çºã®åº§æ¨ã¯ ã§ãããçº 1 ããåºçºãã¦ããã¹ã¦ã®çºã訪ãããã次㮠2 ã¤ã®æãâ¦
æååã®åããã·ãã¥ã¬ã¼ã·ã§ã³ããªããæ大å¤ãæ´æ°ãã¦ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãæã£ã¦ãã¦ãæå㯠0 ã§ããã é·ã ã®æåå ã«å¾ã£ã¦ãããã使ã£ã¦ åã®æä½ãè¡ã£ãã åç®ã®æä½ã§ã¯ãæå ã 'I' ãªãã° ã 1 å¢ããã'D' ãªãã° ãâ¦
mod 998244353 ã®ç·´ç¿ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ éè² æ´æ° ãä¸ããããã ã 998244353 ã§å²ã£ãä½ããæ±ããã å¶ç´ èããã㨠ã足ãç®ã»å¼ãç®ã»ããç®ããããè¨ç®çµæã 998244353 ã§å²ã£ãä½ããæ±ããæ¹æ³è«ã«ã¤ãã¦ã¯ã次ã®è¨äºã«è©³ããæ¸ããã â¦
ç´ å æ°å解ãä¸æã«æ´»ç¨ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ããããã ã®æ£ã®ç´æ°ã®åæ°ã 1000000007 ã§å²ã£ãä½ããæ±ããã å¶ç´ èããã㨠ãç´æ°ã®åæ°ããã¾ã¨ãã«èå¯ããå ´åã«ã¯ãç´ å æ°å解ãå½¹ã«ãã¤ãã¨ãå¤ããä¸è¬ã«æ£ã®æ´æ° ãâ¦
ã¨ã¦ãæè²ç㪠Greedy åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®éè² æ´æ°ãããªãæ°å ãä¸ããããããã®æ°åã«å¯¾ãã¦ã ãæ£ã®æ´æ°ã§ããè¦ç´ ã 1 ã¤é¸ã³ã-1 ããã ã¨ããæä½ãç¹°ãè¿ããã¨ã§ãã©ã®é£æ¥ãã 2 åã®è¦ç´ ã®åã 以ä¸ã¨ãªãããã«ãããã ãâ¦
å¶ç´ã ã¨å¤§ããã®ã§ãã¡ããã¨æ´æ°è«çå¦çãããªãã¨ãããªãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä»¥ä¸ ä»¥ä¸ã®æ´æ°ã®ãã¡ã ã®åæ°ã¯ä½åãããï¼ å¶ç´ èããã㨠å¶ç´ã ã¨æ¥µãã¦å¤§ããã®ã§æ¢ç´¢ææ³ã§è§£ããã¨ã¯é£ãããæ°å¦çã«æ±ãããã¨ãèããã ã¾ããã â¦
äºæ¬¡å ã°ãªããã®åºæ¬åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªãããä¸ãããããåãã¹ã®æå㯠'.' ã '*' ã§ããã ãã®ã°ãªããã縦æ¹åã« 2 åã«å¼ã伸ã°ãã¦åºåããã è§£æ³ åã®æååã®å ¥åãåãåããåè¡ãã¨ã« 2 åãã¤åºåãã¦ããã° OKã #includâ¦
åãã åãé¸ã¶è¨å®ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ°å¤ ãä¸ãããã (è² å¤ããããã)ã ãããã®æ´æ°ãã åé¸ãã§ç©ãã¨ã£ãå¤ã®æ大å¤ãã1000000007 ã§å²ã£ãä½ããæ±ããã å¶ç´ èããã㨠æ¬è³ªçã«ã次㮠2 ãã¿ã¼ã³ã«åãããã¨èãããâ¦
ãç·å½¢æ¢ç´¢ãã¨ãæå°å¤ãæ±ãããã®çµã¿åããæï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®ãã¢å¤ ãä¸ããããã ãæºãããã㪠ã«ã¤ãã¦ã®ã ã®æå°å¤ãæ±ããããã®ãã㪠ãåå¨ããªãå ´å㯠"TLE" ã¨åºåããã è§£æ³ for æãç¨ãã¦ãå i ã«ã¤ã㦠t[i] <= T â¦
ã¡ãã£ã¨é ã使ãç³»ã®åé¡ããã®ææã® ABC-A ã«ã¯ãããããã®ãå¤ãã£ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ããããã¡ããã© åè²·ããã åæã£ã¦ åè²·ã åæã£ã¦ åè²·ã ã®ããããã«ãã£ã¦ãã¡ããã© åè²·ãããã®æå°ã³ã¹ããæ±ããã è§£æ³ ä»¥ä¸ã®ããããâ¦
äºæ¬¡å ã°ãªããä¸ãä¸ä¸å·¦å³ã«åãã¦ããã·ãã¥ã¬ã¼ã·ã§ã³åé¡ãç¡éã«ã¼ãã®å¤å®ãå°ããããããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããããããåãã¹ã«ã¯ U, D, L, R ã®ãããããæ¸ããã¦ããããããããä¸ãä¸ãå·¦ãå³ã¸ã¨é²ãæ示ã表ãã¦ããã ãâ¦
äºæ¬¡å é åãäºé for æã§èª¿ã¹ãæä½ã©ã¤ã³ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããã«ã¢ã«ãã¡ãããæåãæ¸ããããã®ã 2 㤠() ä¸ãããã¾ãã ããã㯠1 ç®æã®ã¿ç°ãªã£ã¦ãããã¨ãä¿è¨¼ããã¾ãã ã§ãããã㪠ãçãã¦ãã ããã å¶ç´ è§£æ³ (C++) â¦
ç¾å®ä¸çã£ã½ãé¡æãæ±ã£ãã¡ãã£ã¨æ¥½ããåé¡ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãã¼ã A ã¨ãã¼ã B ãéç対æ¦ããã9 å表ã¾ã§çµäºãã¦ãã¦ã (ãã¼ã A ã®å¾ç¹) ⧠(ãã¼ã B ã®å¾ç¹) ã¨ãªã£ã¦ããããã¼ã B ã 9 åè£ã§åå©ããã®ã«å¿ è¦ãªæå°è¿½å ç¹ãæ±ãâ¦
éåæ¬ B11 ã¨ã»ã¼åãåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 身é·ã ã§ãããã㪠人ãããã以ä¸ã® åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã æ´æ° key ãä¸ããããã®ã§ã身é·ã key 以ä¸ã®äººãä½äººããããçããã å¶ç´ èããã㨠0-indexed ã§èãã¾ãã æåã«ã â¦
ãã®åãB 㨠C ãç°å¸¸é£æ度ã ã£ãããã«ãD ãå®éã®é£æ度ãããã ã㶠Diff ãä¸ãã£ã¦ããã ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å°ã®ã½ãªããããããããããã«ã¤ã å¹å¿ è¦ã¨ããã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã ããã«ã¤ã å¹ããã¨ãã«ãæ大ã§ä½å°â¦
ãçãã§äºåæ¢ç´¢ãã®ãã¡ããã¡ãããç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å°ã®ããªã³ã¿ã¼ãããã çªç®ã®ããªã³ã¿ã¼ã¯ ç§å¾ã«ããªã³ãããã åãã㦠çªç®ã®ããªã³ããè¡ãããã®ã¯ä½ç§å¾ãï¼ å¶ç´ çãã 以ä¸] è§£æ³ éåæ¬ã®åé¡ãªã®ã§ãéåæ¬åç §ã 1â¦
lower_bound() ã®ç·´ç¿ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®é å ãä¸ããããããã®é åã«å¯¾ã㦠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã æ´æ° ãä¸ããããã®ã§ãé å ã®ä¸ã« ããå°ããè¦ç´ ãä½åããããæ±ããã å¶ç´ è§£æ³ github.com ã³ã¼ã #include <bits/stdc++.h> using</bits/stdc++.h>â¦
ãã®æã®ç´¯ç©åé«éåãå端ãããªãè¦æãªãã¨ãããã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã ãã®æ°åãããã¤ãã®åºéã«åå²ããæ¹æ³ã®ãã¡ã çªç®ã®åºéã«å«ã¾ããæ°åã®è¦ç´ ã®ç·åã ã§å²ãåãããããªãã®ã®åæ°ã 1000000007 ã§â¦
ããã¯ã¡ãã£ã¨æ´çã大å¤ãªåé¡ãæã åé¡æã«ç»å ´ãã 0.5 ã¨ããæ°å¤ããªããªã®ããç¥ããåé¡ã¨ãè¨ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®åºéããããååºé㯠4 ã¿ã¤ãããã ã¿ã¤ã 1ï¼åºé ã¿ã¤ã 2ï¼åºé ã¿ã¤ã 3ï¼åºé ã¿ã¤ã 4ï¼åºé ã¨ãªã£ã¦ãâ¦
ããçµæ§é£ããï¼ æ°å¼ãä¸å¯§ã«ç«ã¦ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ç®±ã«æ°´è²ã®ãã¼ã«ã åå ¥ã£ã¦ããã ã箱㫠åã®æ°´è²ã®ãã¼ã«ã¨ã åã®èµ¤è²ã®ãã¼ã«ãå ¥ãããã¨ããæä½ãç¹°ãè¿ããã¨ã§ã赤è²ã®ãã¼ã«ã®åæ°ãæ°´è²ã®ãã¼ã«ã®åæ°ã® å以ä¸ã¨ãªãããã«â¦
ããã¯ãããeditorial ã«ããå³ããã¹ã¦ãªã®ã§åå¿é²ç¨åº¦ã«ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªãããããã åã®ç³ããããç³ ã¯ã ã㤠ãæºãããããªãã¹ ã«ç½®ããã¨ãã§ããã ãã ããã©ã®è¡ã»ã©ã®åã«ã¤ãã¦ãã2 å以ä¸ã®ç³ãç½®ãããªãããã«ãããâ¦
ã«ã¿ã©ã³æ°ãããã£ã¦ããã°ã§ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ãããããé»ããã¼ã« åã¨ãç½ããã¼ã« åãä¸åã«ä¸¦ã¹ãæ¹æ³ã®ãã¡ã次ã®æ¡ä»¶ãæºãããã®ã®åæ°ã 1000000007 ã§å²ã£ãä½ããæ±ããã ãæ¡ä»¶ã ã©ã® ã«ã¤ãã¦ããåã®å·¦ãã â¦
è²ããªæ¹æ³ãããããã§ããã ã楽ã«ããããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å調å¢å 㪠è¦ç´ ãããªãæ°å ãããããã®æ°åã«ã¤ãã¦ã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã æ´æ° ãä¸ããããã®ã§ã ã®ã©ãã¨ãç°ãªãæ°å¤ (ããæ°ã¨å¼ã¶ãã¨ã¨ãã) ã®ãã¡ãâ¦
æç´ã« ã ãæ±ãããã¨ããã¨ãè²ããªçç±ã§ãããããªã£ã¦ãã¾ããæ°å¦çã«ç¶ºéºã«å¦çãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ããããã 㨠ã®å¤§å°é¢ä¿ãæ±ãã (大ãããå°ãããçãã)ã å¶ç´ èããã㨠ã ã¯ã¾ã¨ãã«è¨ç®ããã¨ãã®ãããæ¡æ°ã«â¦
ããããªæ¹æ³ãèããããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 1 ä»¥ä¸ ä»¥ä¸ã®æ´æ°ãããªãæ°å ãä¸ãããã¾ãã ãã®æ°åã ã並ã³æ¿ãããããã¨ã§å¾ããããã©ãããå¤å®ããã å¶ç´ èããã㨠åé¡æã¯ã ã並ã³æ¿ãããã¨ã§ ã«ä¸è´ããããããããåããããâ¦
ããã§ã¯ãlower_bound() ã使ã£ã¦è§£ãã¦ã¿ããã¨ã«ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å°ããé ã«ä¸¦ã¹ãããé å ãä¸ããããã å¤ ã ã®ä¸ã§ä½çªç®ã®è¦ç´ ã®å¤ã§ããããæ±ããããã ãã ã®ä¸ã«å¤ ã®è¦ç´ ã¯å«ã¾ãã¦ããã¨ããã å¶ç´ èããã㨠å®ã¯åç´ãª â¦
while æã®ç·´ç¿ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 0 æ¥ç®ã«ã¯ 0 cm ã®æ¤ç©ãããã æ¥ç®ã®å¤ã«æ¤ç©ã¯ cm 伸ã³ãã æã«æ¤ç©ã観å¯ããã¨ããé«ããæåã« ãè¶ ããã®ã¯ä½æ¥ç®ãï¼ å¶ç´ èããã㨠ãé«ãã 以ä¸ã§ãããã¡ã¯å復ãç¶ãããã¨ãããã㪠while æãâ¦
æååãè¾æ¸é ã«ã½ã¼ãããæ¹æ³ã確èªãã¦ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 人ã®ã¦ã¼ã¶ã¼ããã¦ã 人ç®ã®åå㯠ãã¬ã¼ãã£ã³ã°ã¯ ã§ããã ã¬ã¼ãã£ã³ã°ã®ç·åã ã§å²ã£ãä½ãã ã¨ããã¨ããåã¦ã¼ã¶ã¼ã®ååã®ãã¡ãè¾æ¸é ã§å°ããé ã« çªç®ã®ãã®ãæ±â¦
ããããªæ¹æ³ããããããããããã®ã工夫ãã¦è§£ãåãè åã¯ãã¤ã ã£ã¦å¤§äºã«ãªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®ãã¢å¤ ãä¸ããããã ãã ã«ã¤ã㦠ã㤠ãæºããã¨ãããã¢å¤ ãåé¤ããæä½ãç¹°ãè¿ãã æå¾ã«æ®ãã«ã¼ãã®éåãæ±ããã å¶ç´ èâ¦
å¨ææ§ããã¾ããã¨æ´»ç¨ãã¦ãªãã¨ãããåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 座æ¨å¹³é¢ä¸ã§ä¸ã®å³ã®ãããªç½é»æ¨¡æ§ãä¸ãããã (åé¡æãã)ã å·¦ä¸ã®é ç¹ã ãå³ä¸ã®é ç¹ã ã§ãããããªé·æ¹å½¢é åå é¨ã®é»è²é¨åã®é¢ç© (ã® 2 å) ãæ±ããã å¶ç´ èããã㨠â¦