From 12dca0095d038230531f3a5023b81c577b259a91 Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 26 Aug 2025 17:43:21 +0900 Subject: [PATCH] =?UTF-8?q?[20250826]=20BOJ=20/=20P5=20/=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=20=EC=A4=84=EC=9D=B4=EA=B8=B0=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\244\204\354\235\264\352\270\260.md" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" diff --git "a/khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" "b/khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" new file mode 100644 index 00000000..40436a5c --- /dev/null +++ "b/khj20006/202508/26 BOJ P5 \353\254\270\354\240\234 \354\210\230 \354\244\204\354\235\264\352\270\260.md" @@ -0,0 +1,94 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N; + static int[] a; + static long[][] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + a = new int[N+1]; + for(int i=1;i<=N;i++) a[i] = io.nextInt(); + + dp = new long[N+1][4]; + dp[1][0] = a[1]; + for(int j=1;j<4;j++) dp[1][j] = -(long)1e18; + + for(int i=2;i<=N;i++) { + long xor = 0; + for(int j=0;j<4;j++) { + if(i-j-1 < 0) { + dp[i][j] = -(long)1e18; + continue; + } + xor ^= a[i-j]; + long max = -(long)1e18; + for(int k=0;k<4;k++) if(k != j) max = Math.max(max, dp[i-j-1][k]); + dp[i][j] = max + xor; + } + } + long max = 0; + for(int j=0;j<4;j++) max = Math.max(max, dp[N][j]); + io.write(max + "\n"); + + io.close(); + + } + +} +```