실수모음
-
이분탐색에서 구간 [lo, hi]에 답이 없는 경우는 예외처리할 것실수모음 2024. 1. 29. 17:59
lo와 hi 범위 안에 avail이 true인게 반드시 존재해야 함. 그렇지 않으면 예외처리 할 것. // binary search sudo code lo, hi ← (답이 될 수 있는 가장 작은 값), (답이 될 수 있는 가장 큰 값) ans ← (답이 될 수 없는 값) while lo ≤ hi: mid = (lo+hi)/2 if avail(mid): ans = mid hi = mid - 1 // 경우에 따라 lo = mid + 1 else: lo = mid + 1 // 경우에 따라 hi = mid - 1 Problem - E - Codeforces codeforces.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27..
-
테스트케이스가 있는 문제에서 배열 초기화는 사용한 만큼만 하자실수모음 2023. 11. 15. 00:01
최대 경우에 대해 매 테스트케이스마다 초기화 하면 초기화하다가 시간 다감
-
dfs를 이용한 완탐시, 방문 해제 모두 하고 return true실수모음 2023. 10. 24. 18:05
9944번: NxM 보드 완주하기 N×M 보드 위에서 할 수 있는 게임이 있다. 보드는 크기가 1×1인 정사각형 칸으로 나누어져 있다. 보드의 각 칸은 빈 칸 또는 장애물이다. 장애물은 아래 그림에선 어두운 사각형으로 표시되어져 www.acmicpc.net 틀린 코드(42번째 줄에서 바로 return true 하면 안됨) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 7..
-
또~~~~ 버 플로우(경우를 세는 경우 오버플로우 날 수 있다)실수모음 2023. 10. 17. 13:12
3079번: 입국심사 첫째 줄에 N과 M이 주어진다. (1 ≤ N ≤ 100,000, 1 ≤ M ≤ 1,000,000,000) 다음 N개 줄에는 각 심사대에서 심사를 하는데 걸리는 시간인 Tk가 주어진다. (1 ≤ Tk ≤ 109) www.acmicpc.net 틀림(22번째 줄에서 오버플로우 남) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include #define endl '\n' // don't use when you cover interactive problem #define all(v) v.begin(), v.end() using namespace std; typedef lon..
-
지문을 멋대로 해석해버린 예시실수모음 2023. 9. 22. 15:55
일반화의 오류 순서쌍의 위치에 의미가 있을것이라고 생각 순서쌍에 대한 배경지식이 작용하여 순서쌍의 각 위치에도 의미(순서쌍의 첫 번째 오는 팀이 상대적인 순위가 더 높아졌다고 착각)가 있을것이라고 생각했다. 예시를 보고 이해하되, 그 예시가 강조하고 싶었던 것이 무었이었는지 다시 한번 상기하자. 2 1 2 1 1 2 답 : 2 1 오답 : 1 2 3665번: 최종 순위 올해 ACM-ICPC 대전 인터넷 예선에는 총 n개의 팀이 참가했다. 팀은 1번부터 n번까지 번호가 매겨져 있다. 놀랍게도 올해 참가하는 팀은 작년에 참가했던 팀과 동일하다. 올해는 인터넷 예선 본부에 www.acmicpc.net 물리적으로 한 칸씩 움직일것이라고 생각(이 또한 문제를 잘못 읽은 것이었음....) 문제가 일상에서 볼 수 있..
-
-
1차원 dp를 사용할 땐, 중복 갱신에 주의해야 함(경우에 따라 역순으로 갱신할것)실수모음 2023. 8. 28. 14:29
12865번: 평범한 배낭 첫 줄에 물품의 수 N(1 ≤ N ≤ 100)과 준서가 버틸 수 있는 무게 K(1 ≤ K ≤ 100,000)가 주어진다. 두 번째 줄부터 N개의 줄에 거쳐 각 물건의 무게 W(1 ≤ W ≤ 100,000)와 해당 물건의 가치 V(0 ≤ V ≤ 1,000) www.acmicpc.net 잘못된 코드(19번째 줄에서 dp[w - weight] 이라서 역순으로 갱신해야 함) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include #define endl '\n' // don't use when you cover interactive problem using namespace std; typedef pai..