éåæ¬Aåé¡
mod 1000000007 ãããåé¡ãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ããããã ã 1000000007 ã§å²ã£ãä½ããæ±ããã å¶ç´ ã³ã¼ã #include <bits/stdc++.h> using namespace std; // a^n mod m template<class T> T mod_pow(T a, T n, T m) { T </class></bits/stdc++.h>â¦
mod ã®ç·´ç¿ãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æåãé»æ¿ã« 0 ã¨ããæ°ãæ¸ããã¦ããã以ä¸ã® åã®æä½ãå®è¡ãããåæä½ã§ã¯æå ã¨æ° ãä¸ããããã = '+' ã®ã¨ãï¼é»æ¿ã«æ¸ãããæ°ãã ã足ããæ°ã«æ¸ãç´ã = '-' ã®ã¨ãâ¦
æå¤§å ¬ç´æ°ãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 2 ã¤ã®æ£ã®æ´æ° ã®æå¤§å ¬ç´æ°ãæ±ããã å¶ç´ ã³ã¼ã #include <bits/stdc++.h> using namespace std; long long GCD(long long x, long long y) { if (y == 0) return x; else return GCD(y, x % y)</bits/stdc++.h>â¦
ã°ãªããä¸ã®æççµè·¯ã®æ°ãä¸ãããã DPãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããããããåãã¹ã¯å£ã¾ãã¯éè·¯ã§ãããå·¦ä¸ãã¹ã¨å³ä¸ãã¹ã¯éè·¯ã§ããã å·¦ä¸ãã¹ããå³ä¸ãã¹ã¸ã¨ãå³æ¹åã¨ä¸æ¹åã®ç§»åã®ã¿ãç¹°ãè¿ããâ¦
LISãéåæ¬ã®åé¡ãªã®ã§ã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ã® LIS ã®é·ããæ±ããã å¶ç´ ã³ã¼ã #include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; int main() { int N, res = 0; cin >> N; vector<int> A(N); for (int i = 0; i < N; </int></bits/stdc++.h>â¦
dp[ã©ãã¾ã§è¦ãã][ããã] ã¨ããã¿ã¤ãã®ããã DPãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªãããä¸ãããããåãã¹ã¯ 0 ã¾ã㯠1 ã§ãããããã¤ãã®è¡ãé¸ãã§ã次ã®æ¡ä»¶ãæºããããã«ããããé¸ã¶ã¹ãè¡æ°ã®æå°å¤ãæ±ãâ¦
ä¸æ¬¡å DP ã§ãé ã DPããæ¸ããããåé¡ãéåæ¬ã®åé¡ãªã®ã§ã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãã¹ç®ã« ã¨è¨ããã ãã¹ã®åå ãããã1 ããã¹ã¿ã¼ãã㦠ã¸é²ã¿ããã ãã¹ ãããã¹ () ã«é²ããã¨ãã§ãã¦ï¼100pt ç²å¾ ãã¹ ãããã¹ () ã«é²ããâ¦
åºéã®å·¦ç«¯ã¨å³ç«¯ãæ·»åã«ãã¡ã¤ã¤ã左端ãé¤å»ãããå³ç«¯ãé¤å»ããããã DPãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ããã㯠ããã®é ã«ä¸åã«ä¸¦ãã§ãã¦ãã左端ã®ãããã¯ã¾ãã¯å³ç«¯ã®ãããã¯ãé¤å»ãããã¨ããæä½ã åè¡ã£ã¦â¦
ç´ æ°å¤å®ãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ° ãããããç´ æ°ã§ãããã©ãããå¤å®ããã å¶ç´ ã³ã¼ã #include <bits/stdc++.h> using namespace std; bool is_prime(int N) { if (N <= 1) return false; for (int x = 2; x * x <= N; x+</bits/stdc++.h>â¦
LCS ãæ±ãã DP ã®ç·´ç¿ãéåæ¬ã®åé¡ãªã®ã§ã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 2 ã¤ã®æåå ãä¸ããããã ã®é¨ååã§ã ã®é¨ååã§ããããããªæååã®é·ãã®æ大å¤ãæ±ããã å¶ç´ ã³ã¼ã #include <bits/stdc++.h> using namespace std; int main() { string S, </bits/stdc++.h>â¦
ããããµãã¯åé¡ãéåæ¬ã®åé¡ãªã®ã§ã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å®ç®±ã«ã¯ åã®åç©ãå ¥ã£ã¦ãããåç© ã®éã㯠ã価å¤ã¯ ã§ããã 太éåã¯ãããã¤ãã®åç©ãé¸ãã§æã¡å¸°ãããã¨èãã¦ãããããããå½¼ã®ãããã¶ãã¯ã«ã¯å®¹éå¶éãããã®â¦
é¨åååé¡ãéåæ¬ã®åé¡ãªã®ã§ãã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ° ããããã¤ãé¸ãã§ãç·åã ã«ãããã¨ãå¯è½ãã©ãããå¤å®ããã å¶ç´ ã³ã¼ã #include <bits/stdc++.h> using namespace std; int main() { int N, S; cin >> N >> S; vector<int> A(N); for</int></bits/stdc++.h>â¦
DP ã®çµè·¯å¾©å ãå¦ã¶åé¡ãéåæ¬ã®åé¡ãªã®ã§ã³ã¼ãã®ã¿ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãããã³ã¸ã§ã³ã«ã¯ åã®é¨å±ãããã ã¨çªå·ãã¤ãã¦ããããã®ãã³ã¸ã§ã³ã¯ä¸æ¹éè¡ã§ãããéè·¯ãä»ã㦠1 ã¤å ã¾ã㯠2 ã¤å ã®é¨å±ã«ç§»åãããã¨ãã§ãããåéè·¯ã«â¦
Frog 1 ã¨ã»ã¼åãåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãããã³ã¸ã§ã³ã«ã¯ åã®é¨å±ãããã ã¨çªå·ãã¤ãã¦ããããã®ãã³ã¸ã§ã³ã¯ä¸æ¹éè¡ã§ãããéè·¯ãä»ã㦠1 ã¤å ã¾ã㯠2 ã¤å ã®é¨å±ã«ç§»åãããã¨ãã§ãããåéè·¯ã«ããã移åæéã¯ä»¥ä¸ã®éãã é¨å±â¦
座æ¨å§ç¸®ãããã¨ããåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã®ã§ã座æ¨å§ç¸®ããã å¶ç´ èããã㨠座æ¨å§ç¸®ã¯æ¬¡ã®è¨äºã«è©³ããæ¸ããã drken1215.hatenablog.com ã³ã¼ã #include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; v</bits/stdc++.h>â¦
ååå ¨åæã®å ¸ååé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ãã ã® 4 ã¤ã®æ°åãä¸ããããããããããè¦ç´ ã 1 åãã¤ã¨ã£ã¦ãã¦ãç·åã ã«ãããã¨ãå¯è½ãå¤å®ããã å¶ç´ ã¡ã¢ ãååå ¨åæããç¨ããã詳細ã¯éåæ¬ã«ã¦ã ã³ã¼ã #include <bits/stdc++.h> using namespace</bits/stdc++.h>â¦
ã»ã°ã¡ã³ãæ¨ã BIT ã®æåã®ç·´ç¿åé¡ã«ãããããªåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ããããæåã¯ãã¹ã¦ã®è¦ç´ ã 0 ã¨ãªã£ã¦ããããã®æ°åã«å¯¾ãã¦ã以ä¸ã® 2 種é¡ã®ã¯ã¨ãªã«çãã ( åã®ã¯ã¨ãªãä¸ãããã)ã ã¯ã¨ãª 1ï¼ ãä¸ããããã®ã§ã â¦
ã¹ã¿ãã¯ãç¨ãã¦è§£æ±ºã§ããå ¸ååé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã å ã«å¯¾ãã¦ã ã㤠ãæºããæ大㮠ãæ±ãã (åå¨ããªãå ´å㯠-1)ã å¶ç´ ã¡ã¢ ã¹ã¿ãã¯ã使ã㨠ã®è¨ç®éã§è§£ããã詳細ã¯éåæ¬ãåç §ã ã³ã¼ã #include <bits/stdc++.h> usi</bits/stdc++.h>â¦
åªå 度ä»ããã¥ã¼ã人çã§åãã¦è©¦ãã®ã«ããåé¡ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã® 3 種é¡ã®ã¯ã¨ãª ( å) ãé«éã«å¦çããããã°ã©ã ãå®è£ ããã販売ã·ã¹ãã ã模ãã¦ããã ã¯ã¨ãªã¿ã¤ã 1ï¼ä¾¡æ ¼ã åã®ååã追å ããã ã¯ã¨ãªã¿ã¤ã 2ï¼ä»ããååã®â¦
ãã¥ã¼ã®ä½¿ãæ¹ã®ç¢ºèªï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã® 3 種é¡ã®ã¯ã¨ãª ( å) ãé«éã«å¦çããããã°ã©ã ãå®è£ ãããè¡å管çã·ã¹ãã ã模ãã¦ããã ã¯ã¨ãªã¿ã¤ã 1ï¼è¡åã®æå¾å°¾ã« ããã並㶠ã¯ã¨ãªã¿ã¤ã 2ï¼è¡åã®å é ã«ãã人ã®ååãçãã ã¯ã¨â¦
人çã§æåã«è§£ãããã¹ã¿ãã¯ã®åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã® 3 種é¡ã®ã¯ã¨ãª ( å) ãé«éã«å¦çããããã°ã©ã ãå®è£ ããã ã¯ã¨ãªã¿ã¤ã 1ï¼ ã¨ããé¡åã®æ¬ãæºã®ä¸çªä¸ã«ç©ã ã¯ã¨ãªã¿ã¤ã 2ï¼ä¸çªä¸ã«ç©ã¾ãã¦ããæ¬ã®é¡åãçãã ã¯ã¨ãªã¿ã¤â¦
ãããã¨ãæ³ã®åºæ¬ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ° ãä¸ããããããããã®æ´æ°ããç°ãªã 2 åãé¸ã¶æ¹æ³ã®ãã¡ã2 åã®å¤ã®å·®ã 以ä¸ã§ãããã®ã®åæ°ãæ±ããã å¶ç´ è§£æ³ (1)ï¼ãããã¨ãæ³ éåæ¬ã®åé¡ãªã®ã§ãéåæ¬ãåç § #include <bits/stdc++.h> using nam</bits/stdc++.h>â¦
ãçãã§äºåæ¢ç´¢ãã®ãã¡ããã¡ãããç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å°ã®ããªã³ã¿ã¼ãããã çªç®ã®ããªã³ã¿ã¼ã¯ ç§å¾ã«ããªã³ãããã åãã㦠çªç®ã®ããªã³ããè¡ãããã®ã¯ä½ç§å¾ãï¼ å¶ç´ çãã 以ä¸] è§£æ³ éåæ¬ã®åé¡ãªã®ã§ãéåæ¬åç §ã 1â¦
ããã§ã¯ãlower_bound() ã使ã£ã¦è§£ãã¦ã¿ããã¨ã«ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å°ããé ã«ä¸¦ã¹ãããé å ãä¸ããããã å¤ ã ã®ä¸ã§ä½çªç®ã®è¦ç´ ã®å¤ã§ããããæ±ããããã ãã ã®ä¸ã«å¤ ã®è¦ç´ ã¯å«ã¾ãã¦ããã¨ããã å¶ç´ èããã㨠å®ã¯åç´ãª â¦
å·¦å³ããã®ç´¯ç©åã»ç´¯ç© max ãåå¦çã§æ±ãã¦ããã®ã¯ãããããå ¸åï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ°ãããªãæ°å ãä¸ããããã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã åºé ãä¸ããããã®ã§ãæ°åãããã®åºéãé¤å¤ããé åã«ã¤ãã¦ãæ´æ°å¤ã®æâ¦
äºæ¬¡å ãããæ³ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããã«ããã¦ã æ¥ééªãéã£ãã æ¥ç®ã«ã¯ããã¹ ãå·¦ä¸ã¨ãã ãå³ä¸ã¨ããé·æ¹å½¢é åã«éªã 1 cm ã ãéã£ã (溶ããªãã¨ãã)ã æçµçãªåãã¹ã®ç©éªéãæ±ããã å¶ç´ è§£æ³ äºæ¬¡å ãããæ³ããã¾ããâ¦
äºæ¬¡å ç´¯ç©åï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªãããããããã¹ ã«ã¯å¤ ãæ¸ããã¦ããã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã å·¦ä¸ã ãå³ä¸ã ã§ãããããªé·æ¹å½¢é åãä¸ããããã®ã§ãé åå ã®ãã¹ã«æ¸ãããæ´æ°ã®ç·åãæ±ããã å¶ç´ è§£æ³ éåæ¬ã«â¦
ãããæ³ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ¥éã®ã¤ãã³ã㫠人ã®åå è ãåºå¸ãããåå è 㯠æ¥ç®ãã æ¥ç®ã¾ã§åºå¸ããã åæ¥ã®åºå¸è æ°ãæ±ããã å¶ç´ è§£æ³ éåæ¬ã®åé¡ãªã®ã§ãæ¬ã®æ¹ãåç §ï¼ï¼ ã³ã¼ã #include <bits/stdc++.h> using namespace std; int main() { in</bits/stdc++.h>â¦
ç´¯ç©åã«é¢ããåé¡ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ¥éã«ãããã¤ãã³ããéå¬ããæ¥ ã«ã¯ 人ãæ¥å ´ããã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã åã¯ã¨ãªã§ã¯ ãä¸ããããã®ã§ã æ¥ç®ãã æ¥ç®ã¾ã§ã®éã«åè¨ä½äººãæ¥å ´ããããçããã å¶ç´ è§£æ³ ç´¯ç©åâ¦
è¨ç®æéã®æèãå¿ è¦ã«ãªãåé¡ï¼ éåæ¬ã®åé¡ãªã®ã§ã¡ã¢ç¨åº¦ã«ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 赤ã»éã»ç½ã® 3 æã®ã«ã¼ãããããããããã« 1 ä»¥ä¸ ä»¥ä¸ã®æ´æ°ãæ¸ãè¾¼ãã 3 æã®ã«ã¼ãã®æ°ã®åè¨ã ã«ããæ¸ãæ¹ã¯ä½éããããï¼ å¶ç´ ã¡ã¢ 赤ã»éã»ç½ã®â¦