ãã£ã¡ããã©ã¯ã¿ã«ãªåé¡ã ï¼
é¡é¡ã¨ã
åé¡æ¦è¦
JOI ã®ãã´ã¯ãä¸å³ã®ããã«ãªã£ã¦ãã (åé¡æãã)ã
- ã¬ãã« ã®ãã´ã¯ 1 à 1 ã®ã°ãªãã㧠"J" ã®ã¿ãããªã
- ã¬ãã« ã®ãã´ã¯ã ã®ã°ãªããã§ããã以ä¸ã®ããã«æ§æããã
- å·¦ä¸ã® ã«ã¤ãã¦ã¯ "J"
- å³ä¸ã® ã«ã¤ãã¦ã¯ "O"
- å·¦ä¸ã® ã«ã¤ãã¦ã¯ "I"
- å³ä¸ã® ã«ã¤ãã¦ã¯ãã¬ãã« ã®ã°ãªãã
æ´æ° ãä¸ãããããã¬ãã« ã®ãã´ã®ã è¡ç®ã® æåãåºåããã
å¶ç´
èãããã¨
ãããããã©ã¯ã¿ã«æ§é ããã¤åé¡ã¯ãå帰é¢æ°ã«ä¸¸æããã¦ãã¾ãæ¹æ³ãä¸ã¤ãããã¤ã¾ãã次ã®ãããªå帰é¢æ°ãèããã®ã ããã ã 㯠0-indexed ã§èãããã¨ã«ããã
// ã¬ãã« n ã®ãã´ã® k è¡ç® (0-indexed) ãæ±ãã string rec(int n, int k) { int mid = (2 ã® n - 1 ä¹); if (k < mid) { return (J ã mid å) + (O ã mid å); } else { return (I ã mid å) + rec(n - 1, k - mid); } }
ãã¨ã¯ãã®å帰é¢æ°ã®è©³ç´°ãã¡ããã¨è©°ããã° OKãè¨ç®é㯠ã¨ãªãã
ã³ã¼ã
#include <bits/stdc++.h> using namespace std; string rec(int N, int K) { if (N == 0) return "J"; int mid = 1<<(N-1); if (K < mid) return string(mid, 'J') + string(mid, 'O'); else return string(mid, 'I') + rec(N-1, K-mid); } int main() { int N, K; cin >> N >> K; cout << rec(N, K-1) << endl; }