Skip to content

Commit b08f7a5

Browse files
authored
[20250214] BOJ / P5 / The Way / 권혁준
1 parent 6350393 commit b08f7a5

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st;
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static int nextInt() {return Integer.parseInt(st.nextToken());}
15+
static long nextLong() {return Long.parseLong(st.nextToken());}
16+
static void bwEnd() throws Exception {bw.flush();bw.close();}
17+
18+
// Additional field
19+
static int N;
20+
static long mod = (long)1e9 + 9;
21+
static long[] dp;
22+
static int[] G = {1,2,1,-1,-2,-1};
23+
24+
public static void main(String[] args) throws Exception {
25+
26+
ready();
27+
solve();
28+
29+
bwEnd();
30+
}
31+
32+
static void ready() throws Exception{
33+
34+
N = Integer.parseInt(br.readLine());
35+
dp = new long[N+1];
36+
37+
}
38+
39+
static void solve() throws Exception{
40+
41+
dp[1] = 1;
42+
for(int i=2;i<=N;i++) dp[i] = (dp[i-1]*3 + dp[i-2] + G[i%6]) % mod;
43+
bw.write(dp[N] +"\n");
44+
45+
}
46+
47+
}
48+
49+
```

0 commit comments

Comments
 (0)