티스토리 뷰
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import java.io.*;
import java.util.StringTokenizer;
public class boj_11723 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer st;
static int s = 0;
public static void main(String[] args) throws IOException {
int m = Integer.parseInt(br.readLine());
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine());
String op = st.nextToken();
if (op.equals("all")) {
s = (1 << 20) - 1;
} else if (op.equals("empty")) {
s = 0;
} else {
int val = Integer.parseInt(st.nextToken());
operate(op, val);
}
}
bw.flush();
bw.close();
}
static void operate(String op, int val) throws IOException {
switch (op) {
case "add" -> {
if ((s & (1 << val)) == 0) {
s |= (1 << val);
}
}
case "remove" -> {
if ((s & (1 << val)) != 0) {
s &= ~(1 << val);
}
}
case "toggle" -> s ^= (1 << val);
default -> {
if ((s & (1 << val)) == 0) {
bw.append("0");
} else {
bw.append("1");
}
bw.newLine();
}
}
}
}
|
cs |
- 비트마스크
- switch문 바뀐거로 해서 java 15로 돌려봤는데 메모리 초과 떴는데 더 이상 어떻게 고쳐야할지 모르겠음
- 맞는거같은데 ,, 뭐가 문제지 ..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import java.util.*;
import java.io.*;
public class boj_11723 {
public static void main(String args[]) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = 20;
int m = Integer.valueOf(bf.readLine());
int s = 0;
StringBuilder sb = new StringBuilder();
while (m-- > 0) {
String[] line = bf.readLine().split(" ");
if (line[0].equals("add")) {
int x = Integer.valueOf(line[1]) - 1;
s = (s | (1 << x));
} else if (line[0].equals("remove")) {
int x = Integer.valueOf(line[1]) - 1;
s = (s & ~(1<<x));
} else if (line[0].equals("check")) {
int x = Integer.valueOf(line[1]) - 1;
int res = (s & (1 << x));
if (res == 0) {
sb.append("0\n");
} else {
sb.append("1\n");
}
} else if (line[0].equals("toggle")) {
int x = Integer.valueOf(line[1]) - 1;
s = (s ^ (1 << x));
} else if (line[0].equals("all")) {
s = (1 << n) - 1;
} else if (line[0].equals("empty")) {
s = 0;
}
}
System.out.print(sb);
}
}
|
cs |
- 똑같은 코드로 JAVA 15 돌리면 메모리 초과나온다.
- JAVA 8, JAVA 11 에서는 통과
- JAVA 15 에 문제가 있는듯 ,,
'PS > boj' 카테고리의 다른 글
boj)1991 - 트리 순회 (0) | 2020.12.11 |
---|---|
boj)7562 - 나이트의 이동 (0) | 2020.12.10 |
boj)14391 - 종이 조각 (0) | 2020.12.09 |
boj)2529 - 부등호 (0) | 2020.12.08 |
boj)15661 - 링크와 스타트 (0) | 2020.12.06 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 이펙티브자바 아이템60
- java
- js promise
- 드림코딩
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- 김영한 http
- 킹수빈닷컴
- dreamcoding
- js array
- http
- BOJ
- 김영한 JPA
- 패스트캠퍼스 컴퓨터공학 완주반
- js api
- 프로그래머스
- ㅇㄷㅇㅈ
- HTTP 완벽 가이드
- 이펙티브자바 아이템59
- 이펙티브자바 스터디
- 프로그래머스 SQL
- 백기선 스터디
- GCP
- 모던자바스크립트
- 백준
- JS 딥다이브
- REST API
- HTTP 완벽가이드
- JPA 연관관계 매핑
- Spring Security
- 이펙티브자바
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함