Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8fe7264

Browse files
authored
Merge pull request #223 from GreatAlgorithm-Study/xubin
[16์ฃผ์ฐจ] ๋ฐฐ์ˆ˜๋นˆ
2 parents cb2d54f + ff5c5e3 commit 8fe7264

File tree

7 files changed

+296
-0
lines changed

7 files changed

+296
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Arrays;
5+
import java.util.StringTokenizer;
6+
7+
public class SB_2258 {
8+
static int N, M;
9+
static int[][] dp;
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
14+
N = Integer.parseInt(st.nextToken());
15+
M = Integer.parseInt(st.nextToken());
16+
17+
dp = new int[N][2];
18+
for (int i = 0; i < N; i++) {
19+
st = new StringTokenizer(br.readLine());
20+
dp[i][0] = Integer.parseInt(st.nextToken()); // ๋ฌด๊ฒŒ
21+
dp[i][1] = Integer.parseInt(st.nextToken()); // ๊ฐ€๊ฒฉ
22+
}
23+
24+
// ๊ฐ€๊ฒฉ ์˜ค๋ฆ„์ฐจ์ˆœ, ๋ฌด๊ฒŒ ๋‚ด๋ฆผ์ฐจ์ˆœ
25+
Arrays.sort(dp, (o1, o2) -> {
26+
if (o1[1] != o2[1]) return o1[1] - o2[1];
27+
return o2[0] - o1[0]; // ๊ฐ€๊ฒฉ์ด ๊ฐ™์„๋• ๋ฌด๊ฒŒ ๊ธฐ์ค€ ๋‚ด๋ฆผ์ฐจ์ˆœ
28+
});
29+
30+
31+
int total = 0;
32+
int price = 0;
33+
int mn = Integer.MAX_VALUE;
34+
boolean flag = false;
35+
36+
for (int i = 0; i < N; i++) {
37+
total += dp[i][0]; // ๋ฌด๊ฒŒ ๊ณ„์† ๋ˆ„์  ๋จ
38+
39+
if (i > 0 && dp[i-1][1] == dp[i][1]) // ๊ฐ™์€ ๊ฐ€๊ฒฉ์˜ ๊ณ ๊ธฐ๋Š” ๋ˆ ์ง€๋ถˆ
40+
price += dp[i][1];
41+
else price = dp[i][1]; // ๋‹ค๋ฅธ ๊ฐ€๊ฒฉ์ด๋ฉด, ์ด ๊ฐ€๊ฒฉ์œผ๋กœ ์ง€๊ธˆ๊นŒ์ง€ ๊ณ ๊ธฐ ๋‹ค ์‚ด ์ˆ˜ ์žˆ์Œ(๊ฐ€๊ฒฉ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ)
42+
43+
if (total >= M){
44+
flag = true;
45+
mn = Math.min(mn, price); // ๋™์ผํ•œ ๊ฐ€๊ฒฉ์ด ๋ˆ„์ ๋์„๋•Œ, ์ƒˆ๋กœ์šด ๊ฐ’์ด ๋” ์Œ€ ์ˆ˜ ์žˆ์Œ
46+
}
47+
}
48+
49+
System.out.println(flag ? mn : -1);
50+
51+
}
52+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
public class SB_20002 {
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st;
10+
11+
int N = Integer.parseInt(br.readLine());
12+
int[][] board = new int[N][N];
13+
for (int i = 0; i < N; i++) {
14+
st = new StringTokenizer(br.readLine());
15+
for (int j = 0; j < N; j++) {
16+
board[i][j] = Integer.parseInt(st.nextToken());
17+
}
18+
}
19+
20+
int[][] dp = new int[N + 1][N + 1];
21+
for (int i = 1; i <= N; i++) { // ๋ˆ„์ ํ•ฉ
22+
for (int j = 1; j <= N; j++) {
23+
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + board[i - 1][j - 1];
24+
}
25+
}
26+
27+
int mx = Integer.MIN_VALUE;
28+
for (int k = 0; k < N; k++) {
29+
for (int i = 1; i < N - k + 1; i++) {
30+
for (int j = 1; j < N - k + 1; j++) {
31+
int box = dp[i+k][j+k]-dp[i-1][j+k]-dp[i+k][j-1]+dp[i-1][j-1];
32+
mx = Math.max(mx, box);
33+
}
34+
}
35+
}
36+
37+
System.out.println(mx);
38+
39+
}
40+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
import java.util.TreeSet;
6+
7+
public class SB_23326 {
8+
static int N, Q;
9+
static TreeSet<Integer> place = new TreeSet<>();
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
StringBuilder sb = new StringBuilder();
14+
15+
N = Integer.parseInt(st.nextToken());
16+
Q = Integer.parseInt(st.nextToken());
17+
18+
st = new StringTokenizer(br.readLine());
19+
for (int i = 0; i < N; i++) {
20+
if (Integer.parseInt(st.nextToken())==1) place.add(i);
21+
}
22+
23+
int cur = 0;
24+
while (Q-- > 0) {
25+
st = new StringTokenizer(br.readLine());
26+
int cmd = Integer.parseInt(st.nextToken());
27+
switch (cmd) {
28+
case 1:
29+
int p = Integer.parseInt(st.nextToken()) - 1;
30+
if (place.contains(p)) place.remove(p);
31+
else place.add(p);
32+
break;
33+
case 2:
34+
int val = Integer.parseInt(st.nextToken());
35+
cur = (cur + val) % N;
36+
break;
37+
case 3:
38+
if (place.isEmpty()) sb.append(-1).append('\n');
39+
else if (place.contains(cur)) sb.append(0).append('\n');
40+
else {
41+
Integer right = place.higher(cur);
42+
if (right != null) sb.append(right - cur).append('\n');
43+
else {
44+
Integer left = place.first();
45+
sb.append(N - cur + left).append('\n');
46+
}
47+
}
48+
break;
49+
}
50+
}
51+
System.out.println(sb);
52+
}
53+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
/*
7+
* ์˜ค๋ฆ„์ฐจ์ˆœ: ์„ธ์–ด์˜จ ๊ฐœ์ˆ˜๊ฐ€ L์ด์ƒ์ด๊ณ  ๋‹ค์Œ ๋†’์ด๋ž‘ 1์ฐจ์ด๋‚˜๋ฉด ๊ฐ€๋Šฅ
8+
* ๋‚ด๋ฆผ์ฐจ์ˆœ: ์ด์ „๊ฐ’ pre, ์ดํ›„ ์„ธ๋Š” ๊ฐœ์ˆ˜๊ฐ€ L์ด์ƒ์ด๊ณ  pre๋ž‘ ๋†’์ด 1์ฐจ์ด๋‚˜๋ฉด ๊ฐ€๋Šฅ
9+
* */
10+
public class SB_๋ณด๋„๋ธ”๋Ÿญ {
11+
static int N, L;
12+
static int[][] board;
13+
static int ans = 0;
14+
15+
private static boolean canPass(int[] line) {
16+
boolean[] used = new boolean[N];
17+
for (int i = 0; i < N - 1; i++) {
18+
if (line[i]==line[i+1]) continue; // ๊ฐ™์€ ๋†’์ด
19+
if (line[i+1]-line[i]==1) { // ์˜ค๋ฆ„์ฐจ์ˆœ
20+
for (int j = 0; j < L; j++) { // ์ž๊ธฐ์ž์‹ ๋ถ€ํ„ฐ ๊ฒฝ์‚ฌ๋กœ ์„ค์น˜ ๋จ
21+
if (i-j < 0 || line[i] != line[i-j] || used[i-j]) return false;
22+
used[i-j] = true;
23+
}
24+
} else if (line[i+1]-line[i]==-1) { // ๋‚ด๋ฆผ์ฐจ์ˆœ
25+
for (int j = 1; j <= L; j++) { // ์ž๊ธฐ ์•ž์—๋ถ€ํ„ฐ ๊ฒฝ์‚ฌ๋กœ ์„ค์น˜
26+
if (i+j >=N || line[i+1] != line[i+j] || used[i+j]) return false;
27+
used[i+j] = true;
28+
}
29+
} else return false; // ๋†’์ด์ฐจ๋กœ ๊ฒฝ์‚ฌ๋กœ ์„ค์น˜ ๋ถˆ๊ฐ€
30+
}
31+
return true;
32+
}
33+
public static void main(String[] args) throws IOException {
34+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
35+
StringTokenizer st = new StringTokenizer(br.readLine());
36+
37+
N = Integer.parseInt(st.nextToken());
38+
L = Integer.parseInt(st.nextToken());
39+
40+
board = new int[N][N];
41+
for (int i = 0; i < N; i++) {
42+
st = new StringTokenizer(br.readLine());
43+
for (int j = 0; j < N; j++) {
44+
board[i][j] = Integer.parseInt(st.nextToken());
45+
}
46+
}
47+
48+
for (int[] row : board){ // ๊ฐ€๋กœ ํ™•์ธ
49+
if (canPass(row)) ans++;
50+
}
51+
52+
for (int j = 0; j < N; j++) { // ์„ธ๋กœ ํ™•์ธ
53+
int[] col = new int[N];
54+
for (int i = 0; i < N; i++) {
55+
col[i] = board[i][j];
56+
}
57+
if (canPass(col)) ans++;
58+
}
59+
60+
System.out.println(ans);
61+
}
62+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
public class SB_131703 {
2+
static int N, M;
3+
static int[][] tg;
4+
5+
private static boolean isSame(int[][] board){
6+
for (int i = 0; i < N; i++) {
7+
for (int j = 0; j < M; j++) {
8+
if (board[i][j] != tg[i][j]) return false;
9+
}
10+
}
11+
return true;
12+
}
13+
14+
private static void flipRow(int[][] board, int r) { // ํ–‰ ๋’ค์ง‘๊ธฐ
15+
for (int c = 0; c < M; c++) {
16+
board[r][c] ^= 1;
17+
}
18+
}
19+
private static void flipCol(int[][] board, int c) { // ์—ด ๋’ค์ง‘๊ธฐ
20+
for (int r = 0; r < N; r++) {
21+
board[r][c] ^= 1;
22+
}
23+
}
24+
25+
private static int[][] copy(int[][] origin) {
26+
int[][] board = new int[N][M];
27+
for (int i = 0; i < N; i++) {
28+
for (int j = 0; j < M; j++) {
29+
board[i][j] = origin[i][j];
30+
}
31+
}
32+
return board;
33+
}
34+
public static int solution(int[][] beginning, int[][] target) {
35+
N = target.length;
36+
M = target[0].length;
37+
tg = copy(target);
38+
39+
int mn = Integer.MAX_VALUE;
40+
41+
for (int rowMask = 0; rowMask < (1 << N); rowMask++) { // ๋ชจ๋“  ํ–‰์˜ ๋’ค์ง‘๊ธฐ ์กฐํ•ฉ
42+
for (int colMask = 0; colMask < (1 << M); colMask++) { // ๋ชจ๋“  ์—ด์˜ ๋’ค์ง‘๊ธฐ ์กฐํ•ฉ
43+
int[][] tmp = copy(beginning);
44+
int flip = 0;
45+
46+
// ๋’ค์ง‘๊ธฐ์— ํ•ด๋‹นํ•˜๋Š” ํ–‰ ์ฐพ๊ธฐ
47+
for (int r = 0; r < N; r++) {
48+
if ((rowMask & (1<<r)) !=0){
49+
flipRow(tmp, r);
50+
flip++;
51+
}
52+
}
53+
54+
// ๋’ค์ง‘๊ธฐ์— ํ•ด๋‹นํ•˜๋Š” ์—ด ์ฐพ๊ธฐ
55+
for (int c = 0; c < M; c++) {
56+
if ((colMask & (1 << c)) != 0) {
57+
flipCol(tmp, c);
58+
flip++;
59+
}
60+
}
61+
62+
// ๋ชฉํ‘œํ•œ ์ƒํƒœ๋ž‘ ์ผ์น˜ํ•˜๋Š”์ง€ ์ฒดํฌ
63+
if (isSame(tmp)) mn = Math.min(mn, flip);
64+
}
65+
}
66+
return (mn==Integer.MAX_VALUE) ? -1 : mn;
67+
}
68+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Write your MySQL query statement below
2+
# ์‚ฌ์šฉ์ž์˜ ํ™•์ธ์œจ์€ 'ํ™•์ธ'๋œ ๋ฉ”์‹œ์ง€์˜ ์ˆ˜๋ฅผ ์š”์ฒญ๋œ ํ™•์ธ ๋ฉ”์‹œ์ง€์˜ ์ด ์ˆ˜๋กœ ๋‚˜๋ˆˆ ๊ฐ’์ž…๋‹ˆ๋‹ค. ํ™•์ธ ๋ฉ”์‹œ์ง€๋ฅผ ์š”์ฒญํ•˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž์˜ ํ™•์ธ์œจ์€ 0์ž…๋‹ˆ๋‹ค. ํ™•์ธ์œจ์„ ์†Œ์ˆ˜์  ๋‘ ์ž๋ฆฌ๋กœ ๋ฐ˜์˜ฌ๋ฆผํ•ฉ๋‹ˆ๋‹ค.
3+
4+
SELECT s.user_id,
5+
ROUND(IFNULL(AVG(c.action="confirmed"),0),2) AS confirmation_rate
6+
FROM Signups s
7+
LEFT JOIN Confirmations c ON s.user_id = c.user_id
8+
GROUP BY s.user_id
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
2+
BEGIN
3+
SET N = N-1;
4+
RETURN (
5+
# Write your MySQL query statement below.
6+
# Employee ํ…Œ์ด๋ธ”์—์„œ n๋ฒˆ์งธ๋กœ ํฐ ๊ธ‰์—ฌ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” query๋ฅผ ์ž‘์„ฑ
7+
# ๋งŒ์•ฝ์— n๋ฒˆ์งธ๋กœ ํฐ ๊ธ‰์—ฌ ์ •๋ณด๊ฐ€ ์—†๋‹ค๋ฉด, NULL์„ ๋ฐ˜ํ™˜
8+
SELECT DISTINCT salary
9+
FROM Employee
10+
ORDER BY salary DESC
11+
LIMIT 1 OFFSET N
12+
);
13+
END

0 commit comments

Comments
(0)

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /