ããã°ã£ããããã¦ã¼ãã¨è¨ã£ã¦ããåå¿è ã®äººã®ã³ã¼ããè¦ãã¨ãã¾ãã ãã°ãè¦ã¤ãã¦ãããã®ã¯ï¼å¤ãã®å ´åï¼ç°¡åã§ããããããä¼ããã ãã§ã¯æé·ã«ã¤ãªãããªãããªãã¨ãæãã¾ãã
ãããããã¨ããããããã£ã¦ç¢ºèªããããããããããããªã£ãã®ã§è¦ã¤ãã£ãããã¿ãããªãã¨ãæãã¦ãããã¨ããã¨æã£ãã®ã§ãããæ¯åããã¨é¢åãªã®ã§ãè¨äºã«ã¾ã¨ãã¾ãã ããã¾ã§ãã³ã¡ããã®æ¹æ³ãªã®ã§ãä»ã®äººã¯éããã¨ããã¦ããããããã¾ããã
æè¿ãã¾ãä»äººã®ãããã°ããã¦ããªãã®ã§ãè¨æ¶ã¨å¦æ³ã§æ¸ãã¦ããã¨ããã¯ããã¾ãã 追è¨ããããã¨ãçºçã次第ã追è¨ãããã¨æãã¾ãã
è¨äºã®æ¬ç·¨ã§ã¯ C++ ãä»®å®ãã¾ãã
Python ã®äººåããããã°ï¼
- numpy ãä½ãã®æ¼ç®ã§ãªã¼ãã¼ããã¼ãã¦ãã
- æ´æ°ã®åãæ¨ã¦é¤ç®ãæµ®åå°æ°ç¹æ°ãä»ãã¦ãã¦èª¤å·®ãçãã¦ãã
- ãã®ä»ãããããã
ä»äººã®ã³ã¼ãã®ãããã°ãããã¨ãã¯ãã¾ã #define int long long
ããã¦ãããã©ããã確èªãã¦ããã¾ãããã
ãªã¼ãã¼ããã¼ãã¦ããããªç®æãè¦ã¤ãã¦ãããå®ã¯ long long
ã§ãããã¨ããã®ã¯ããªãå«ãªæ°åã«ãªãã®ã§ã
åæ
ä¸å¿ verdict ãã¨ã«åãã¦èãã¾ããããé åå¤åç §ï¼æªå®ç¾©åä½ï¼ã®çµæãTLE ãçºçãããã¨ãã¯ãããã話ãªã®ã§ããTLE ãªãã ããé åå¤åç §ã¨ãã§ã¯ãªãã¯ããã®ãããªæ±ºãã¤ãã¯ãããªãã§ããã
ãã¨å¿æ§ãã®è©±ãªã®ã§ãããã1 ã±ã¼ã¹ WA ã ããå°ãå¤ããã ãã§ããã¯ããã®ãããªèãæ¹ã¯ãããæ¹ãããã¨æãã¾ããå ¨ãã®å解æ³ã ã£ãå ´åã«æ°ã¥ãã®ãé ããåå ãªã®ã§ã éã«è¨ãã°ãå ¨ã±ã¼ã¹ WA ã ããå°ãå¤ãã¦ãéããªãã¯ããã¨ããã®ããããªãã§ã*1ã
ã¨ãããããã¾ããã³ã³ãã¤ã©ã®è¦åãè¦ã¾ãããåæåããã¦ãªãããã¨ããé¢æ°ã®è¿ãå¤ããªããããªã©ã¯ããããæ¬è³ªçãªå ´åãããã®ã§ã ãããåé¡ãªããã°ãverdict ã«å¾ããå ¸åçãªãã¹ãæ¢ãã¦ããã¾ãã
確èªãããã¨ãã¡
TLE
å¤ãã®å ´åã¯ãè¨ç®éã®è¦ç©ãããééã£ã¦ãããã ã¨æãã¾ãã
_GLIBCXX_DEBUG
ããã¯ããã¾ã§ãããã°ç¨ã®æ©è½ã§ãããé¢æ°ã«ãã£ã¦ã¯ãªã¼ãã¼ãæªåãããã¨ãããã®ã§ãï¼ããã£ã¦ãã¦ããããå ´åãé¤ãã¦ï¼æåºã³ã¼ãã§æ¸ãã®ã¯é¿ãã¾ãããã ãªãã®ãã¨ãããããªã人ã¸ï¼
ã³ã³ããã®ç¡é§ãªã³ãã¼
é¢æ°ã« vector
ãªã©ã®ã³ã³ããã渡ãã¨ãã以ä¸ã®ããã«æ¸ãã¨ãé¢æ°ãå¼ã³åºããã³ã«ã³ãã¼ï¼ãµã¤ãºã«å¯¾ãã¦ç·å½¢æéï¼ãçºçãã¾ãã
int f(vector<int> v) { ... }
é¢æ°ã®ä¸ã§ç·å½¢æéã®æä½ããã¦ãããªãå®æ°åã®éããããªãã®ã§åé¡ããªããã¨ã¯å¤ãã§ã*2ã ããã§ãªãå ´åï¼ä¸é¨ã®è¦ç´ ã ããè¦ã¦çµããå ´åãªã©ï¼ã¯ããªã¼ãã¼ãæªåãã¦ãã¾ãã®ã§ã以ä¸ã®ããã«ç´ãã¾ãããã
int f(vector<int>& v) { ... }
v
ãæ¸ãæããªãã®ãªãã次ã®ããã«æ¸ãæãã¦ãããã§ãã
int f(vector<int> const& v) { ... }
ã¤ãã¬ã¼ã¿ã®æä½
set<int> s;
lower_bound(s.begin(), s.end(), x);
ããã¯ç·å½¢æéãªãã§ãããã
WA
mod ãééã£ã¦ãã
1000000007 ãªã®ã« 998244353 ã使ã£ã¦ããã¨ãã998244353 ãæ¸ãééã£ã¦ããã¨ãã§ãã ä»ã®ãã¹ã«æ¯ã¹ã¦ãã確èªã§ããã¯ããªã®ã§ããããã¾ãã
æ¯åãã¾ããè¨ç®ãããã³ã« %= 998244353
ã¨ãæ¸ãã¦ãã人ããããããã¾ããããï¼ç¢ºèªãé¢åãªã®ã§ï¼ã
é©å½ã«å®æ°ã宣è¨ãã¦ãããã使ãã¾ãããã
const int mod = 998244353;
大æåå°æåãééã£ã¦ãã
ãããããã§ããã
YES
㨠Yes
ã¨ãããããããã¤ã§ãã
ç¹ã«ãå ´ååããè¤éã§ãè¤æ°åæ¸ããããå ´åã¯æ³¨æãå¿
è¦ã§ãã
ãªã¼ãã¼ããã¼
æãç®ãã¦ããã¨ãããä¸éã確ããã¾ãã
ããæ°ã§å²ã£ããã¾ããæ±ããã¨ããa * b * c % mod
ã ã¨ãa * b * c
ã®æç¹ã§ãªã¼ãã¼ããã¼ããã¨ã ãã§ãã
ã¾ããc
ãã¨ã¦ã大ããã¨ãã¯ãa * b % mod * (c % mod) % mod
ã®ããã«ããå ´åãããã§ããããå¶ç´ãè¦ãªããã¡ããã¨èãã¾ãã
足ãç®ã§ãªã¼ãã¼ããã¼ããåé¡ã¯ãã¾ããªãæ°ããã¾ããããããæ°ãã¤ãã¾ãããã
精度
æµ®åå°æ°ç¹æ°ã¯ç¡é精度ã§ã¯ãªãã®ã§ãæå¾
éãã«åããªããã¨ãå¤ãã§ãã
æªãã®ã¯æµ®åå°æ°ç¹æ°ã¡ããã§ã¯ãªãã¦ãå¤ãªæå¾
ããã人ã§ã*3ã
ãã¨ãã°ãdouble
㧠\(2^{53}+1\) ãªã©ãè¨ç®ãã¦ã¿ã¾ããããå¶æ°ãåºåããã¦ã³ã£ããã§ãã
精度ã足ããªãããªã®ã«éä¿¡ãããããªã³ã¼ããæ¸ããã¦ããããããã注ææ·±ãè¦ã¾ãã 該å½ããããªåé¡ã¨ãã¦ã¯ãã«ã¼ãã®ã㤠ã¨ããæãç®ã®ã㤠ã¨ããããã¾ããã
off-by-one ã¨ã©ã¼
æ·»åãªã©ã +1 ã -1 ã®æ¸ãå¿ããä¸è¦ãªæ¸ã足ããªã©ã§ééãã«ãªã£ã¦ãããã®ã®ç·ç§°ã§ãã 極端ãªã±ã¼ã¹ï¼ãµã¤ãºãæå°ã®å ´åãæ·»åãæ大ã®å ´åãªã©ï¼ãèããã¨ãããããã¨ãã¯æ°ã¥ãããããã¨ãå¤ãã§ãã
ããããè¨äºãããã¾ãï¼ rsk0315.hatenablog.com
å¤æ°åã®ééã
xa
xb
ya
yb
ã¿ãããªã®ãããããåºã¦ãã¦ããããããã³ã¼ãã¯ã使ãééã£ã¦ãã¦ãæ°ã¥ãã®ã大å¤ã§ãã
åºç¾åæ°ãåãã§ããã¹ãå¤æ°åã®åºç¾åæ°ãéã£ããããããããªãã¨ã¯æãã¾ãããããã§ãªãã¨é¢åã§ããããã§ããã
è¬è²ªæ¬²ãªã©ã®åèå¯
èªåã§ã¯æ°ã¥ãã«ãããã¨ãå¤ãã§ãã ãã¨ã§ç´¹ä»ããæ¹æ³ã¨ä½µãã¦ãå°ããã±ã¼ã¹ã§æã§ç¢ºèªããã¨ãããããã«ãã®è²ªæ¬²ã¯ããããããã¨ãªããå ´åãå¤ãã§ãã
RE
é åå¤åç §
é åãµã¤ãºã¯ã¡ããã¨ç¢ºèªãã¾ãããã å¦çãè¤éãªå ´åã¯ããã¢ã¯ã»ã¹ãããã¨ã«ãªãæ·»åã«å¯¾ãã¦ãµã¤ãºã¯ååãï¼ãã¿ãããªãã¨ãèããå¿ è¦ãããã¨æãã¾ãã
ã¼ãé¤ç®
é¤ç®ã®ãã³ã«ãå²ãæ°ãã¼ãã§ã¯ãªãã確ããã¦ãååãªãããã§ããæ°å¦ã§ããããã®ã¨åæ§ã§ãã
å²ãæ°ã x-1
ã®ãããªå ´åãx
ã 1
ã«ãªããªãã確ãããã¨ãã§ããã
ãã ã¨ãã§ãã
ãã以å¤
ããã¾ããªãããã§ãã ãã¸ãã¯ãééã£ã¦ãã¦ãå帰ãç¡éã«çºçãã¦ããã¨ãã¯ããããï¼
ã ãã ã£ãå ´å
C++ ã®ä»æ§ã®åéãã§ééã£ã¦ããã¨ãã¯ããããããã¾ããã æã ã£ãã ãã ã¨ã ãã ã¨ããè¦ã¦ããã°ãã°ããã¨æããã§ããããããè¨ã£ã¦ãããªãå ´åã®æ¹éã示ãã¾ãã
æç´è§£ãæ¸ãã¾ãã ããã§æç´è§£ãæ£ããæ¸ããªãã¨ã©ããããããªãã®ã§ãããããã¯ããã°ã£ã¦ã»ããã§ãã
ããã§è¨ãæç´è§£ã¨ããã®ã¯ããã¨ãã°ããå¶ç´ã \(n \le 10\) ã ã£ãå ´åã«æ¸ãã³ã¼ããã®ãããªãã®ãèãã¦ãã ããã
bit å
¨æ¢ç´¢ãããã¨ãã8 éã«ã¼ããæ¸ãã¨ããå
¨é åã next_permutation
ã§è©¦ãã¨ãããããã§ãããããã¯ããã¯ãã§ãã
...ã¨ããã®ãæ¸ãã¾ã*4ã
次ã«ããã¹ãã±ã¼ã¹ãèªåã§çæããã³ã¼ããæ¸ãã¾ãã ä¹±æ°ãçºçãããã®ã大å¤ã ã£ãããã¾ãããæ軽ã«ã¯ã以ä¸ã®ãããªãã®ãèãããã¾ãã
#include <iostream> #include <random> std::random_device rd; std::mt19937 rng(rd()); int randint(int lo, int hi) { // lo ä»¥ä¸ hi 以ä¸ã®ä¹±æ°ãè¿ã return std::uniform_int_distribution<int>(lo, hi)(rng); } int main() { // 10 ä»¥ä¸ 20 以ä¸ã®ä¹±æ°ãåºåãã std::cout << randint(10, 20) << '\n'; }
ããããã®ãé§ä½¿ããªããã該å½ããåé¡ã®ãã©ã¼ãããã«æ²¿ã£ãã±ã¼ã¹ãçæããã³ã¼ããæ¸ãã¾ãããã
ãã¨ã¯ãããã使ã£ã¦ãå ã ã®èªåã®æ¸ããã³ã¼ãã®åºåã¨ä¸ä¸è´ã«ãªãã±ã¼ã¹ãæ¢ãã¾ãã
online-judge-tools ãç¥ã£ã¦ãã¾ããï¼ ãããå°å
¥ããã®ãä¸çªæã£åãæ©ãã¯ãã§ãã
pip3
ã使ããã¨ãã¦ã以ä¸ã®ã³ãã³ããå®è¡ãã¾ãããã
$ pip3 install --user online-judge-tools
online-judge-tools.readthedocs.io
ãã¨ãã°ãå
ã
ã®è§£æ³ã®å®è¡ãã¡ã¤ã«ã ./X
ãæç´ã ./X-naive
ãã±ã¼ã¹ã®çæå¨ã ./X-generator
ã ã¨ãã¾ãã
以ä¸ã®ã³ãã³ããå®è¡ããã¨ãä¸ä¸è´ã«ãªãã±ã¼ã¹ãè¦ã¤ããã¾ã§åæã«ããã°ã£ã¦ããã¾ãã
$ oj g/i -c ./X-naive --hack ./X ./X-generator
è¦ã¤ããã¨ããã®ã±ã¼ã¹ï¼å ¥åã¨ãæ³å®ãããåºåããããã誤ã£ãèªåã®åºåï¼ãåºåãããã®ã§ããããè¦ãªãããæãé ã使ã£ã¦èãã¾ãã ãã©ãèãã¦ãããããèå¯ããããã¨ãããæã§ã¯åã£ã¦ããã ããå®è£ ãããããã¯ãããããã¨ãæ°ã¥ãã¯ãã§ãã å¾è ãªããé©å® print ãããã°*5ãªã©ããããªããã¦ããã°ãæ¢ãã¦ãã ããã
人ã«ãã£ã¦ã¯ï¼chokudai ããã¨ããï¼ã解æ³ã®ã³ã¼ãã«ãã¹ããç´æ¥æ¸ãè¾¼ãã ãããæ¹æ³ãç´¹ä»ãã¦ãã¾ã ãããã³ã¡ããçã«ã¯ãã¾ãããããããªãã§ãã ãã¹ãé¨åã®æ¶ãå¿ãã§å ¥åãèªã¿ééããã¨ããæç´ã®æ¹ãå®è¡ãããã¾ã¾æåºãã¦ãã¾ã£ãã¨ãããããããã¹ãæ¸å¿µãããããã§ãã ã¨ããããã¹ãããªãã«ãã¦ããããã¹ãããã¾ããã£ããã®å¾ã®ãæåºç¨ã«æ¸ãç´ããã®æéãé¿ãããã§ãã
åè¿°ã®æ¹æ³ã§ããã°ã./X
ã¯ãã¹ãç¨ã¨æåºç¨ã§æ¸ãæããå¿
è¦ããªãã®ã§ãæåºã楽ã§ããã§ãã
æåºããã®ã¯ãã¹ãã«éã£ãã³ã¼ããã®ã¾ã¾ãªã®ã§ãæ¸ãç´ããã¹ã¨ããå¿é
ããå¿
è¦ãããã¾ããã
ããã§ãã ãã ã£ãã
ãããªãã¨ããï¼ èªåã§ã³ã¼ãã¼ã±ã¼ã¹ã£ã½ããã®ãèãã¦ãæç´è§£ã¨æ¯è¼ãããããããããªãã§ããï¼
å°ããã±ã¼ã¹ã§ã¯çºçããªããã°ã¨ããããã¨ã¯æãã¾ãããã¼ã¼ã¼ããã¼ããã ã£ããããå°ãæç´ãæ¹è¯ãã¦å¤§ããã®ã±ã¼ã¹ã§è©¦ãã°ããããããªãã§ããï¼ å¤§ããã±ã¼ã¹ã ã¨ã©ãééã£ã¦ããã調ã¹ãã®ã大å¤ã ã£ãããã¾ããã
ãã¼ãã¨ãããããªã®æç´ã®æ¸ãããããï¼ ã©ããããããªããªãï¼ãã¨ããã®ã¯ãã©ããããããªãããã§ããããããã¦ã æ§ç¯ç³»ã®åé¡ã¨ãã¯ããç¨åº¦å¤§å¤ããããã¾ãããã
ããã
AC ããã§ã¨ãã
ãã
ãã¶ãããã³ã¡ããèªèº«ã¯ãoff-by-one ã¨åèå¯ä»¥å¤ã ã¨ãä¸è¨ã«å½ã¦ã¯ã¾ãã³ã¼ãã¯ããããæåããæ¸ããªãæ°ããã¾ãã åèå¯ã®ç¨®é¡ã¯äººã«ãã£ã¦ããç¨åº¦éãã¨æãã®ã§ããèªåãèå¯ã®éã«æ¼ããããããã¨ä¸è¦§ãã¿ãããªã®ãã¾ã¨ãã¦ããã¨ããããããªãã§ããï¼ ãã¶ãèªåã§æ¸ããã¨ã«ãæå³ã¯ããã¨æãã¾ãã
ããããã°ãICPC ã«åãã¦åºãã¨ãã¯ãã©ã¤ãã©ãªã«ããããã¡ãªãã¹ä¸è¦§ãã¿ãããªã®ãè¼ãã¦ãæ°ããã¾ãã
*1:æ§ç¯ã§ãåºåã®è¡æ°ãæ¸ãå¿ãã¦ããããYes ãæ¸ãå¿ãã¦ããããªã©ããµã³ãã«ãè½ã¡ãã®ã¯ããããã¨ãããã¨ã§è¦ç´ãã¹ãã§ããã
*2:ã ã¨ãã¦ããããããå®æ°åã®éãæ¸ãæ¹ãããã¡ãªããã¯ãå¤ãã®å ´åç¡ãã¯ãã§ããã
*3:ææ³ãåºã¦ãã¾ãã
*4:ã³ã³ãã¹ãå¾ã§ããã°ãä»äººã®é©å½ãª AC ã³ã¼ããæã£ã¦ããã¨ããèãããã¾ãããè¨ç·´ã ã¨æã£ã¦èªåã§æ¸ãã¦ãã ãããèªåã§æ¸ãã®ã«æ £ãã¦ããã°ã³ã³ãã¹ãä¸ã«å°ã£ã¦ã対å¿ã§ããã®ã§ã
*5:å¤æ°ãé©å½ãªç®æã§åºåãã¦ãèªåã®æ³å®éãã確èªããæ¹æ³ã§ãã