Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/rhs0266/FastCampus into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rhs0266 committed Jul 20, 2021
2 parents b08a100 + 5ac3690 commit 637b587
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,28 @@ public class Main {
static FastReader scan = new FastReader();
static StringBuilder sb = new StringBuilder();

static int N, M;
static int[] A;
static int N, K;

static void input() {
N = scan.nextInt();
M = scan.nextInt();
A = new int[M + 1];
for (int i = 1; i <= M; i++) {
A[i] = scan.nextInt();
}
K = scan.nextInt();
}

static boolean determination(int height) {
int last = 0; // 밝혀진 마지막 위치
for (int i = 1; i <= M; i++) {
if (A[i] - last <= height) {
last = A[i] + height;
} else {
return false;
}
static boolean determination(long candidate) {
// candidate 이하의 숫자가 K개 이상인가?
long sum = 0;
for (int i = 1; i <= N; i++) {
sum += Math.min(N, candidate / i);
}
return last >= N;
return sum >= K;
}

static void pro() {
int L = 0, R = N, ans = N;

Arrays.sort(A, 1, M + 1);
long L = 1, R = (long) N * N, ans = 0;
// [L ... R] 범위 안에 정답이 존재한다!
// 이분 탐색과 determination 문제를 이용해서 answer를 빠르게 구하자!
while (L <= R) {
int mid = (L + R) / 2;
long mid = (L + R) / 2;
if (determination(mid)) {
ans = mid;
R = mid - 1;
Expand Down Expand Up @@ -98,4 +88,4 @@ String nextLine() {
return str;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ static void pro() {
int target = -A[i];
int L = i + 1, R = N;
while (L < R){ // L == R 인 상황이면 용액이 한 개 뿐인 것이므로, L < R 일 때까지만 반복한다.
if (best_sum > Math.abs((long)target + A[L] + A[R])) {
best_sum = Math.abs((long)target + A[L] + A[R]);
v1 = target;
if (best_sum > Math.abs(-(long)target + A[L] + A[R])) {
best_sum = Math.abs(-(long)target + A[L] + A[R]);
v1 = -target;
v2 = A[L];
v3 = A[R];
}
Expand Down Expand Up @@ -91,4 +91,4 @@ String nextLine() {
return str;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ public class Main {
static FastReader scan = new FastReader();

// board 의 상태를 입력받는 함수
static void input(){
static void input() {
n = scan.nextInt();
m = scan.nextInt();
R = scan.nextInt();
a = new int[n+1][m+1];
backup = new int[n+1][m+1];
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++) {
a = new int[n + 1][m + 1];
backup = new int[n + 1][m + 1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
a[i][j] = scan.nextInt();
backup[i][j] = a[i][j];
}
}

// 게임 순서에 맞게 진행시키는 함수
static void pro(){
for (int i=1;i<=R;i++){
static void pro() {
for (int i = 1; i <= R; i++) {
int X, Y;
String dir;

Expand All @@ -44,8 +44,8 @@ static void pro(){

// 정답 출력
System.out.println(ans);
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 0) System.out.print("F ");
else System.out.print("S ");
}
Expand All @@ -59,9 +59,9 @@ public static void main(String[] args) {
}

// x 행 y 열에 있는 도미노를 dir 방향으로 밀어버리는 함수
static void attack(int x,int y, char dir){
static void attack(int x, int y, char dir) {
if (a[x][y] == 0) return;

// dx, dy 는 도미노가 넘어지는 방향을 좌표 변화량으로 표현한 것
int dx = 0, dy = 0;
if (dir == 'E') dy = 1;
Expand Down Expand Up @@ -131,4 +131,4 @@ String nextLine() {
return str;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import java.io.*;
import java.util.*;


public class Main {
static class Interval{
int left;
long satisfy;
}
static int N, K;
static long[] A, Dy;
static ArrayList<Interval>[] intervals;
// a[x] : x 번 먹이의 만족도
// dy[x] : x 번 먹이까지 먹어서 얻을 수 있는 최대 탈피 에너지
static FastReader scan = new FastReader();
static PrintWriter out = new PrintWriter(System.out);

static void input() {
N = scan.nextInt();
K = scan.nextInt();
A = new long[N + 1];
Dy = new long[N + 1];
for (int i = 1; i <= N; i++) {
A[i] = scan.nextLong();
}
intervals = new ArrayList[N + 1];
for (int i = 1; i <= N; i++){
intervals[i] = new ArrayList<>();
}
}

static void pro() {
long sum = 0;
for (int L = 1, R = 0; L <= N; L++){

while (R + 1 <= N && sum < K) sum += A[++R];

if (sum >= K) {
Interval i = new Interval();
i.left = L;
i.satisfy = sum - K;
intervals[R].add(i);
}

sum -= A[L];
}

for (int R = 1; R <= N; R++){
Dy[R] = Dy[R-1];
for (Interval i: intervals[R]){
Dy[R] = Math.max(Dy[R], Dy[i.left - 1] + i.satisfy);
}
}

out.print(Dy[N]);
out.close();
}

public static void main(String[] args) {
input();
pro();
}

static class FastReader {
BufferedReader br;
StringTokenizer st;

public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}

public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}

String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

long nextLong() {
return Long.parseLong(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}

0 comments on commit 637b587

Please sign in to comment.