Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions khj20006/202502/11 BOJ P3 도형.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
```java

import java.util.*;
import java.io.*;


class Main {

// IO field
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer st;

static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
static int nextInt() {return Integer.parseInt(st.nextToken());}
static long nextLong() {return Long.parseLong(st.nextToken());}
static void bwEnd() throws Exception {bw.flush();bw.close();}

// Additional field

static int[] A;
static long[][] dp;
static long[][] sum;
static int N, K;

public static void main(String[] args) throws Exception {

ready();
solve();

bwEnd();
}

static void ready() throws Exception{

N = Integer.parseInt(br.readLine());
A = new int[N];
nextLine();
for(int i=0;i<N;i++) A[i] = nextInt();
K = Integer.parseInt(br.readLine());
dp = new long[500001][K+1];
sum = new long[500001][K+1];

}

static void solve() throws Exception{

Arrays.sort(A);
dp[A[0]][1] = 1;
sum[A[0]][1] = 1;
for(int i=1;i<N;i++) {
for(int s=500000;s>2*A[i];s--) {
for(int k=K;k>2;k--) {
dp[s][k] += sum[s-A[i]][k-1];
}
}
for(int s=500000;s>A[i];s--) {
for(int k=K;k>1;k--) {
sum[s][k] += sum[s-A[i]][k-1];
}
}
for(int s=500000;s>A[i];s--) if(dp[s-A[i]][1] != 0) dp[s][2] += dp[s-A[i]][1];
dp[A[i]][1]++;
sum[A[i]][1]++;
}

long ans = 0;
for(int i=1;i<=500000;i++) ans += dp[i][K];
bw.write(ans+"\n");

}

}

```
91 changes: 91 additions & 0 deletions khj20006/202502/11 BOJ P5 팀 편성.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
```java

import java.util.*;
import java.io.*;


class Main {

// IO field
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer st;

static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
static int nextInt() {return Integer.parseInt(st.nextToken());}
static long nextLong() {return Long.parseLong(st.nextToken());}
static void bwEnd() throws Exception {bw.flush();bw.close();}

// Additional field
static int N;
static boolean[][] know;
static int[] vis;
static boolean res = true;

public static void main(String[] args) throws Exception {

ready();
solve();

bwEnd();
}

static void ready() throws Exception{

N = Integer.parseInt(br.readLine());
know = new boolean[N+1][N+1];
vis = new int[N+1];
nextLine();
for(int a = nextInt(), b = nextInt();a != -1;) {
know[a][b] = true;
know[b][a] = true;
nextLine();
a = nextInt();
b = nextInt();
}

}

static void solve() throws Exception{

for(int i=1;i<=N;i++) if(vis[i] == 0) {
vis[i] = 1;
dfs(i,1);
}
if(!res) bw.write("-1");
else {
List<Integer> A = new ArrayList<>();
List<Integer> B = new ArrayList<>();
for(int i=1;i<=N;i++) if(vis[i] == 1) A.add(i); else B.add(i);
bw.write("1\n");
for(int i:A) bw.write(i+" ");
bw.write("-1\n");
for(int i:B) bw.write(i+" ");
bw.write("-1\n");
}

}

static void dfs(int n, int team) throws Exception {
if(!res) return;
List<Integer> next = new ArrayList<>();
int opposite = team == 1 ? 2 : 1;
for(int i=1;i<=N;i++) {
if(know[n][i] || i == n) continue;
if(vis[i] == 0) {
vis[i] = opposite;
next.add(i);
continue;
}
else if(vis[i] == opposite) continue;
res = false;
return;
}
for(int i:next) {
dfs(i,opposite);
}
}

}

```