Skip to content

Commit 12dca00

Browse files
authored
[20250826] BOJ / P5 / 문제 수 줄이기 / 권혁준
1 parent fea6373 commit 12dca00

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens()) nextLine();
24+
return st.nextToken();
25+
}
26+
27+
int nextInt() throws Exception {
28+
return Integer.parseInt(nextToken());
29+
}
30+
31+
long nextLong() throws Exception {
32+
return Long.parseLong(nextToken());
33+
}
34+
35+
double nextDouble() throws Exception {
36+
return Double.parseDouble(nextToken());
37+
}
38+
39+
void close() throws Exception {
40+
bw.flush();
41+
bw.close();
42+
}
43+
44+
void write(String content) throws Exception {
45+
bw.write(content);
46+
}
47+
48+
}
49+
50+
public class Main {
51+
52+
static IOController io;
53+
54+
//
55+
56+
static int N;
57+
static int[] a;
58+
static long[][] dp;
59+
60+
public static void main(String[] args) throws Exception {
61+
62+
io = new IOController();
63+
64+
N = io.nextInt();
65+
a = new int[N+1];
66+
for(int i=1;i<=N;i++) a[i] = io.nextInt();
67+
68+
dp = new long[N+1][4];
69+
dp[1][0] = a[1];
70+
for(int j=1;j<4;j++) dp[1][j] = -(long)1e18;
71+
72+
for(int i=2;i<=N;i++) {
73+
long xor = 0;
74+
for(int j=0;j<4;j++) {
75+
if(i-j-1 < 0) {
76+
dp[i][j] = -(long)1e18;
77+
continue;
78+
}
79+
xor ^= a[i-j];
80+
long max = -(long)1e18;
81+
for(int k=0;k<4;k++) if(k != j) max = Math.max(max, dp[i-j-1][k]);
82+
dp[i][j] = max + xor;
83+
}
84+
}
85+
long max = 0;
86+
for(int j=0;j<4;j++) max = Math.max(max, dp[N][j]);
87+
io.write(max + "\n");
88+
89+
io.close();
90+
91+
}
92+
93+
}
94+
```

0 commit comments

Comments
 (0)