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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions April/Week2/SeMin/G4_1339.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.io.*;
import java.util.*;


public class Main {
static int N;
static int [] arr = new int[26];

public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());

for (int i = 0; i < N; i++) {
String str = br.readLine();
for (int j = 0; j < str.length(); j++) {
char c = str.charAt(j);
arr[c-'A'] += (int)Math.pow(10, str.length() - 1 - j);
}
}

Arrays.sort(arr);

int num = 9;
int turn = 25;
int ans = 0;
while(arr[turn] != 0) {
ans += arr[turn]*num;
turn--;
num--;
}

System.out.print(ans);
}
}
39 changes: 39 additions & 0 deletions April/Week2/SeMin/G4_9663.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.*;
import java.io.*;

class Main {
static int n;
static int arr[];
static int count = 0;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
arr = new int[n];

nQueen(0);
System.out.println(count);
}

static void nQueen(int depth){
if(depth == n){
count++;
return;
}
for (int i = 0; i < n; i++) {
arr[depth] = i;
if(check(depth)){
nQueen(depth + 1);
}
}
}

static boolean check(int d){
for (int i = 0; i < d; i++) {
if(arr[d] == arr[i]) return false;
}
for (int i = 0; i < d; i++) {
if(Math.abs(arr[d] - arr[i]) == Math.abs(d - i)) return false;
}
return true;
}
}
44 changes: 44 additions & 0 deletions April/Week2/SeMin/G5_10597.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.util.*;
import java.io.*;

class Main {
static String str;
static int n;
static boolean[] visited = new boolean[51];

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
n = str.length();

backtracking(0, 0, "");
}
static void backtracking(int idx, int max, String ans){
if(n == idx){
for (int i = 1; i <= max; i++) {
if(!visited[i]) return;
}
System.out.println(ans);
System.exit(0);
}

String s = str.substring(idx, idx + 1);
int num = Integer.parseInt(s);

if(!visited[num]){
visited[num] = true;
backtracking(idx + 1, (num > max)? num : max, ans + " " + s);
visited[num] = false;
}

if(idx < n - 1){
s = str.substring(idx, idx + 2);
num = Integer.parseInt(s);
if(num < 51 && !visited[num]){
visited[num] = true;
backtracking(idx + 2, (num > max)? num : max, ans + " " + s);
visited[num] = false;
}
}
}
}
58 changes: 58 additions & 0 deletions April/Week2/SeMin/G5_1911.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.io.*;
import java.util.*;

public class Main {

public static int answer = 0;
public static int N,L;

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

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());

int[] waters = new int[2 * N];

for (int i=0; i<2*N; i+=2) {
st = new StringTokenizer(br.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
waters[i] = start;
waters[i+1] = end;
}

Arrays.sort(waters);

int lastIdx = 0;

for (int i = 0; i< 2 * N; i += 2) {

int start = waters[i];

if (lastIdx >= start) {
start = lastIdx + 1;
}

int end = waters[i+1];
int length = end - start;

if (length <= 0) continue;

int cnt = length/L;

int res = length%L;

if (res != 0) {
cnt++;
lastIdx = waters[i+1]-1 + (L - res);
}

answer += cnt;
}

System.out.println(answer);
}
}
39 changes: 39 additions & 0 deletions April/Week2/SeMin/G5_2212.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;

int N = Integer.parseInt(br.readLine());
int K = Integer.parseInt(br.readLine());

if (K >= N) {
System.out.println(0);
return;
}

int[] censor = new int[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
int temp = Integer.parseInt(st.nextToken());
censor[i] = temp;
}
Arrays.sort(censor);

int[] dif = new int[N - 1];
for (int i = 0; i < N - 1; i++) {
dif[i] = censor[i + 1] - censor[i];
}
Arrays.sort(dif);

int ans = 0;
for (int i = 0; i < N - K; i++) {
ans += dif[i];
}

System.out.println(ans);
}

}
45 changes: 45 additions & 0 deletions April/Week2/SeMin/S3_1459.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.io.*;
import java.util.*;

public class Main {
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
long x = Long.parseLong(st.nextToken());
long y = Long.parseLong(st.nextToken());
long w = Long.parseLong(st.nextToken());
long s = Long.parseLong(st.nextToken());

long min = Integer.MAX_VALUE;

long time = (x+y) * w;
min = Math.min(time, min);

if(2*w < s) {
time = (x+y) * w;
}
else if(w>s) {
if((x+y) % 2 ==0) {
time = Math.max(x, y)*s;
}
else {
time = (Math.max(x, y)- 1) *s;
time += w;
}
}
else {
if(x == y) {
time = s * x;
}
else {
time = Math.min(x*s, y*s);
time += Math.abs(x-y)*w;
}
}

System.out.println(time);
}
}