restructure zeta/** to storage/zeta/**

This commit is contained in:
2025-05-10 21:54:24 +09:00
parent 2886820691
commit 2f2e0759fd
407 changed files with 7 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
#include<stdio.h>
#define 정수 int
#define 반환 return
#define 출력 printf
#define 입력 scanf
#define 더하기 +
main() {
, ;
("%d %d", &, &);
("%d\n", );
0;
}

View File

@@ -0,0 +1,54 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int x, y;
} Point;
int main() {
Point queens[64];
int length = 0;
char temp[8];
Point temp_pos;
bool flag = true;
for (int i = 0; i < 8; i++) {
scanf("%s", temp);
for (int j = 0; j < 8; j++) {
if (temp[j] == '*') {
queens[length].x = i;
queens[length].y = j;
length++;
}
}
}
if (length != 8) flag = false;
Point a, b;
for (int i = 0; i < length; i++) {
if (flag == false) {
break;
}
a = queens[i];
for (int j = 0; j < i; j++) {
b = queens[j];
if (a.x == b.x) {
flag = false;
break;
} else if (a.y == b.y) {
flag = false;
break;
} else if (abs(a.x - b.x) == abs(a.y - b.y)) {
flag = false;
break;
}
}
}
flag ? printf("valid\n") : printf("invalid\n");
return 0;
}

View File

@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
return *(int *) a - *(int *) b;
}
int is_in(int x, int *cards, int size) {
int begin = 0, end = size - 1, mid;
while (begin <= end) {
mid = (begin + end) / 2;
if (cards[mid] == x) {
return 1;
} else if (cards[mid] > x) {
end = mid - 1;
} else {
begin = mid + 1;
}
}
return 0;
}
int main() {
int N;
scanf("%d", &N);
int cards[N];
for (int i = 0; i < N; i++) {
scanf("%d", &cards[i]);
}
qsort(cards, N, sizeof(int), comp);
int M;
scanf("%d", &M);
int check[M];
for (int i = 0; i < M; i++) {
scanf("%d", &check[i]);
}
for (int i = 0; i < M - 1; i++) {
printf("%d ", is_in(check[i], cards, N));
}
printf("%d\n", is_in(check[M - 1], cards, N));
return 0;
}

View File

@@ -0,0 +1,18 @@
#include<stdio.h>
int main() {
int min=1e6; int max=-1e6;
int N; int a;
scanf("%d", &N);
for (int i=0;i<N;i++) {
scanf("%d", &a);
if (a < min) {
min = a;
}
if (a > max){
max = a;
}
}
printf("%d %d", min, max);
}

View File

@@ -0,0 +1,11 @@
#include<stdio.h>
int main() {
int a; int b;
scanf("%d %d", &a, &b);
printf("%d\n", a+b);
printf("%d\n", a-b);
printf("%d\n", a*b);
printf("%d\n", a/b);
printf("%d\n", a%b);
}

View File

@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
void solve(int *arr, int n, int k) {
int *temparr = calloc(n, sizeof(int));
if (temparr == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return;
}
int cnt_longlive = 0;
int cnt;
int idx = -1;
for (int i = 0; i < n; i++) {
cnt = 0;
while (cnt < k) {
idx = (idx + 1) % n;
if (temparr[idx] == 0) {
cnt++;
}
}
temparr[idx] = 1;
arr[cnt_longlive++] = idx + 1;
}
free(temparr);
}
void print_result(int *arr, int n) {
printf("<");
for (int i = 0; i < n; i++) {
printf("%d", arr[i]);
if (i != n - 1) {
printf(", ");
}
}
printf(">\n");
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
int *arr = calloc(n, sizeof(int));
if (arr == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return 1;
}
solve(arr, n, k);
print_result(arr, n);
free(arr);
return 0;
}

View File

@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int STR_LEN = 501;
int comp(const void *a, const void *b) {
return strcmp((char *) a, (char *) b);
}
int is_in(char *a, char (*S)[STR_LEN], int N) {
// binary search
int low = 0, high = N - 1;
while (low <= high) {
int mid = (low + high) / 2;
int k = (int) strcmp(a, S[mid]);
if (k == 0) return 1;
else if (k < 0)
high = mid - 1;
else if (k > 0)
low = mid + 1;
}
return 0;
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
char S[N][STR_LEN];
char check[M][STR_LEN];
for (int i = 0; i < N; i++) {
scanf("%s", (S[i]));
}
for (int i = 0; i < M; i++) {
scanf("%s", (check[i]));
}
qsort(S, N, sizeof(char) * 501, comp);
int count = 0;
for (int i = 0; i < M; i++) {
count += is_in((check[i]), S, N);
}
printf("%d\n", count);
return 0;
}

View File

@@ -0,0 +1,50 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct IntPair {
int first;
int second;
} IntPair;
bool fox(int N, IntPair *pairs) {
bool _b13 = false;
bool _b14 = false;
bool _b34 = false;
for (int i = 0; i < N; i++) {
if (pairs[i].first == 2 || pairs[i].first == 5 || pairs[i].second == 2 || pairs[i].second == 5) return false;
if (pairs[i].first == 1) {
if (pairs[i].second == 3) {
_b13 = true;
} else if (pairs[i].second == 4) {
_b14 = true;
}
} else if (pairs[i].first == 3) {
if (pairs[i].second == 1) {
_b13 = true;
} else if (pairs[i].second == 4) {
_b34 = true;
}
} else if (pairs[i].first == 4) {
if (pairs[i].second == 1) {
_b14 = true;
} else if (pairs[i].second == 3) {
_b34 = true;
}
}
}
return _b13 && _b14 && _b34;
}
int main(void) {
int N;
scanf("%d", &N);
IntPair *pairs = (int *) calloc(N, sizeof(IntPair));
for (int i = 0; i < N; i++) {
scanf("%d %d", &pairs[i].first, &pairs[i].second);
}
bool isFox = fox(N, pairs);
isFox ? printf("Wa-pa-pa-pa-pa-pa-pow!\n") : printf("Woof-meow-tweet-squeek\n");
return 0;
}

View File

@@ -0,0 +1,102 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1000000
typedef struct {
int x;
int y;
} Position;
Position stack[MAX_SIZE];
int top = -1;
void push(Position item) {
stack[++top] = item;
}
Position pop() {
return stack[top--];
}
int is_empty() {
if (top == -1) {
return 1;
} else {
return 0;
}
}
int main() {
int N;
scanf("%d", &N);
int **A = (int **) calloc(N, sizeof(int *));
A[0] = (int *) calloc(N * N, sizeof(int));
for (int i = 1; i < N; i++) {
A[i] = A[i - 1] + N;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &A[i][j]);
}
}
int **V = (int **) calloc(N, sizeof(int *));
V[0] = (int *) calloc(N * N, sizeof(int));
for (int i = 1; i < N; i++) {
V[i] = V[i - 1] + N;
}
int flag = 0;
Position nowainit;
nowainit.x = 0;
nowainit.y = 0;
push(nowainit);
Position now;
Position target;
int amount;
while (!is_empty()) {
now = pop();
amount = A[now.x][now.y];
if (V[now.x][now.y]) {
continue;
}
V[now.x][now.y] = 1;
if (amount == 0) {
continue;
} else if (amount == -1) {
flag = 1;
break;
}
if (now.x + amount >= N) {
} else {
target.x = now.x + amount;
target.y = now.y;
push(target);
}
if (now.y + amount >= N) {
} else {
target.x = now.x;
target.y = now.y + amount;
push(target);
}
}
if (flag) printf("HaruHaru");
else
printf("Hing");
free(A[0]);
free(A);
free(V[0]);
free(V);
return 0;
}

View File

@@ -0,0 +1,80 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 21
typedef struct _Element {
int index;
char name[MAX_LENGTH];
} Element;
int ecomp(const void *a, const void *b) {
int c = strcmp((*(Element *) a).name, (*(Element *) b).name);
return c;
}
Element binsearch_idx(Element *dict, int N, int x) {
int start = 0;
int end = N - 1;
int mid;
while (start <= end) {
mid = (start + end) / 2;
if (dict[mid].index == x) {
break;
} else if (dict[mid].index > x) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return dict[mid];
}
Element binsearch_str(Element *dict, int N, char *x) {
int start = 0;
int end = N - 1;
int mid;
while (start <= end) {
mid = (start + end) / 2;
int c = strcmp(dict[mid].name, x);
if (c == 0) {
break;
} else if (c > 0) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return dict[mid];
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
Element *dictionary = (Element *) calloc(N, sizeof(Element));
Element *str_dictionary = (Element *) calloc(N, sizeof(Element));
for (int i = 0; i < N; i++) {
scanf("%s", dictionary[i].name);
dictionary[i].index = i + 1;
}
memmove(str_dictionary, dictionary, sizeof(Element) * N);
qsort(str_dictionary, N, sizeof(Element), ecomp);
for (int i = 0; i < M; i++) {
char temp[MAX_LENGTH];
scanf("%s", temp);
Element e;
if (temp[0] <= '9' && temp[0] >= '0') {
e = binsearch_idx(dictionary, N, atoi(temp));
printf("%s\n", e.name);
} else {
e = binsearch_str(str_dictionary, N, temp);
printf("%d\n", e.index);
}
}
return 0;
}

View File

@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
int max3(int x, int y, int z) {
if (x > y)
if (x > z)
return x;
else
return z;
else if (y > z)
return y;
else
return z;
}
int comp(const void *a, const void *b) {
return (*(int *) b - *(int *) a);
}
int main() {
int N, M, temp = 0;
scanf("%d %d", &N, &M);
int *scores = (int *) calloc(N * M, sizeof(int));
int *maxes = (int *) calloc(M * M * M, sizeof(int));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
scanf("%d", scores + M * i + j);
}
}
for (int i = 0; i < M; i++) {
for (int j = 0; j < M; j++) {
if (j == i) continue;
for (int k = 0; k < M; k++) {
if (k == j || k == i) continue;
temp = 0;
for (int n = 0; n < N; n++) {
temp += max3(scores[M * n + i], scores[M * n + j], scores[M * n + k]);
}
maxes[M * M * i + M * j + k] = temp;
}
}
}
qsort(maxes, M * M * M, sizeof(int), comp);
printf("%d", maxes[0]);
free(scores);
free(maxes);
return 0;
}

View File

@@ -0,0 +1,61 @@
#include <stdio.h>
#include <stdlib.h>
typedef long long LL;
int ccw(int x1, int y1, int x2, int y2, int x3, int y3) {
LL s = (LL) (x2 - x1) * (LL) (y3 - y1) - (LL) (y2 - y1) * (LL) (x3 - x1);
if (s > 0) return 1;
if (s < 0) return -1;
return 0;
}
int compare_leq(int x1, int y1, int x2, int y2) {
if (x1 == x2) {
return y1 <= y2;
}
return x1 <= x2;
}
int isIntersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
int d1 = ccw(x1, y1, x2, y2, x3, y3);
int d2 = ccw(x1, y1, x2, y2, x4, y4);
int d3 = ccw(x3, y3, x4, y4, x1, y1);
int d4 = ccw(x3, y3, x4, y4, x2, y2);
int c1 = d1 * d2;
int c2 = d3 * d4;
if (c1 == 0 && c2 == 0) {
if (compare_leq(x2, y2, x1, y1)) {
int temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
}
if (compare_leq(x4, y4, x3, y3)) {
int temp = x3;
x3 = x4;
x4 = temp;
temp = y3;
y3 = y4;
y4 = temp;
}
return (compare_leq(x1, y1, x4, y4) &&
compare_leq(x3, y3, x2, y2));
}
return c1 <= 0 && c2 <= 0;
}
int main() {
int x1, y1, x2, y2;
int x3, y3, x4, y4;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
scanf("%d %d %d %d", &x3, &y3, &x4, &y4);
printf("%d\n", isIntersect(x1, y1, x2, y2, x3, y3, x4, y4));
return 0;
}

View File

@@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// M 개수에 주요한 변수를 가지고 있음. N = 1이면 무조건 1
// 1 1 1 1 1
// 1 1 1 1 1
int sick_knight(int N, int M) {
if (N == 1) {
return 1;
} else if (M == 1) {
return 1;
} else if (M == 2) {
if (N < 3) {
return 1;
} else {
return 2;
}
} else if (M == 3) {
if (N < 3) {
return 2;
} else {
return 3;
}
} else if (M == 4) {
if (N < 3) {
return 2;
} else {
return 4;
}
} else if (M == 5) {
if (N < 3) {
return 3;
} else {
return 4;
}
} else if (M == 6) {
if (N < 3) {
return 3;
} else {
return 4;
}
} else if (M >= 7) {
if (N < 3) {
return 4;
} else {
return M - 2;
}
}
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
printf("%d\n", sick_knight(N, M));
return 0;
}

View File

@@ -0,0 +1,69 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct Honeycomb {
int x;
int loc;
int compressed;
} Honeycomb;
int compare_x(const void *a, const void *b) {
Honeycomb A = *(Honeycomb *) a;
Honeycomb B = *(Honeycomb *) b;
if (A.x > B.x) {
return 1;
} else if (A.x < B.x) {
return -1;
} else {
return 0;
}
}
int compare_loc(const void *a, const void *b) {
Honeycomb A = *(Honeycomb *) a;
Honeycomb B = *(Honeycomb *) b;
if (A.loc > B.loc) {
return 1;
} else if (A.loc < B.loc) {
return -1;
} else {
return 0;
}
}
// 좌표 압축 알고리즘
void compress(int N, Honeycomb *arr) {
qsort(arr, N, sizeof(Honeycomb), compare_x);
for (int i = 1; i < N; i++) {
if (arr[i].x == arr[i - 1].x) {
arr[i].compressed = arr[i - 1].compressed;
} else {
arr[i].compressed = arr[i - 1].compressed + 1;
}
}
qsort(arr, N, sizeof(Honeycomb), compare_loc);
}
// C11(Clang)에서 런타임에러: 백준 clang에서 qsort가 정렬을 제대로 하지 못하는 문제
int main() {
int N;
scanf("%d", &N);
Honeycomb *arr;;
arr = (Honeycomb *) calloc(N, sizeof(Honeycomb));
for (int i = 0; i < N; i++) {
scanf("%d", &arr[i].x);
arr[i].loc = i;
arr[i].compressed = 0;
}
compress(N, arr);
for (int i = 0; i < N - 1; i++) {
printf("%d ", arr[i].compressed);
}
printf("%d\n", arr[N - 1].compressed);
free(arr);
return 0;
}

View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c, d, e, f;
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
for (int x = -999; x <= 999; x++) {
for (int y = -999; y <= 999; y++) {
if (a * x + b * y == c && d * x + e * y == f) {
printf("%d %d\n", x, y);
goto finish;
}
}
}
finish:
return 0;
}

View File

@@ -0,0 +1,54 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int compare(const void *first, const void *second) {
if (*(int *) first < *(int *) second)
return 1;
else if (*(int *) first > *(int *) second)
return -1;
else
return 0;
}
int main() {
int T;
scanf("%d", &T);
int N, X, Y;
int *V;
for (int i = 0; i < T; i++) {
scanf("%d %d %d", &N, &X, &Y);
V = (int *) calloc(N, sizeof(int));
for (int j = 0; j < N; j++) {
scanf("%d", &V[j]);
}
int my_speed = V[N - 1];
qsort(V, N - 1, sizeof(int), compare);
int rival_speed = V[0];
double rival_time;
if (my_speed > rival_speed) {
printf("%d\n", 0);
free(V);
continue;
} else {
rival_time = (double) X / (double) rival_speed;
}
double Z;
int iZ;
if (rival_time >= 1) {
Z = X - (rival_time - 1) * my_speed;
} else {
Z = rival_speed + 1;
}
iZ = floor(Z + 1);
if (iZ > Y) {
printf("%d\n", -1);
} else {
printf("%d\n", iZ);
}
free(V);
}
return 0;
}

View File

@@ -0,0 +1,41 @@
#include <stdbool.h>
#include <stdio.h>
typedef struct TitleCondition {
char title[12];
int condition;
} TitleCondition;
TitleCondition total[100000];
int N, M;
// tc[i-1] < x <= tc[i]일 때, tc[i]
TitleCondition *get_title(int x) {
int start = -1, end = N;
int mid;
while (start + 1 < end) {
mid = (start + end) / 2;
if (total[mid].condition < x) {
start = mid;
} else {
end = mid;
}
}
return total + end;
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%s %d", &total[i].title, &total[i].condition);
}
int temp;
for (int i = 0; i < M; i++) {
scanf("%d", &temp);
printf("%s\n", get_title(temp)->title);
}
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#define max(x, y) (x) > (y) ? (x) : (y)
// 영웅이 표기법 31 -> 16 + 8 + 4 + 2 + 1 11111
// 5(101) = 4 + 1, 7(111) = 4 + 2 + 1, 11 = 8 + 2 + 1 1011
// all 1001 5빼면 1100(12) 7빼면 1110(14) 당첨
// 하나 빼기
// 짝수면 제거 --> 사라지면 없음
// 홀수면 생존 --> 생기면 뭐
int (int N, int *A) {
int all = 0;
for (int i = 0; i < N; i++) {
all ^= A[i];
}
int M = all;
for (int i = 0; i < N; i++) {
M = max(M, all ^ A[i]);
}
return M;
}
int main() {
int power[22] = {0};
int N;
scanf("%d", &N);
int *A = (int *) calloc(N, sizeof(int));
for (int i = 0; i < N; i++) {
scanf("%d", A + i);
}
int r = (N, A);
printf("%d%d\n", r, r);
return 0;
}

View File

@@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
printf("%d\n%d\n", n, 1);
return 0;
}

View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * n, 2);
return 0;
}

View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * (n - 1L) / 2L, 2);
return 0;
}

View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * n * n, 3);
return 0;
}

View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * (n - 1L) * (n - 2L) / 6L, 3);
return 0;
}

View File

@@ -0,0 +1,18 @@
#include <stdio.h>
int main() {
int a1, a0, c, n0;
scanf("%d %d\n%d\n%d", &a1, &a0, &c, &n0);
int cond = 1;
for (int i = n0; i <= 100; i++) {
if (a1 * i + a0 > c * i) {
cond = 0;
break;
}
}
printf("%d\n", cond);
return 0;
}

View File

@@ -0,0 +1,40 @@
#include <stdio.h>
int check(a2, a1, a0, c, n0) {
if (c - a2 < 0) {
return 0;
} else if (c - a2 == 0) {
if (a1 == 0) {
if (-a0 >= 0) {
return 1;
}
} else if (-a1 > 0) {
if ((-a1) * n0 - a0 >= 0) {
return 1;
}
}
return 0;
} else {
int p = (c - a2) * n0 * n0 - a1 * n0 - a0;
if (p >= 0) {
int d = a1 * a1 + 4 * (c - a2) * a0;
if (d <= 0) {
return 1;
} else {
double axis = (double) (a1) / (2.0 * (double) (c - a2));
if (n0 >= axis) {
return 1;
}
}
}
return 0;
}
}
int main() {
int a2, a1, a0, c, n0;
scanf("%d %d %d", &a2, &a1, &a0);
scanf("%d", &c);
scanf("%d", &n0);
printf("%d\n", check(a2, a1, a0, c, n0));
}

View File

@@ -0,0 +1,27 @@
#include <stdio.h>
int main() {
int N, k;
scanf("%d %d\n", &N, &k);
int [N + 1];
int ;
for (int i = 0; i < N; i++) {
scanf("%d", &[i]);
}
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N - 1; j++) {
if ([j] < [j + 1]) {
= [j];
[j] = [j + 1];
[j + 1] = ;
}
}
}
printf("%d\n", [k - 1]);
}

View File

@@ -0,0 +1,5 @@
#include<stdio.h>
int main() {
printf("Hello World!");
}

View File

@@ -0,0 +1,30 @@
#include <stdio.h>
int main() {
int [5];
int = 0;
int ;
scanf("%d\n%d\n%d\n%d\n%d", &[0], &[1], &[2], &[3], &[4]);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 4; j++) {
if ([j] > [j + 1]) {
= [j];
[j] = [j + 1];
[j + 1] = ;
}
}
}
for (int i = 0; i < 5; i++) {
+= [i];
}
printf("%d\n", / 5);
printf("%d\n", [2]);
return 0;
}

View File

@@ -0,0 +1,100 @@
#include <stdio.h>
typedef struct Date {
int year, month, day;
} Date;
Date *newDate(int year, int month, int day) {
if (0 <= year && year <= 99) {
if (1 <= month && month <= 12) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
if (1 <= day && day <= 31) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
} else if (month == 2 && year % 4 == 0) {
if (1 <= day && day <= 29) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
} else if (month == 2 && year % 4 != 0) {
if (1 <= day && day <= 28) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
} else {
if (1 <= day && day <= 30) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
}
}
}
return NULL;
}
void delDate(Date *date) {
free(date);
date = NULL;
}
int valid(Date *x, Date now) {
if (x == NULL) {
return 1;
}
if (x->year < now.year) {
return 0;
} else if (x->year > now.year) {
return 1;
}
if (x->month < now.month) {
return 0;
} else if (x->month > now.month) {
return 1;
}
if (x->day < now.day) {
return 0;
} else if (x->day >= now.day) {
return 1;
}
return 0;
}
int main() {
int N;
Date NOW;
int first, second, third;
scanf("%d %d %d", &NOW.year, &NOW.month, &NOW.day);
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d %d %d", &first, &second, &third);
Date *d1 = newDate(first, second, third);
Date *d2 = newDate(third, second, first);
Date *d3 = newDate(third, first, second);
if (d1 == NULL && d2 == NULL && d3 == NULL) {
printf("invalid\n");
} else if (valid(d1, NOW) && valid(d2, NOW) && valid(d3, NOW)) {
printf("safe\n");
} else {
printf("unsafe\n");
}
delDate(d1);
delDate(d2);
delDate(d3);
}
}

View File

@@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
int get(int map[], int x, int y) {
return map[19 * x + y];
}
int main() {
int Map[19 * 19];
int dx[] = {1, 0, 1, 1};
int dy[] = {0, 1, 1, -1};
int flag;
int last_color;
int last_pos_x, last_pos_y;
for (int i = 0; i < 19; i++) {
for (int j = 0; j < 19; j++) {
scanf("%d", Map + i + j * 19);
}
}
for (int x = 0; x < 19; x++) {
for (int y = 0; y < 19; y++) {
int now = get(Map, x, y);
if (now == 0) {
continue;
} else {
for (int d = 0; d < 4; d++) {
if (19 > x - dx[d] && x - dx[d] >= 0 && 19 > y - dy[d] && y - dy[d] >= 0) {
if (get(Map, x - dx[d], y - dy[d]) == now) {
flag = 0;
continue;
}
}
flag = 1;
for (int i = 1; i < 5; i++) {
if (19 > x + i * dx[d] && x + i * dx[d] >= 0 && 19 > y + i * dy[d] && y + i * dy[d] >= 0) {
if (get(Map, x + i * dx[d], y + i * dy[d]) != now) {
flag = 0;
break;
}
} else {
flag = 0;
break;
}
}
if (flag) {
if (19 > x + 5 * dx[d] && x + 5 * dx[d] >= 0 && 19 > y + 5 * dy[d] && y + 5 * dy[d] >= 0) {
if (get(Map, x + 5 * dx[d], y + 5 * dy[d]) == now) {
flag = 0;
continue;
}
}
}
if (flag) {
break;
}
}
}
if (flag) {
last_color = now;
last_pos_x = x;
last_pos_y = y;
break;
}
}
if (flag) {
break;
}
}
flag ? printf("%d\n%d %d\n", last_color, last_pos_y + 1, last_pos_x + 1) : printf("%d\n", 0);
return 0;
}

View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, M, J, cnt = 0, tmp, now = 1, flag;
scanf("%d %d", &N, &M);
scanf("%d", &J);
int *pos = (int *) calloc(J, sizeof(int));
for (int i = 0; i < J; i++) {
scanf("%d", pos + i);
}
for (int i = 0; i < J; i++) {
flag = 1;
while (flag) {
if (now <= pos[i] && pos[i] <= now + M - 1) {
flag = 0;
} else if (now > pos[i]) {
now--;
cnt++;
} else {
now++;
cnt++;
}
}
}
printf("%d\n", cnt);
}

View File

@@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int getNextInt(char **s1) {
for (int i = 0; i < 3; i++) {
if (s1[i][0] == 'F' || s1[i][0] == 'B') {
continue;
} else {
return atoi(s1[i]) + (3 - i);
}
}
return 0;
}
void getNext(char *s2, char **s1) {
int ni = getNextInt(s1);
if (ni % 3 == 0 && ni % 5 == 0) {
strcpy(s2, "FizzBuzz");
} else if (ni % 3 == 0) {
strcpy(s2, "Fizz");
} else if (ni % 5 == 0) {
strcpy(s2, "Buzz");
} else {
sprintf(s2, "%d", ni);
}
}
int main() {
char **s1 = malloc(sizeof(char *) * 3);
if (s1 == NULL) {
exit(1);
}
for (int i = 0; i < 3; i++) {
s1[i] = malloc(sizeof(char) * 10);
if (s1[i] == NULL) {
exit(1);
}
}
for (int i = 0; i < 3; i++) {
scanf("%s", s1[i]);
}
char *s2 = malloc(sizeof(char) * 10);
if (s2 == NULL) {
exit(1);
}
getNext(s2, s1);
printf("%s\n", s2);
free(s2);
for (int i = 0; i < 3; i++) {
free(s1[i]);
}
free(s1);
return 0;
}

View File

@@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct Alphabets {
char *string;
int len;
} Alphabets;
char shift(char x) {
if (x == 90) return 65;
else
return x + 1;
}
void querry_shift(Alphabets *alphas, int left, int right) {
for (int i = left - 1; i < right; i++) {
*(alphas->string + i) = shift(*(alphas->string + i));
}
}
int querry_string(Alphabets *alphas, int left, int right) {
int cnt = 0;
char head = 0, now;
for (int i = left - 1; i < right; i++) {
now = *(alphas->string + i);
if (head != now) {
head = now;
cnt++;
}
}
return cnt;
}
int querry(Alphabets *alphas, int left, int right, int type) {
if (type == 2) {
querry_shift(alphas, left, right);
return -1;
} else {
return querry_string(alphas, left, right);
}
}
int main() {
int N, Q, left, right, type, ret;
scanf("%d %d", &N, &Q);
Alphabets alphas;
alphas.len = N;
alphas.string = (char *) malloc(alphas.len * sizeof(char));
scanf("%s", alphas.string);
for (int i = 0; i < Q; i++) {
scanf("%d %d %d", &type, &left, &right);
ret = querry(&alphas, left, right, type);
if (ret < 0) {
continue;
} else {
printf("%d\n", ret);
}
}
free(alphas.string);
}

View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _Item {
char name[6];
char isin;
} Item;
int comp(const void *a, const void *b) {
int cmp = strcmp((*(Item *) a).name, (*(Item *) b).name);
return -cmp;
}
int main() {
int N;
scanf("%d", &N);
Item res[N + 1];
for (int i = 0; i < N; i++) {
char temp[6];
scanf("%s %s", res[i].name, temp);
if (temp[0] == 'e') {
res[i].isin = 1;
} else {
res[i].isin = 0;
}
}
qsort(res, N, sizeof(Item), comp);
for (int i = 0; i < N; i++) {
if (comp(&res[i], &res[i + 1]) == 0) {
i++;
} else {
printf("%s\n", res[i].name);
}
}
return 0;
}

View File

@@ -0,0 +1,6 @@
#include<iostream>
int main() {
int A, B;
std::cin >> A >> B;
std::cout << A+B;
}

View File

@@ -0,0 +1,6 @@
#include<iostream>
int main() {
int A, B;
std::cin >> A >> B;
std::cout << A-B;
}

View File

@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
int main() {
int sides[3];
for (int i = 0; i < 3; i++) {
cin >> sides[i];
}
if (sides[0] + sides[1] + sides[2] != 180) {
cout << "Error";
return 0;
}
if (sides[0] == 60 and sides[1] == 60 and sides[2] == 60) {
cout << "Equilateral";
return 0;
}
if (sides[0] == sides[1] or sides[0] == sides[2] or sides[1] == sides[2]) {
cout << "Isosceles";
return 0;
}
cout << "Scalene";
return 0;
}

View File

@@ -0,0 +1,35 @@
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<string> S;
string temp;
for (int i = 0; i < 5; i++) {
cin >> temp;
S.push_back(temp);
}
bool is_fin = false;
bool flag = false;
int j = 0;
while (!is_fin) {
flag = false;
for (int i = 0; i < 5; i++) {
if (S[i].length() <= j) {
is_fin = is_fin;
continue;
}
flag = true;
cout << S[i][j];
}
if (!flag) is_fin = true;
j++;
}
return 0;
}

View File

@@ -0,0 +1,41 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
char translate(int c) {
if (0 <= c && c <= 9) {
return 48 + c;
} else {
return 55 + c;
}
}
vector<char> calculate(int N, int B) {
vector<int> S(0);
while (N >= B) {
S.push_back(N % B);
N /= B;
}
S.push_back(N % B);
reverse(S.begin(), S.end());
vector<char> ST(0);
for(auto i: S) {
ST.push_back(translate(i));
}
return ST;
}
int main() {
int N;
int B;
cin >> N >> B;
vector<char> s = calculate(N, B);
for(auto i: s) {
cout << i;
}
return 0;
}

View File

@@ -0,0 +1,53 @@
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
bool comp(std::pair<char, int> a, std::pair<char, int> b);
int solve(int N, std::string W[]) {
std::map<char, int> V;
for (int i = 0; i < N; ++i) {
std::string w = W[i];
for (int j = 0; j < w.length(); j++) {
if (V.find(w[j]) != V.end()) {
V[w[j]] += (int) pow(10, (double) (w.length() - j - 1));
} else {
V[w[j]] = (int) pow(10, (double) (w.length() - j - 1));
}
}
}
std::vector<std::pair<char, int>> v(V.begin(), V.end());
sort(v.begin(), v.end(), comp);
int s = 0;
for (int i = 0; i < v.size(); i++) {
s += (9 - i) * v[i].second;
}
return s;
}
bool comp(std::pair<char, int> a, std::pair<char, int> b) {
return a.second > b.second;
}
int main() {
int N;
std::cin >> N;
std::string W[N];
for (int i = 0; i < N; i++) {
std::cin >> W[i];
}
std::cout << solve(N, W);
return 0;
}

View File

@@ -0,0 +1,22 @@
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
int sides[3];
for (int i = 0; i < 3; i++) {
cin >> sides[i];
}
sort(sides, sides + 3);
if (sides[2] >= sides[1] + sides[0]) {
sides[2] = sides[1] + sides[0] - 1;
}
cout << accumulate(sides, sides + 3, 0) << endl;
return 0;
}

View File

@@ -0,0 +1,30 @@
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int get_max(int N, int *S) {
for (int i = 0; i < N - 2; i++) {
if (S[i] < S[i + 1] + S[i + 2]) return S[i] + S[i + 1] + S[i + 2];
}
return -1;
}
int main() {
int N;
int S[1000000];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
}
sort(S, S + N, greater<>());
cout << get_max(N, S) << endl;
return 0;
}

View File

@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int T;
int A, B;
std::cin >> T;
for (int i = 0; i < T; i++) {
std::cin >> A >> B;
std::cout << A + B << '\n';
}
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <iostream>
using namespace std;
long long solve(long long n) {
return 4 * n;
}
int main() {
long long n;
cin >> n;
cout << solve(n);
return 0;
}

View File

@@ -0,0 +1,11 @@
#include <iostream>
using namespace std;
int main() {
long long A, B;
cin >> A >> B;
cout << A * A - B * B;
return 0;
}

View File

@@ -0,0 +1,49 @@
#include <iostream>
#include <algorithm>
using namespace std;
bool isExist(int x, int L[], int size) { // binsearch
int begin = 0;
int end = size - 1;
int mid;
int sep;
while (begin <= end) {
mid = (begin + end) / 2;
sep = L[mid];
if (x == sep) {
return true;
} else if (x < sep) {
end = mid - 1;
} else {
begin = mid + 1;
}
}
return false;
}
int main() {
int N, M;
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
sort(A, A + N);
cin >> M;
int x;
for (int i = 0; i < M; i++) {
cin >> x;
if (isExist(x, A, N)) {
cout << "1\n";
} else {
cout << "0\n";
}
}
return 0;
}

View File

@@ -0,0 +1,27 @@
#include <iostream>
#include <queue>
int main() {
std::cin.tie(0);
std::cout.tie(0);
std::ios_base::sync_with_stdio(0);
std::priority_queue<unsigned int, std::vector<unsigned int>, std::greater<int>> q;
int N;
std::cin >> N;
for (int i = 0; i < N; i++) {
int x;
std::cin >> x;
if (x != 0) {
q.push(x);
} else {
if (q.size() != 0) {
std::cout << q.top() << "\n";
q.pop();
} else {
std::cout << 0 << "\n";
}
}
}
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <iostream>
using namespace std;
int cnt1, cnt2, f[42];
int fib(int n) {
if (n == 1 or n == 2) {
cnt1++;
return 1;
} else return (fib(n - 1) + fib(n - 2));
}
int fibonacci(int n) {
return f[n];
}
int main() {
int n;
cin >> n;
fib(n);
f[1] = 1;
f[2] = 1;
for (int i = 3; i <= n; i++) {
f[i] = f[i - 1] + f[i - 2];
cnt2++;
}
cout << cnt1 << " " << cnt2 << endl;
return 0;
}

View File

@@ -0,0 +1,29 @@
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int count = 1;
int N, K;
cin >> N >> K;
if(K == 1) {
cout << 1 << endl;
return 0;
}
for(int i=2;i<=N;i++) {
if (N%i == 0) {
count += 1;
if (count == K) {
cout << i << endl;
break;
}
}
}
if (K > count) {
cout << 0 << endl;
}
return 0;
}

View File

@@ -0,0 +1,52 @@
#include<iostream>
double convert_grade(const std::string &g);
int main() {
double sum_of_score = 0;
double sum_of_prod_score_grade = 0;
for (int i = 0; i < 20; i++) {
std::string category;
double score;
std::string grade;
std::cin >> category >> score >> grade;
double s_grade = convert_grade(grade);
if (s_grade < 0) {
continue;
} else {
sum_of_score += score;
sum_of_prod_score_grade += score * s_grade;
}
}
std::cout << sum_of_prod_score_grade / sum_of_score;
return 0;
}
double convert_grade(const std::string &g) {
if (g == "A+") {
return 4.5;
} else if (g == "A0") {
return 4.0;
} else if (g == "B+") {
return 3.5;
} else if (g == "B0") {
return 3.0;
} else if (g == "C+") {
return 2.5;
} else if (g == "C0") {
return 2.0;
} else if (g == "D+") {
return 1.5;
} else if (g == "D0") {
return 1.0;
} else if (g == "F") {
return 0.0;
} else {
return -1.0;
}
}

View File

@@ -0,0 +1,6 @@
#include<iostream>
int main() {
std::cout<<"Hello World!";
return 0;
}

View File

@@ -0,0 +1,30 @@
#include <iostream>
using namespace std;
void add_paper(int P[], int x, int y) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
P[(x - 1 + i) * 100 + y - 1 + j] = 1;
}
}
}
int main() {
int Paper[100 * 100] = {0,};
int N;
cin >> N;
int _x, _y;
for (int i = 0; i < N; i++) {
cin >> _x >> _y;
add_paper(Paper, _x, _y);
}
int A = 0;
for (int i = 0; i < 10000; i++) {
A += Paper[i];
}
cout << A;
return 0;
}

View File

@@ -0,0 +1,21 @@
#include<iostream>
int main() {
int TM = 0;
int now;
int idx_x, idx_y;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
std::cin >> now;
if (now >= TM) {
TM = now;
idx_x = i + 1;
idx_y = j + 1;
}
}
}
std::cout << TM << std::endl;
std::cout << idx_x << " " << idx_y << std::endl;
}

View File

@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
void solve(int x, int c[], int cat[]) {
for (int i = 0; i < 4; i++) {
c[i] = (x / cat[i]);
x %= cat[i];
}
}
int main() {
int cat[4] = {25, 10, 5, 1};
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int x;
int coins[4];
cin >> x;
solve(x, coins, cat);
for (int j = 0; j < 4; j++) {
cout << coins[j] << " ";
}
cout << endl;
}
return 0;
}

View File

@@ -0,0 +1,10 @@
#include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
cout << A * B;
return 0;
}

View File

@@ -0,0 +1,46 @@
#include<iostream>
#include<vector>
using namespace std;
auto sum(int N, int M, int A[], int B[], int S[]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
S[i * M + j] = A[i * M + j] + B[i * M + j];
}
}
return S;
}
void display(int N, int M, int S[]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cout << S[i * M + j];
if (j < M - 1) {
cout << " ";
}
}
cout << endl;
}
}
int main() {
int N, M;
cin >> N >> M;
int A[N * M];
int B[N * M];
int S[N * M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> A[i * M + j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> B[i * M + j];
}
}
sum(N, M, A, B, S);
display(N, M, S);
return 0;
}

View File

@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
char c = s[i];
if (65 <= c && c <= 90) {
s[i] += 32;
} else {
s[i] -= 32;
}
}
cout << s;
return 0;
}

View File

@@ -0,0 +1,30 @@
#include <iostream>
#include <cmath>
using namespace std;
int translate(char c) {
if (48 <= c && c <= 57) {
return c - 48;
} else {
return c - 55;
}
}
int calculate(string s, int n) {
int l = s.length();
int r = 0;
for (int i = 0; i < l; i++) {
r += translate(s[i]) * pow(n, l - i - 1);
}
return r;
}
int main() {
string s;
int n;
cin >> s >> n;
cout << calculate(s, n);
return 0;
}

View File

@@ -0,0 +1,42 @@
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
string s;
cin >> s;
float v;
if (s == "A+") {
v = 4.3;
} else if (s == "A0") {
v = 4.0;
} else if (s == "A-") {
v = 3.7;
} else if (s == "B+") {
v = 3.3;
} else if (s == "B0") {
v = 3.0;
} else if (s == "B-") {
v = 2.7;
} else if (s == "C+") {
v = 2.3;
} else if (s == "C0") {
v = 2.0;
} else if (s == "C-") {
v = 1.7;
} else if (s == "D+") {
v = 1.3;
} else if (s == "D0") {
v = 1.0;
} else if (s == "D-") {
v = 0.7;
} else if (s == "F")
v = 0.0;
else {
v = 0.0;
}
cout << fixed << std::setprecision(1) << v;
return 0;
}

View File

@@ -0,0 +1,10 @@
#include<iostream>
int main() {
std::string s; int N;
std::cin >> s;
std::cin >> N;
std::cout << s[N-1];
return 0;
}

View File

@@ -0,0 +1,9 @@
#include <iostream>
#include <cmath>
int main() {
int n;
std::cin >> n;
std::cout << (int) pow(((1 << n) + 1), 2);
return 0;
}

View File

@@ -0,0 +1,35 @@
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int sides[3];
while (true) {
for (int i = 0; i < 3; i++) {
cin >> sides[i];
}
if (sides[0] == 0) {
break;
}
sort(sides, sides + 3);
if (sides[0] + sides[1] <= sides[2]) {
cout << "Invalid\n";
continue;
}
if (sides[0] == sides[1] and sides[1] == sides[2] and sides[2] == sides[0]) {
cout << "Equilateral\n";
continue;
}
if (sides[0] == sides[1] or sides[0] == sides[2] or sides[1] == sides[2]) {
cout << "Isosceles\n";
continue;
}
cout << "Scalene\n";
}
}

View File

@@ -0,0 +1,18 @@
#include <iostream>
int main() {
int *arr = new int[30]{0};
int index;
for (int i = 0; i < 30; i++) {
std::cin >> index;
arr[index - 1] = 1;
}
for (int i = 0; i < 30; i++) {
if (!arr[i]) {
std::cout << i + 1 << std::endl;
}
}
return 0;
}

View File

@@ -0,0 +1,20 @@
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
int xs[N], ys[N];
int x, y;
for (int i = 0; i < N; i++) {
cin >> x >> y;
xs[i] = x;
ys[i] = y;
}
sort(xs, xs + N);
sort(ys, ys + N);
cout << (xs[N - 1] - xs[0]) * (ys[N - 1] - ys[0]) << endl;
}

View File

@@ -0,0 +1,13 @@
#include <iostream>
int main() {
int N;
std::string s;
std::cin >> N;
for (int i = 0; i < N; i++) {
std::cin >> s;
std::cout << s[0] << s.back() << std::endl;
}
return 0;
}

View File

@@ -0,0 +1,48 @@
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int lenLCSeq(string s1, string s2) {
vector<vector<int>> DP(s1.length(), vector<int>(s2.length(), 0));
for (int i = 0; i < s1.length(); i++) {
for (int j = 0; j < s2.length(); j++) {
if (s1[i] == s2[j]) {
if (i == 0 && j == 0) {
DP[i][j] = 1;
} else if (i == 0 && j != 0) {
DP[i][j] = 1;
} else if (i != 0 && j == 0) {
DP[i][j] = 1;
} else {
DP[i][j] = DP[i - 1][j - 1] + 1;
}
} else {
if (i == 0 && j == 0) {
} else if (i == 0 && j != 0) {
DP[i][j] = DP[i][j - 1];
} else if (i != 0 && j == 0) {
DP[i][j] = DP[i - 1][j];
} else {
DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
}
}
}
}
return DP[s1.length() - 1][s2.length() - 1];
}
int main(void) {
string s1, s2;
cin >> s1 >> s2;
cout << lenLCSeq(s1, s2) << endl;
return 0;
}

View File

@@ -0,0 +1,45 @@
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
vector<int> isPerfect(int N) {
vector<int> v;
for (int i = 1; i < N; i++) {
if (N % i == 0) {
v.push_back(i);
}
}
int result = accumulate(v.begin(), v.end(), 0);
if (result == N) {
return v;
} else {
return vector<int>();
}
}
int main() {
int input;
vector<int> out;
cin >> input;
while (input != -1) {
out = isPerfect(input);
if (out.size() > 0) {
cout << input << " = " << out[0];
for (int i = 1; i < out.size(); i++) {
cout << " + " << out[i];
}
cout << endl;
} else {
cout << input << " is NOT perfect." << endl;
}
cin >> input;
}
return 0;
}

View File

@@ -0,0 +1,34 @@
import kotlin.text.toInt
operator fun Pair<Int, Int>.plus(b: Pair<Int, Int>) = Pair<Int, Int>(first + b.first, second + b.second)
val Mem = Array<Pair<Int, Int>>(50) { idx ->
if (idx == 0) {
Pair<Int, Int>(1, 0)
} else if (idx == 1) {
Pair<Int, Int>(0, 1)
} else {
Pair<Int, Int>(0, 0)
}
}
fun getFib(n: Int): Pair<Int, Int> {
val m = Mem[n];
if (m.first == 0 && m.second == 0) {
Mem[n] = getFib(n - 1) + getFib(n - 2)
return Mem[n]
} else {
return m;
}
}
fun main() {
val T = readLine()!!.toInt()
for (i in 1..T) {
val N = readLine()!!.toInt()
println(getFib(N).toList().joinToString(" "))
}
}

View File

@@ -0,0 +1,3 @@
fun main() {
println(readLine()?.split(",")?.size)
}

View File

@@ -0,0 +1,34 @@
import kotlin.math.min
fun solve(N: Int, W: Array<Array<Int>>): Int {
val D = ArrayDeque<Triple<Int, Int, Array<Int>>>() // now, cost, visited
D.addLast(Triple(0, 0, Array(N) { 0 }.also { it[0] = 1 }))
var min_cost = Int.MAX_VALUE
while (D.isNotEmpty()) {
val (now, cost, visited) = D.removeLast()
if (visited.all { it == 1 }) {
if (W[now][0] > 0) min_cost = min(min_cost, cost + W[now][0])
continue
} else {
for (i in 1 until N) {
if (visited[i] == 0 && W[now][i] > 0) {
D.addLast(Triple(i, W[now][i] + cost, visited.copyOf().also { it[i] = 1 }))
}
}
}
}
return min_cost
}
fun main() {
val N = readln().toInt()
val W = Array<Array<Int>>(N) { // 0 to N-1
readln().split(' ').map(String::toInt).toTypedArray()
}
println(solve(N, W))
}

View File

@@ -0,0 +1,18 @@
import kotlin.math.max
val Mem = Array<Long>(101) { 0 }
fun solve(N: Int): Long {
for (i in 1..N) {
Mem[i] = Mem[i - 1] + 1
for (j in 3 until i) {
Mem[i] = max(Mem[i], Mem[i - j] * (j - 1))
}
}
return Mem[N]
}
fun main() {
val N = readln().toInt()
println(solve(N))
}

View File

@@ -0,0 +1,32 @@
import kotlin.math.min
fun List<Int>.toTriple(): Triple<Int, Int, Int> {
return Triple(this[0], this[1], this[2])
}
fun solve(N: Int, C: Array<Triple<Int, Int, Int>>): Int {
val T = Array<Triple<Int, Int, Int>>(N) { Triple(0, 0, 0) }
T[0] = C[0]
for (i in 1 until N) {
T[i] = Triple(
min(T[i - 1].second, T[i - 1].third) + C[i].first,
min(T[i - 1].first, T[i - 1].third) + C[i].second,
min(T[i - 1].first, T[i - 1].second) + C[i].third
)
}
return minOf(T[N - 1].first, T[N - 1].second, T[N - 1].third)
}
fun main() {
val N = readln().toInt()
val C = Array<Triple<Int, Int, Int>>(N) {
readln().split(' ').map { s: String ->
s.toInt()
}.toTriple()
}
println(solve(N, C))
}

View File

@@ -0,0 +1,24 @@
val Mem = Array<Int>(1001) { i ->
if (i == 1) {
1
} else if (i == 2) {
3
} else {
0
}
}
fun get(N: Int): Int {
if (Mem[N] != 0) {
return Mem[N]
} else {
Mem[N] = (get(N - 1) + 2 * get(N - 2)) % 10007
return Mem[N]
}
}
fun main() {
val N = readln().toInt()
println(get(N))
}

View File

@@ -0,0 +1,60 @@
import java.util.PriorityQueue
import java.util.Scanner
fun solve(
N: Int,
M: Int,
D: MutableList<Int>,
E: HashMap<Int, MutableList<Pair<Int, Int>>>,
start: Int,
end: Int
): Triple<Int, Int, List<Int>> {
val pq = PriorityQueue<Triple<Int, Int, List<Int>>> { a, b -> a.first.compareTo(b.first) } // min heap
pq.add(Triple(0, start, listOf(start)))
D[start] = 0
val ret: MutableList<Triple<Int, Int, List<Int>>> = mutableListOf()
while (pq.isNotEmpty()) {
val (cost, now, path) = pq.remove()
if (cost > D[now]) {
continue
}
if (now == end) {
return Triple(cost, path.size, path)
}
for ((v, w) in E[now]!!) {
val nd = cost + w
if (D[v] > nd) {
D[v] = nd
pq.add(Triple(nd, v, path + listOf(v)))
}
}
}
println(D.toString())
return ret.last()
}
fun main() = with(Scanner(System.`in`)) {
val N = nextLine().toInt()
val D = MutableList<Int>(N + 1, { Int.MAX_VALUE });
val M = nextLine().toInt()
val E: HashMap<Int, MutableList<Pair<Int, Int>>> = HashMap()
for (i in 0..N) {
E[i] = mutableListOf()
};
for (i in 0 until M) {
val v = nextLine().trim().split(' ').map(String::toInt)
E[v.first()]!!.add(v[1] to v[2])
}
val (start, end) = nextLine().trim().split(' ').map(String::toInt)
val result = solve(start, M, D, E, start, end)
println(result.first)
println(result.second)
println(result.third.joinToString(separator = " "))
}

View File

@@ -0,0 +1,33 @@
fun solve(N: Int, S: Int, I: List<Int>): Int {
val D = ArrayDeque<Pair<Int, Int>>()
D.addLast(Pair(0, 0))
var cnt = 0
while (D.isNotEmpty()) {
val (now, accum) = D.removeLast()
if (now == N) {
if (accum == S) {
cnt += 1
}
continue
} else {
D.addLast(Pair(now + 1, accum)) // 안 더하기
D.addLast(Pair(now + 1, accum + I[now]))
}
}
if (S == 0) {
cnt -= 1;
}
return cnt
}
fun main() {
val (N, S) = readln().split(' ').map(String::toInt)
val I = readln().split(' ').map(String::toInt)
println(solve(N, S, I))
}

View File

@@ -0,0 +1,24 @@
fun bfs(N: Int): Int {
val D = ArrayDeque<Pair<Int, Int>>()
D.addLast(Pair(N, 0))
while (D.isNotEmpty()) {
val (now, step) = D.removeFirst()
if (now == 1) {
return step
}
if (now % 3 == 0) {
D.addLast(Pair(now / 3, step + 1))
}
if (now % 2 == 0) {
D.addLast(Pair(now / 2, step + 1))
}
D.addLast(Pair(now - 1, step + 1))
}
return -1
}
fun main() {
val N = readln().toInt()
println(bfs(N));
}

View File

@@ -0,0 +1,24 @@
fun solve(N: Int, A: Array<Int>): Int {
val T = Array<Triple<Int, Int, Int>>(N) {
Triple(0, 0, 0)
} // 0 안 마시기 ,1번째 마시기, 2번째 마시기
T[0] = Triple(0, A[0], 0)
for (i in 1 until N) {
T[i] = Triple(
maxOf(T[i - 1].first, T[i - 1].second, T[i - 1].third), T[i - 1].first + A[i], T[i - 1].second + A[i]
)
}
return maxOf(T[N - 1].first, T[N - 1].second, T[N - 1].third)
}
fun main() {
val N = readln().toInt()
val A = Array<Int>(N) {
readln().toInt()
}
println(solve(N, A))
}

View File

@@ -0,0 +1,5 @@
fun main() {
val n: Int = readLine()!!.toInt()
println("1")
println("0")
}

View File

@@ -0,0 +1,3 @@
fun main() {
print("Hello World!")
}

View File

@@ -0,0 +1,40 @@
import kotlin.math.*
class NarockSolver(val s: String) {
companion object {
val HAXIM: Int = 1000000007
}
fun solve(): Int {
var cntR = 0
var cntO = 0
var cntC = 0
var cntS = 0
var rfront = 1
for (v: Char in s) {
if (v == 'R') {
cntR += rfront
cntR %= HAXIM
} else if (v == 'O') {
cntO += cntR
cntO %= HAXIM
} else if (v == 'C') {
cntC += cntO
cntC %= HAXIM
} else if (v == 'K') {
cntS += cntC
cntS %= HAXIM
}
rfront *= 2
rfront %= HAXIM
}
return cntS
}
}
fun main() {
readLine()
val s: String = readLine()!!
val solver = NarockSolver(s)
println(solver.solve())
}

View File

@@ -0,0 +1,7 @@
fun main(){
val (a, b) = readLine()!!.split(" ")
val a_ = a.reversed().toInt()
val b_ = b.reversed().toInt()
if (a_ > b_) {println(a_)} else {println(b_)}
}

View File

@@ -0,0 +1,56 @@
import java.io.*
class GoldenTicketSolver(
val n: Int,
val m: Int,
val k: Int,
val teams: List<Pair<String, String>>
) {
fun solve(): List<String> {
val goldenticked = mutableListOf<String>()
val inst_goldenticked = mutableMapOf<String, Int>()
var kcnt = 0
for ((index, teaminst) in this.teams.withIndex()) {
if (index < this.m) {
inst_goldenticked[teaminst.second] = 1
} else {
if (kcnt >= this.k) {
break
}
val tmp = inst_goldenticked.getOrDefault(teaminst.second, 0)
if (tmp == 0) {
inst_goldenticked[teaminst.second] = 2
goldenticked.add(teaminst.first)
kcnt += 1
} else if (tmp == 1) {
continue
} else if (tmp == 2) {
continue
}
}
}
return goldenticked
}
}
fun main() {
val tknz = StreamTokenizer(System.`in`.bufferedReader())
fun StreamTokenizer.nextInt(): Int {
nextToken()
return nval.toInt()
}
fun StreamTokenizer.nextString(): String {
nextToken()
return sval
}
val (n, m, k) = (1..3).map { tknz.nextInt() }
val tms = (1..n).map { Pair(tknz.nextString(), tknz.nextString()) }
val solver = GoldenTicketSolver(n, m, k, tms)
val solved = solver.solve()
println(solved.size)
solved.forEach { i -> println(i) }
}

View File

@@ -0,0 +1,2 @@
a,b =io.read("n", "n")
print(a + b)

View File

@@ -0,0 +1,2 @@
a,b =io.read("n", "n")
print(a - b)

9
storage/zeta/py/11025.py Normal file
View File

@@ -0,0 +1,9 @@
def solve(N, K):
ret = 1
for i in range(2, N + 1):
ret = (ret + K - 1) % i + 1
return ret
if __name__ == "__main__":
print(solve(*map(int, input().split())))

26
storage/zeta/py/1111.py Normal file
View File

@@ -0,0 +1,26 @@
"""
1111: IQ Test
문제:
IQ Test의 문제 중에는 공통된 패턴을 찾는 문제가 있다. 수열이 주어졌을 때, 다음 수를 찾는 문제이다.
예를 들어, 1, 2, 3, 4, 5가 주어졌다. 다음 수는 무엇인가? 당연히 답은 6이다.
약간 더 어려운 문제를 보면, 3, 6, 12, 24, 48이 주어졌을 때, 다음 수는 무엇인가? 역시 답은 96이다.
이제 제일 어려운 문제를 보자.
1, 4, 13, 40이 주어졌을 때, 다음 수는 무엇일까? 답은 121이다.
그 이유는 항상 다음 수는 앞 수*3+1이기 때문이다.
은진이는 위의 3문제를 모두 풀지 못했으므로, 자동으로 풀어주는 프로그램을 작성하기로 했다.
항상 모든 답은 구하는 규칙은 앞 수*a + b이다. 그리고, a와 b는 정수이다.
수 N개가 주어졌을 때, 규칙에 맞는 다음 수를 구하는 프로그램을 작성하시오.
입력:
첫째 줄에 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에는 N개의 수가 주어진다. 이 수는 모두 절댓값이 100보다 작거나 같은 정수이다.
출력:
다음 수를 출력한다. 만약 다음 수가 여러 개일 경우에는 A를 출력하고, 다음 수를 구할 수 없는 경우에는 B를 출력한다.
"""
"""
TC1:
Input:
4
1 4 13 40
Output:
121
"""

23
storage/zeta/py/1158.py Normal file
View File

@@ -0,0 +1,23 @@
from collections import deque
def solve(N, K):
q = deque(range(1, N + 1))
tq = deque()
cnt = 0
ret = []
while q:
while q:
cnt += 1
cnt %= K
if cnt % K == 0:
ret.append(q.popleft())
else:
tq.append(q.popleft())
q = tq
tq = deque()
return "<" + ", ".join(map(str, ret)) + ">"
if __name__ == "__main__":
print(solve(*map(int, input().split())))

0
storage/zeta/py/11726.py Normal file
View File

23
storage/zeta/py/11866.py Normal file
View File

@@ -0,0 +1,23 @@
from collections import deque
def solve(N, K):
q = deque(range(1, N + 1))
tq = deque()
cnt = 0
ret = []
while q:
while q:
cnt += 1
cnt %= K
if cnt % K == 0:
ret.append(q.popleft())
else:
tq.append(q.popleft())
q = tq
tq = deque()
return "<" + ", ".join(map(str, ret)) + ">"
if __name__ == "__main__":
print(solve(*map(int, input().split())))

15
storage/zeta/py/12100.py Normal file
View File

@@ -0,0 +1,15 @@
import sys
input = sys.stdin.readline
class Pane2048:
def __init__(self, N: int, pane: list[list[int]]):
self.N = N
self.pane = pane
@staticmethod
def move(direction: int, N: int, pane: list[list[int]]):
pass
if __name__ == '__main__':
pass

13
storage/zeta/py/12101.py Normal file
View File

@@ -0,0 +1,13 @@
n, k = map(int, input().split())
t = []
# TODO:
#
#
#
#
#
#
#

24
storage/zeta/py/1214.py Normal file
View File

@@ -0,0 +1,24 @@
# Px+Qy >= D
def solve(D, P, Q):
if D % P == 0 or D % Q == 0:
return D
Q, P = sorted((P, Q))
p_bound = (D // P) + 1
min_S = 10 ** 13
for x in range(0, p_bound + 1):
d, m = divmod(D - P * x, Q)
if m == 0:
return D
new_S = (d + 1) * Q + P * x
if new_S < min_S:
min_S = new_S
if min_S == D:
return min_S
return min_S
if __name__ == '__main__':
D, P, Q = map(int, input().split())
print(solve(D, P, Q))

33
storage/zeta/py/1485.py Normal file
View File

@@ -0,0 +1,33 @@
N = int(input())
def check90(p1, p2, p3):
if p2[0] - p1[0] == 0:
if p3[1] - p1[1] == 0:
return True
elif p3[0] - p1[0] == 0:
if p2[1] - p1[1] == 0:
return True
return - (p3[0] - p1[0]) * (p2[1] - p1[1]) == (p3[1] - p1[1]) * (p2[0] - p1[0])
for _ in range(N):
P = [(p1x, p1y), (p2x, p2y), (p3x, p3y), (p4x, p4y)] = \
map(int, input().split()), map(int, input().split()), map(int, input().split()), map(int, input().split())
if check90((p1x, p1y), (p2x, p2y), (p3x, p3y)):
(opox, opoy) = p4x, p4y
(remx, remy) = p3x, p3y
elif check90((p1x, p1y), (p2x, p2y), (p4x, p4y)):
(opox, opoy) = p3x, p3y
(remx, remy) = p2x, p2y
elif check90((p1x, p1y), (p3x, p3y), (p4x, p4y)):
(opox, opoy) = p2x, p2y
(remx, remy) = p4x, p4y
else:
print(0)
continue
if (opox - p1x) ** 2 + (opoy - p1y) ** 2 == 2 * (remx - p1x) ** 2 + 2 * (remy - p1y) ** 2:
print(1)
else:
print(0)

12
storage/zeta/py/1509.py Normal file
View File

@@ -0,0 +1,12 @@
import sys
input = sys.stdin.readline
class PalindromePartition:
def __init__(self, s: str):
self.s = s
self.N = len(s)
if __name__ == "__main__":
s = input().rstrip()

View File

@@ -0,0 +1,4 @@
# 먼저 최대 개수까지 빈 리스트 만듬;
# 그 다음 반복문 돔
# 그리고 배수만큼을 없앰
# 그리고 반복

35
storage/zeta/py/17386.py Normal file
View File

@@ -0,0 +1,35 @@
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
vx1, vy1 = x2 - x1, y2 - y1
vx2, vy2 = x4 - x3, y4 - y3
if vx1 == 0 and vy1 == 0:
print(0)
elif vx1 == 0 or vy1 == 0:
if vx1 == 0:
rx = x1
ry = (vy2/vx2) * (rx - x3) + y3
t0 = (ry - y1) / vy1
t1 = (rx - x3) / vy2
else:
rx = x3
ry = (vy1 / vx1) * (rx-x1) + y1
t0 = (rx - x1) / vx1
t1 = (ry - y3) / vy2
if t0 < 0 or t0 > 1 or t1 < 0 or t1 > 1: print(0)
else: print(1)
else:
a0 = vy1 / vx1
a1 = vy2 / vx2
rx = (a0 * x1 - a1 * x3 + y3 - y1 )/ (a0 - a1)
ry = a0 * (rx - x1) + y1
t0 = (rx - x1) / vx1
t1 = (rx - x3) / vx2
if a0 == a1: print(0)
elif t0 < 0 or t0 > 1 or t1 < 0 or t1 > 1: print(0)
else:
print(1)

2
storage/zeta/py/18870.py Normal file
View File

@@ -0,0 +1,2 @@
def solve(N, X):

10
storage/zeta/py/1920.py Normal file
View File

@@ -0,0 +1,10 @@
N = int(input())
A = list(map(int, input().split()))
M = int(input())
K = list(map(int, input().split()))
for k in K:
if k in A:
print(1)
else:
print(0)

0
storage/zeta/py/19940.py Normal file
View File

52
storage/zeta/py/2085.py Normal file
View File

@@ -0,0 +1,52 @@
import sys
input = sys.stdin.readline
def count_nums(post: list[str], base: int):
n = len(post)
subpost = [[0 for _ in range(n)] for _ in range(n)]
cnts = [[0 for _ in range(n)] for _ in range(n)]
P = [0] * n
for i in range(n):
cnt = 0
for j in range(i, n):
subpost[i][j] = int("".join(post[i:j + 1]))
for i in range(n):
cnt = 0
for j in range(i+1):
if subpost[j][i] < base:
pass
class BaseSpliter:
def __init__(self, s: str):
self.s: str = s
self.post = []
if len(self.s) <= 1:
return
self.flag = False
if self.s[0] == "0":
if len(self.s) > 1 and self.s[1] == 0:
pass
else:
self.flag = True
return
for c in self.s:
if c == "0":
self.post[-1] += c
else:
self.post.append(c)
print(self.post)
def solve(self) -> int:
if not self.post:
return 0
elif self.flag:
return 1
if __name__ == "__main__":
S = input().rstrip()
solver = BaseSpliter(S)
# print(solver.solve())
count_nums(["1", "2", "3"], 4)

Some files were not shown because too many files have changed in this diff Show More