├── 1 ├── 1 │ ├── wrong │ │ ├── infikei_wrong_1.in │ │ ├── infikei_wrong_2.in │ │ ├── infikei_wrong_3.in │ │ ├── infikei_wrong_4.in │ │ ├── infikei_wrong_5.in │ │ ├── infikei_wrong_6.in │ │ └── infekei_wrong.cpp │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol.cpp │ ├── gh_sol_stream.java │ └── gh_sol.java ├── 2 │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol_dfs.c │ ├── gh_sol_dfs_and_cutting.c │ ├── gh_sol.cpp │ └── gh_sol.java ├── 3 │ ├── gh_sol.py │ ├── gh_sol_tuple.cpp │ ├── README.md │ ├── gh_sol_with_class_obj_compare.py │ ├── wrong │ │ └── gh_bf_tle.cpp │ ├── gh_sol.cpp │ └── gh_sol.java ├── 4 │ ├── README.md │ ├── wrong │ │ └── gh_bf.py │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 5 │ ├── README.md │ ├── unordered_attacker │ │ ├── bucket_count_calc.cpp │ │ └── unordered_map_modular_attack.py │ ├── random_generator │ │ ├── game.py │ │ └── Main.py │ ├── gh_sol.cpp │ └── gh_sol_bit.cpp ├── 6 │ ├── README.md │ └── gh_sol.py ├── 7 │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 8 │ ├── README.md │ └── gh_sol.py ├── sol.pdf ├── 단계별_모의고사_4회_sol.pdf └── README.md ├── 2 ├── 1 │ ├── README.md │ ├── gh_sol_dsu_pattern.py │ ├── gh_sol.py │ ├── gh_sol_dsu_pattern.cpp │ ├── generator │ │ └── gen_prefix_common_many.py │ ├── gh_sol.cpp │ ├── ryunian_sol.java │ ├── gh_sol.java │ └── gh_sol_compress_long.cpp ├── 2 │ ├── README.md │ ├── gh_sol_set_oper.py │ ├── gh_sol.py │ ├── gh_sol.java │ └── gh_sol.cpp ├── 3 │ ├── README.md │ ├── gh_sol.py │ └── gh_sol.cpp ├── 4 │ ├── double_att.in │ ├── README.md │ └── gh_sol.cpp ├── 5 │ ├── README.md │ └── gh_sol.py ├── 6 │ ├── gh_sol.py │ ├── gh_sol_2d_dp.cpp │ ├── README.md │ ├── gh_sol.cpp │ ├── gh_sol_numpy.py │ └── gh_sol.java ├── 7 │ ├── generator │ │ └── zigzag.py │ └── README.md ├── 8 │ ├── wrong │ │ ├── shallow_copy_wrong.in │ │ └── gh_py_wrong.py │ ├── README.md │ └── gh_sol.py ├── sol.pdf ├── 단계별_모의고사_6회_sol.pdf └── README.md ├── 3 ├── 1 │ ├── conv_notepad_regex.png │ ├── README.md │ ├── data_to_code.py │ ├── station.txt │ ├── base_code.txt │ └── gh_sol.py ├── 2 │ ├── README.md │ └── gh_sol.cpp ├── 3 │ └── README.md ├── 4 │ ├── generator │ │ ├── gen_img.jpg │ │ └── gen_0_and_1.py │ └── README.md ├── 5 │ └── README.md ├── sol.pdf └── README.md ├── 4 ├── 1 │ ├── wrong │ │ ├── fraction_att.in │ │ └── gh_fraction_wrong.cpp │ ├── gh_sol.py │ ├── gh_sol.cpp │ ├── README.md │ └── gh_sol.java ├── 2 │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol.java │ └── gh_sol.cpp ├── 3 │ ├── gh_sol_constant_permission.py │ ├── README.md │ └── gh_sol.py ├── 4 │ └── README.md ├── 5 │ └── README.md ├── 6 │ ├── README.md │ ├── gh_sol.py │ └── gh_sol_opt.py ├── sol.pdf └── README.md ├── 5 ├── 1 │ ├── README.md │ └── gh_sol.cpp ├── 2 │ ├── README.md │ └── gh_sol.cpp ├── 3 │ ├── README.md │ └── gh_sol.cpp ├── 4 │ ├── README.md │ └── gh_sol.cpp ├── 5 │ ├── README.md │ └── gh_sol.cpp ├── 6 │ └── README.md ├── 7 │ └── README.md ├── 8 │ └── README.md ├── 9 │ └── wrong │ │ └── wrong_because_1_process.in ├── sol.pdf └── README.md ├── 6 ├── 10 │ ├── README.md │ ├── gh_sol.java │ ├── gh_sol.cpp │ └── gh_sol_no_sort.cpp ├── 11 │ ├── README.md │ └── tle │ │ └── gh_tle_bf.py ├── 06 │ ├── wrong │ │ ├── gh_wrong_2_counter_case.in │ │ ├── gh_wrong_3.py │ │ ├── gh_wrong_1.cpp │ │ └── gh_wrong_2.cpp │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol_key_note.py │ ├── gh_sol.java │ └── gh_sol.cpp ├── sol.pdf ├── 01 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 02 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 03 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 04 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 05 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 07 │ ├── generator │ │ ├── line_1.py │ │ ├── line_0.py │ │ └── line_2.py │ ├── README.md │ └── gh_sol.cpp ├── 08 │ ├── gh_sol.cpp │ └── gh_sol.java └── 09 │ ├── validator │ └── file_to_input.py │ └── gh_sol.py ├── 7 ├── 12 │ ├── README.md │ ├── gh_sol.py │ └── gh_sol.java ├── sol.pdf ├── 07 │ ├── 7회7번.pdf │ ├── gh_sol.py │ └── gh_sol.cpp ├── 08 │ ├── 7회8번.pdf │ ├── gh_sol.py │ ├── README.md │ ├── gh_sol.cpp │ └── gh_sol.java ├── 01 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 02 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 04 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 09 │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol.java │ └── gh_sol.cpp ├── 05 │ ├── gh_sol.cpp │ ├── gh_sol.java │ ├── README.md │ └── gh_sol.py ├── 03 │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java └── 06 │ ├── README.md │ ├── gh_sol.py │ ├── gh_sol.cpp │ └── gh_sol.java ├── 8 ├── 11 │ └── gh_sol.cpp ├── sol.pdf ├── 03 │ └── gh_sol.cpp ├── 01 │ └── gh_sol.cpp ├── 04 │ └── gh_sol.py ├── 05 │ └── gh_sol.cpp ├── 06 │ └── gh_sol.py ├── 02 │ └── gh_sol.cpp ├── 07 │ └── gh_sol.cpp ├── 08 │ └── gh_sol.cpp └── 09 │ └── gh_sol.cpp ├── .gitignore ├── scripts ├── util.py ├── API.py ├── build_readme.py └── db.py ├── .github └── workflows │ └── codingtest-readme-update.yml ├── LICENSE ├── README.md └── 번외 └── 26080 └── gh_sol.cpp /4/1/wrong/fraction_att.in: -------------------------------------------------------------------------------- 1 | 500 80 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | *__pycache__* -------------------------------------------------------------------------------- /6/06/wrong/gh_wrong_2_counter_case.in: -------------------------------------------------------------------------------- 1 | DDDDDD 2 | DDDDDDDDDDDDDDDDDD 3 | -------------------------------------------------------------------------------- /1/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/1/sol.pdf -------------------------------------------------------------------------------- /2/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/2/sol.pdf -------------------------------------------------------------------------------- /3/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/3/sol.pdf -------------------------------------------------------------------------------- /4/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/4/sol.pdf -------------------------------------------------------------------------------- /5/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/5/sol.pdf -------------------------------------------------------------------------------- /6/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/6/sol.pdf -------------------------------------------------------------------------------- /7/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/7/sol.pdf -------------------------------------------------------------------------------- /8/sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/8/sol.pdf -------------------------------------------------------------------------------- /7/07/7회7번.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/7/07/7회7번.pdf -------------------------------------------------------------------------------- /7/08/7회8번.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/7/08/7회8번.pdf -------------------------------------------------------------------------------- /1/단계별_모의고사_4회_sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/1/단계별_모의고사_4회_sol.pdf -------------------------------------------------------------------------------- /2/단계별_모의고사_6회_sol.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/2/단계별_모의고사_6회_sol.pdf -------------------------------------------------------------------------------- /2/4/double_att.in: -------------------------------------------------------------------------------- 1 | 1 2 2 | 999999999 1000000000 20 3 | 999999998 999999999 30 4 | 999999997 999999998 40 5 | -------------------------------------------------------------------------------- /3/4/generator/gen_img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/3/4/generator/gen_img.jpg -------------------------------------------------------------------------------- /2/8/wrong/shallow_copy_wrong.in: -------------------------------------------------------------------------------- 1 | 2 4 2 | 1 2 1 3 3 | 2 1 3 4 | 2 2 4 5 | ADD 1 6 | ADD 1 7 | ADD 3 8 | ADD 2 9 | -------------------------------------------------------------------------------- /3/1/conv_notepad_regex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdog-gh/gh_coding_test/HEAD/3/1/conv_notepad_regex.png -------------------------------------------------------------------------------- /5/9/wrong/wrong_because_1_process.in: -------------------------------------------------------------------------------- 1 | 25 6 2 | 3 9 23 3 | 9 20 5 4 | 9 11 1 5 | 9 10 1 6 | 16 20 5 7 | 23 25 23 8 | -------------------------------------------------------------------------------- /4/1/gh_sol.py: -------------------------------------------------------------------------------- 1 | a, b = map(int, input().split()) 2 | if (a * (100 - b))/100 >= 100: 3 | print('0') 4 | else: 5 | print('1') -------------------------------------------------------------------------------- /6/01/gh_sol.py: -------------------------------------------------------------------------------- 1 | arr = list(map(int, input().split())) 2 | res = [k for k in arr if arr[0] - k <= 1000] 3 | print(f"{len(res)-1}") 4 | -------------------------------------------------------------------------------- /7/01/gh_sol.py: -------------------------------------------------------------------------------- 1 | s = int(input()) 2 | f = int(input()) 3 | if f < s: 4 | print('flight') 5 | else: 6 | print('high speed rail') -------------------------------------------------------------------------------- /8/03/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | char s1[202]; 3 | char s2[202]; 4 | int main(void) 5 | { 6 | scanf("%s\n%s", &s1, &s2); printf("%c%s\n", s1[0], s1); return 0; 7 | } -------------------------------------------------------------------------------- /scripts/util.py: -------------------------------------------------------------------------------- 1 | def min_to_string(m: int): 2 | hh = m // 60 3 | mm = m % 60 4 | if mm == 0: 5 | return f"{hh:02d}시" 6 | return f"{hh:02d}시 {mm:02d}분" 7 | -------------------------------------------------------------------------------- /7/02/gh_sol.py: -------------------------------------------------------------------------------- 1 | r = int(input()) 2 | f1, f2, f3 = map(int, input().split()) 3 | f = f1 + f2 + f3 4 | if r <= f or r <= 240: 5 | print('high speed rail') 6 | else: 7 | print('flight') -------------------------------------------------------------------------------- /5/1/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 Gahui and Soongsil university station 2 | implementation 3 |
4 | 🔑Hint 1 5 | what does "go down x stairs or x steps" mean in the problem? 6 |
-------------------------------------------------------------------------------- /7/01/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int s, f; scanf("%d%d", &s, &f); 5 | if(s <= f) printf("high speed rail\n"); 6 | else printf("flight\n"); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /8/01/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char s1[50]; 4 | char s2[50]; 5 | int main(void) 6 | { 7 | scanf("%s\n%s", s1, s2); 8 | printf("%d\n", strcmp(s1, s2) == 0?0:1550); 9 | } -------------------------------------------------------------------------------- /7/04/gh_sol.py: -------------------------------------------------------------------------------- 1 | s = input() 2 | if s[-1] == ')': 3 | main, sub = s.replace(")", "").split("(") 4 | print(main.strip() + " ") 5 | print(sub.strip() + " ") 6 | else: 7 | print(s + " ") 8 | print("- ") 9 | -------------------------------------------------------------------------------- /8/04/gh_sol.py: -------------------------------------------------------------------------------- 1 | Q = int(input()) 2 | for _ in range(Q): 3 | k = int(input()) 4 | base = 60 * 6 + 6 5 | ans = base + (k // 50) * 12 6 | HH = ans // 60 7 | MM = ans % 60 8 | print(f"{HH:02d}:{MM:02d}") -------------------------------------------------------------------------------- /5/2/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 열리지 않는 건널목 2 | 구현 3 |
4 | 🔑힌트 1 5 | 하루는 86400초입니다. 열차의 수도 많지 않네요. 6 |
7 |
8 | 🔑힌트 2 9 | 열차가 지나갔는지 체크만 해 둬도 되겠지요? 10 |
-------------------------------------------------------------------------------- /6/02/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | n = int(input()) 4 | s = int(input()) 5 | arr = map(int, input().split()) 6 | ret = 1 7 | for v in arr: 8 | if v > s: 9 | ret += 1 10 | print(ret) 11 | -------------------------------------------------------------------------------- /1/1/wrong/infikei_wrong_1.in: -------------------------------------------------------------------------------- 1 | 11 11 2 | 2 5 3 5 3 | ........... 4 | ........... 5 | ........... 6 | ........... 7 | ........... 8 | ........... 9 | ........... 10 | ....GGGGG.. 11 | ....GGGGGPP 12 | ......PPPPP 13 | ......PPPPP -------------------------------------------------------------------------------- /1/1/wrong/infikei_wrong_2.in: -------------------------------------------------------------------------------- 1 | 11 11 2 | 2 5 4 5 3 | ........... 4 | ........... 5 | ........... 6 | ........... 7 | ........... 8 | ........... 9 | ........... 10 | ....GGGGG.. 11 | ....GGGGG.. 12 | ....PPPPP.. 13 | ....PPPPP.. -------------------------------------------------------------------------------- /1/1/wrong/infikei_wrong_3.in: -------------------------------------------------------------------------------- 1 | 11 11 2 | 2 5 4 5 3 | ........... 4 | ........... 5 | ........... 6 | ........... 7 | ........... 8 | ........... 9 | ........... 10 | GGGGG...... 11 | GGGGG...... 12 | PPPPP...... 13 | PPPPP...... -------------------------------------------------------------------------------- /1/1/wrong/infikei_wrong_4.in: -------------------------------------------------------------------------------- 1 | 11 11 2 | 2 5 4 5 3 | ........... 4 | ........... 5 | ........... 6 | ........... 7 | ........... 8 | ........... 9 | ........... 10 | ......GGGGG 11 | ......GGGGG 12 | ......PPPPP 13 | ......PPPPP -------------------------------------------------------------------------------- /1/1/wrong/infikei_wrong_5.in: -------------------------------------------------------------------------------- 1 | 11 11 2 | 1 5 3 5 3 | ........... 4 | ........... 5 | ........... 6 | ........... 7 | ........... 8 | ........... 9 | ........... 10 | ........... 11 | GGGGG...... 12 | PPPPP...... 13 | PPPPP...... -------------------------------------------------------------------------------- /1/1/wrong/infikei_wrong_6.in: -------------------------------------------------------------------------------- 1 | 11 11 2 | 5 2 11 2 3 | GG......... 4 | GG......... 5 | GG......... 6 | GG......... 7 | GG......... 8 | PP......... 9 | PP......... 10 | PP......... 11 | PP......... 12 | PP......... 13 | PP......... -------------------------------------------------------------------------------- /4/2/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 방어율 무시 2 | 구현, 시각 처리 3 |
4 | 🔑힌트 1 5 | 영역이 무엇을 의미하나요? 6 |
7 |
8 | 🔑힌트 2 9 | 12시간을 주기로 돈다. 나머지 처리와 관련이 있지 않을까요? 10 |
11 | -------------------------------------------------------------------------------- /7/02/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int s, a, f, b; scanf("%d%d%d%d", &s, &a, &f, &b); 5 | if(s <= a + f + b || s <= 240) printf("high speed rail\n"); 6 | else printf("flight\n"); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /6/02/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n, a, b, tot = 1; scanf("%d%d", &n, &a); 5 | for(int i=1; i a); 8 | } 9 | printf("%d\n", tot); 10 | } 11 | -------------------------------------------------------------------------------- /2/6/gh_sol.py: -------------------------------------------------------------------------------- 1 | dp = [0] * 20002 2 | n, M = map(int, input().split(' ')) 3 | dp[0] = dp[2] = 1 4 | for i in range(4, n, 2): 5 | dp[i] = dp[i-2] 6 | for j in range(2, i, 2): 7 | dp[i] = dp[i] + dp[j] * dp[i-j-2] 8 | dp[i] %= M 9 | print(dp[n-2]) -------------------------------------------------------------------------------- /4/1/wrong/gh_fraction_wrong.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | double a, b; scanf("%lf%lf", &a, &b); 5 | double mi = a * (1-b/100); 6 | 7 | if(mi >= 100) 8 | printf("0"); 9 | else 10 | printf("1"); 11 | } -------------------------------------------------------------------------------- /6/03/gh_sol.py: -------------------------------------------------------------------------------- 1 | p, r = map(int, input().split()) 2 | percent = (100 * p) // r 3 | if percent < 20: 4 | print('weak') 5 | elif percent < 40: 6 | print('normal') 7 | elif percent < 60: 8 | print('strong') 9 | else: 10 | print('very strong') 11 | -------------------------------------------------------------------------------- /3/1/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 무궁화호 2 | 구현 3 |
4 | 🔑힌트 1 5 | 표를 긁어서 파싱하면 될 거 같습니다. 정규식이 문득 떠오르는데요. 6 |
7 |
8 | 🔑힌트 2 9 | 정규식을 이용해서 replace를 할 수 없을까요? 줄 하나를 전체 capture 하면 어떤가요? 10 |
11 | -------------------------------------------------------------------------------- /4/1/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int a, b; scanf("%d%d", &a, &b); 5 | a = a * 100; // 200 ~> 20000 6 | int mi = (a/100)*b; 7 | 8 | if(a - mi >= 10000) 9 | printf("0"); 10 | else 11 | printf("1"); 12 | } -------------------------------------------------------------------------------- /6/01/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int arr[5]; 3 | int main(void) 4 | { 5 | int ans = 0; 6 | for(int i=0; i<5; i++) scanf("%d", arr+i); 7 | for(int i=1; i<5; i++) ans += (arr[0] - arr[i] <= 1000); 8 | printf("%d\n", ans); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /3/1/data_to_code.py: -------------------------------------------------------------------------------- 1 | ori_data = [] 2 | with open("station.txt", "r") as f: 3 | ori_data = [" \"" + k.strip() + "\"" for k in f.readlines()] 4 | with open("base_code.txt", "w") as f: 5 | f.write("data = [\n") 6 | s = ",\n".join(ori_data) 7 | f.write(s) 8 | f.write("\n]"); 9 | -------------------------------------------------------------------------------- /5/5/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 Gahui and ILGAM lake 2 | prefix sum 3 |
4 | 🔑Hint 1 5 | How to quickly get following answer? 6 |
    7 |
  • What is the distance from point f to point t?
    8 |
  • The distance to go around the lake.
    9 |
10 |
-------------------------------------------------------------------------------- /8/05/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | int main(void) 4 | { 5 | ll Q; scanf("%lld", &Q); 6 | for(ll i=1; i<=Q; i++) 7 | { 8 | ll c, k; scanf("%lld%lld", &c, &k); 9 | printf("%lld %lld\n", c*k, c/k); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /6/04/gh_sol.py: -------------------------------------------------------------------------------- 1 | lv, verdict = input().split() 2 | lv = int(lv) 3 | r = 0 4 | if verdict == 'bad': 5 | r = lv * 200 6 | elif verdict == 'cool': 7 | r = lv * 400 8 | elif verdict == 'great': 9 | r = lv * 600 10 | elif verdict == 'perfect': 11 | r = lv * 1000 12 | print(r) 13 | -------------------------------------------------------------------------------- /2/2/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 키워드 2 | 구현, 자료구조 3 |
4 | 🔑힌트 1 5 | 키워드가 매우 많네요. 필요한 연산은 키워드가 있는지 여부겠군요. 6 |
7 |
8 | 🔑힌트 2 9 |
    10 |
  • = 연산에 최적화된 자료 구조
    11 |
  • <, = 연산에 최적화된 자료 구조
    12 |
13 | 두 경우에 맞는 자료구조는 무엇일까요?
14 |
-------------------------------------------------------------------------------- /6/05/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | print = sys.stdout.write 3 | 4 | 5 | co = [0] * 505050 6 | ans = list() 7 | s, k = map(int, input().split()) 8 | for v in range(s, 0, -1): 9 | if not co[v + k]: 10 | co[v] = 1 11 | ans.append(v) 12 | print(f"{len(ans)}\n") 13 | ret_s = "\n".join(map(str, ans)) 14 | print(ret_s) 15 | -------------------------------------------------------------------------------- /2/1/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 파일 탐색기 2 | 구현 3 |
4 | 🔑힌트 1 5 | 확장자가 매우 많습니다. os에서 인식하는 확장자인지 어떻게 빠르게 판단할까요? 6 |
7 |
8 | 🔑힌트 2 9 | 제일 빠른 정렬을 하는 경우, 비교 횟수는 무엇에 비례하나요? 10 |
11 |
12 | 🔑힌트 3 13 | 프로그램이 매우 느리다면, 어떤 부분을 미리 전처리 할 수 있을까요? 14 |
-------------------------------------------------------------------------------- /7/01/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int s = sc.nextInt(); 7 | int f = sc.nextInt(); 8 | if(f < s) System.out.println("flight"); 9 | else System.out.println("high speed rail"); 10 | } 11 | } -------------------------------------------------------------------------------- /1/1/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희야 거기서 자는 거 아니야 2 | 구현, 수학 3 |
4 | 🔑힌트 1 5 | 베개가 가려진 것인가요? 가희가 가려진 것인가요? 6 |
7 |
8 | 🔑힌트 2 9 | '어떤 것'을 기준으로 탐색해야 할까요? 가희인가요? 베개인가요? 10 |
11 |
12 | 🔑힌트 3 13 | 가희로 인해 가려졌다면, 보여지는 베개의 넓이는 어떻게 된 것일까요? 14 |
15 | -------------------------------------------------------------------------------- /6/03/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int p, r; scanf("%d%d", &p, &r); 5 | int v = (100 * p) / r; 6 | if(v < 20) 7 | printf("weak"); 8 | else if(v < 40) 9 | printf("normal"); 10 | else if(v < 60) 11 | printf("strong"); 12 | else 13 | printf("very strong"); 14 | } 15 | -------------------------------------------------------------------------------- /1/1/gh_sol.py: -------------------------------------------------------------------------------- 1 | R, C = map(int, input().split()) 2 | _, _, Rp, Cp = map(int, input().split()) 3 | ans = 0 4 | for i in range(R): 5 | ''' 6 | if counting character in string 7 | use count method rather than list comprehension. 8 | ''' 9 | ans = ans + input().count('P') 10 | if ans != Rp*Cp: 11 | print('1') 12 | else: 13 | print('0') -------------------------------------------------------------------------------- /2/2/gh_sol_set_oper.py: -------------------------------------------------------------------------------- 1 | import sys 2 | my_input = sys.stdin.readline 3 | my_print = sys.stdout.write 4 | key = set() 5 | n, m = map(int, my_input().split(' ')) 6 | for i in range(n): 7 | key.add(my_input().replace('\n', '')) 8 | for i in range(m): 9 | s = set(my_input().replace('\n', '').split(',')) 10 | key -= s 11 | my_print(str(len(key))+'\n') 12 | -------------------------------------------------------------------------------- /7/04/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char str[303030]; 4 | int main(void) 5 | { 6 | scanf("%[^\n]", str); 7 | char *o = strchr(str, '('); 8 | if(o != NULL){ 9 | char *c = strchr(str, ')'); 10 | *c = *o = 0; 11 | printf("%s\n%s", str, o+1); 12 | } 13 | else 14 | { 15 | printf("%s\n-", str); 16 | } 17 | } -------------------------------------------------------------------------------- /7/09/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 전기 요금 2 2 | 수학, dp 3 |
4 | 🔑힌트 1 5 | 컴퓨터를 쓰면 전기 요금이라는 비용이 발생하네요. 6 |
7 |
8 | 🔑힌트 2 9 | 전기 요금은 30만원을 넘어가지 않는다고 했고, 컾뮤터 수는 200대 이하네요. 10 |
11 |
12 | 🔑힌트 3 13 | 사용하고 안 하고. 이거 그냥 상태 테이블을 채우면 되지 않을까요?
14 | 결국 냅색과 비슷하게 처리하면 될 것 같습니다. 15 |
16 | -------------------------------------------------------------------------------- /5/1/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char str[10]; 4 | int main(void) 5 | { 6 | int ans = 0, num; 7 | for(int i=0; i<4; i++) 8 | { 9 | scanf("\n%s %d", str, &num); 10 | if(strcmp(str, "Stair") == 0) 11 | ans = ans + 17 * num; 12 | else 13 | ans = ans + 21 * num; 14 | } 15 | printf("%d\n", ans); 16 | } -------------------------------------------------------------------------------- /1/4/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 로그파일 2 | 이진탐색, 누적합, 문자열, 파싱 3 |
4 | 🔑힌트 1 5 | 로그의 종류는 최대 몇 개인가요? 6 |
7 |
8 | 🔑힌트 2 9 | 시각은 최대 몇 가지가 나오나요?
10 | 이벤트 시각에 대해 어떤 처리를 하면 될까요? 11 |
12 |
13 | 🔑힌트 3 14 | 시각 s에서부터 e까지 발생한 로그를 어떻게 하면 빠르게 구할 수 있을까요?
15 | 어떤 정보를 들고 있으면 좋을까요? 16 |
-------------------------------------------------------------------------------- /1/7/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 리버스 가희와 프로세스 2 | 애드혹, 그리디, 수학 3 |
4 | 🔑힌트 1 5 | 우선 순위가 같으면 id가 작은 것이 먼저 실행됩니다. 6 |
7 |
8 | 🔑힌트 2 9 | 실행 기록이 5 3이였다고 해 봅시다. 5는 3보다 우선 순위가 높았을까요? 낮았을까요? 아니면 같아도 될까요? 10 |
11 |
12 | 🔑힌트 3 13 | 실행 기록이 3 5였다고 해 봅시다. 3은 5보다 우선 순위가 높았을까요? 낮았을까요? 아니면 같아도 될까요? 14 |
15 | -------------------------------------------------------------------------------- /4/1/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 방어율 무시 2 | 구현, 수학 3 |
4 | 🔑힌트 1 5 | 문제를 요약하면 이런 의미인가요? 6 |
    7 |
  • 몬스터의 방어율 중 일정 %를 무시한다.
    8 |
9 |
10 |
11 | 🔑힌트 2 12 | 정수만을 이용해서 처리할 수 없을까요? 13 |
    14 |
  • n%가 무시된다는 말은 전체 중 n/100만큼 무시된다는 의미입니다.
    15 |
  • 양 변에 100을 곱해 볼까요? 그래도 부등호의 방향이 바뀌나요?
    16 |
17 |
18 | -------------------------------------------------------------------------------- /5/8/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 코드 2 | 구현, 런타임 전의 전처리 3 |
4 | 🔑힌트 1 5 | 반음이 무엇인가요? 그리고 반음 n개의 거리는 무엇인가요? 6 |
7 |
8 | 🔑힌트 2 9 | major, minor, aug, dim 코드가 있었어요. 10 | major 코드와 공통점, minor 코드 등의 공통점은 무엇인가요? 11 |
12 |
13 | 🔑힌트 3 14 | 어떤 음을 base로 해서 미리 전처리 하고 있으면 어떤가요? 음 이름은 수로 표현할 수 있을 거에요. 15 |
-------------------------------------------------------------------------------- /2/6/gh_sol_2d_dp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | /* 4 | dp[x][h] : x위치에서 고도가 h이다. 5 | */ 6 | ll dp[4004][4004]; 7 | int main(void) 8 | { 9 | ll d, m; scanf("%lld%lld",&d, &m); dp[0][0] = 1; 10 | for(int x=1; x 4 | 🔑힌트 1 5 | 인접 역간 소요 시간이 모두 같다는 것을 무엇을 의미하나요? 6 | 7 |
8 | 🔑힌트 2 9 | 환승역이 최대 몇 개인가요? 10 |
11 |
12 | 🔑힌트 3 13 | 역간 이동을 할 때 케이스가 아래와 같이 나누어지지 않나요? 14 |
    15 |
  • 환승역을 지나는 경우
    16 |
  • 환승역을 지나지 않는 경우
    17 |
18 |
19 | -------------------------------------------------------------------------------- /7/05/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | int main(void){ 4 | ll Q, a, b; scanf("%lld", &Q); 5 | for(int i=1; i<=Q; i++){ 6 | scanf("%lld%lld", &a, &b); 7 | // 소비전력이 aW, b분 사용. 8 | // 요율 : 105.6 / Kwh 9 | 10 | // 60,000 = 1 unit. 11 | ll ans = (1056 * (a * b)) / 600000; 12 | printf("%lld\n", ans); 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /6/02/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | int a = sc.nextInt(); 8 | int tot = 1; 9 | for(int i=1; i a) tot++; 12 | } 13 | System.out.println(tot); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /2/1/gh_sol_dsu_pattern.py: -------------------------------------------------------------------------------- 1 | import sys 2 | my_input = sys.stdin.readline 3 | my_print = sys.stdout.write 4 | n, m = map(int, my_input().split(' ')) 5 | files = [tuple(my_input().split('.')) for i in range(n)] 6 | dic = set([my_input() for i in range(m)]) 7 | deco = sorted([[k[0], k[1] not in dic, k[1]] for k in files]) 8 | files = [tuple([k[0], k[2]]) for k in deco] 9 | for i in range(n): 10 | my_print(f'{files[i][0]}.{files[i][1]}') -------------------------------------------------------------------------------- /4/1/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | import java.util.*; 3 | public class Main { 4 | public static void main(String []args){ 5 | Scanner sc = new Scanner(System.in); 6 | int a = sc.nextInt(); 7 | int b = sc.nextInt(); 8 | int real = (a * (100-b)) / 100; 9 | if(real < 100) 10 | System.out.println("1"); 11 | else 12 | System.out.println("0"); 13 | } 14 | } -------------------------------------------------------------------------------- /7/05/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | long Q = sc.nextLong(); 7 | for(int i=1; i<=Q; i++){ 8 | long a = sc.nextLong(); 9 | long b = sc.nextLong(); 10 | long ans = (1056 * a * b) / (600000); 11 | System.out.println(ans); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /6/07/generator/line_0.py: -------------------------------------------------------------------------------- 1 | import random as rd 2 | n = 200000 3 | q = 200000 4 | print(f'{n} {q}') 5 | li = list(rd.sample(range(1, n+1), k=n)) 6 | for i in range(1, len(li)): 7 | c = rd.randrange(1, 10**9) 8 | ti = rd.randrange(1, 10**9) 9 | print(f'{li[i-1]} {li[i]} {c} {ti}') 10 | li2 = list(rd.sample(range(1, n+1), k=2)) 11 | c2 = rd.randrange(1, 10**9) 12 | ti2 = rd.randrange(1, 10**9) 13 | print(f'{li2[0]} {li2[1]} {c2} {ti2}') 14 | -------------------------------------------------------------------------------- /7/03/gh_sol.py: -------------------------------------------------------------------------------- 1 | def func(s: int, e: int): 2 | if e < s: # ex. s = 243, e = 202 3 | e += 43 4 | inner = 2 * (e - s) 5 | outer = 2 * 43 - inner 6 | if inner < outer: 7 | print("Inner circle line") 8 | elif inner > outer: 9 | print("Outer circle line") 10 | else: 11 | print("Same") 12 | 13 | 14 | Q = int(input()) 15 | for _ in range(Q): 16 | a, b = map(int, input().split()) 17 | func(a, b) -------------------------------------------------------------------------------- /3/4/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 베개 2 | bfs, dfs, 그래프 이론, union find 3 |
4 | 🔑힌트 1 5 | 양방향 그래프인가요? 단방향 그래프인가요? 6 |
7 |
8 | 🔑힌트 2 9 | 양방향 그래프에서 Component를 왜 구할까요? Component의 의미가 무엇일까요? 10 |
11 |
12 | 🔑힌트 3 13 | 경사로의 개수가 최대 몇 개인가요? 14 |
15 |
16 | 🔑힌트 4 17 | 경사로를 놓는 경우는 4가지입니다. 이 중 정말 봐야하는 경우는 몇 가지일까요? 18 |
19 | -------------------------------------------------------------------------------- /5/2/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int t[86400 + 86400]; 3 | int main(void) 4 | { 5 | int n, c, t1, t2, t3, ans=0; scanf("%d%d", &n, &c); 6 | for(int i=0; i 2 | #include 3 | using namespace std; 4 | int arr[505050]; 5 | vector ans; 6 | int main(void) 7 | { 8 | int s, k; scanf("%d%d", &s, &k); 9 | for(int i=s; i>0; i--) 10 | { 11 | if(arr[i+k]) continue; 12 | arr[i] = 1; ans.push_back(i); 13 | } 14 | printf("%d\n", (int)ans.size()); 15 | for(int i=0; i<(int)ans.size(); i++) printf("%d\n", ans[i]); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /7/02/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int r = sc.nextInt(); 7 | int f1 = sc.nextInt(); 8 | int f2 = sc.nextInt(); 9 | int f3 = sc.nextInt(); 10 | int f = f1 + f2 + f3; 11 | if(r <= f || r <= 240) System.out.println("high speed rail"); 12 | else System.out.println("flight"); 13 | } 14 | } -------------------------------------------------------------------------------- /1/2/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 고구마 먹방 2 | 구현, 브루트 포스 3 |
4 | 🔑힌트 1 5 | 이동 횟수의 제한이 작네요. 어떤 방법이 떠오르시나요? 6 |
7 |
8 | 🔑힌트 2 9 | 고구마가 있는 곳에 여러 번 방문해도 한 번만 먹어야 합니다. 어떤 자료구조가 떠오르시나요? 10 |
11 |
12 | 🔑힌트 3 13 | 백트래킹은 이 문제에서 적합한 구조인가요? 만약 그렇다면 어떻게 설계해야 하나요? 14 |
15 |
16 | 🔑힌트 4 17 | 고구마가 있는 위치일 때 이미 방문한 경우를 어떻게 관리해야 할까요? 18 |
-------------------------------------------------------------------------------- /1/3/gh_sol.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | import sys 3 | T, n = map(int, sys.stdin.readline().split()) 4 | pq = [] 5 | for i in range(n): 6 | idx, time, prio = map(int, sys.stdin.readline().split()) 7 | heapq.heappush(pq, (-prio, idx, time)) 8 | for i in range(T): 9 | prio, idx, time = heapq.heappop(pq) 10 | time = time - 1 11 | prio = prio + 1 12 | sys.stdout.write(f'{idx}\n') 13 | if time != 0: 14 | heapq.heappush(pq, (prio, idx, time)) 15 | -------------------------------------------------------------------------------- /2/2/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | my_input = sys.stdin.readline 3 | my_print = sys.stdout.write 4 | keyword_dic = {} 5 | n, m = map(int, my_input().split(' ')) 6 | for i in range(n): 7 | s = my_input().replace('\n', '') 8 | keyword_dic[s] = '' 9 | for i in range(m): 10 | s = my_input().replace('\n', '').split(',') 11 | for keyword in s: 12 | if keyword in keyword_dic: 13 | keyword_dic.pop(keyword) 14 | my_print(str(len(keyword_dic))+'\n') 15 | -------------------------------------------------------------------------------- /1/5/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 자원 놀이 2 | 자료구조, 구현, 수학 3 |
4 | 🔑힌트 1 5 | 유저는 카드를 최대 몇 개 들고 있을 수 있나요? 6 |
7 |
8 | 🔑힌트 2 9 | 자원은 어디에만 갈 수 있나요? 10 |
11 |
12 | 🔑힌트 3 13 | 공용 공간에 있는 자원의 수가 더 작나요? 아니면 유저 공간에 있는 자원의 수가 더 작나요? 14 |
15 |
16 | 💻cs 17 |
    18 |
  • dead lock
    19 |
  • lock
    20 |
21 |
22 | -------------------------------------------------------------------------------- /1/8/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 프로세스 2 2 | 이분 탐색 3 |
4 | 🔑힌트 1 5 | 3번에서 현재 실행중인 프로세스는 실행이 끝나고 우선 순위를 1 감소시킨다고 했습니다. 6 |
7 |
8 | 🔑힌트 2 9 | 현재 실행되고 있는 프로세스의 우선 순위를 기준으로 관찰해 봅시다. 10 |
11 |
12 | 🔑힌트 3 13 | 실행 시간이 k이고 초기 우선 순위가 p라면, 이 프로세스는 실행되면서 우선순위가 어떻게 바뀌나요? 14 |
15 |
16 | 🔑힌트 4 17 | 이 정보를 우리에게 익숙한 구간으로 치환해 봅시다. 18 |
19 | -------------------------------------------------------------------------------- /2/6/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 비행기 2 | 다이나믹 프로그래밍 3 |
4 | 🔑힌트 1 5 | (0, 0)에서 출발하는 경우만 있네요. 기저 조건을 먼저 잡아볼까요? 6 |
7 |
8 | 🔑힌트 2 9 | (x, y)에 비행기가 오는 방법은 어떻게 계산될까요? 관계식을 세워볼 수 있나요? 10 |
11 |
12 | 🔑힌트 3 13 | x = 0일 때와 x = d일 때 제외하고 고도는 얼마 이상으로 낮아지면 안 되나요? 14 |
15 |
16 | 🔑힌트 4 17 | 올라가는 행동을 '('로, 내려가는 행동을 ')'로 잡아 봅시다. 그러면 어떤 경우의 수와 같아지나요? 18 |
-------------------------------------------------------------------------------- /2/6/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //#define M 1000000007LL 3 | typedef long long ll; 4 | ll dp[4002]; 5 | int main(void) 6 | { 7 | ll n, M; scanf("%lld%lld",&n,&M); 8 | dp[0] = dp[2] = 1; 9 | for(ll i=4; i<=4000; i=i+2) 10 | { 11 | dp[i] = dp[i-2]; 12 | for(ll j=2; j 4 | 🔑힌트 1 5 | 극값을 생각해 볼까요? 6 | 7 |
8 | 🔑힌트 2 9 | 항상 고도가 최소가 되는 곳이나 최대가 되는 위치를 고정할 수 있나요? 10 |
11 |
12 | 🔑힌트 3 13 | 만약에 고도가 최소가 되는 값을 고정해 놓았다면, 고도가 최대가 되는 위치만 변하면 되겠군요. 14 |
    15 |
  • 최소 위치를 x라고 하고
    16 |
  • 최대 위치를 y라 합시다. 이걸 y'으로 바꾸려고 해요.
    17 |
  • 최대 위치를 y보다 y'의 고도를 어떻게 하면 될까요?
    18 |
19 |
-------------------------------------------------------------------------------- /7/05/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 전기 요금 1 2 | 수학 3 |
4 | 🔑힌트 1 5 | 요율이 무엇인가요? 6 |
7 |
8 | 🔑힌트 2 9 | 1kw, 1kwh, 1w, 1wh는 무엇인가요? 10 |
11 |
12 | 🔑힌트 3 13 | 요율을 알고 있다면, x kwh를 사용했을 때 요금도 알겠네요. 비례식을 세워 볼까요? 14 |
15 |
16 | 🔑힌트 4 17 | float이나 double 연산을 줄이거나, 없애는 방법은 무엇이 있을까요? 25238번이랑 비슷하지 않나요? 18 |
-------------------------------------------------------------------------------- /2/3/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 은행 2 | 구현, 자료구조 3 |
4 | 🔑힌트 1 5 | 대기 큐는 어떤 특징을 가지나요? 6 |
7 |
8 | 🔑힌트 2 9 | 시간 1초가 지날 때 마다 어떤 일이 일어나나요? 10 |
11 |
12 | 🔑힌트 3 13 | 유저가 들어오는 것은 event로 볼 수 있나요? 그러면 유저가 들어오는 것과 도착한 순서에 대한 처리는 어떻게 하면 될까요? 14 |
15 |
16 | 🪤함정 1 17 | 0초에 들어온 유저들을 c++ 의 sort 함수로 정렬하면 어떻게 될까요? 18 | stable sort와 unstable sort의 차이점이 무엇인가요? 19 |
-------------------------------------------------------------------------------- /5/3/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char str[10]; 4 | int main(void) 5 | { 6 | /* 7 | idea : 최솟 위치를 1번째 역으로 고정시켜 놓고 8 | 최대값을 하나씩 늘려나간다. 9 | 이런 류의 문제를 풀 때에는 극값을 생각해 보는 것도 좋은 습관 중 하나임. 10 | */ 11 | int n, m; scanf("%d%d", &n, &m); 12 | printf("%d\n", 2*m+1); 13 | printf("U 1 -1\n"); 14 | for(int i=1; i<=m; i++) 15 | { 16 | int a; scanf("%d", &a); 17 | printf("U %d %d\n", a+1, i+1); 18 | printf("P\n"); 19 | } 20 | } -------------------------------------------------------------------------------- /8/06/gh_sol.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | ini = stdin.readline 4 | 5 | 6 | def go(): 7 | n = int(ini().strip()) 8 | st = ini().strip().split(" ") 9 | no_underbar = list() 10 | no_underbar = [k for k in st if k.find("-") == -1] 11 | if len(st) == 1 or len(st) != len(no_underbar): 12 | print("NO") 13 | return 14 | print("YES" if len({k[-2:] for k in no_underbar}) == 1 else "NO") 15 | 16 | 17 | Q = int(ini().strip()) 18 | for _ in range(Q): 19 | go() 20 | -------------------------------------------------------------------------------- /1/5/unordered_attacker/bucket_count_calc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | typedef long long ll; 5 | unordered_set ss; 6 | /* 7 | execute this program. 8 | */ 9 | int main(void) 10 | { 11 | for(ll i=1; i<=300000; i++) 12 | { 13 | ll kei = i + 1; 14 | 15 | //3*10^5 item insert. 16 | ss.insert(kei); 17 | } 18 | //and get the bucket number 19 | printf("%d\n",(int)ss.bucket_count()); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /5/4/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 서울 지하철 3호선 2 | 수학, 브루트 포스 3 |
4 | 🔑힌트 1 5 | 역의 개수가 최대 20입니다. 일단 굉장히 작은 제한인 것은 확실합니다. 6 |
7 |
8 | 🔑힌트 2 9 | 그런데 층수가 될 수 있는 층수가 많습니다. 11의 20승은 상당히 큽니다?
10 | 상태를 압축할 방법이 필요합니다. 11 |
12 |
13 | 🔑힌트 3 14 | 각 역의 상태를 미리 저장해 두었습니다. 역의 층 수가 바뀐 경우, 다른 역이 될 수 있는 층 수 가지수에 영향을 미치나요? 15 |
16 |
17 | 🔑힌트 4 18 | 곱사건과 합사건을 잘 생각해 봅시다. 19 |
-------------------------------------------------------------------------------- /6/04/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char str[10]; 4 | int main(void){ 5 | int lv, sc = 0; scanf("%d %s", &lv, str); 6 | if(strcmp("miss", str) == 0) 7 | sc = 0; 8 | if(strcmp("bad", str) == 0) 9 | sc = 200; 10 | if(strcmp("cool", str) == 0) 11 | sc = 400; 12 | if(strcmp("great", str) == 0) 13 | sc = 600; 14 | if(strcmp("perfect", str) == 0) 15 | sc = 1000; 16 | printf("%d\n", sc * lv); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /7/05/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | input = sys.stdin.readline 3 | 4 | 5 | Q = int(input()) 6 | ans = [] 7 | for _ in range(Q): 8 | a, m = map(int, input().split()) 9 | 10 | # 소비 전력 a / 1000 kW 11 | # m 분동안 씀. 12 | 13 | # kWh = (a * m) / (1000 * 3600) 14 | # cost per kWh = 1056/10 15 | # (1056 * a * m) / (1000 * 3600 * 10) 16 | # 1000W, 60분 => 105원임. 17 | a = (1056 * a * m * 60) // (1000 * 3600 * 10) 18 | ans.append(a) 19 | print("\n".join([str(k) for k in ans])) 20 | -------------------------------------------------------------------------------- /1/1/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | char str[101][101]; 3 | int main(void) 4 | { 5 | int r,c,r1,c1,r2,c2,gh = 0, pa = 0; 6 | scanf("%d%d\n",&r,&c); 7 | scanf("%d%d%d%d\n",&r1,&c1,&r2,&c2); 8 | for(int i=0;i k != arr[0]) 10 | .filter(k -> arr[0] - k <= 1000) 11 | .toArray(); 12 | System.out.println(res.length); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2/1/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | my_input = sys.stdin.readline 3 | my_print = sys.stdout.write 4 | files = [] 5 | n, m = map(int, my_input().split(' ')) 6 | for i in range(n): 7 | name, ext = my_input().split('.') 8 | files.append([name, 0, ext]) 9 | dic = {} 10 | for i in range(m): 11 | e = my_input() 12 | dic[e] = '' 13 | for i in range(n): 14 | if files[i][2] not in dic: 15 | files[i][1] = 1 16 | files = sorted(files) 17 | for i in range(n): 18 | my_print(f'{files[i][0]}.{files[i][2]}') 19 | -------------------------------------------------------------------------------- /8/02/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int go(int g, int a, int b, int c) 3 | { 4 | int cut = ((g == 1)? 100: 90); 5 | if(g >= 3) return 0; 6 | if(c < 50) return 0; 7 | if(3 * a < cut && 3 * b < cut) return 1; 8 | if(a < 19 + 3 || b < 19 + 3) return 1; 9 | return 0; 10 | } 11 | int main(void) 12 | { 13 | int Q, g, a, b, c; scanf("%d", &Q); 14 | for(int i=1; i<=Q; i++) 15 | { 16 | scanf("%d%d%d%d", &g, &a, &b, &c); 17 | printf("%s\n", go(g, a, b, c)?"YES":"NO"); 18 | } 19 | } -------------------------------------------------------------------------------- /7/04/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | String s = sc.nextLine(); 7 | ArrayList res = new ArrayList<>( 8 | Arrays.asList(s.replaceAll("[()]", "#").split("#")) 9 | ); 10 | if(res.size() < 2) { 11 | res.add("-"); 12 | res.add("-"); 13 | } 14 | System.out.println(res.get(0)); 15 | System.out.println(res.get(1)); 16 | } 17 | } -------------------------------------------------------------------------------- /7/06/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 클럽 오디션 3 2 | 수학, dp 3 |
4 | 🔑힌트 1 5 | 문제에서 물어보는 것이 무엇인가요? 중요한 factor는 무엇인가요? 6 |
7 |
8 | 🔑힌트 2 9 | 역방향 노트를 lv개 중 k개 뽑고 생각해 봅시다. 10 |
11 |
12 | 🔑힌트 3 13 | 정방향 노트에 대해서 역방향 노트 하나씩 존재한다고 했나요?
14 | 그러면 정방향 lv개 해 놓고, 그 중 몇 개를 선택해서 역방향으로 설정하면 어떨까요? 15 |
16 |
17 | 💡풀이 2 18 | dp[lv][rev]를 아래와 같이 정의하면 어떨까요?
19 | 키 노트의 레벨이 lv이고, 역 방향 키 노트의 개수가 rev인 가짓수. 20 |
-------------------------------------------------------------------------------- /2/7/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 거북이 인형 2 | 구현, bfs 3 |
4 | 🔑힌트 1 5 | 거북이를 이루는 요소는 많지만, 장애물은 20개입니다. 그러면 6 |
    7 |
  • 거북이가 1칸 이동할 때 마다 거북이가 움직이는 게 아니라
    8 |
  • 장애물과 베개가 움직여야 겠군요. 9 |
10 |
11 |
12 | 🔑힌트 2 13 | 거북이를 고정시켜 봅시다. 14 |
    15 |
  • 장애물이 고정된 상태에서 거북이가 1칸 아래로 움직인 것과
    16 |
  • 거북이가 가만히 있고 장애물이 어느 방향으로 움직인 것과 상황이 같을까요? 17 |
18 |
19 |
20 | 🪤함정 1 21 | 거북이를 고정시켰을 때, 장애물 컴포넌트가 맵을 넘어가는 경우가 있을까요? 22 |
-------------------------------------------------------------------------------- /3/2/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 탑 2 | 해 구성하기, greedy 3 |
4 | 🔑힌트 1 5 | 사전순으로 앞선다는 것은 무엇을 의미하나요? 6 |
7 |
8 | 🔑힌트 2 9 | 사전순으로 앞서려면 1을 최대한 어떻게 넣어야 할까요? 10 |
11 |
12 | 🔑힌트 3 13 | 불가능한 경우가 있을까요? 가희와 단비가 동시에 볼 수 있는 건물은 최대 몇 개인가요? 14 |
15 |
16 | 🔑힌트 4 17 |
    18 |
  • 맨 앞에 높이가 1짜리인 건물이 있습니다.
    19 |
  • 맨 앞이 아닌 어떤 위치에 높이가 1보다 큰 건물이 있습니다.
    20 |
21 | 이 경우 가희는 몇 개의 건물을 볼 수 있을까요? 22 |
23 | -------------------------------------------------------------------------------- /6/03/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Main { 3 | public static void main(String[] args){ 4 | Scanner sc = new Scanner(System.in); 5 | int p = sc.nextInt(); 6 | int r = sc.nextInt(); 7 | int v = (100 * p) / r; 8 | if(v < 20) 9 | System.out.println("weak"); 10 | else if(v < 40) 11 | System.out.println("normal"); 12 | else if(v < 60) 13 | System.out.println("strong"); 14 | else 15 | System.out.println("very strong"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /6/04/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int lv = sc.nextInt(); 7 | String verdict = sc.next(); 8 | Map verdictData = Map.of( 9 | "miss", 0, 10 | "bad", 200, 11 | "cool", 400, 12 | "great", 600, 13 | "perfect", 1000 14 | ); 15 | int ans = verdictData.get(verdict) * lv; 16 | System.out.println(ans); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /2/8/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 읽기 쓰기 놀이 2 2 | 구현, 자료구조 3 |
4 | 🔑힌트 1 5 | 2개 이상 있는 수가 적혀진 카드는 최대 몇 개 나오나요? 6 |
7 |
8 | 🔑힌트 2 9 | 각 수마다 어떤 사람이 들고 있는지를 매번 저장해 둡시다. 예를 들어 10 |
    11 |
  • 2가 적힌 카드를 3, 5, 6번 사람이 들고 있다 해 봅시다. 그러면
    12 |
  • 3번이 2가 적힌 카드를 택할 수도 있고, 5, 6번이 선택할 수도 있겠죠?
    13 |
  • 이걸 뎁스가 들어갈 때 마다 반영하고 원복시켜 주면 되겠군요. 14 |
15 |
16 |
17 | 🔑힌트 3 18 | 뎁스를 타고 들어갈 때 마다 카드 x가 있는 사람이 있는지를 알고 싶어요.
19 | 어떤 자료구조를 쓰면 빠르게 찾을 수 있나요? 20 |
-------------------------------------------------------------------------------- /7/08/gh_sol.py: -------------------------------------------------------------------------------- 1 | import operator as op 2 | from functools import reduce 3 | from collections import Counter 4 | 5 | 6 | def combi(n, k): 7 | if k == 0 or k == n: 8 | return 1 9 | t = reduce(op.mul, range(n, n-k, -1)) 10 | d = reduce(op.mul, range(1, k+1)) 11 | return t // d 12 | 13 | 14 | mod = 1000000007 15 | leni = int(input()) 16 | c = Counter(input()) 17 | tot = combi(leni, 2) 18 | for k in c: 19 | v = c[k] 20 | if v < 2: 21 | continue 22 | tot += (2 ** v) - 1 - combi(v, 1) - combi(v, 2) 23 | tot %= mod 24 | print(tot) 25 | -------------------------------------------------------------------------------- /1/7/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | T = int(sys.stdin.readline()) 3 | li = map(int, sys.stdin.readline().split()) 4 | s = [0x3f3f3f3f] * 1000001 5 | e = [0] * 1000001 6 | prev = -1 7 | ti = 1 8 | for cur_process in li: 9 | if prev >= cur_process: 10 | ti = ti + 1 11 | s[cur_process] = min(s[cur_process], ti) 12 | e[cur_process] = max(e[cur_process], ti) 13 | prev = cur_process 14 | pn = 0 15 | ret = [k for k in range(1000001) if e[k] != 0] 16 | sys.stdout.write(f'{len(ret)}\n') 17 | for i in ret: 18 | sys.stdout.write(f'{i} {e[i] - s[i] + 1} {1000000 - s[i]}\n') -------------------------------------------------------------------------------- /3/5/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 btd5 2 2 | 자료구조, oop, 최적화 3 |
4 | 🔑힌트 1 5 | 유닛에서 어떤 것이 중요한가요? 6 |
7 |
8 | 🔑힌트 2 9 | 공격 우선 순위가 각각 다르네요. 우선 순위하면 떠오르는 자료구조가 있나요? 10 |
11 |
12 | 🔑힌트 3 13 | 각 풍선마다 속성이 다릅니다. 어떻게 관리해야 할까요? 14 |
15 |
16 | 💡생각해 볼 만한 것 17 |
    18 |
  • 공격 우선 순위를 유닛이 가집니다. 유닛 클래스는 어떻게 설계하면 더 깔끔할까요?
    19 |
  • 필요 없는 정보를 제거하는 트릭은 이 문제에서도 유용하게 쓰일까요?
    20 |
  • 이 문제를 저는 python으로 풀지 않았습니다. 왜? python으로 풀 수 있을까요? 21 |
22 |
-------------------------------------------------------------------------------- /2/6/gh_sol_numpy.py: -------------------------------------------------------------------------------- 1 | """ 2 | does not supported numpy in acmicpc.net 3 | """ 4 | import time 5 | import numpy as np 6 | dp_np = np.array([1]) 7 | n, M = map(int, input().split(' ')) 8 | s = time.time_ns() 9 | ''' 10 | A = [-1, 0, 1, 2, ... ] 11 | B = [1, 2, 3, 4, ... ] 12 | REAL = [0, 1, 2, 3, ... ] 13 | dp[x][h] = dp[x-1][h+1] + dp[x-1][h-1]을 vector operation으로 치환. 14 | ''' 15 | for i in range(1, n-1): 16 | A = np.append([0], dp_np[:i]) 17 | B = np.append(dp_np[1:], [0, 0]) 18 | dp_np = np.sum([A, B], axis=0) % M 19 | e = time.time_ns() 20 | print(f'{(e-s)/(10**9):.2f} {dp_np[0]}') 21 | -------------------------------------------------------------------------------- /5/6/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 지하철역 저장 시스템 1 2 | 자료구조, bit operation 3 |
4 | 🔑힌트 1 5 | 제한을 잘 읽어보세요. 6 |
7 |
8 | 🔑힌트 2 9 | 모든 U 요청에 나타난 특징의 종류는 9개 이하라는 조건은 무엇을 의미할까요? 10 |
11 |
12 | 🔑힌트 3 13 | 어떤 역이 A, B, C의 특징을 가지고 있어요. 저는 특징 A, C를 모두 가진 역을 찾으려고 해요. 14 | 어떻게 찾으면 될까요? bit 연산에서는 어떻게 하면 될까요? 15 |
16 |
17 | 🔑힌트 4 18 | 2의 9승은 얼마인가요? 19 |
20 |
21 | 🔑힌트 5 22 | 쿼리에서 유효한 키워드는 최대 몇 개인가요? U 업데이트에 나오지 않은 것은 어떻게 처리하면 될까요? 23 |
-------------------------------------------------------------------------------- /4/2/gh_sol.py: -------------------------------------------------------------------------------- 1 | hh, mm = map(int, input().split(':')) 2 | cur = (60 * hh + mm) % 720 3 | hp = list(map(int, input().split())) 4 | flag = [1] * 6 5 | event = int(input()) 6 | for i in range(event): 7 | _, q2 = input().split() 8 | if q2 == '^': 9 | flag[cur // 120] = 0 10 | elif q2.endswith('HOUR'): 11 | cur = cur + int(q2[:1]) * 60 12 | cur = cur % 720 13 | else: 14 | cur = cur + int(q2[:2]) 15 | cur = cur % 720 16 | ans = 0 17 | for i in range(6): 18 | ans = ans + flag[i] * hp[i] 19 | if ans >= 100: 20 | print('100\n') 21 | else: 22 | print(ans) -------------------------------------------------------------------------------- /6/05/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.stream.IntStream; 3 | 4 | public class Main { 5 | public static void main(String []args){ 6 | Scanner sc = new Scanner(System.in); 7 | int s = sc.nextInt(); 8 | int k = sc.nextInt(); 9 | int []res = IntStream.range(1, s+1) 10 | .map(v -> s-v) 11 | .filter(v -> (v % (2*k) < k)) 12 | .sorted() 13 | .map(v -> s-v).toArray(); 14 | System.out.println(res.length); 15 | for(int item: res) 16 | System.out.println(item); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /7/06/gh_sol.py: -------------------------------------------------------------------------------- 1 | import operator as op 2 | from functools import reduce 3 | 4 | 5 | def combi(n, k): 6 | if k == 0 or k == n: 7 | return 1 8 | # redoce의 경우 1번째 인자로 연산, 2번째 인자로 iterable한 것을 받는다. 9 | # iterable한 것을 돌면서 연산을 적용한다. 10 | t = reduce(op.mul, range(n, n-k, -1)) 11 | # 이 경우, 1부터 k까지 곱하는 것임. 12 | d = reduce(op.mul, range(1, k+1)) 13 | return t // d 14 | 15 | 16 | lv = int(input()) 17 | if lv <= 5: 18 | print(4 ** lv) 19 | else: 20 | rr = reduce(op.add, [combi(lv, rev) for rev in range(0, 6+1)]) 21 | note = 8 ** lv 22 | ans = (rr * note) % 1000000007 23 | print(ans) -------------------------------------------------------------------------------- /1/3/gh_sol_tuple.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | typedef tuple proc_data; 6 | priority_queue pq; 7 | int main(void) 8 | { 9 | int n,T; scanf("%d%d",&T,&n); 10 | for(int i=0;i(pd)); 18 | if(get<2>(pd) -1 > 0) 19 | pq.push(make_tuple(get<0>(pd)-1, get<1>(pd), get<2>(pd)-1)); 20 | } 21 | } -------------------------------------------------------------------------------- /6/06/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 클럽 오디션 2 2 | 구현, 파싱 3 |
4 | 🔑힌트 1 5 | 어떤 문자가 있는 경우에 방향을 판단하기 위해 뒤의 문자를 읽어야 하나요? 6 |
7 |
8 | 🔑힌트 2 9 | !은 어떤 역할을 하나요? !이 있으면 어떻게 처리해야 하나요? 10 |
11 |
12 | 🔑힌트 3 13 | lv개의 키가 일치할 때의 로직을 단순화 하는 방법이 없을까요? 14 |
15 | 16 | 17 |
18 | 🪤함정 1 19 | endswith 등으로 suffix 비교만 하면 끝날까요? 20 |
21 |
22 | 💡생각해 볼 만한 것 23 |
    24 |
  • 일일히 파싱하는 방법 말고 다른 방법이 있을까요?
    25 |
  • 다른 방법이 있다면, 리팩토링을 할 때에도 유용하게 적용할 수 있을까요? 언제?
    26 |
27 |
-------------------------------------------------------------------------------- /2/5/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 수인 분당선 1 2 | 구현 3 |
4 | 🔑힌트 1 5 | 목적지에 제일 빨리 가기 위해, 먼저 오는 지하철을 잡나요? 나중에 오는 지하철을 잡나요? 6 |
7 |
8 | 🔑힌트 2 9 | 특정한 구간에서만 소요 시간이 2분이 아닙니다. 어떻게 처리해야 하나요? 10 |
11 |
12 | 🔑힌트 3 13 | 특정한 (종착)역에서 안 내리고 계속 가는 식으로 구현하기에는 간단하지 않을 거 같네요. 14 |
    15 |
  • 고색역에서 종착하는 열차를 탔을 때
    16 |
  • 종착역 역할을 하는 죽전역에서 내렸다가
    17 |
  • 다시 타도 될까요?
    18 |
19 |
20 |
21 | 🪤함정 1 22 | 특정 역에서 열차를 다시 탈 때 조심해야 할 점이 무엇이 있을까요? 23 |
  • 열차가 해당 역에서 운행을 종료하는 경우
    24 |
  • 열차가 이미 출발해 버린 경우 25 |
  • -------------------------------------------------------------------------------- /7/09/gh_sol.py: -------------------------------------------------------------------------------- 1 | dp = [[0 for _ in range(0, 50000+1)] for _ in range(200+1)] 2 | mod = 1000000007 3 | n = int(input()) 4 | dp[0][0] = 1 5 | for lo in range(1, n+1): 6 | a, m = map(int, input().split()) 7 | cost = (96 * a * m) // 60000 8 | unit_cost = cost // 6 9 | for c in range(0, 50000+1): 10 | dp[lo][c] = dp[lo-1][c] 11 | if c >= unit_cost: 12 | dp[lo][c] += dp[lo-1][c - unit_cost] 13 | dp[lo][c] %= mod 14 | ans = 0 15 | c1, c2 = map(int, input().split()) 16 | for c in range(0, 50000+1): 17 | real_cost = 6*c 18 | if c1 <= real_cost <= c2: 19 | ans += dp[n][c] 20 | ans %= mod 21 | print(ans) 22 | -------------------------------------------------------------------------------- /1/6/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 읽기 쓰기 놀이 2 | 브루트 포스, 구현 3 |
    4 | 🔑힌트 1 5 | 9!은 40320입니다. 6 |
    7 |
    8 | 🔑힌트 2 9 |
      10 |
    • 카드 c는 유저 u가 내야 한다.
      11 |
    • 유저 u는 카드들을 일정 순서대로 내야 한다.
      12 |
    13 | 이 두 상황을 자료구조로 표현해 볼까요?
    14 |
    15 |
    16 | 🔑힌트 3 17 | 힌트 2에서 유저 u가 내야 하는 카드를 어떻게 관리할 수 있을까요? 18 |
    19 |
    20 | 🔑힌트 4 21 | 순서가 정해진 배열에서 1번째 원소를 빼면, 2번째로 내야 할 카드가 나오지요. 22 |
    23 |
    24 | 💻cs 25 |
      26 |
    • race condition
      27 |
    • critical section
      28 |
    29 |
    -------------------------------------------------------------------------------- /6/07/generator/line_2.py: -------------------------------------------------------------------------------- 1 | import random as rd 2 | # n = 200000 3 | li = list() 4 | for i in range(100000, 1, -1): 5 | c = (len(li) + 1) * 20 6 | ti = rd.randrange(1, 10**9) 7 | li.append([i+1, i, c, ti]) 8 | for j in range(100000, 10000, -1): 9 | c = (len(li) + 1) * 20 10 | ti = rd.randrange(1, 10**9) 11 | b = rd.randrange(2, 100000) 12 | li.append([1, j, c, ti]) 13 | for b in range(100000, 110000): 14 | c = (len(li) + 1) * 20 15 | ti = rd.randrange(1, 10**9) 16 | a = 99999 17 | li.append([b, a, c, ti]) 18 | n = 109999 19 | Q = len(li) 20 | print(f'{n} {Q}') 21 | for item in li: 22 | print(f'{item[0]} {item[1]} {item[2]} {item[3]}') 23 | -------------------------------------------------------------------------------- /6/11/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 집 2 | 누적 합, 자료 구조 3 |
    4 | 🔑힌트 1 5 | ㅁ자 모양은 어떻게 만들 수 있나요? 6 |
    7 |
    8 | 🔑힌트 2 9 | 축 하나와 역 ㄷ자로 나눠 봅시다. 그리고 왼쪽으로 1칸 늘렸을 때 어떤 것이 바뀌나요? 10 |
    11 |
    12 | 🔑힌트 3 13 | 전체 데이터에 +a 만큼 더해지고, 값이 k인 데이터가 추가됩니다.
    14 | 이 연산을 어떻게 바꿀 수 있을까요? 15 |
    16 |
    17 | 🔑힌트 4 18 | 힌트 3의 상황을 다시 봅시다. 19 |
      20 |
    • 전체 데이터에 +a를 더하는 대신
      21 |
    • 추가할 때 -a+k를 추가하면 어떤가요? 힌트 3과 같은 상황 아닌가요?
      22 |
    23 |
    24 |
    25 | 🔑힌트 5 26 | 우리는 후보 해 중 최소값, 혹은 최대값만 찾으면 됩니다. 이것을 빠르게 찾는 방법이 있습니다. 27 |
    -------------------------------------------------------------------------------- /1/1/gh_sol_stream.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | import java.util.*; 3 | public class Main { 4 | public static void main(String []args){ 5 | Scanner sc = new Scanner(System.in); 6 | int R = sc.nextInt(); sc.nextInt(); 7 | int ans = 0; 8 | sc.nextInt(); sc.nextInt(); 9 | int Rp = sc.nextInt(); 10 | int Cp = sc.nextInt(); 11 | sc.nextLine(); 12 | //use stream filter & count 13 | for(int i=0;i v == 'P').count(); 15 | if(ans != Rp * Cp) 16 | System.out.println("1"); 17 | else 18 | System.out.println("0"); 19 | } 20 | } -------------------------------------------------------------------------------- /4/6/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 사직 구장 2 | 구현, 브루트 포스, 정렬 3 |
    4 | 🔑힌트 1 5 | 제한을 보니까, 아이돌 3명을 일일히 다 배치해 봐도 통과할 것 같습니다. 6 |
    7 |
    8 | 🔑힌트 2 9 | 얻을 수 있는 점수가 큰 순서대로 정렬을 한 후, 어떻게 처리하면 될까요? 10 |
    11 |
    12 | 🔑힌트 3 13 | 상위 r명의 아이돌을 모두 선택했을 때 점수는 빠르게 구할 수 있습니다. 14 |
      15 |
    • 1위부터 r위까지 점수만 누적하면 되지 않나요?
      16 |
    • 결국 누적합입니다.
      17 |
    18 | 문제는 세 명이 상위 n-3 위에 속햐냐는 것입니다. 19 |
    20 |
    21 | 🔑힌트 4 22 | 세 명이 상위 n-3위에 속한다고 해도, n+1위까지 볼 이유가 있을까요? 23 |
      24 |
    • 상위 n-3위에 속한다면 일단 누적에서 빼 주고
      25 |
    • 최후에 3명에 대해 누적시켜 주면 됩니다.
      26 |
    27 |
    -------------------------------------------------------------------------------- /7/03/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int Inner[303][303]; 3 | int Outer[303][303]; 4 | int main(void) 5 | { 6 | for(int s=201; s<=243; s++) 7 | { 8 | for(int j=1; j<=42; j++){ 9 | int e1 = (s + j); 10 | if(e1 > 243) e1 -= 43; 11 | int e2 = (s - j); 12 | if(e2 < 201) e2 += 43; 13 | Inner[s][e1] = j; 14 | Outer[s][e2] = j; 15 | } 16 | } 17 | int Q, a, b; scanf("%d", &Q); 18 | for(int i=0; i 4 | 🔑힌트 1 5 | 같은 방향에 있다는 것은 무엇을 의미할까요? 6 | 7 |
    8 | 🔑힌트 2 9 | 데미지 d가 들어올 때 모든 풍선에 데미지 d를 주면 느릴 겁니다.
    10 | 누적해서 준 데미지를 가지고 있으면 어떨까요? 11 |
    12 |
    13 | 🔑힌트 3 14 | hp가 4인 풍선 1과 hp가 6인 풍선 2가 있었습니다.
    15 | 누적해서 준 데미지가 5라면 어떤 풍선만 남아 있을까요? 16 |
    17 |
    18 | 🔑힌트 4 19 | 공격하는 방향에 있는 모든 풍선에 데미지를 준다는 말은 무엇을 의미할까요? 20 |
    21 |
    22 | 🪤함정 1 23 | 기울기를 double로 처리하면 어떨까요? 이것만으로 오차가 충분히 잡힐까요? 24 |
    25 |
    26 | 🪤함정 2 27 | (0, y')에 풍선이 배치된 경우 어떻게 처리해야 할까요? 28 |
    -------------------------------------------------------------------------------- /1/1/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | import java.util.*; 3 | public class Main { 4 | public static void main(String []args){ 5 | Scanner sc = new Scanner(System.in); 6 | int R = sc.nextInt(); 7 | int C = sc.nextInt(); 8 | int ans = 0; 9 | int Rg = sc.nextInt(); 10 | int Cg = sc.nextInt(); 11 | int Rp = sc.nextInt(); 12 | int Cp = sc.nextInt(); 13 | sc.nextLine(); 14 | for(int i=0;i 4 | 🔑힌트 1 5 | 세뇨와 달세뇨는 어떤 역할을 하나요? 6 | 7 |
    8 | 🔑힌트 2 9 | 음악 기호는 최대 2개 넣을 수 있습니다. 1개일 때도 어렵지 않으니까 그것부터 해 볼까요?
    10 | 언제 반복되나요? DS일때 반복되나요? S일 때 반복되나요? 11 |
    12 |
    13 | 🔑힌트 3 14 | 2개를 넣어야 할 때는 어떤 경우가 제일 어렵나요?
    15 | 세뇨 뒤에 달세뇨가 오는 경우가 어렵지 않나요? 그러면 무엇이 필요한가요? 16 |
    17 |
    18 | 🔑힌트 4 19 | 힌트 3을 계산하기 위해서 무엇이 필요한가요? 아래 둘이 필요하지 않을까요? 20 |
      21 |
    • 달세뇨 위치에 대해서 i에서부터 누적합의 최댓값
      22 |
    • 현재 세뇨 위치의 누적합
      23 |
    24 |
    25 |
    26 | 🔑힌트 5 27 | 입력이 복잡해 보이는데, 공백을 다른 문자로 치환해서 처리하는 방법은 없을까요? 28 |
    -------------------------------------------------------------------------------- /1/3/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 프로세스 1 2 | 자료구조, 물리 3 |
    4 | 🔑힌트 1 5 | 가장 큰, 가장 작은. 가장이라는 말이 들어가면 어떤 자료구조가 떠오르시나요? 6 |
    7 |
    8 | 🔑힌트 2 9 | A와 B가 북쪽으로 달리고 있었습니다. A를 내 차, B를 내 차를 제외한 모든 차입니다. 10 |
    11 |
    12 | 🔑힌트 3 13 | A의 속도가 1 감소했습니다. B 입장에서 A는 어떻게 보일까요? 14 |
    15 |
    16 | 🔑힌트 4 17 |
      18 |
    • 실행 중인 프로세스 이외의 프로세스들의 우선 순위가 1 증가한다.
      19 |
    • 실행 중인 프로세스의 우선 순위가 1 감소한다.
      20 |
    21 | 이 둘의 차이는 무엇일까요?
    22 |
    23 |
    24 | 💻cs 25 |
      26 |
    • aging
      27 |
    • starvation
      28 |
    • preemptive vs non preemptive scheduling
      29 |
    30 |
    -------------------------------------------------------------------------------- /7/08/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 타카하시의 카드 게임 2 | 수학, 조합론 3 |
    4 | 🪤함정 1 5 | 아래 두 문장은 어떤 의미일까요? 6 |
      7 |
    • 카드가 적어도 하나 이상 남아 있어야 한다.
      8 |
    • 가희가 항상 승리한다.
      9 |
    10 |
    11 |
    12 | 🔑힌트 1 13 | 랜덤 박스에서 카드를 2개 이상 뽑았다고 합시다. 어떻게 뽑아야 항상 가희가 승리할까요? 14 |
    15 |
    16 | 🔑힌트 2 17 | 가희가 승리한다는 말은 항상 팰린드롬이 만들어진다는 이야기와 같습니다.
    18 | 그렇다면, 2개의 카드를 뽑았을 때 다른 문자가 적혀있으면 어떨까요? 19 |
    20 |
    21 | 🔑힌트 3 22 | 카드를 1개, 2개, 3개, 4개 뽑았을 때 어떻게 뽑아야 가희가 항상 승리할까요? 23 |
    24 |
    25 | 🔑힌트 4 26 | A를 만족하는 가짓수를 구하는 것이 어렵습니다. 그런데 27 |
      28 |
    • 전체 가짓수를 구하는 건 쉽습니다.
      29 |
    • A를 만족하지 않는 가짓수를 구하는 것도 쉽습니다. 30 |
    31 | 그러면 어떤 사건을 떠올리면 될까요? 32 |
    -------------------------------------------------------------------------------- /1/4/wrong/gh_bf.py: -------------------------------------------------------------------------------- 1 | import time 2 | import random as rd 3 | 4 | 5 | def str_to_int(tar): 6 | from_1970 = time.strptime(tar, '%Y-%m-%d %H:%M:%S') 7 | return int(time.mktime(from_1970)) 8 | 9 | 10 | def sec_to_str(sec): 11 | date_tuple = time.localtime(sec) 12 | return time.strftime('%Y-%m-%d %H:%M:%S', date_tuple) 13 | 14 | 15 | n, Q = map(int, input().split()) 16 | li = [] 17 | for i in range(n): 18 | dt, lv = input().split('#') 19 | dt = str_to_int(dt) 20 | lv = int(lv) 21 | li.append((dt, lv)) 22 | for i in range(Q): 23 | ds, de, lv = input().split('#') 24 | ds = str_to_int(ds) 25 | de = str_to_int(de) 26 | lv = int(lv) 27 | ans = 0 28 | for d in li: 29 | if ds <= d[0] <= de and lv <= d[1]: 30 | ans = ans + 1 31 | print(ans) 32 | -------------------------------------------------------------------------------- /6/07/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 여행 가요 [풀이](https://codingdog.pe.kr/2024/01/07/%ed%81%ac%eb%a3%a8%ec%8a%a4%ec%b9%bc-%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%a0%95%eb%8b%b9%ec%84%b1-%ec%a6%9d%eb%aa%85%ec%9d%84-%ed%95%b4-%eb%b4%85%ec%8b%9c%eb%8b%a4/) 2 | 그래프 이론, 그리디, 최소 스패닝 트리 3 |
    4 | 🔑힌트 1 5 | 비용을 최소로 하는 조건이 걸려 있으면 어떻게 풀면 되나요? 6 |
    7 |
    8 | 🔑힌트 2 9 | 이제, 건설 시간을 최소로 하라고 했습니다. 10 |
      11 |
    • 비용이 같은 경우
      12 |
    • 건설 시간이 더 큰 간선을 선택하면 어떻게 되나요?
      13 |
    14 | 건설 시간이 더 작은 간선을 선택해 보세요. 큰 것을 선택할 때 보다 항상 이득이 되게 만들 수 있나요? 15 |
    16 |
    17 | 💡생각해 볼 만한 것 18 | 크루스칼 알고리즘의 유니온 파인드를 구현할 때 아래 두 가지를 많이 이용합니다. 19 |
      20 |
    • by path compression
      21 |
    • by rank
      22 |
    23 | 두 번째 방법으로 구할 때 시간 복잡도는 어떻게 될까요? 24 |
    -------------------------------------------------------------------------------- /6/06/gh_sol.py: -------------------------------------------------------------------------------- 1 | rev = { 2 | "LU!": "3", 3 | "LD!": "9", 4 | "RU!": "1", 5 | "RD!": "7", 6 | "W!": "2", 7 | "A!": "6", 8 | "S!": "8", 9 | "D!": "4", 10 | } 11 | ori = { 12 | "LU": "7", 13 | "LD": "1", 14 | "RU": "9", 15 | "RD": "3", 16 | "W": "8", 17 | "A": "4", 18 | "S": "2", 19 | "D": "6", 20 | } 21 | note = input() 22 | for k in rev: 23 | note = note.replace(k, rev[k]) 24 | for k in ori: 25 | note = note.replace(k, ori[k]) 26 | ini = input() 27 | for k in ori: 28 | ini = ini.replace(k, ori[k]) 29 | s = 0 30 | for i in range(len(ini)): 31 | if s == len(note): 32 | s = 0 33 | else: 34 | if ini[i] == note[s]: 35 | s += 1 36 | else: 37 | s = 0 38 | if s == len(note): 39 | print("Yes") 40 | else: 41 | print("No") 42 | -------------------------------------------------------------------------------- /6/06/wrong/gh_wrong_3.py: -------------------------------------------------------------------------------- 1 | rev = { 2 | "LU!": "3", 3 | "LD!": "9", 4 | "RU!": "1", 5 | "RD!": "7", 6 | "W!": "2", 7 | "A!": "6", 8 | "S!": "8", 9 | "D!": "4", 10 | } 11 | ori = { 12 | "LU": "7", 13 | "LD": "1", 14 | "RU": "9", 15 | "RD": "3", 16 | "W": "8", 17 | "A": "4", 18 | "S": "2", 19 | "D": "6", 20 | } 21 | note = input() 22 | for k in ori: 23 | note = note.replace(k, ori[k]) 24 | for k in rev: 25 | note = note.replace(k, rev[k]) 26 | ini = input() 27 | for k in ori: 28 | ini = ini.replace(k, ori[k]) 29 | s = 0 30 | for i in range(len(ini)): 31 | if s == len(note): 32 | s = 0 33 | else: 34 | if ini[i] == note[s]: 35 | s += 1 36 | else: 37 | s = 0 38 | if s == len(note): 39 | print("Yes") 40 | else: 41 | print("No") 42 | -------------------------------------------------------------------------------- /6/10/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 gahui and sousenkyo 6 2 | 수학, 해 구성하기 3 |
    4 | 🔑힌트 1 5 | xor 연산의 특징은 무엇인가요? 6 |
    7 |
    8 | 🔑힌트 2 9 | 0부터 x까지 xor를 해 봅시다.
    특정한 수까지 xor을 했을 때 xor 값이 0이 되는 순간이 존재하지 않나요? 10 |
    11 |
    12 | 🔑힌트 3 13 | 2진수 100100을 만드는 방법은 어떻게 만들면 될까요? 14 |
      15 |
    • 바로 100100을 넣는 방법도 있습니다만
      16 |
    • 111111에 무엇을 xor 하면 될까요?
      17 |
    18 |
    19 |
    20 | 🔑힌트 4 21 | 힌트 3을 다시 봅시다. 0이 있는 상황보다 1만 있는 상황이 컨트롤 하기 쉬워 보입니다. 22 |
      23 |
    • 그러면 0인 bit가 있는 값을 컨트롤 하는 것 보다
      24 |
    • bit가 1로만 채워진 것을 컨트롤 하는 게 더 쉽지 않을까요?
      25 |
    26 |
    27 |
    28 | 💡다른 방법 29 | 수를 random 하게 n - 1개 선택하면 어떨까요? 그것과 x를 xor한 값과 겹칠 확률은 얼머나 될까요?
    30 | 설령 그게 안 된다고 해도 10번, 20번 시도할 시간은 충분하지 않을까요? 31 |
    -------------------------------------------------------------------------------- /2/2/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | public class Main { 5 | public static void main(String []args) throws IOException { 6 | BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); 7 | String []parse; 8 | Map kMap = new HashMap<>(); 9 | parse = bf.readLine().split(" "); 10 | int n = Integer.parseInt(parse[0]); 11 | int m = Integer.parseInt(parse[1]); 12 | for(int i=0;inull); 18 | sb.append(kMap.size()+"\n"); 19 | } 20 | System.out.println(sb.toString()); 21 | } 22 | } -------------------------------------------------------------------------------- /6/08/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define M 998244353LL 4 | typedef long long ll; 5 | ll dp[55000][7]; 6 | int main(void) 7 | { 8 | //memset(dp, -1, sizeof(ll)*7*55000); 9 | ll s; dp[0][0] = 1; scanf("%lld", &s); 10 | for(ll i=1; i<=s; i++) 11 | { 12 | for(ll j=0; j<=6; j++) 13 | { 14 | //(i-1, j-1) ~> (i, j) 15 | if(j) 16 | dp[i][j] += dp[i-1][j-1]; 17 | //(i-1, j) -> (i, j) 18 | dp[i][j] += (6 * dp[i-1][j]); 19 | dp[i][j] %= M; 20 | } 21 | } 22 | ll totari = 1; 23 | for(ll i=1; i<=s; i++) 24 | { 25 | totari *= 7; 26 | totari %= M; 27 | } 28 | ll mi = 0; 29 | for(ll i=0; i<=6; i++) 30 | mi += dp[s][i]; 31 | mi %= M; 32 | ll ans = (totari - mi + M)%M; printf("%lld\n", ans); 33 | } 34 | -------------------------------------------------------------------------------- /7/09/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Main { 3 | static long M = 1000000007; 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int [][]dp = new int[201][300001]; 7 | int n = sc.nextInt(); 8 | dp[0][0] = 1; 9 | for(int i=1; i<=n; i++){ 10 | long a = sc.nextLong(); long m = sc.nextLong(); 11 | long cost = (96 * a * m) / 60000; 12 | for(int j=0; j<=300000; j++){ 13 | dp[i][j] = dp[i-1][j]; 14 | if(j >= cost) dp[i][j] += dp[i-1][j-(int)cost]; 15 | dp[i][j] %= M; 16 | } 17 | } 18 | long ans = 0; 19 | int c1 = sc.nextInt(); int c2 = sc.nextInt(); 20 | for(int i=c1; i<=c2; i++) 21 | ans = (ans + dp[(int)n][i]) % M; 22 | System.out.println(ans); 23 | } 24 | } -------------------------------------------------------------------------------- /7/09/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 1000000007LL 3 | typedef long long ll; 4 | ll dp[201][50001]; 5 | int main(void) 6 | { 7 | // dp[x][y] : x번 컴퓨터까지 고려했을 때, 총 y/8 kwh를 쓴 가짓수. 8 | ll n, ans = 0; scanf("%lld", &n); dp[0][0] = 1LL; 9 | for(ll i=1; i<=n; i++) 10 | { 11 | ll a, b, unit; scanf("%lld%lld", &a, &b); 12 | // 1 kwh = 16 unit 13 | unit = (a * b * 16)/ (60 * 1000); 14 | for(ll j=0; j<=50000; j++) 15 | { 16 | dp[i][j] = dp[i-1][j]; 17 | if(j >= unit) dp[i][j] += dp[i-1][j-unit]; 18 | dp[i][j] %= M; 19 | } 20 | } 21 | ll c1, c2; scanf("%lld%lld", &c1, &c2); 22 | for(ll i=0; i<=50000; i++) 23 | { 24 | ll cost = 6 * i; 25 | if(cost < c1 || cost > c2) continue; 26 | ans += dp[n][i]; ans %= M; 27 | } 28 | printf("%lld\n", ans); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /7/03/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int Q = sc.nextInt(); 7 | for(int i=1; i<=Q; i++){ 8 | int a = sc.nextInt(); 9 | int b = sc.nextInt(); 10 | int inner = 0; 11 | int outer = 0; 12 | // 총 86 => 43 13 | if(a > b){ 14 | // 출발 228, 도착 216 15 | outer = (a - b); 16 | inner = 43 - outer; 17 | } 18 | else { 19 | // 출발 216, 도착 228 20 | inner = (b - a); 21 | outer = 43 - inner; 22 | } 23 | if(inner < outer) 24 | System.out.println("Inner circle line"); 25 | else 26 | System.out.println("Outer circle line"); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /7/06/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 1000000007LL 3 | #define LV 50000 4 | typedef long long ll; 5 | /* dp[lv][rev] : key note의 레벨이 lv이고 역방향 키가 rev 개인 가짓수 */ 6 | ll dp[50001][7]; 7 | int main(void) 8 | { 9 | ll lv; scanf("%lld", &lv); 10 | if(lv <= 5) 11 | { 12 | printf("%lld\n", (1LL<<(2*lv))); 13 | return 0; 14 | } 15 | dp[0][0] = 1LL; 16 | for(ll v=1; v<=LV; v++) 17 | { 18 | for(ll rev=0; rev<=6; rev++) 19 | { 20 | dp[v][rev] = 8*dp[v-1][rev]; 21 | // v-1개까지 보았을 때 rev개인 경우와, rev-1개인 경우가 있으므로 이를 더해줘야 한다. 22 | // Combination dp가 채워지는 원리랑 동일함. 23 | if(rev) 24 | dp[v][rev] += (8*dp[v-1][rev-1]); 25 | dp[v][rev] %= M; 26 | } 27 | } 28 | printf("%lld\n", (dp[lv][0] + dp[lv][1] + dp[lv][2] + dp[lv][3] + dp[lv][4] + dp[lv][5] + dp[lv][6]) % M); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /2/3/gh_sol.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import collections 3 | wait_queue = collections.deque() 4 | my_input = sys.stdin.readline 5 | my_print = sys.stdout.write 6 | n, t, w = map(int, my_input().split(' ')) 7 | for i in range(n): 8 | idx, need_time = map(int, my_input().split(' ')) 9 | wait_queue.append([idx, need_time, 0]) 10 | m = int(my_input()) 11 | ev = {} 12 | for i in range(m): 13 | idx, need_time, come_time = map(int, my_input().split(' ')) 14 | ev[come_time] = [idx, need_time, 0] 15 | for ti in range(w): 16 | if ti in ev: 17 | wait_queue.append(ev[ti]) 18 | if wait_queue[0][1] == 0: 19 | wait_queue.popleft() 20 | elif wait_queue[0][2] == t: 21 | wait_queue[0][2] = 0 22 | front = wait_queue.popleft() 23 | wait_queue.append(front) 24 | else: 25 | pass 26 | wait_queue[0][1] -= 1 27 | wait_queue[0][2] += 1 28 | my_print(f'{wait_queue[0][0]}\n') 29 | -------------------------------------------------------------------------------- /1/2/gh_sol.py: -------------------------------------------------------------------------------- 1 | import itertools 2 | st = [] 3 | dx = [-1, 0, 1, 0] 4 | dy = [0, -1, 0, 1] 5 | 6 | 7 | def func(start_x, start_y, r, c, q, ma): 8 | cx = start_x 9 | cy = start_y 10 | visit = {} 11 | temp = 0 12 | for op in q: 13 | cx = cx + dx[op] 14 | cy = cy + dy[op] 15 | if cx < 0 or cy < 0 or cx >= r or cy >= c: 16 | return 0 17 | if ma[cx][cy] == '#': 18 | return 0 19 | visit[(cx, cy)] = 1 20 | for cx, cy in visit: 21 | if ma[cx][cy] == 'S': 22 | temp += 1 23 | return temp 24 | 25 | 26 | R, C, T = map(int, input().split()) 27 | sx = -1 28 | sy = -1 29 | for i in range(R): 30 | st.append(input()) 31 | if st[i].find('G') != -1: 32 | sx, sy = i, st[i].find('G') 33 | ans = 0 34 | for query in itertools.product([0, 1, 2, 3], repeat=T): 35 | ans = max(ans, func(sx, sy, R, C, query, st)) 36 | print(ans) 37 | -------------------------------------------------------------------------------- /1/3/gh_sol_with_class_obj_compare.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | import sys 3 | 4 | 5 | class Process: 6 | prio: int 7 | id: int 8 | time: int 9 | 10 | def __init__(self, prio: int, idx: int, time: int): 11 | self.prio = prio 12 | self.id = idx 13 | self.time = time 14 | 15 | def __lt__(self, other): 16 | if self.prio != other.prio: 17 | return self.prio > other.prio 18 | return self.id < other.id 19 | 20 | 21 | T, n = map(int, sys.stdin.readline().split()) 22 | pq = [] 23 | for i in range(n): 24 | p_id, p_time, p_prio = map(int, sys.stdin.readline().split()) 25 | heapq.heappush(pq, Process(prio=p_prio, time=p_time, idx=p_id)) 26 | 27 | for i in range(T): 28 | item = heapq.heappop(pq) 29 | p_time = item.time - 1 30 | p_prio = item.prio - 1 31 | p_id = item.id 32 | sys.stdout.write(f'{p_id}\n') 33 | if p_time != 0: 34 | heapq.heappush(pq, Process(prio=p_prio, time=p_time, idx=p_id)) 35 | -------------------------------------------------------------------------------- /6/08/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | public static void main(String []args){ 4 | long M = 998244353; 5 | long [][]dp = new long[55000][7]; 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | long mi = 0; 9 | dp[0][0] = 1; 10 | for(int i=1; i<=n; i++){ 11 | for(int j=0; j<=6; j++){ 12 | //dp[i-1][j] -> dp[i][j] :: 6* 13 | dp[i][j] += dp[i-1][j] * 6; 14 | if(j > 0) dp[i][j] += dp[i-1][j-1]; 15 | //dp[i-1][j-1] -> dp[i][j] :: 1* 16 | dp[i][j] %= M; 17 | } 18 | } 19 | for(int i=0; i<=6; i++) 20 | mi += dp[n][i]; 21 | mi %= M; 22 | long tot = 1; 23 | for(int i=1; i<=n; i++) { 24 | tot *= 7; 25 | tot %= M; 26 | } 27 | long ans = (tot - mi + M) % M; 28 | System.out.println(ans); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /6/09/validator/file_to_input.py: -------------------------------------------------------------------------------- 1 | """ 2 | validator 작성이 쉽지 않기 때문에 (특히 token parsing) 3 | parsing 후 다시 data rebuild한 결과 input'과 input을 비교한 것. 4 | local에서는 input_to_file -> file_to_input으로 compare. 5 | """ 6 | name = "" 7 | team = "" 8 | group = "" 9 | pp = list() 10 | rr = list() 11 | flag = 0 12 | # name Group group Team team 13 | while True: 14 | try: 15 | s = input() 16 | except EOFError: 17 | break 18 | if s.startswith('---'): 19 | flag = 1 20 | continue 21 | if s.startswith("group: "): 22 | s = s.replace("group: ", "") 23 | group = s 24 | elif s.startswith("team : "): 25 | s = s.replace("team : ", "") 26 | team = s 27 | elif s.startswith("name : "): 28 | s = s.replace("name : ", "") 29 | name = s 30 | ss = f"{name} Group {group} Team {team}" 31 | if flag: 32 | rr.append(ss) 33 | else: 34 | pp.append(ss) 35 | print(" ".join(pp)) 36 | print(" ".join(rr)) 37 | -------------------------------------------------------------------------------- /7/08/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 1000000007LL 3 | typedef long long ll; 4 | ll co[128]; 5 | char str[1010101]; 6 | ll two[1010101]; 7 | ll nc_2(ll x) 8 | { 9 | return (x*(x-1))/2; 10 | }; 11 | int main(void) 12 | { 13 | ll n; scanf("%lld\n%s", &n, str); two[0] = 1; 14 | for(int i=1; i<1010101; i++) 15 | two[i] = (two[i-1] * 2)%M; 16 | for(int i=0; str[i]; i++) 17 | co[str[i]]++; 18 | // 길이가 2인 가짓수. 19 | ll base = nc_2(n); base %= M; 20 | for(ll i=0; i<128; i++) 21 | { 22 | if(co[i] <= 2) continue; 23 | ll w = co[i]; 24 | ll temp = two[w]; temp = (temp - 1 + M) % M; 25 | temp = (temp - w + M) % M; 26 | temp = (temp - nc_2(w) % M + M) % M; 27 | base = (base + temp) % M; 28 | // 모두 같은 것을 꺼내는 경우를 세야 하는데, 1개, 2개인 경우는 제외해야 한다. 29 | // 제외하는 가짓수를 빼는 게 더 빠르기 때문에 여사건으로 접근하면 된다. 30 | // 배반사건 (교집합이 없는 케이스)와 혼동되는 경우 주의. 31 | } 32 | printf("%lld\n", base); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /1/3/wrong/gh_bf_tle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This solution may be Time Limit Exceed (TLE) 3 | */ 4 | #include 5 | #include 6 | using namespace std; 7 | struct moo 8 | { 9 | int a,b,c; 10 | }; 11 | //id, time, prio 12 | typedef struct moo moo; 13 | moo p[100000]; 14 | int f(int n) 15 | { 16 | int prio_mmx = -1 * 0x3f3f3f3f; 17 | int lo = -1; 18 | for(int i=0;i prio_mmx) 23 | { 24 | lo = i; 25 | prio_mmx = p[i].c; 26 | } 27 | } 28 | p[lo].b -= 1; 29 | p[lo].c -= 1; 30 | return p[lo].a; 31 | } 32 | bool cmp(moo a,moo b) 33 | { 34 | return a.a < b.a; 35 | } 36 | int main(int argc, char **argv) 37 | { 38 | int T, n; scanf("%d %d\n",&T, &n); 39 | for(int i=0; i 2 | #include 3 | #include 4 | using namespace std; 5 | struct moo 6 | { 7 | int a,b,c; 8 | }; 9 | //id, time, prio 10 | typedef struct moo moo; 11 | struct compare 12 | { 13 | bool operator()(moo &I, moo &C) 14 | { 15 | if(C.c != I.c) 16 | return C.c > I.c; 17 | return C.a < I.a; 18 | } 19 | }; 20 | priority_queue , compare> pq; 21 | moo p[100000]; 22 | int main(int argc, char **argv) 23 | { 24 | int T, n; scanf("%d %d\n",&T, &n); 25 | for(int i=0; i 0) 40 | pq.push(I); 41 | } 42 | } -------------------------------------------------------------------------------- /8/07/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define INF 0x3f3f3f3f 5 | using namespace std; 6 | struct Query 7 | { 8 | int f, t; 9 | }; 10 | typedef struct Query Query; 11 | unordered_map con[200001]; 12 | int co[202020]; 13 | Query q[404040]; 14 | int ans[202020]; 15 | void add(int from, int to, int c) 16 | { 17 | int r = INF; 18 | if(con[from].find(to) != con[from].end()) 19 | r = con[from][to]; 20 | if(c < r) 21 | con[from][to] = c; 22 | }; 23 | int get(int from, int to) 24 | { 25 | if(con[from].find(to) == con[from].end()) return -1; 26 | return con[from][to]; 27 | }; 28 | int main(void) 29 | { 30 | int n, m, Q; scanf("%d%d%d", &n, &m, &Q); memset(ans, 0x3f, sizeof(int)*202020); 31 | for(int i=1; i<=m; i++) 32 | { 33 | int a, b, c; scanf("%d%d%d", &a, &b, &c); add(a, b, c); add(b, a, c); 34 | } 35 | for(int i=1; i<=Q; i++) 36 | { 37 | scanf("%d%d", &(q[i].f), &(q[i].t)); 38 | printf("%d\n", get(q[i].f, q[i].t)); 39 | } 40 | } -------------------------------------------------------------------------------- /.github/workflows/codingtest-readme-update.yml: -------------------------------------------------------------------------------- 1 | name: Auto Update CODINGTEST README 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | ref: main 14 | - name: Setup Python 15 | uses: actions/setup-python@v1 16 | with: 17 | python-version: '3.x' 18 | architecture: 'x64' 19 | - name: Setup pip 20 | run: | 21 | python -m pip install --upgrade pip 22 | pip install requests 23 | - name: Run update codingtest readme 24 | run: | 25 | python scripts/build_readme.py --all 26 | - name: Commits 27 | run: | 28 | git config --local user.email "${{ secrets.USER_EMAIL }}" 29 | git config --local user.name "${{ secrets.USER_NAME }}" 30 | git add . 31 | git commit -m "Auto UPDATE 코딩테스트 README" 32 | - name: Push 33 | uses: ad-m/github-push-action@master 34 | with: 35 | branch: 'main' 36 | github_token: $ 37 | -------------------------------------------------------------------------------- /4/3/gh_sol_constant_permission.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from collections import defaultdict 3 | input = sys.stdin.readline 4 | 5 | 6 | u, f = map(int, input().split()) 7 | grp = defaultdict(dict) 8 | fi = dict() 9 | permission = {"0": "", "1": "X", "2": "W", "3": "XW", "4": "R", "5": "RX", "6": "RW", "7": "RWX"} 10 | for i in range(u): 11 | dt = input().strip().split() 12 | grp[dt[0]][dt[0]] = 1 13 | if len(dt) > 1: 14 | groups = dt[1].split(",") 15 | for group in groups: 16 | grp[group][dt[0]] = 1 17 | for i in range(f): 18 | fn, pf, o, og = map(str, input().strip().split()) 19 | fi[fn] = [pf, o, og] 20 | ans = [] 21 | q = int(input()) 22 | for i in range(q): 23 | un, fn, o = map(str, input().strip().split()) 24 | f_data = fi[fn] 25 | f_owner = f_data[1] 26 | f_group = f_data[2] 27 | f_perm = f_data[0] 28 | perm_lo = 0 if un == f_owner else (1 if un in grp[f_group] else 2) 29 | if o in permission[f_perm[perm_lo]]: 30 | ans.append("1") 31 | else: 32 | ans.append("0") 33 | 34 | ret = "\n".join(ans) 35 | print(ret) -------------------------------------------------------------------------------- /6/06/gh_sol_key_note.py: -------------------------------------------------------------------------------- 1 | rev = { 2 | "LU!": "3", 3 | "LD!": "9", 4 | "RU!": "1", 5 | "RD!": "7", 6 | "W!": "2", 7 | "A!": "6", 8 | "S!": "8", 9 | "D!": "4", 10 | } 11 | ori = { 12 | "LU": "7", 13 | "LD": "1", 14 | "RU": "9", 15 | "RD": "3", 16 | "W": "8", 17 | "A": "4", 18 | "S": "2", 19 | "D": "6", 20 | } 21 | to = { 22 | "1!": "9", 23 | "2!": "8", 24 | "3!": "7", 25 | "4!": "6", 26 | "6!": "4", 27 | "7!": "3", 28 | "8!": "2", 29 | "9!": "1" 30 | } 31 | note = input() 32 | for k in ori: 33 | note = note.replace(k, ori[k]) 34 | for k in rev: 35 | note = note.replace(k, rev[k]) 36 | for k in to: 37 | note = note.replace(k, to[k]) 38 | lv = len(note) 39 | ini = input() 40 | for k in ori: 41 | ini = ini.replace(k, ori[k]) 42 | s = 0 43 | 44 | # dummy character # add because logic more simple. 45 | note += '#' 46 | for i in range(len(ini)): 47 | if ini[i] == note[s]: 48 | s += 1 49 | else: 50 | s = 0 51 | if s == lv: 52 | print("Yes") 53 | else: 54 | print("No") 55 | -------------------------------------------------------------------------------- /5/4/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define M 1000000007LL 3 | typedef long long ll; 4 | ll g(ll s, ll x) 5 | { 6 | if(s & (1< mmx) mmx = cur; 26 | } 27 | if(mmx != yeon) 28 | return 0; 29 | for(ll i=0; i 4 | 🔑힌트 1 5 | 어떻게 기능을 분리해야 할까요? 6 | 7 |
    8 | 🔑힌트 2 9 | 문제에서 설명한 캐시 알고리즘은 어떻게 동작하나요? 10 |
    11 |
    12 | 🔑힌트 3 13 | 프로그램을 이렇게 나누어 볼까요? 14 |
      15 |
    • lru cache를 구현한 class
      16 |
    • 최단 거리를 미리 전처리 하는 코드
      17 |
    • bucket 노드 x가 주어졌을 때 가장 가까운 캐시 노드 c를 가져오는 함수
      18 |
    19 |
    20 |
    21 | 🔑힌트 4 22 | 힌트 3의 기능들을 어떻게 구현할까요? 23 |
      24 |
    • python orderedDict이나, java LinkedHashMap 등을 이용하면 되겠군요.
      25 |
    • 노드 수가 많아야 300이네요? 그러면 floyd도 이용할 수 있겠군요.
      26 |
    • 전처리 된 dist 배열을 가지고, 제일 가까운 캐시 노드 c를 전처리 해야 겠군요.
      27 |
    28 |
    29 |
    30 | 💡생각해 볼 만한 것 1 31 | 만약에 java LinkedHashMap이나 python orderedDict를 사용하지 못하면 어떻게 구현하면 될까요? 32 |
      33 |
    • hashmap + queue
      34 |
    • hashmap + linkedlist
      35 |
    36 | 두 번째 방법으로 구할 때 시간 복잡도는 어떻게 될까요? 37 |
    38 |
    39 | 💡생각해 볼 만한 것 2 40 | 언어별로 제공되는 순서가 유지되는 hash 자료구조에 대해 알아보세요. 41 |
    -------------------------------------------------------------------------------- /7/08/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Main { 3 | static long M = 1000000007; 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | long n = sc.nextLong(); sc.nextLine(); 7 | long []ch = new long[128]; 8 | 9 | String s = sc.nextLine(); 10 | long ans = 0; 11 | for(int i=0; i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | vector > files; 10 | vector > deco; 11 | set ext_set; 12 | char str[101]; 13 | int main(void) 14 | { 15 | int n,m; scanf("%d %d\n",&n,&m); 16 | for(int i=0;i(files[i]); 30 | deco.push_back(make_tuple(get<0>(files[i]), 31 | (ext_set.find(ext) == ext_set.end())?1:0, 32 | get<1>(files[i]))); 33 | } 34 | sort(deco.begin(), deco.end()); 35 | for(int i=0;i(deco[i]).c_str(), get<2>(deco[i]).c_str()); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /7/07/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int F[2020]; 6 | int ans[2020]; 7 | vector v; 8 | int main(void) 9 | { 10 | int n, c, k; scanf("%d%d%d", &n, &c, &k); 11 | for(int i=1; i<=k; i++) 12 | { 13 | int a; scanf("%d", &a); F[a] = 1; 14 | } 15 | for(int i=1; i<=n; i++) 16 | { 17 | if(F[i] == 0) continue; 18 | v.push_back(i); 19 | } 20 | for(int i=1; i<=n; i++) ans[i] = i; 21 | if(k == 0) 22 | { 23 | ans[1] = n + 1; 24 | } 25 | else 26 | { 27 | int prev = 1; 28 | for(int i=0; i<(int)v.size(); i++) 29 | { 30 | int te = v[i]; 31 | // printf("%d <-> %d\n", prev, te); 32 | swap(ans[prev], ans[te]); 33 | prev = te + 1; 34 | } 35 | } 36 | // 후 처리 37 | if(k != 0) 38 | { 39 | int b = v.back(); 40 | if(b != n) ans[b+1] = 999999; 41 | } 42 | for(int i=1; i -v) 30 | .sorted() 31 | .map(v -> -v) 32 | .mapToObj(String::valueOf) 33 | .toArray(String[]::new); 34 | System.out.println(str.length); 35 | System.out.println(String.join("\n", str)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /7/06/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.Math; 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | long []F = {1L, 4L, 16L, 64L, 256L, 1024L}; 7 | long []E = new long[50001]; 8 | long mod = 1000000007L; 9 | E[0] = 1; 10 | for(int i=1; i<=50000; i++) E[i] = (8 * E[i-1]) % mod; 11 | long [][]C = new long[50001][11]; 12 | 13 | for(int i=1; i<=50000; i++) 14 | { 15 | C[i][0] = 1; if(i <= 10) C[i][i] = 1; 16 | } 17 | for(int i=2; i<=50000; i++) 18 | { 19 | for(int j=1; j 4 | 🔑힌트 1 5 | 몇 개의 연산을 없애 봅시다.
    6 |
      7 |
    • 강한 연결 관계만 있고
      8 |
    • 강한 연결 관계만 끊는다고 해 봅시다.
      9 |
    • 그리고 M 연산만 있다고 해 봅시다.
      10 |
    11 | 가비지는 어떻게 없앨 수 있을까요? 12 | 13 |
    14 | 🔑힌트 2 15 | 강한 연결 관계와 약한 연결 관계는 어떤 속성만 다른가요? 16 |
    17 |
    18 | 🔑힌트 3 19 | 시간 제한이 빡빡해 보입니다. 연결 관계를 관리하는 데 hashmap이나 treemap이 왜 필요한가요? 20 |
    21 |
    22 | 🔑힌트 4 23 |
      24 |
    • a -> b의 연결 관계가 만들어진 시각이 3입니다.
      25 |
    • a -> b의 연결 관계가 제거된 시각이 7입니다.
      26 |
    27 | 이 두 정보가 저장되어 있을 때 쓸모없는 정보는 어떤 것인가요?
    28 | 그리고 이 쓸모 없는 정보는 어느 연산에서 처리하면 될까요? 29 |
    30 |
    31 | 🔑힌트 5 32 | 삭제 연산이 없다면, 동적 배열만으로 처리할 수 있을까요? 어떻게 처리할까요?
    33 |
    34 |
    35 | 💻cs 36 | gc (garbage collection) 37 |
      38 |
    • 가비지
      39 |
    • mark & sweep
      40 |
    • java reference class
      41 |
    42 |
    43 |
    44 | 💡생각해 볼 만한 것 45 |
      46 |
    • 쓸모 없는 정보를 제거하는 트릭은 어떻게 쓰일까요?
      47 |
    • java reference class, 혹은 이와 유사한 역할을 하는 클래스를 조사해 보세요.
      48 |
    49 |
    -------------------------------------------------------------------------------- /6/10/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | typedef long long ll; 5 | ll ans[1000001]; 6 | int main(void) 7 | { 8 | ll n, s; scanf("%lld%lld", &n, &s); 9 | ll filled = ((1LL<<31) - 1) - s; 10 | ll M = (1LL << 31); 11 | if(n % 4 == 0) 12 | { 13 | for(ll i=0; i=0; i--) 45 | printf("%lld\n", ans[i]); 46 | } -------------------------------------------------------------------------------- /4/3/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 파일 탐색기 2 2 | 구현, 자료구조 3 |
    4 | 🔑힌트 1 5 | Q번 수행하는 연산이 무엇인가요? 6 |
    7 |
    8 | 🔑힌트 2 9 | 파일의 소유자와 그룹은 쉽게 구할 수 있습니다. 남은 건 무엇인가요? 10 |
    11 |
    12 | 🔑힌트 3 13 | 특정 그룹에 user가 속해있는지 빠르게 구하고 싶어요. 어떻게 하면 될까요? 14 |
      15 |
    • 일단 그룹을 key로 가집니다.
      16 |
    • 그룹에 대한 정보를 value로 가지는 자료구조를 하나 선언하면 되겠죠?
      17 |
    18 | 여기서 무엇을 더 해야 할까요? 19 |
    20 |
    21 | 🔑힌트 4 22 | 그룹에 속하는 유저는 최대 몇 명일까요? 23 |
      24 |
    • 만약에 속할 수 있는 유저가 매우 많다면
      25 |
    • 그룹에 속한 유저의 정보도 key를 기반으로 빠르게 찾는 자료 구조로 관리하면 되지 않을까요?
      26 |
    27 |
    28 |
    29 | 🔑힌트 5 30 | 문제를 잘 읽어 보면, 유저가 속한 그룹 수는 최대 11개임을 알 수 있습니다.
    31 | 그런데 쿼리에서는 연산을 실행하는 유저 이름도 알고 있단 말이지요? 그렇다면 32 |
      33 |
    • 유저 이름을 key로 삼고
      34 |
    • value로 group의 정보들을 관리해도 되겠네요.
      35 |
    36 |
    37 |
    38 | 🔑힌트 6 39 | 권한은 어떻게 관리해야 할까요? 권한은 8개 밖에 없네요? 40 |
      41 |
    • 우직하게 구현해도 되지만
      42 |
    • 8개 정도면 하드 코딩해도 큰 문제는 없지 않을까요?
      43 |
    44 |
    45 |
    46 | 💻cs 47 |
      48 |
    • linux file permission
      49 |
    • 권한
      50 |
    51 |
    -------------------------------------------------------------------------------- /2/1/generator/gen_prefix_common_many.py: -------------------------------------------------------------------------------- 1 | # string prefix 많이 겹치게 데이터 세팅. 2 | import random as rd 3 | 4 | 5 | def get_name(tar): 6 | ret = "" 7 | for _ in range(10): 8 | ret = chr(ord('a') + tar % 26) + ret 9 | tar = tar // 26 10 | return ret 11 | 12 | 13 | def get_name_set(tar, start=None): 14 | li = [] 15 | if start: 16 | cur = start 17 | else: 18 | cur = rd.randint(0, 10**14) 19 | for _ in range(tar): 20 | li.append(get_name(cur)) 21 | cur = cur + rd.randint(1, 26) 22 | return cur, li 23 | 24 | 25 | _, nn = get_name_set(2) # 파일 조합 2개 26 | sn, ne = get_name_set(200000) # 확장자 200000개 27 | _, ext = get_name_set(200000, start=sn) # 비슷 비슷한 확장자 200000개 28 | n = 2*(10**5) 29 | m = 200000 30 | M = 1000000000 31 | dic = {} 32 | file_num = 24 33 | with open(f'{file_num}.in', 'w') as f: 34 | f.write(f'{n} {m}\n') 35 | for i in range(n): 36 | while True: 37 | A = rd.randrange(0, len(nn)) 38 | B = rd.randrange(0, len(ext)) 39 | kei = M*A + B 40 | if kei not in dic: 41 | dic[kei] = 1 42 | f.write(f'{nn[A]}.{ext[B]}\n') 43 | break 44 | rd.shuffle(ne) # 확장자 shuffle 45 | for ext in ne: 46 | f.write(f'{ext}\n') 47 | -------------------------------------------------------------------------------- /3/README.md: -------------------------------------------------------------------------------- 1 | ## 3회 [바로 가기](https://www.acmicpc.net/contest/view/755) 2 | 2022년 01월 23일 13시부터 18시 10분까지 3회 코딩테스트가 열렸습니다. 3 | 4 | |문제 번호|제목|풀러 가기|힌트|난이도| 5 | |:------:|:-------------:|:-----:|:-----:|:-----:| 6 | |A|가희와 무궁화호|[바로가기](https://www.acmicpc.net/problem/24336)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/3/1)| | 7 | |B|가희와 탑|[바로가기](https://www.acmicpc.net/problem/24337)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/3/2)| | 8 | |C|가희와 쓰레기 놀이|[바로가기](https://www.acmicpc.net/problem/24339)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/3/3)| | 9 | |D|가희와 베개|[바로가기](https://www.acmicpc.net/problem/24338)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/3/4)| | 10 | |E|가희와 btd5 2|[바로가기](https://www.acmicpc.net/problem/24340)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/3/5)| | 11 | 12 | 마지막 업데이트 날짜 : 2025-12-14 00:08:21.709907Z -------------------------------------------------------------------------------- /4/4/README.md: -------------------------------------------------------------------------------- 1 | # 🔒 가희와 중부 내륙선 2 | 구현, parsing, 자료 구조 3 |
    4 | 🔑힌트 1 5 | 이벤트는 어떤 순서로 일어나나요? 6 |
    7 |
    8 | 🔑힌트 2 9 | 열차가 둘 이상 접근하면 안 되는 곳이 있습니다. 어떻게 컨트롤 되나요? 10 |
    11 |
    12 | 🔑힌트 3 13 | 힌트 1과 2를 조합해 보았을 때, 구간을 운행하는 이벤트는 어떤 순으로 이루어 지나요? 14 |
      15 |
    • 구간을 운행할 수 있는지 검사한다.
      16 |
    • 운행할 수 있으면 운행한다.
      17 |
    18 | 이 순서로 일어납니다. 19 |
    20 |
    21 | 🔑힌트 4 22 | 각 구간에 대해서는 어떻게 관리하면 될까요? 23 |
      24 |
    • 구간을 운행할 수 있는지 없는지를 관리하면 되겠네요.
      25 |
    • 즉, 운행 열차가 있는지 없는지 관리하면 됩니다.
      26 |
    27 | 이 순서로 일어납니다. 28 |
    29 |
    30 | 🔑힌트 5 31 | 열차는 어떻게 하면 되나요? 32 |
      33 |
    • 구간을 운행 시작할 때, 소요 시간 뒤에 운행 종료한다는 event를 뿌리면 됩니다.
      34 |
    • 즉 lock을 걸고 t분 후에 lock을 풀겠다는 이벤트를 넣으면 됩니다.
      35 |
    36 | lock을 걸고 풀고는 이벤트 개념으로 보시면 되겠네요? 37 |
    38 |
    39 | 🔑힌트 6 40 | 열차는 나중에 출발하면 번호가 크네요? 41 |
      42 |
    • 번호가 작으면 시발역에서 먼저 출발한 거죠?
      43 |
    • 따라서 대기 큐는 그냥 FIFO로 관리해도 됩니다. PQ로 관리해도 상관 없습니다.
      44 |
    45 | 결국, 대기하는 것도 event로 관리하면 됩니다. 46 |
    47 |
    48 | 💻cs 49 |
      50 |
    • event driven
      51 |
    • lock
      52 |
    53 |
    -------------------------------------------------------------------------------- /1/2/gh_sol_dfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | 시간 복잡도 : O(4^T) 3 | */ 4 | #include 5 | char ma[100][101]; 6 | char vis[100][101]; 7 | int dx[4] = {1, 0, -1, 0}; 8 | int dy[4] = {0, 1, 0, -1}; 9 | int r,c,t,mmx = 0; 10 | void dfs(int cx,int cy,int ans,int depth) 11 | { 12 | /* 13 | 기존에 (cx, cy)에 방문하지 않으면서, 현재 위치에 고구마가 있으면 고구마를 하나 먹은 것이다. 14 | */ 15 | int cur_ans = ans + (ma[cx][cy] == 'S' && vis[cx][cy] == 0); 16 | if(depth == t) 17 | { 18 | if(mmx < cur_ans) 19 | mmx = cur_ans; 20 | return; 21 | } 22 | //(cx, cy)의 방문 횟수만 하나 증가시킨다. 23 | vis[cx][cy]++; 24 | for(int i=0;i<4;i++) 25 | { 26 | int tx = cx + dx[i]; 27 | int ty = cy + dy[i]; 28 | if(tx < 0 || ty < 0 || tx >= r || ty >= c) 29 | continue; 30 | if(ma[tx][ty] == '#') 31 | continue; 32 | dfs(tx,ty,cur_ans,depth+1); 33 | } 34 | //원복할 때에는 당연히 (cx, cy)의 방문 횟수를 하나 감소시키면 된다. 35 | vis[cx][cy]--; 36 | } 37 | int main(void) 38 | { 39 | scanf("%d%d%d\n",&r,&c,&t); 40 | for(int i=0;i 1: 21 | groups = dt[1].split(",") 22 | for group in groups: 23 | add_group(dt[0], group) 24 | 25 | for i in range(f): 26 | fn, pf, o, og = map(str, input().strip().split()) 27 | fi[fn] = [pf, o, og] 28 | 29 | ans = [] 30 | q = int(input()) 31 | for i in range(q): 32 | un, fn, o = map(str, input().strip().split()) 33 | # if user.. 34 | f_data = fi[fn] 35 | f_owner = f_data[1] 36 | f_group = f_data[2] 37 | f_perm = f_data[0] 38 | 39 | p0 = int(f_perm[0]) 40 | p1 = int(f_perm[1]) 41 | p2 = int(f_perm[2]) 42 | 43 | if un == f_owner: 44 | flag = ((p0 & pn[o]) == pn[o]) 45 | elif un in grp[f_group]: 46 | flag = ((p1 & pn[o]) == pn[o]) 47 | else: 48 | flag = ((p2 & pn[o]) == pn[o]) 49 | if flag: 50 | ans.append('1') 51 | else: 52 | ans.append('0') 53 | ret = "\n".join(ans) 54 | print(ret) 55 | -------------------------------------------------------------------------------- /1/2/gh_sol_dfs_and_cutting.c: -------------------------------------------------------------------------------- 1 | #include 2 | char ma[100][101]; 3 | char vis[100][101]; 4 | int dx[4] = {1, 0, -1, 0}; 5 | int dy[4] = {0, 1, 0, -1}; 6 | int r,c,t,mmx = 0; 7 | void dfs(int cx,int cy,int ans,int depth) 8 | { 9 | int cur_ans = ans + (ma[cx][cy] == 'S' && vis[cx][cy] == 0); 10 | if(depth == t) 11 | { 12 | if(mmx < cur_ans) 13 | mmx = cur_ans; 14 | return; 15 | } 16 | /* 17 | 이동할 수 있는 거리는 t-depth이고, 이 때 마다 고구마를 먹는다면 18 | 고구마는 cur_ans + (t-depth)만큼 먹을 수 있다. 19 | 20 | 그런데 이 값이 답보다 작거나 같다면 추가로 탐색할 필요가 없다. 21 | */ 22 | if(cur_ans + (t-depth) <= mmx) 23 | return; 24 | vis[cx][cy]++; 25 | for(int i=0;i<4;i++) 26 | { 27 | int tx = cx + dx[i]; 28 | int ty = cy + dy[i]; 29 | if(tx < 0 || ty < 0 || tx >= r || ty >= c) 30 | continue; 31 | if(ma[tx][ty] == '#') 32 | continue; 33 | dfs(tx,ty,cur_ans,depth+1); 34 | } 35 | vis[cx][cy]--; 36 | } 37 | int main(void) 38 | { 39 | scanf("%d%d%d\n",&r,&c,&t); 40 | for(int i=0;i= len(st): 13 | st = 'ERROR' 14 | return st 15 | te = st[:it] + st[it+1:] 16 | st = te 17 | return st 18 | 19 | 20 | pe = [] 21 | ca = [('', '')] 22 | ans = {} 23 | n, c = map(int, sys.stdin.readline().split()) 24 | for i in range(n): 25 | ix = tuple(map(int, sys.stdin.readline().split())) 26 | pe.append(list(ix[1:])) 27 | for i in range(c): 28 | ix = tuple(sys.stdin.readline().replace('\n', '').split(',')) 29 | ca.append(ix) 30 | perm = [] 31 | for i in range(n): 32 | for j in range(len(pe[i])): 33 | perm.append(i) 34 | for p in itertools.permutations(perm): 35 | pos = [0] * 15 36 | oper = [] 37 | for i in range(len(p)): 38 | pn = p[i] 39 | oper.append(pe[pn][pos[pn]]) 40 | pos[pn] = pos[pn] + 1 41 | 42 | tar = '' 43 | for i in oper: 44 | tar = work(tar, ca[i]) 45 | if tar == 'ERROR': 46 | break 47 | if tar == '': 48 | tar = 'EMPTY' 49 | ans[tar] = 1 50 | ret = sorted(list(ans)) 51 | 52 | for t in ret: 53 | sys.stdout.write(f'{t}\n') 54 | -------------------------------------------------------------------------------- /1/4/gh_sol.py: -------------------------------------------------------------------------------- 1 | import bisect 2 | import sys 3 | 4 | 5 | def calc(x1, y1, y2, nx): 6 | return nx[6][y2] - nx[x1 - 1][y2] - nx[6][y1 - 1] + nx[x1 - 1][y1 - 1] 7 | 8 | 9 | n, Q = map(int, sys.stdin.readline().split()) 10 | ev = [] 11 | qu = [] 12 | time_set = [""] 13 | arr = [[0 for _ in range(2 * Q + n + 1)] for _ in range(7)] 14 | nj = [[0 for _ in range(2 * Q + n + 1)] for _ in range(7)] 15 | for i in range(n): 16 | it = sys.stdin.readline().split('#') 17 | lv = int(it[1]) 18 | ev.append((str(it[0]), lv)) 19 | time_set.append(str(it[0])) 20 | for i in range(Q): 21 | it = sys.stdin.readline().split('#') 22 | lv = int(it[2]) 23 | 24 | # time 대소 비교만 하는 것이므로, YYYY-MM-DD hh:mm:ss 꼴로 parsing해도 된다. 25 | qu.append((str(it[0]), str(it[1]), lv)) 26 | time_set.append(str(it[0])) 27 | time_set.append(str(it[1])) 28 | time_set = sorted(time_set) 29 | 30 | for i in range(n): 31 | time, lv = ev[i] 32 | arr[lv][bisect.bisect_left(time_set, time)] += 1 33 | for i in range(1, 7): 34 | for j in range(1, n + 2 * Q + 1): 35 | nj[i][j] = nj[i - 1][j] + nj[i][j - 1] - nj[i - 1][j - 1] + arr[i][j] 36 | for i in range(Q): 37 | time_s, time_e, lv = qu[i] 38 | time_s = bisect.bisect_left(time_set, time_s) 39 | time_e = bisect.bisect_left(time_set, time_e) 40 | ans = calc(lv, time_s, time_e, nj) 41 | sys.stdout.write(f'{ans}\n') 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gh coding test 2 | 가희배 코딩테스트에 출제된 문제들을 모아놓은 레포지토리입니다. 3 | 4 | | 회차 번호 | 바로 가기 | 자료 | 난이도 | 5 | |:-----:|:-------------------------------------------------:|:-----------------------------------------------------------:|:-------------:| 6 | | 1 | [바로가기](https://www.acmicpc.net/contest/view/644) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/1) |😆| 7 | | 2 | [바로가기](https://www.acmicpc.net/contest/view/658) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/2) |😆| 8 | | 3 | [바로가기](https://www.acmicpc.net/contest/view/755) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/3) |🤮| 9 | | 4 | [바로가기](https://www.acmicpc.net/contest/view/819) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/4) |😠| 10 | | 5 | [바로가기](https://www.acmicpc.net/contest/view/946) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/5) |😠| 11 | | 6 | [바로가기](https://www.acmicpc.net/contest/view/1201) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/6) |😆| 12 | | 7 | [바로가기](https://www.acmicpc.net/contest/view/1415) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/7) |😆| 13 | | 8 | [바로가기](https://www.acmicpc.net/contest/view/1578) | [자료](https://github.com/cdog-gh/gh_coding_test/tree/main/8) |😆| 14 | 15 | -------------------------------------------------------------------------------- /4/2/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.lang.*; 3 | import java.util.*; 4 | import java.util.stream.Stream; 5 | 6 | public class Main { 7 | public static void main(String []args) throws IOException { 8 | Map time = Map.of( 9 | "10MIN", 10, 10 | "30MIN", 30, 11 | "50MIN", 50, 12 | "2HOUR", 120, 13 | "4HOUR", 240, 14 | "9HOUR", 540 15 | ); 16 | BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); 17 | String []parse = bf.readLine().split(":"); 18 | int hh = Integer.parseInt(parse[0]); 19 | int mm = Integer.parseInt(parse[1]); 20 | int curMin = 60*hh + mm; 21 | int []hp = Stream 22 | .of(bf.readLine().split(" ")) 23 | .mapToInt(Integer::parseInt) 24 | .toArray(); 25 | int Q = Integer.parseInt(bf.readLine()); 26 | for(int i=0; i h > 0).sum(); 34 | if(ans > 100) 35 | ans = 100; 36 | System.out.println(ans); 37 | } 38 | } -------------------------------------------------------------------------------- /8/11/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int dp[201][60001]; 5 | int cc[201]; 6 | vector zz; 7 | vector oo; 8 | void pp(vector tar) 9 | { 10 | for(int i=0; i<(int)tar.size(); i++) 11 | { 12 | if(i == (int)tar.size() - 1) 13 | printf("%d\n", tar[i]); 14 | else 15 | printf("%d ", tar[i]); 16 | } 17 | }; 18 | int main(void) 19 | { 20 | int n, tot=0; scanf("%d", &n); dp[0][0] = 1; 21 | for(int i=1; i<=n; i++) 22 | scanf("%d", cc+i); 23 | if(n == 1) 24 | { 25 | printf("-1\n"); return 0; 26 | } 27 | for(int i=1; i<=n; i++) tot += cc[i]; 28 | for(int i=1; i<=n; i++) 29 | { 30 | for(int j=0; j<=60000; j++) dp[i][j] = dp[i-1][j]; 31 | for(int j=cc[i]; j<=60000; j++) 32 | { 33 | if(dp[i-1][j-cc[i]] == 0) continue; 34 | dp[i][j] = dp[i-1][j-cc[i]]; 35 | } 36 | } 37 | int lo = -1; 38 | for(int i=1; i <= tot/2; i++) 39 | { 40 | if(dp[n][i]) lo = i; 41 | } 42 | int cur = lo; 43 | for(int i=n; i>=1; i--) 44 | { 45 | int a = cur - cc[i]; 46 | if(a < 0 || dp[i-1][a] == 0) zz.push_back(i); 47 | else {oo.push_back(i); cur = a;} 48 | } 49 | printf("%d\n", (int)zz.size()); 50 | pp(zz); 51 | printf("%d\n", (int)oo.size()); 52 | pp(oo); 53 | } -------------------------------------------------------------------------------- /1/7/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int arr[100001]; 6 | int ps[1000001]; 7 | int pe[1000001]; 8 | int calc(int lo) 9 | { 10 | int prev = arr[lo]; 11 | for(int i=lo+1;;i++) 12 | { 13 | if(prev >= arr[i]) 14 | return i; 15 | prev = arr[i]; 16 | } 17 | } 18 | int main(void) 19 | { 20 | int T, ti = 1; scanf("%d",&T); 21 | memset(ps, 0x3f, sizeof(int)*1000001); 22 | for(int i=0;i= 2, impossible 52 | for example, 1 1 2 2 2 2 2 1 53 | [1] [1 2] [2] [2] [2] [2] [1] 54 | 1's gugan is 1~2, 7~7. more than 1. 55 | */ 56 | } -------------------------------------------------------------------------------- /8/08/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | ll pow2[62]; 4 | char A[2][1010101]; 5 | void f(ll r, ll c, ll x); 6 | void f_14(ll r, ll c); 7 | void f_23(ll r, ll c); 8 | int main(void) 9 | { 10 | ll Q, r, c, x; scanf("%lld", &Q); 11 | pow2[0] = 1LL; 12 | for(ll i=1; i<=60; i++) 13 | pow2[i] = (pow2[i-1] * 2); 14 | for(ll i=1; i<=Q; i++) 15 | { 16 | scanf("%lld%lld%lld", &r, &c, &x); 17 | f(r, c, x); 18 | // printf("---\n"); 19 | } 20 | } 21 | void f(ll r, ll c, ll x) 22 | { 23 | if(r == 1 || c % 3) 24 | { 25 | printf("-1\n"); return; 26 | } 27 | if(c < 61 * 3 && pow2[c/3LL] < x) 28 | { 29 | printf("-1\n"); return; 30 | } 31 | x--; 32 | for(ll i=0; i= arr[i]) 20 | ti++; 21 | int pid = arr[i]; 22 | s[pid] = Math.min(s[pid], ti); 23 | e[pid] = Math.max(e[pid], ti); 24 | prev = arr[i]; 25 | } 26 | int count = 0; 27 | StringBuilder sb = new StringBuilder(); 28 | for(int i=0; i<=pidMax; i++){ 29 | if(e[i] == 0) 30 | continue; 31 | count++; 32 | int b = e[i] - s[i] + 1; 33 | int c = pidMax - s[i]; 34 | sb.append(i + " " + b + " " + c + "\n"); 35 | } 36 | System.out.println(count); 37 | System.out.print(sb.toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /2/2/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | typedef long long ll; 8 | char str[100]; 9 | ll fe[128]; 10 | int co[200000]; 11 | vector v; 12 | void init() 13 | { 14 | for(ll i=0;i<26;i++) 15 | fe[i + 'a'] = i+1; 16 | for(ll i=0;i<10;i++) 17 | fe[i + '0'] = i+27; 18 | } 19 | ll f(const char *str) 20 | { 21 | ll reti = 0; 22 | for(ll i=0; str[i]; i++){ 23 | reti = 37*reti + fe[str[i]]; 24 | } 25 | return reti; 26 | } 27 | ll oioi(ll x) 28 | { 29 | ll lo = lower_bound(v.begin(), v.end(), x) - v.begin(); 30 | if(lo == (ll)v.size()) 31 | return 0; 32 | if(v[lo] != x) 33 | return 0; 34 | if(co[lo] == 1) 35 | return 0; 36 | co[lo] = 1; 37 | return 1; 38 | } 39 | int main(void) 40 | { 41 | ll n,m; scanf("%lld %lld\n",&n, &m); init(); 42 | for(int i=0;i 2 | #include 3 | #include 4 | #define inf 0x3f3f3f3f3f3f3f3fLL 5 | using namespace std; 6 | typedef long long ll; 7 | typedef struct moo moo; 8 | ll arr[404040]; 9 | ll nj[404040]; 10 | unordered_map dist; 11 | ll calc(ll a, ll b) 12 | { 13 | //printf("a = %lld b = %lld\n", a, b); 14 | if(a <= b) 15 | return nj[b] - nj[a]; 16 | else 17 | return nj[401010] - nj[a] + nj[b] - nj[0]; 18 | } 19 | int main(void) 20 | { 21 | ll n, totari; scanf("%lld", &n); 22 | for(ll i=1; i<=4*n; i++) 23 | { 24 | ll d; scanf("%lld", &d); arr[i+1] = d; 25 | } 26 | for(ll i=1; i<404040; i++){ 27 | nj[i] = nj[i-1] + arr[i]; 28 | totari = nj[i]; 29 | } 30 | for(ll i=1; i<=4; i++) 31 | { 32 | ll a, b, c; scanf("%lld%lld%lld", &a, &b, &c); 33 | ll r = min(a, min(b, c)); 34 | dist[n*i] = r; 35 | } 36 | ll Q; scanf("%lld", &Q); 37 | for(ll i=1; i<=Q; i++) 38 | { 39 | ll k; scanf("%lld", &k); 40 | ll ans = inf; 41 | for(ll ji=1; ji<=4; ji++) 42 | { 43 | //anti clockwise + a 44 | ll di = calc(k, n*ji); 45 | ll r1 = di + dist[n*ji]; 46 | ans = min(ans, r1); 47 | //clockwise + a 48 | ll r2 = (totari - di) + dist[n*ji]; 49 | ans = min(ans, r2); 50 | } 51 | printf("%lld\n", ans); 52 | } 53 | return 0; 54 | } -------------------------------------------------------------------------------- /7/12/gh_sol.py: -------------------------------------------------------------------------------- 1 | dp = [0 for _ in range(505050)] 2 | s_pos = [0 for _ in range(505050)] 3 | ds_pos = [0 for _ in range(505050)] 4 | tar = [0 for _ in range(505050)] 5 | nj = [0 for _ in range(505050)] 6 | right_dp = [0 for _ in range(505050)] 7 | right_ds_freq = [0 for _ in range(505050)] 8 | inf = 0x3f3f3f3f3f3f3f3f 9 | 10 | n = int(input()) 11 | s = input().strip() 12 | s = s.replace(" or ", "#or#") 13 | arr = s.split() 14 | for i, v in enumerate(arr): 15 | lo = i + 1 16 | if v == "S": 17 | s_pos[lo] = 1 18 | elif v == "DS": 19 | ds_pos[lo] = 1 20 | elif v == 'DS#or#S' or v == 'S#or#DS': 21 | ds_pos[lo] = 1 22 | s_pos[lo] = 1 23 | else: 24 | tar[lo] = int(v) 25 | 26 | for i in range(1, 505050): 27 | nj[i] = nj[i-1] + tar[i] 28 | 29 | mx = nj[n] 30 | base = mx 31 | # DS 한 번 나왔을 때. 32 | for i in range(1, 505050): 33 | if ds_pos[i] == 0: 34 | continue 35 | t = base + nj[i] 36 | mx = max(mx, t) 37 | 38 | r_mx = -inf 39 | r_freq = 0 40 | for i in range(505050-1, 0, -1): 41 | right_ds_freq[i] = r_freq 42 | if ds_pos[i] != 0: 43 | r_mx = max(r_mx, nj[i]) 44 | r_freq += 1 45 | right_dp[i] = r_mx 46 | 47 | # DS 2번 나왔을 때 48 | for i in range(1, 505050): 49 | if s_pos[i] == 0: 50 | continue 51 | 52 | # i+1 ~ ... 까지 DS가 나올 수 있는 pos 에서 최대치 찾는다. 53 | if right_ds_freq[i] == 0: 54 | continue 55 | v = (right_dp[i] - nj[i]) 56 | mx = max(mx, base + v) 57 | print(mx) 58 | -------------------------------------------------------------------------------- /3/1/base_code.txt: -------------------------------------------------------------------------------- 1 | data = [ 2 | "1 Seoul 0.0 Y 23 Chupungnyeong 234.7 N", 3 | "2 Yeongdeungpo 9.1 Y 24 Gimcheon 253.8 Y", 4 | "3 Anyang 23.9 N 25 Gumi 276.7 Y", 5 | "4 Suwon 41.5 Y 26 Sagok 281.3 N", 6 | "5 Osan 56.5 N 27 Yangmok 289.5 N", 7 | "6 Seojeongri 66.5 N 28 Waegwan 296.0 Y", 8 | "7 Pyeongtaek 75.0 Y 29 Sindong 305.9 N", 9 | "8 Seonghwan 84.4 N 30 Daegu 323.1 Y", 10 | "9 Cheonan 96.6 Y 31 Dongdaegu 326.3 Y", 11 | "10 Sojeongni 107.4 N 32 Gyeongsan 338.6 N", 12 | "11 Jeonui 114.9 N 33 Namseonghyeon 353.1 N", 13 | "12 Jochiwon 129.3 Y 34 Cheongdo 361.8 N", 14 | "13 Bugang 139.8 N 35 Sangdong 372.2 N", 15 | "14 Sintanjin 151.9 N 36 Miryang 381.6 Y", 16 | "15 Daejeon 166.3 Y 37 Samnangjin 394.1 N", 17 | "16 Okcheon 182.5 N 38 Wondong 403.2 N", 18 | "17 Iwon 190.8 N 39 Mulgeum 412.4 N", 19 | "18 Jitan 196.4 N 40 Hwamyeong 421.8 N", 20 | "19 Simcheon 200.8 N 41 Gupo 425.2 Y", 21 | "20 Gakgye 204.6 N 42 Sasang 430.3 N", 22 | "21 Yeongdong 211.6 Y 43 Busan 441.7 Y", 23 | "22 Hwanggan 226.2 N" 24 | ] -------------------------------------------------------------------------------- /scripts/API.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import copy 3 | 4 | base = "https://solved.ac/api/v3" 5 | 6 | 7 | # get gh problem 8 | def build_gh_problem(target: list, pre_data: dict) -> list: 9 | try: 10 | build_data = [pre_data.get(k, dict()) for k in target] 11 | temp_data = copy.deepcopy(build_data) 12 | for i, item in enumerate(temp_data): 13 | if item: 14 | continue 15 | problem_num = target[i] 16 | res = requests.get(f"{base}/search/problem", params={ 17 | "query": problem_num 18 | }).json() 19 | build_data[i] = { 20 | "lv": res["items"][0]["level"], 21 | "title": res["items"][0]["titleKo"], 22 | "problemNo": res["items"][0]["problemId"], 23 | "tags": [tag["key"] for tag in res["items"][0]["tags"]] 24 | } 25 | return build_data 26 | except: 27 | assert False, "request error" 28 | 29 | 30 | def build_init_data() -> dict: 31 | try: 32 | res = requests.get(f"{base}/search/problem", params={ 33 | "query": "가희" 34 | }).json() 35 | gh_problem_data = { 36 | k["problemId"]: { 37 | "lv": k["level"], "title": k["titleKo"], "problemNo": k["problemId"], 38 | "tags": [tag["key"] for tag in k["tags"]] 39 | } for k in res["items"] 40 | } 41 | return gh_problem_data 42 | except: 43 | assert False, "request error" 44 | -------------------------------------------------------------------------------- /3/2/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int ans[101010]; 5 | void print(int n) 6 | { 7 | for(int i=1; i<=n; i++) 8 | printf("%d ", ans[i]); 9 | printf("\n"); 10 | } 11 | int main(void) 12 | { 13 | int n, a, b; scanf("%d%d%d", &n, &a, &b); 14 | fill(ans + 1, ans + n + 1, 1); //높이 1로 초기화 15 | if(a + b > n + 1) 16 | { 17 | printf("-1\n"); return 0; 18 | } 19 | if(a == 1 && b == 1) 20 | { 21 | print(n); return 0; 22 | } 23 | //코너 케이스이므로 조심! 24 | if(a == 1) 25 | { 26 | //b > 1임. 27 | //먼저 ans[1] = b 28 | ans[1] = b; 29 | for(int i=1; i rev = new LinkedHashMap<>(); 5 | rev.put("LU!", "3"); 6 | rev.put("LD!", "9"); 7 | rev.put("RU!", "1"); 8 | rev.put("RD!", "7"); 9 | rev.put("W!", "2"); 10 | rev.put("A!", "6"); 11 | rev.put("S!", "8"); 12 | rev.put("D!", "4"); 13 | LinkedHashMap ori = new LinkedHashMap<>(); 14 | ori.put("LU", "7"); 15 | ori.put("LD", "1"); 16 | ori.put("RU", "9"); 17 | ori.put("RD", "3"); 18 | ori.put("W", "8"); 19 | ori.put("A", "4"); 20 | ori.put("S", "2"); 21 | ori.put("D", "6"); 22 | Scanner sc = new Scanner(System.in); 23 | String note = sc.nextLine(); 24 | String input = sc.nextLine(); 25 | for(String key: rev.keySet()) 26 | note = note.replaceAll(key, rev.get(key)); 27 | for(String key: ori.keySet()) 28 | note = note.replaceAll(key, ori.get(key)); 29 | for(String key: ori.keySet()) 30 | input = input.replaceAll(key, ori.get(key)); 31 | int pos = 0; 32 | for(int i=0; i 2 | #include 3 | #define INF 2000000000000000000LL 4 | using namespace std; 5 | typedef long long ll; 6 | unordered_map dp[200002]; 7 | char ans[808080]; 8 | ll get(ll x, ll y) 9 | { 10 | if(x >= 200002) 11 | return 0; 12 | if(dp[x].find(y) == dp[x].end()) 13 | return 0; 14 | return dp[x][y]; 15 | } 16 | void build_dp(ll y) 17 | { 18 | ll ban = y/2; 19 | //(x, 0) to (ban, ban) 20 | if(get(ban+1, ban+1) >= INF){ 21 | dp[ban][ban] = INF; 22 | return; 23 | } 24 | for(ll x=0; x<=ban; x++, y--) 25 | { 26 | if(x == 0) 27 | continue; 28 | dp[x][y] = get(x-1, y+1) + get(x+1, y+1); 29 | dp[x][y] = min(INF, dp[x][y]); 30 | } 31 | } 32 | void track(ll d, ll k) 33 | { 34 | ll cur_x = 0; 35 | ll cur_y = 0; 36 | ll cur_gaji = k; 37 | //Operation number : d 38 | for(ll i=0; i=0; i=i-2) 65 | build_dp(i); 66 | dp[0][0] = dp[1][1]; 67 | if(dp[0][0] < k){ 68 | printf("-1\n"); 69 | return 0; 70 | } 71 | track(d, k); 72 | return 0; 73 | } -------------------------------------------------------------------------------- /2/1/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | struct moo 8 | { 9 | string name; 10 | string ext; 11 | int flag; 12 | }; 13 | typedef struct moo moo; 14 | moo arr[200000]; 15 | char str[30]; 16 | vector ext; 17 | bool cmp(moo a,moo b) 18 | { 19 | if(a.name.compare(b.name) != 0) 20 | return a.name.compare(b.name) < 0; 21 | if(a.flag != b.flag) 22 | return a.flag > b.flag; 23 | return a.ext.compare(b.ext) < 0; 24 | } 25 | int main(void) 26 | { 27 | int n,m; moo I; scanf("%d %d\n",&n,&m); 28 | for(int i=0;i 2 | #include 3 | #include 4 | int arr[6]; 5 | int flag[6]; 6 | char str1[30]; 7 | char str2[30]; 8 | int main(void) 9 | { 10 | int hh, mm, curi; scanf("%s\n", str1); str1[2] = 0; 11 | hh = atoi(str1); 12 | mm = atoi(str1 + 3); 13 | curi = 60*hh + mm; 14 | for(int i=0; i<6; i++) 15 | scanf("%d", &(arr[i])); 16 | int L; scanf("\n%d", &L); 17 | for(int i=1; i<=L; i++) 18 | { 19 | scanf("\n%s %s", str1, str2); 20 | if(strcmp(str2, "^") == 0) 21 | { 22 | int yy = curi / 120; 23 | flag[yy] = 1; 24 | } 25 | else if(strcmp(str2, "10MIN") == 0) 26 | { 27 | curi = curi + 10; 28 | } 29 | else if(strcmp(str2, "30MIN") == 0) 30 | { 31 | curi = curi + 30; 32 | } 33 | else if(strcmp(str2, "50MIN") == 0) 34 | { 35 | curi = curi + 50; 36 | } 37 | else if(strcmp(str2, "2HOUR") == 0) 38 | { 39 | curi = curi + 60*2; 40 | } 41 | else if(strcmp(str2, "4HOUR") == 0) 42 | { 43 | curi = curi + 60*4; 44 | } 45 | else if(strcmp(str2, "9HOUR") == 0) 46 | { 47 | curi = curi + 60*9; 48 | } 49 | curi = curi % (12 * 60); 50 | } 51 | int ans = 0; 52 | for(int i=0; i<6; i++) 53 | { 54 | if(flag[i]) 55 | continue; 56 | ans = ans + arr[i]; 57 | } 58 | if(ans > 100) ans = 100; 59 | printf("%d\n",ans); 60 | return 0; 61 | } -------------------------------------------------------------------------------- /1/5/random_generator/game.py: -------------------------------------------------------------------------------- 1 | class game: 2 | def __init__(self, rc_num): 3 | self.rc_num = rc_num 4 | self.resource = dict() # 사용하는 리소스 5 | self.card = dict() # card 에 대한 정보 6 | self.player = [0] * 500001 7 | 8 | def get_resource_owner(self, rn): 9 | if rn not in self.resource: 10 | return -1 11 | return self.resource.get(rn) 12 | 13 | # card_op = card_id, oper, num tuple 14 | def is_available(self, pn, card_op): 15 | _, oper, num = card_op 16 | # next 인 경우에는 무조건 True 이다. 17 | if oper == 'next': 18 | return True 19 | if oper == 'release': 20 | return self.get_resource_owner(num) == pn 21 | if oper == 'acquire': 22 | return self.get_resource_owner(num) != pn 23 | 24 | def current_card(self, pn): 25 | if self.player[pn] == 0: 26 | return None 27 | return self.card[self.player[pn]] 28 | 29 | def process_turn(self, pn, card_op): 30 | cid, oper, num = card_op 31 | self.card[cid] = card_op 32 | if oper == 'next': 33 | self.player[pn] = 0 34 | return 35 | elif oper == 'acquire': 36 | if self.get_resource_owner(num) != pn and self.get_resource_owner(num) != -1: 37 | self.player[pn] = cid 38 | else: 39 | self.player[pn] = 0 40 | self.resource[num] = pn 41 | else: 42 | if self.get_resource_owner(num) == pn: 43 | self.player[pn] = 0 44 | self.resource.pop(num) 45 | else: 46 | exit(-1) 47 | -------------------------------------------------------------------------------- /6/10/gh_sol_no_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | typedef long long ll; 6 | ll ans[1000001]; 7 | char temp[50]; 8 | char p_ans[45000000]; 9 | int main(void) 10 | { 11 | ll n, s; scanf("%lld%lld", &n, &s); 12 | ll filled = ((1LL<<31) - 1) - s; 13 | ll M = (1LL << 31); 14 | if(n % 4 == 0) 15 | { 16 | for(ll i=0; i=0; i--) 50 | { 51 | sprintf(temp, "%lld\n", ans[i]); 52 | t_ans = stpcpy(t_ans, temp); 53 | } 54 | for(int i=(n/4)*4; i= 86400: 58 | print('-1') 59 | else: 60 | print(f'{cur_sec//3600:02d}:{(cur_sec%3600)//60:02d}:{(cur_sec%3600)%60:02d}') 61 | -------------------------------------------------------------------------------- /4/README.md: -------------------------------------------------------------------------------- 1 | ## 4회 [바로 가기](https://www.acmicpc.net/contest/view/819) 2 | 2022년 06월 06일 13시부터 18시까지 4회 코딩테스트가 열렸습니다. 3 | 4 | |문제 번호|제목|풀러 가기|힌트|난이도| 5 | |:------:|:-------------:|:-----:|:-----:|:-----:| 6 | |A|가희와 방어율 무시|[바로가기](https://www.acmicpc.net/problem/25238)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/1)| | 7 | |B|가희와 카오스 파풀라투스|[바로가기](https://www.acmicpc.net/problem/25239)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/2)| | 8 | |C|가희와 파일 탐색기 2|[바로가기](https://www.acmicpc.net/problem/25240)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/3)| | 9 | |D|가희와 중부내륙선|[바로가기](https://www.acmicpc.net/problem/25243)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/4)| | 10 | |E|가희와 지하철|[바로가기](https://www.acmicpc.net/problem/25242)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/5)| | 11 | |F|가희와 사직 구장|[바로가기](https://www.acmicpc.net/problem/25241)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/6)| | 12 | |G|가희와 영상 추천 시스템|[바로가기](https://www.acmicpc.net/problem/25244)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/4/7)| | 13 | 14 | 마지막 업데이트 날짜 : 2025-12-14 00:08:21.710033Z -------------------------------------------------------------------------------- /2/3/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | struct moo 6 | { 7 | int id; 8 | int need_time; 9 | int worked_time; 10 | }; 11 | typedef struct moo moo; 12 | deque wait_q; 13 | moo event[200001]; 14 | int main(void) 15 | { 16 | int n,t,m,p; moo I, C; scanf("%d%d%d",&n,&t,&p); 17 | memset(event, -1, sizeof(moo)*200001); 18 | for(int i=0;i""" 31 | f.write(f"""|{ch}|{problem_title}|[바로가기]({problem_link})|[힌트]({hint_link})| {img_script} |\n""") 32 | 33 | from datetime import datetime 34 | from datetime import timezone 35 | 36 | f.write(f"\n마지막 업데이트 날짜 : {str(datetime.now(timezone.utc)).replace('+00:00', 'Z')}") -------------------------------------------------------------------------------- /1/2/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int dx[4] = {-1, 0, 1, 0}; 7 | int dy[4] = {0, 1, 0, -1}; 8 | int temp[25]; 9 | int na[25]; 10 | int M = 202; 11 | char str[105][105]; 12 | set visit; 13 | int mmx = 0; 14 | void gogo(int sx, int sy, int T) 15 | { 16 | int cx = sx; 17 | int cy = sy; 18 | int ans = 0; 19 | visit.clear(); visit.insert(cx * M + cy); 20 | for(int i=0;i::iterator iter = visit.begin(); iter != visit.end(); iter++) 28 | { 29 | int U = (*iter); 30 | int tx = U/M; int ty = U%M; 31 | ans = ans + (str[tx][ty] == 'S'); 32 | } 33 | mmx = max(ans, mmx); 34 | } 35 | int main(void) 36 | { 37 | int R, C, T; scanf("%d %d %d",&R, &C, &T); 38 | for(int i=0; i<=R+1; i++) 39 | memset(str[i], '#', sizeof(char)*(C+2)); 40 | for(int i=1; i<=R; i++){ 41 | scanf("\n%s",&(str[i][1])); 42 | str[i][C+1] = '#'; 43 | } 44 | int sx = -1, sy = -1; 45 | for(int i=1; i<=R; i++) 46 | { 47 | for(int j=1; j<=C; j++) 48 | { 49 | if(str[i][j] == 'G') 50 | { 51 | sx = i; sy = j; 52 | } 53 | } 54 | } 55 | 56 | for(int i=0; i<(1<<(2*T)); i++) 57 | { 58 | for(int j=0; j<2*T; j++) 59 | { 60 | if(i&(1<=0; i--){ 38 | dp_r[i] = rv; 39 | if(DS[i] == 1) rv = Math.max(rv, nj[i]); 40 | } 41 | for(int i=0; i 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | struct moo 7 | { 8 | int id; 9 | string op; 10 | string resource; 11 | }; 12 | typedef struct moo moo; 13 | set ss; 14 | deque dummy; 15 | moo player[500002]; 16 | int turn[500002]; 17 | char str[20]; 18 | int main(void) 19 | { 20 | int n, T, id; scanf("%d %d\n",&n, &T); 21 | for(int i=1;i<=T;i++) 22 | scanf("%lld",turn + i); 23 | for(int i=1;i<=n;i++) 24 | player[i].id = -1; 25 | for(int i=1;i<=T;i++) 26 | { 27 | moo I; 28 | scanf("\n%d %s",&id, str); 29 | string temp = string(str); 30 | I.id = id; I.op = temp; 31 | if(temp.compare("next") != 0) 32 | { 33 | scanf(" %s",str); 34 | I.resource = string(str); 35 | } 36 | dummy.push_back(I); 37 | } 38 | for(int i=1;i<=T;i++) 39 | { 40 | int pn = turn[i]; 41 | 42 | if(player[pn].id == -1) 43 | { 44 | //deck에서 카드 하나 뽑는다. 45 | player[pn] = dummy.front(); dummy.pop_front(); 46 | } 47 | printf("%d\n",player[pn].id); 48 | if(player[pn].op.compare("next") == 0) 49 | { 50 | player[pn].id = -1; 51 | } 52 | else if(player[pn].op.compare("acquire") == 0) 53 | { 54 | string rr = player[pn].resource; 55 | if(ss.find(rr) == ss.end()) 56 | { 57 | ss.insert(rr); 58 | player[pn].id = -1; 59 | } 60 | } 61 | else 62 | { 63 | //resource 제거 64 | string rr = player[pn].resource; 65 | if(ss.find(rr) == ss.end()) while(1){} 66 | ss.erase(ss.find(rr)); 67 | player[pn].id = -1; 68 | } 69 | } 70 | return 0; 71 | } -------------------------------------------------------------------------------- /1/5/gh_sol_bit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | struct moo 8 | { 9 | int id; 10 | string op; 11 | string resource; 12 | }; 13 | typedef struct moo moo; 14 | //set ss; 15 | //누군가 카드를 점유하고 있는지 카드 id별로 flag를 저장한다. 16 | bitset <2000000002> ss; 17 | deque dummy; 18 | moo player[500002]; 19 | int turn[500002]; 20 | char str[20]; 21 | int main(void) 22 | { 23 | int n, T, id; scanf("%d %d\n",&n, &T); ss.reset(); 24 | for(int i=1;i<=T;i++) 25 | scanf("%lld",turn + i); 26 | for(int i=1;i<=n;i++) 27 | player[i].id = -1; 28 | for(int i=1;i<=T;i++) 29 | { 30 | moo I; 31 | scanf("\n%d %s",&id, str); 32 | string temp = string(str); 33 | I.id = id; I.op = temp; 34 | if(temp.compare("next") != 0) 35 | { 36 | scanf(" %s",str); 37 | I.resource = string(str); 38 | } 39 | dummy.push_back(I); 40 | } 41 | for(int i=1;i<=T;i++) 42 | { 43 | int pn = turn[i]; 44 | 45 | if(player[pn].id == -1) 46 | { 47 | //deck에서 카드 하나 뽑는다. 48 | player[pn] = dummy.front(); dummy.pop_front(); 49 | } 50 | printf("%d\n",player[pn].id); 51 | if(player[pn].op.compare("next") == 0) 52 | { 53 | player[pn].id = -1; 54 | } 55 | else if(player[pn].op.compare("acquire") == 0) 56 | { 57 | int rr = stoi(player[pn].resource); 58 | if(ss[rr] == 0) 59 | { 60 | ss[rr] = 1; 61 | player[pn].id = -1; 62 | } 63 | } 64 | else 65 | { 66 | //resource 제거 67 | int rr = stoi(player[pn].resource); 68 | ss[rr] = 0; 69 | player[pn].id = -1; 70 | } 71 | } 72 | return 0; 73 | } -------------------------------------------------------------------------------- /2/README.md: -------------------------------------------------------------------------------- 1 | ## 2회 [바로 가기](https://www.acmicpc.net/contest/view/658) 2 | 2021년 07월 18일 13시부터 18시까지 2회 코딩테스트가 열렸습니다. 3 | 4 | |문제 번호|제목|풀러 가기|힌트|난이도| 5 | |:------:|:-------------:|:-----:|:-----:|:-----:| 6 | |A|가희와 파일 탐색기|[바로가기](https://www.acmicpc.net/problem/22232)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/1)| | 7 | |B|가희와 키워드|[바로가기](https://www.acmicpc.net/problem/22233)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/2)| | 8 | |C|가희와 은행|[바로가기](https://www.acmicpc.net/problem/22234)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/3)| | 9 | |D|가희와 btd5|[바로가기](https://www.acmicpc.net/problem/22238)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/4)| | 10 | |E|가희와 수인 분당선 1|[바로가기](https://www.acmicpc.net/problem/22235)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/5)| | 11 | |F|가희와 비행기|[바로가기](https://www.acmicpc.net/problem/22236)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/6)| | 12 | |G|가희와 거북이 인형|[바로가기](https://www.acmicpc.net/problem/22237)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/7)| | 13 | |H|가희와 읽기 쓰기 놀이 2|[바로가기](https://www.acmicpc.net/problem/22239)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/2/8)| | 14 | 15 | 마지막 업데이트 날짜 : 2025-12-14 00:08:21.709807Z -------------------------------------------------------------------------------- /1/README.md: -------------------------------------------------------------------------------- 1 | ## 1회 [바로 가기](https://www.acmicpc.net/contest/view/644) 2 | 2021년 05월 23일 13시부터 18시까지 1회 코딩테스트가 열렸습니다. 3 | 4 | |문제 번호|제목|풀러 가기|힌트|난이도| 5 | |:------:|:-------------:|:-----:|:-----:|:-----:| 6 | |A|가희야 거기서 자는 거 아니야|[바로가기](https://www.acmicpc.net/problem/21771)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/1)| | 7 | |B|가희의 고구마 먹방|[바로가기](https://www.acmicpc.net/problem/21772)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/2)| | 8 | |C|가희와 프로세스 1|[바로가기](https://www.acmicpc.net/problem/21773)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/3)| | 9 | |D|가희와 로그 파일|[바로가기](https://www.acmicpc.net/problem/21774)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/4)| | 10 | |E|가희와 자원 놀이|[바로가기](https://www.acmicpc.net/problem/21775)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/5)| | 11 | |F|가희와 읽기 쓰기 놀이|[바로가기](https://www.acmicpc.net/problem/21776)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/6)| | 12 | |G|리버스 가희와 프로세스 1|[바로가기](https://www.acmicpc.net/problem/21777)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/7)| | 13 | |H|가희와 프로세스 2|[바로가기](https://www.acmicpc.net/problem/21778)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/1/8)| | 14 | 15 | 마지막 업데이트 날짜 : 2025-12-14 00:08:21.709647Z -------------------------------------------------------------------------------- /2/1/ryunian_sol.java: -------------------------------------------------------------------------------- 1 | /* 2 | Author : ryunian 3 | */ 4 | import java.io.*; 5 | import java.util.*; 6 | 7 | class Main { 8 | private static class Node { 9 | String str; 10 | String extension; 11 | 12 | public Node(String str, String extension) { 13 | this.str = str; 14 | this.extension = extension; 15 | } 16 | 17 | public String getStr() { 18 | return str; 19 | } 20 | 21 | public String getExtension() { 22 | return extension; 23 | } 24 | } 25 | 26 | public static void main(String[] args) throws IOException { 27 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 28 | StringTokenizer st = new StringTokenizer(br.readLine()); 29 | int n = Integer.parseInt(st.nextToken()); 30 | int m = Integer.parseInt(st.nextToken()); 31 | 32 | // 파일 리스트 33 | List list = new ArrayList<>(); 34 | while (n-- > 0) { 35 | st = new StringTokenizer(br.readLine(), "."); 36 | list.add(new Node(st.nextToken(), st.nextToken())); 37 | } 38 | 39 | // OS에서 인식하는 파일확장자 정보 40 | Set extInfo = new HashSet<>(); 41 | while (m-- > 0) { 42 | extInfo.add(br.readLine()); 43 | } 44 | 45 | // Comparator 의 thenComparing 이용한 다중 정렬 46 | // 람다를 쓰기 위해선 마지막 thenComparing 에서 가능하기 때문에 47 | // OS 가 인식하는 파일 확장자 정렬조건 chk 추가 48 | Comparator chk = Comparator.comparingInt(o -> (extInfo.contains(o.extension) == true ? -1 : 1)); 49 | list.sort(Comparator.comparing(Node::getStr).thenComparing(chk).thenComparing(Node::getExtension)); 50 | 51 | 52 | // 출력 53 | StringBuilder sb = new StringBuilder(); 54 | for (int i = 0; i < list.size(); i++) { 55 | sb.append(list.get(i).str).append(".").append(list.get(i).extension).append("\n"); 56 | } 57 | System.out.print(sb.toString()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /scripts/db.py: -------------------------------------------------------------------------------- 1 | gh_test_num = 8 2 | gh_contest_db = [{} for _ in range(0, gh_test_num + 1)] 3 | gh_contest_db[1] = { 4 | "problems": [21771, 21772, 21773, 21774, 21775, 21776, 21777, 21778], 5 | "yyyy": 2021, 6 | "mm": 5, 7 | "dd": 23, 8 | "start": 13 * 60, 9 | "end": 18 * 60, 10 | "id": 644 11 | } 12 | gh_contest_db[2] = { 13 | "problems": [22232, 22233, 22234, 22238, 22235, 22236, 22237, 22239], 14 | "yyyy": 2021, 15 | "mm": 7, 16 | "dd": 18, 17 | "start": 13 * 60, 18 | "end": 18 * 60, 19 | "id": 658 20 | } 21 | gh_contest_db[3] = { 22 | "problems": [24336, 24337, 24339, 24338, 24340], 23 | "yyyy": 2022, 24 | "mm": 1, 25 | "dd": 23, 26 | "start": 13 * 60, 27 | "end": 18 * 60 + 10, 28 | "id": 755 29 | } 30 | gh_contest_db[4] = { 31 | "problems": [25238, 25239, 25240, 25243, 25242, 25241, 25244], 32 | "yyyy": 2022, 33 | "mm": 6, 34 | "dd": 6, 35 | "start": 13 * 60, 36 | "end": 18 * 60, 37 | "id": 819 38 | } 39 | gh_contest_db[5] = { 40 | "problems": [27880, 27885, 27883, 27884, 27881, 27888, 27882, 27887, 27886], 41 | "yyyy": 2023, 42 | "mm": 4, 43 | "dd": 2, 44 | "start": 13 * 60, 45 | "end": 18 * 60, 46 | "id": 946 47 | } 48 | gh_contest_db[6] = { 49 | "problems": [30791, 30792, 30793, 30794, 30796, 30801, 30797, 30799, 30795, 30798, 30800], 50 | "yyyy": 2023, 51 | "mm": 12, 52 | "dd": 3, 53 | "start": 19 * 60, 54 | "end": 23 * 60, 55 | "id": 1201 56 | } 57 | gh_contest_db[7] = { 58 | "problems": [32775, 32776, 32777, 32778, 32779, 32780, 32786, 32781, 32783, 32784, 32785, 32782], 59 | "yyyy": 2024, 60 | "mm": 11, 61 | "dd": 30, 62 | "start": 19 * 60, 63 | "end": 23 * 60, 64 | "id": 1415 65 | } 66 | gh_contest_db[8] = { 67 | "problems": [34665, 34666, 34667, 34668, 34669, 34670, 34671, 34672, 34673, 34674, 34675, 34676], 68 | "yyyy": 2025, 69 | "mm": 11, 70 | "dd": 2, 71 | "start": 19 * 60, 72 | "end": 23 * 60, 73 | "id": 1578 74 | } -------------------------------------------------------------------------------- /2/8/wrong/gh_py_wrong.py: -------------------------------------------------------------------------------- 1 | """ 2 | Anti Pattern: 3 | 순회를 도는 동안 자료구조를 변형하면 안 된다. 4 | people_list = md[key] 5 | for p in people_list: 6 | md[k].remove(v) 7 | ... 8 | """ 9 | import sys 10 | from collections import defaultdict 11 | my_input = sys.stdin.readline 12 | sys.setrecursionlimit(100000) 13 | n, c = map(int, my_input().split(' ')) 14 | ret_list = list(map(int, my_input().split(' '))) 15 | turn = [[] for _ in range(20001)] 16 | card = [0 for _ in range(c+1)] 17 | for i in range(1, n+1): 18 | turn[i] = list(map(int, my_input().split(' ')))[1:] 19 | # turn[i].append(10**9 + i) 20 | for i in range(1, c+1): 21 | card[i] = int(my_input()[4:]) 22 | for i in range(1, c+1): 23 | for j in range(len(turn[i])): 24 | card_num = turn[i][j] 25 | turn[i][j] = card[card_num] 26 | for i in range(1, c+1): 27 | turn[i].append(10**9 + i) 28 | md = defaultdict(list) 29 | pos = [0] * (n+1) 30 | for i in range(1, n+1): 31 | md[turn[i][0]].append(i) 32 | ans = [0 for _ in range(c)] 33 | 34 | 35 | def dfs(depth): 36 | if depth == c: 37 | s = " ".join(map(str, ans)) 38 | print(s) 39 | exit(0) 40 | key = ret_list[depth] 41 | # 현재 md에 key 값이 k일 때 어떤 people 이 올 수 있는지 적혀져 있음. 42 | if key not in md: 43 | return 44 | people_list = md[key] 45 | # shallow copy를 하고 iteration을 돌림. 46 | for p in people_list: 47 | ans[depth] = p 48 | # iteration을 도는 동안 people_list의 상태가 바뀌어 버림. 49 | # (1) turn[p][pos[p]] :: p del 50 | k, v = turn[p][pos[p]], p 51 | md[k].remove(v) 52 | 53 | pos[p] = pos[p] + 1 54 | # (2) turn[p][pos[p]] :: p add 55 | k, v = turn[p][pos[p]], p 56 | md[k].append(v) 57 | dfs(depth + 1) 58 | # (3) turn[p][pos[p]] :: p del 59 | k, v = turn[p][pos[p]], p 60 | md[k].remove(v) 61 | 62 | pos[p] = pos[p] - 1 63 | # (4) turn[p][pos[p]] :: p add 64 | k, v = turn[p][pos[p]], p 65 | md[k].append(v) 66 | 67 | 68 | dfs(0) 69 | print('-1') -------------------------------------------------------------------------------- /3/4/generator/gen_0_and_1.py: -------------------------------------------------------------------------------- 1 | ma = [ 2 | [0, 1, 0, 1, 0, 1, 3], 3 | [1, 0, 1, 0, 1, 0, 3], 4 | [0, 1, 0, 1, 0, 1, 3], 5 | [1, 0, 1, 0, 1, 0, 3], 6 | [0, 1, 0, 1, 0, 1, 3], 7 | [1, 0, 1, 0, 1, 0, 3], 8 | [2, 1, 0, 1, 0, 1, 3] 9 | ] 10 | right_top = [(0, 1), (0, 3)] 11 | right_down = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (0, 4), 12 | (1, 4), (2, 4), (3, 4)] 13 | unit_r = 105 14 | unit_c = 105 15 | real_ma = [['.' for _ in range(unit_c * 7)] for _ in range(unit_r * 7)] 16 | for i in range(7): 17 | for j in range(7): 18 | sx = unit_r * i 19 | sy = unit_c * j 20 | ex = sx + unit_r 21 | ey = sy + unit_c 22 | 23 | if ma[i][j] == 0: 24 | for x in range(sx, ex): 25 | for y in range(sy, ey): 26 | real_ma[x][y] = '.' 27 | elif ma[i][j] == 1: 28 | for x in range(sx, ex): 29 | for y in range(sy, ey): 30 | real_ma[x][y] = '1' 31 | # present block 32 | elif ma[i][j] == 2: 33 | for x in range(sx, ex): 34 | for y in range(sy, ey): 35 | if (x + y) % 2 == 0 and y != sy: 36 | real_ma[x][y] = 'B' 37 | else: 38 | real_ma[x][y] = '1' 39 | elif ma[i][j] == 3: 40 | for x in range(sx, ex): 41 | for y in range(sy, ey): 42 | if (x + y) % 2 == 0: 43 | real_ma[x][y] = '1' 44 | else: 45 | real_ma[x][y] = '.' 46 | if (i, j) in right_top: 47 | real_ma[sx][ey - 1] = '?' 48 | if (i, j) in right_down: 49 | real_ma[ex - 1][ey - 1] = '?' 50 | file_num = 5 51 | with open(f'large_{file_num}.in', 'w') as f: 52 | f.write(f'{unit_r * 7} {unit_c * 7}\n') 53 | for i in range(unit_r * 7): 54 | s = ''.join(real_ma[i]) 55 | f.write(f'{s}\n') 56 | f.write('1 1\n') -------------------------------------------------------------------------------- /6/11/tle/gh_tle_bf.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from collections import deque 3 | input = sys.stdin.readline 4 | dq = deque() 5 | 6 | 7 | # int도 object이므로, locality가 좋지 않음. 8 | arr = [[0 for j in range(3001)] for i in range(3001)] 9 | nj = [[0 for j in range(3001)] for i in range(3001)] 10 | 11 | 12 | def calc(x1: int, y1: int, x2: int, y2: int) -> int: 13 | return nj[x2][y2] - nj[x2][y1-1] - nj[x1-1][y2] + nj[x1-1][y1-1] 14 | 15 | 16 | def calc_digguk(x1: int, y1: int, ww: int, hh: int) -> int: 17 | bottom = calc(x1, y1, x1, y1+ww) 18 | up = calc(x1+hh, y1, x1+hh, y1+ww) 19 | sero = calc(x1, y1+ww, x1+hh, y1+ww) 20 | return bottom + up + sero - arr[x1][y1+ww] - arr[x1+hh][y1+ww] 21 | 22 | 23 | inf = 0x3f3f3f3f3f3f3f3f 24 | mini = inf 25 | R, C = map(int, input().split()) 26 | h1, h2, w1, w2 = map(int, input().split()) 27 | for r in range(1, R+1): 28 | tmp = [0] + list(map(int, input().split())) 29 | for c in range(1, C+1): 30 | arr[r][c] = tmp[c] 31 | 32 | for i in range(1, R+1): 33 | for j in range(1, C+1): 34 | nj[i][j] = nj[i-1][j] + nj[i][j-1] - nj[i-1][j-1] + arr[i][j] 35 | 36 | for h in range(h1+1, h2+2): 37 | if h > R: 38 | break 39 | base = -(arr[1][C-w1] + arr[h][C-w1]) 40 | h0 = h-1 41 | while dq: 42 | dq.pop() 43 | for w in range(C-w1, 0, -1): 44 | # 역 ㄷ자 구하기. 45 | # 꼭지점, 너비, 높이 46 | base += (arr[1][w] + arr[h][w]) 47 | 48 | # 역 ㄷ자를 구할 건데. 49 | dig = calc_digguk(1, w, w1, h0) 50 | 51 | # dig - base를 넣는다. 어? 왜? 52 | real = dig - base 53 | dq.append(real) 54 | 55 | if len(dq) > w2 - w1 + 1: 56 | dq.popleft() 57 | 58 | # 역 ㄷ 최대 59 | a = min(dq) 60 | a += base 61 | # 1자 더하기 62 | a += (calc(1, w, h, w) - arr[1][w] - arr[h][w]) 63 | if a < mini: 64 | mini = a 65 | # print(f"h = {h} w = {w} lo = {item['lo']}") 66 | 67 | 68 | if mini == inf: 69 | print('No') 70 | else: 71 | print(mini) 72 | -------------------------------------------------------------------------------- /1/2/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.lang.*; 3 | import java.util.*; 4 | public class Main { 5 | private static int []op = new int[20]; 6 | public static void main(String []args) throws IOException { 7 | BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); 8 | String []parse; 9 | parse = bf.readLine().split(" "); 10 | int R = Integer.parseInt(parse[0]); 11 | int C = Integer.parseInt(parse[1]); 12 | String []str = new String[R]; 13 | int T = Integer.parseInt(parse[2]); 14 | int sx = -1, sy = -1; 15 | for(int i=0;i mmx) 30 | mmx = r; 31 | } 32 | System.out.println(mmx); 33 | } 34 | 35 | private static int gogo(int sx, int sy, int R, int C, int t, String []map) 36 | { 37 | int []dx = {1, 0, -1, 0}; 38 | int []dy = {0, 1, 0, -1}; 39 | int cx = sx; 40 | int cy = sy; 41 | int ans = 0; 42 | int kei = 202; 43 | Set ss = new TreeSet<>(); 44 | 45 | for(int i=0;i= R || cy >= C) 50 | return 0; 51 | if(map[cx].charAt(cy) == '#') 52 | return 0; 53 | ss.add(cx * kei + cy); 54 | } 55 | for(int cur:ss){ 56 | int xx = cur/kei; int yy = cur%kei; 57 | if(map[xx].charAt(yy) == 'S') 58 | ans++; 59 | } 60 | return ans; 61 | } 62 | } -------------------------------------------------------------------------------- /6/09/gh_sol.py: -------------------------------------------------------------------------------- 1 | p_in = input().split() 2 | r_in = input().split() 3 | 4 | p_dict = {} 5 | r_dict = {} 6 | 7 | 8 | def read_in(target: list, dic: dict): 9 | temp_name = list() 10 | i = 0 11 | cur_rank = 1 12 | while i < len(target): 13 | token = target[i] 14 | if token != 'Group': 15 | temp_name.append(token) 16 | i += 1 17 | continue 18 | people_name = " ".join(temp_name) 19 | temp_name = list() 20 | group_name = target[i+1] 21 | team_name = target[i+3] 22 | dic[f"{group_name}#{team_name}#{people_name}"] = cur_rank 23 | i += 4 24 | cur_rank += 1 25 | 26 | 27 | def get_tier(r: int): 28 | return (r-1) // 16 + 1 29 | 30 | 31 | read_in(p_in, p_dict) 32 | read_in(r_in, r_dict) 33 | k = 0 34 | for item in p_dict: 35 | p_rank = p_dict.get(item, 81) 36 | c_rank = r_dict.get(item, 81) 37 | p_tier = get_tier(p_rank) 38 | c_tier = get_tier(c_rank) 39 | if p_tier == 1 and c_tier > 1: 40 | k += 30000 41 | 42 | sin = -1 43 | rr = 90 44 | ans = "" 45 | for item in r_dict: 46 | p_rank = p_dict.get(item, 81) 47 | c_rank = r_dict.get(item, 81) 48 | # print(f"{p_rank} {c_rank}") 49 | ret = 0 50 | if c_rank == 81: 51 | continue 52 | p_tier = get_tier(p_rank) 53 | c_tier = get_tier(c_rank) 54 | 55 | # 1 56 | if p_tier > c_tier: 57 | ret = 10000 * (p_tier - c_tier) 58 | 59 | # 2 60 | if p_tier > 1 and c_tier == 1: 61 | ret += k 62 | 63 | # 3 64 | if c_rank % 16 == 1: 65 | ret += 10000 66 | if p_tier > c_tier: 67 | ret += 10000 68 | 69 | if ret > sin: 70 | sin = ret 71 | ans = item 72 | # print(f"{p_rank} {c_rank} : {item} :: {ret}") 73 | rr = c_rank # 90 74 | elif ret == sin and c_rank < rr: 75 | # print(f"!{c_rank} {rr}") 76 | rr = c_rank 77 | # print(f"!{p_rank} {c_rank} {item} :: {ret}") 78 | ans = item 79 | ans = ans.replace("#", "\n") 80 | print(ans) 81 | -------------------------------------------------------------------------------- /1/3/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.lang.*; 3 | import java.util.*; 4 | class Proc implements Comparable{ 5 | private final int id; 6 | private int time; 7 | private int prio; 8 | Proc(int id,int time,int prio){ 9 | this.id = id; 10 | this.time = time; 11 | this.prio = prio; 12 | } 13 | public int getId(){ 14 | return this.id; 15 | } 16 | public int getPrio(){ 17 | return this.prio; 18 | } 19 | public void execute(){ 20 | this.time -= 1; 21 | this.prio -= 1; 22 | } 23 | public boolean isAbleToExecute(){ 24 | return this.time > 0; 25 | } 26 | 27 | @Override 28 | public int compareTo(Proc o) { 29 | if(this.prio != o.getPrio()) 30 | return o.getPrio() - this.prio; 31 | return this.getId() - o.getId(); 32 | } 33 | 34 | public String toString(){ 35 | return "["+this.id + ", " + this.prio + ", " + this.time + "]"; 36 | } 37 | } 38 | public class Main { 39 | public static void main(String []args) throws IOException { 40 | BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); 41 | String []parse; 42 | parse = bf.readLine().split(" "); 43 | int T = Integer.parseInt(parse[0]); 44 | int n = Integer.parseInt(parse[1]); 45 | PriorityQueue pq = new PriorityQueue<>(); 46 | for(int i=0;i ans: 70 | ans = r + r2 71 | print(ans) -------------------------------------------------------------------------------- /1/1/wrong/infekei_wrong.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | author : infikei 3 | */ 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int R, C, Rg, Cg, Rp, Cp; 10 | vector room; 11 | 12 | void input() { 13 | cin >> R >> C; 14 | cin >> Rg >> Cg >> Rp >> Cp; 15 | for (int i = 0; i < R; i++) { 16 | string tmp; 17 | cin >> tmp; 18 | room.push_back(tmp); 19 | } 20 | } 21 | 22 | int solve() { 23 | int Rp_begin = 0, Cp_begin = 0; 24 | for (int i = 0; i < R; i++) { 25 | // 'P'를 발견한 경우, Rp_begin에 넣음. 26 | // 밑에 break 때문에 무조건 빠져 나오게 되어 있음. 27 | if (room[i].find('P') != string::npos) { 28 | Rp_begin = i; 29 | for (int j = 0; j < C; j++) { 30 | // Cp_begin 은 row 에서 'P'가 시작하는 위치임. 31 | if (room[i][j] == 'P') { 32 | Cp_begin = j; 33 | break; 34 | } 35 | } 36 | break; 37 | } 38 | } 39 | 40 | /* 41 | 이 경우 베개가 차지하고 있는 영역은 Rp_begin, Cp_begin 부터 Rp, Cp만큼임. 42 | 그런데 이 전제가 과연 맞을까? 43 | */ 44 | int Rp_end = Rp_begin + Rp; 45 | int Cp_end = Cp_begin + Cp; 46 | for (int i = Rp_begin; i < Rp_end; i++) { 47 | /* 48 | 한 가지 추가 에러. 만약에 탐색 범위 내에 모두 'P'가 들어가 있는데 49 | C 범위를 넘어서까지 탐색한다면? 이 경우 0이 리턴되는데 틀리는 경우가 있음. (infikei_wrong_1.in) 50 | 본질적인 원인은 좌상단을 잘못 가정해서 생긴 것으로 코너 4쪽에 붙이면 저격 데이터를 생성할 수 있음. 51 | 52 | 좌상, 좌하, 우하에 대해서 잘못 찾는 것도 비슷하게 저격 가능. 53 | */ 54 | if (i >= R) { 55 | return 0; 56 | } 57 | for (int j = Cp_begin; j < Cp_end; j++) { 58 | if (j >= C) { 59 | return 0; 60 | } 61 | 62 | if (room[i][j] != 'P') { 63 | return 1; 64 | } 65 | } 66 | } 67 | return 0; 68 | } 69 | 70 | int main() { 71 | ios_base::sync_with_stdio(false); // C++와 C 두 표준 입출력 동기화를 해제한다. 72 | cout.tie(NULL); 73 | cin.tie(NULL); // 입력과 출력이 묶여있는 것을 풀어준다. 74 | 75 | input(); 76 | 77 | cout << solve() << '\n'; 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /6/06/wrong/gh_wrong_1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | char notes[20202]; 6 | char in[20202]; 7 | vector nn; 8 | vector ii; 9 | int input_note(const char *str, int p); 10 | void process(const char *str); 11 | void process2(const char *str2); 12 | int main(void) 13 | { 14 | scanf("%s\n%s", notes, in); 15 | process(notes); 16 | process2(in); 17 | if((int)nn.size() > (int)ii.size()){ 18 | printf("No\n"); 19 | return 0; 20 | } 21 | int sz = (int)nn.size(); 22 | int lo = (int)ii.size() - (int)nn.size(); 23 | // counter case is example 2 24 | for(int i=0; i ans: 74 | ans = r + r2 75 | print(ans) -------------------------------------------------------------------------------- /5/README.md: -------------------------------------------------------------------------------- 1 | ## 5회 [바로 가기](https://www.acmicpc.net/contest/view/946) 2 | 2023년 04월 02일 13시부터 18시까지 5회 코딩테스트가 열렸습니다. 3 | 4 | |문제 번호|제목|풀러 가기|힌트|난이도| 5 | |:------:|:-------------:|:-----:|:-----:|:-----:| 6 | |A|Gahui and Soongsil University station|[바로가기](https://www.acmicpc.net/problem/27880)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/1)| | 7 | |B|가희와 열리지 않는 건널목|[바로가기](https://www.acmicpc.net/problem/27885)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/2)| | 8 | |C|가희와 노선 건설 놀이|[바로가기](https://www.acmicpc.net/problem/27883)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/3)| | 9 | |D|가희와 서울 지하철 3호선|[바로가기](https://www.acmicpc.net/problem/27884)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/4)| | 10 | |E|Gahui and ILGAM lake|[바로가기](https://www.acmicpc.net/problem/27881)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/5)| | 11 | |F|가희와 지하철역 저장 시스템 1|[바로가기](https://www.acmicpc.net/problem/27888)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/6)| | 12 | |G|가희와 지하철역 저장 시스템 2|[바로가기](https://www.acmicpc.net/problem/27882)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/7)| | 13 | |H|가희와 코드|[바로가기](https://www.acmicpc.net/problem/27887)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/8)| | 14 | |I|가희와 서울 지하철 1호선|[바로가기](https://www.acmicpc.net/problem/27886)|[힌트](https://github.com/cdog-gh/gh_coding_test/tree/main/5/9)| | 15 | 16 | 마지막 업데이트 날짜 : 2025-12-14 00:08:21.710163Z -------------------------------------------------------------------------------- /2/1/gh_sol.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | class myFile implements Comparable{ 5 | private String name; 6 | private String ext; 7 | private int isNotExist; 8 | myFile(String name, String ext){ 9 | this.name = name; 10 | this.ext = ext; 11 | } 12 | public void setIsNotExist(int x){ 13 | this.isNotExist = x; 14 | } 15 | public String getName(){ 16 | return this.name; 17 | } 18 | public String getExt(){ 19 | return this.ext; 20 | } 21 | public int getIsNotExist(){ 22 | return this.isNotExist; 23 | } 24 | @Override 25 | public int compareTo(myFile o) { 26 | if(this.name.compareTo(o.getName()) != 0) 27 | return this.name.compareTo(o.getName()); 28 | if(this.isNotExist!=o.getIsNotExist()) 29 | return this.isNotExist-o.getIsNotExist(); 30 | return this.ext.compareTo(o.getExt()); 31 | } 32 | } 33 | public class Main { 34 | public static void main(String []args) throws IOException { 35 | BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); 36 | String []parse; 37 | List li = new ArrayList<>(); 38 | Map eSet = new HashMap<>(); 39 | parse = bf.readLine().split(" "); 40 | int n = Integer.parseInt(parse[0]); 41 | int m = Integer.parseInt(parse[1]); 42 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #define M 200000LL 6 | using namespace std; 7 | typedef long long ll; 8 | vector vv; 9 | struct event 10 | { 11 | ll a; 12 | ll c; 13 | }; 14 | typedef struct event event; 15 | struct query 16 | { 17 | ll a; 18 | ll b; 19 | ll c; 20 | }; 21 | typedef struct query query; 22 | event e[M+1]; 23 | query q[M+1]; 24 | ll arr[7][3*M+1]; 25 | ll nj[7][3*M+1]; 26 | char str[100]; 27 | char str2[100]; 28 | ll conv(char *str){ 29 | ll ret = 0; 30 | for(ll i=0;str[i];i++){ 31 | if(str[i] < '0' || str[i] > '9') 32 | continue; 33 | ret *= 10; 34 | ret = ret + (str[i] - '0'); 35 | } 36 | return ret; 37 | } 38 | ll CC(ll x1, ll y1, ll x2, ll y2) 39 | { 40 | return nj[x2][y2] - nj[x2][y1-1] - nj[x1-1][y2] + nj[x1-1][y1-1]; 41 | } 42 | int main(void) 43 | { 44 | ll n,Q; scanf("%lld%lld",&n,&Q); 45 | ll YY1, MM1, DD1, hh1, mm1, ss1, lv; 46 | ll YY2, MM2, DD2, hh2, mm2, ss2; 47 | vv.push_back(-1LL); 48 | for(ll i=0;i 2 | #include 3 | #include 4 | #include 5 | #define me 1000000000LL 6 | #define ME 2020202020LL 7 | using namespace std; 8 | typedef long long ll; 9 | struct balloon 10 | { 11 | ll x,y,hp; 12 | }; 13 | typedef struct balloon balloon; 14 | struct att 15 | { 16 | ll x,y,d; 17 | }; 18 | typedef struct att att; 19 | balloon b[200000]; 20 | att a[200000]; 21 | ll _gcd(ll x, ll y) 22 | { 23 | if(y == 0) 24 | return x; 25 | if(x % y == 0) 26 | return y; 27 | return _gcd(y, x%y); 28 | } 29 | ll gcd(ll x,ll y) 30 | { 31 | if(x > y) 32 | return _gcd(x, y); 33 | return _gcd(y, x); 34 | } 35 | vector ve; 36 | void add(ll x, ll y) 37 | { 38 | ll tx = x + me; ll ty = y + me; 39 | ve.push_back(ME*tx + ty); 40 | } 41 | ll f(ll x, ll y) 42 | { 43 | ll tx = x + me; ll ty = y + me; 44 | ll lo = lower_bound(ve.begin(), ve.end(), ME*tx + ty) - ve.begin(); 45 | return lo; 46 | } 47 | priority_queue , greater > pq[500005]; 48 | ll nj_D[500005]; 49 | int main(void) 50 | { 51 | ll n, m; scanf("%lld%lld",&n,&m); 52 | for(ll i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | char notes[20202]; 6 | char in[20202]; 7 | vector nn; 8 | vector ii; 9 | int input_note(const char *str, int p); 10 | void process(const char *str); 11 | void process2(const char *str2); 12 | int main(void) 13 | { 14 | scanf("%s\n%s", notes, in); 15 | process(notes); 16 | process2(in); 17 | if((int)nn.size() > (int)ii.size()){ 18 | printf("No\n"); 19 | return 0; 20 | } 21 | int sz = (int)nn.size(); 22 | int pos = 0; 23 | // int lo = (int)ii.size() - (int)nn.size(); 24 | 25 | for(int i=0; i<(int)ii.size(); i++) 26 | { 27 | //모두 일치한 상태에서 키를 친 경우 28 | if(pos == sz || ii[i] != nn[pos]) pos = 0; 29 | // if(ii[i] == nn[pos]) pos++; 30 | else pos++; 31 | } 32 | if(pos == sz) 33 | printf("Yes\n"); 34 | else 35 | printf("No\n"); 36 | } 37 | int input_note(const char *str, int p) 38 | { 39 | char ch1 = str[p++]; 40 | int dir = -1; 41 | if(ch1 == 'L') 42 | { 43 | char ch2 = str[p++]; 44 | if(ch2 == 'U') dir = 0; 45 | else dir = 6; 46 | } 47 | else if(ch1 == 'R') 48 | { 49 | char ch2 = str[p++]; 50 | if(ch2 == 'U') dir = 2; 51 | else dir = 4; 52 | } 53 | else if(ch1 == 'W') dir = 1; 54 | else if(ch1 == 'D') dir = 3; 55 | else if(ch1 == 'S') dir = 5; 56 | else if(ch1 == 'A') dir = 7; 57 | if(str[p] == '!') {p++; dir = (dir + 4) % 8;} 58 | nn.push_back(dir); 59 | return p; 60 | } 61 | void process(const char *str) 62 | { 63 | int k = 0; 64 | for(int p=0; str[p];){ 65 | p = input_note(str, p); k++; 66 | } 67 | } 68 | void process2(const char *str) 69 | { 70 | for(int i=0; str[i]; i++) 71 | { 72 | if(str[i] == '7') ii.push_back(0); 73 | else if(str[i] == 'W' || str[i] == '8') ii.push_back(1); 74 | else if(str[i] == '9') ii.push_back(2); 75 | else if(str[i] == 'D' || str[i] == '6') ii.push_back(3); 76 | else if(str[i] == '3') ii.push_back(4); 77 | else if(str[i] == 'S' || str[i] == '2') ii.push_back(5); 78 | else if(str[i] == '1') ii.push_back(6); 79 | else ii.push_back(7); 80 | } 81 | } -------------------------------------------------------------------------------- /6/07/gh_sol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define M 202020 6 | #define R 1010101010LL 7 | #define INF 0x3f3f3f3f3f3f3f3fLL 8 | using namespace std; 9 | typedef long long ll; 10 | struct moo 11 | { 12 | ll from, to, c, ti; 13 | }; 14 | typedef struct moo moo; 15 | vector v; 16 | ll p[M + 1]; 17 | ll co[M + 1]; 18 | ll _find(ll x) 19 | { 20 | if(p[x] == -1) 21 | return x; 22 | p[x] = _find(p[x]); 23 | return p[x]; 24 | }; 25 | void _merge(ll a, ll b) 26 | { 27 | ll ta = _find(a); 28 | ll tb = _find(b); 29 | if(ta == tb) return; 30 | p[tb] = ta; 31 | }; 32 | ll f(ll n, ll ti); 33 | bool cmp(moo a, moo b) 34 | { 35 | return a.c < b.c; 36 | }; 37 | int main(void) 38 | { 39 | ll n, m; scanf("%lld%lld", &n, &m); 40 | for(ll i=0; i ret) 58 | le = mid + 1; 59 | else 60 | { 61 | ll k2 = f(n, mid-1); 62 | if(k2 > ret) 63 | { 64 | printf("%lld %lld\n", mid, ret); 65 | return 0; 66 | } 67 | else 68 | ri = mid-1; 69 | } 70 | } 71 | return 0; 72 | } 73 | // ti 에 건설되는 아이까지 고려했을 때, MST calc 74 | ll f(ll n, ll ti) 75 | { 76 | if(ti <= 0) 77 | return INF; 78 | memset(p, -1, sizeof(ll)* M); 79 | ll sumi = 0; 80 | for(ll i=0; i<(ll)v.size(); i++) 81 | { 82 | ll from = v[i].from; ll to = v[i].to; ll tt = v[i].ti; 83 | if(tt > ti) continue; 84 | if(_find(from) == _find(to)) 85 | continue; 86 | _merge(from, to); 87 | sumi += v[i].c; 88 | } 89 | for(ll i=1; i<=n; i++) 90 | { 91 | if(_find(i) != _find(1)) 92 | return INF; 93 | } 94 | return sumi; 95 | } 96 | -------------------------------------------------------------------------------- /6/06/wrong/gh_wrong_2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | char notes[20202]; 6 | char in[20202]; 7 | vector nn; 8 | vector ii; 9 | int input_note(const char *str, int p); 10 | void process(const char *str); 11 | void process2(const char *str2); 12 | int main(void) 13 | { 14 | scanf("%s\n%s", notes, in); 15 | process(notes); 16 | process2(in); 17 | if((int)nn.size() > (int)ii.size()){ 18 | printf("No\n"); 19 | return 0; 20 | } 21 | int sz = (int)nn.size(); 22 | int pos = 0; 23 | // int lo = (int)ii.size() - (int)nn.size(); 24 | 25 | for(int i=0; i<(int)ii.size(); i++) 26 | { 27 | //모두 일치한 상태에서 키를 친 경우 28 | if(pos == sz) pos = 0; 29 | //왜 또 체크할까? 30 | if(ii[i] == nn[pos]) pos++; 31 | else pos = 0; 32 | } 33 | if(pos == sz) 34 | printf("Yes\n"); 35 | else 36 | printf("No\n"); 37 | } 38 | int input_note(const char *str, int p) 39 | { 40 | char ch1 = str[p++]; 41 | int dir = -1; 42 | if(ch1 == 'L') 43 | { 44 | char ch2 = str[p++]; 45 | if(ch2 == 'U') dir = 0; 46 | else dir = 6; 47 | } 48 | else if(ch1 == 'R') 49 | { 50 | char ch2 = str[p++]; 51 | if(ch2 == 'U') dir = 2; 52 | else dir = 4; 53 | } 54 | else if(ch1 == 'W') dir = 1; 55 | else if(ch1 == 'D') dir = 3; 56 | else if(ch1 == 'S') dir = 5; 57 | else if(ch1 == 'A') dir = 7; 58 | if(str[p] == '!') {p++; dir = (dir + 4) % 8;} 59 | nn.push_back(dir); 60 | return p; 61 | } 62 | void process(const char *str) 63 | { 64 | int k = 0; 65 | for(int p=0; str[p];){ 66 | p = input_note(str, p); k++; 67 | } 68 | } 69 | void process2(const char *str) 70 | { 71 | for(int i=0; str[i]; i++) 72 | { 73 | if(str[i] == '7') ii.push_back(0); 74 | else if(str[i] == 'W' || str[i] == '8') ii.push_back(1); 75 | else if(str[i] == '9') ii.push_back(2); 76 | else if(str[i] == 'D' || str[i] == '6') ii.push_back(3); 77 | else if(str[i] == '3') ii.push_back(4); 78 | else if(str[i] == 'S' || str[i] == '2') ii.push_back(5); 79 | else if(str[i] == '1') ii.push_back(6); 80 | else ii.push_back(7); 81 | } 82 | } -------------------------------------------------------------------------------- /2/1/gh_sol_compress_long.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | typedef long long ll; 8 | char str[30]; 9 | char name[11]; 10 | char ext[11]; 11 | struct file 12 | { 13 | ll nn, ee, flag; 14 | }; 15 | typedef struct file file; 16 | vector v; 17 | vector ve; 18 | ll f[128]; 19 | char c[128]; 20 | void init() 21 | { 22 | for(ll i=0;i<26;i++) 23 | f[i + 'a'] = i + 11; 24 | for(ll i=0;i<10;i++) 25 | f[i + '0'] = i + 1; 26 | for(ll i=127; i>=0; i--) 27 | c[f[i]] = (char)i; 28 | } 29 | ll foo(char *tar) 30 | { 31 | ll ret = 0; 32 | for(ll i=0;i<10;i++) 33 | { 34 | ret = ret*64 + f[tar[i]]; 35 | } 36 | return ret; 37 | } 38 | void conv(char *tar, ll x) 39 | { 40 | ll cur = x; 41 | //64진법 42 | for(ll i=9; i>=0; i--) 43 | { 44 | tar[i] = c[cur&63LL]; 45 | cur = (cur>>6LL); 46 | } 47 | } 48 | bool cmp(file a, file b) 49 | { 50 | if(a.nn != b.nn) 51 | return a.nn < b.nn; 52 | if(a.flag != b.flag) 53 | return a.flag > b.flag; 54 | return a.ee < b.ee; 55 | } 56 | int main(void) 57 | { 58 | ll n,m; scanf("%lld %lld\n",&n,&m); init(); file I; 59 | 60 | for(ll i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | typedef long long ll; 6 | struct moo 7 | { 8 | ll to, c; 9 | }; 10 | typedef struct moo moo; 11 | vector con[404040]; 12 | ll pp[404040]; 13 | ll depth[404040]; 14 | vector pv; 15 | vector dv; 16 | vector cc; 17 | ll compressed[404040]; 18 | ll C[404040]; 19 | ll combi_two(ll n) 20 | { 21 | return ((n * (n-1)) >> 1LL); 22 | } 23 | void dfs(ll cur, ll par, ll nn); 24 | int main(void) 25 | { 26 | ll n; scanf("%lld", &n); // printf("n = %lld\n", n); 27 | for(ll i=1; i event = new ArrayList<>(); 8 | String []parse; 9 | parse = bf.readLine().split(" "); 10 | int n = Integer.parseInt(parse[0]); 11 | int Q = Integer.parseInt(parse[1]); 12 | 13 | String []eventIdx = new String[n]; 14 | int []eventLv = new int[n]; 15 | 16 | String []queryS = new String[Q]; 17 | String []queryE = new String[Q]; 18 | int []queryLv = new int[Q]; 19 | 20 | int [][]arr = new int[7][n + 2*Q + 1]; 21 | int [][]nj = new int [7][n + 2*Q + 1]; 22 | event.add(""); 23 | for(int i=0;i 7: 36 | dic[items[5]] = float(items[6]) 37 | return dic 38 | 39 | 40 | def time_to_num(time): 41 | return 60 * int(time[0:2]) + int(time[3:5]) 42 | 43 | 44 | # 경부선 역 정보 얻어오기. 45 | gb_info = init_gyeongbu_line_station_info() 46 | n, q = map(int, my_input().split(' ')) 47 | s_dic = {} 48 | s_list = [] 49 | for i in range(n): 50 | # station_name hh:mm hh:mm 51 | dia = my_input().split(' ') 52 | s_list.append(dia[0]) 53 | s_dic[dia[0]] = tuple(dia) 54 | 55 | for i in range(q): 56 | s = my_input().split(' ') 57 | s[1] = s[1].replace('\n', '') 58 | 59 | # 거리 구하기 60 | dist = abs(gb_info[s[1]] - gb_info[s[0]]) 61 | # 시간 구하기 62 | t0 = time_to_num(s_dic[s[0]][2]) # 출발 시각 63 | t1 = time_to_num(s_dic[s[1]][1]) # 도착 시각 64 | if t0 > t1: 65 | t1 = t1 + 24 * 60 66 | delta_min = t1 - t0 67 | ans = (dist * 60) / delta_min 68 | print(f'{ans:.10f}') 69 | --------------------------------------------------------------------------------