백준(C, C++)/골드 24

백준 22116: 창영이와 퇴근 [C/C++]

https://www.acmicpc.net/problem/22116 22116번: 창영이와 퇴근 A1,1에서 AN,N까지, 경로상의 최대 경사의 최솟값을 출력한다. www.acmicpc.net #include static const auto fastio = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }(); using namespace std; int n; int grid[1111][1111]; int visited[1111][1111]; int dy[4] = {0, 1, 0, -1}; int dx[4] = {1, 0, -1, 0}; int dp[1111][1111]; in..

백준 4342: 유클리드 게임 [C/C++]

https://www.acmicpc.net/problem/4342 4342번: 유클리드 게임 유클리드 게임은 두 명이서 하는 게임이고, 자연수 2개로 시작한다. 동혁이와 동규는 유클리드 게임을 하려고 한다. 동혁이가 먼저 시작한다. 동혁이는 큰 수를 작은 수의 배수만큼 뺀다. 이때, www.acmicpc.net 코드 #include #define endl "\n" #define ll long long static const auto fastio = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }(); using namespace std; ll GCD(ll a, ll b){ i..

백준 1863: 스카이라인 쉬운거 [C/C++]

https://www.acmicpc.net/problem/1863 1863번: 스카이라인 쉬운거 첫째 줄에 n이 주어진다. (1 ≤ n ≤ 50,000) 다음 n개의 줄에는 왼쪽부터 스카이라인을 보아 갈 때 스카이라인의 고도가 바뀌는 지점의 좌표 x와 y가 주어진다. (1 ≤ x ≤ 1,000,000. 0 ≤ y ≤ 500,000) 첫 www.acmicpc.net #include #include using namespace std; int n, t, ans; int m[55555]; static const auto fastio = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; ..

백준 2624: 동전 바꿔주기 [C/C++]

https://www.acmicpc.net/problem/2624 2624번: 동전 바꿔주기 명보네 동네 가게의 현금 출납기에는 k 가지 동전이 각각 n1, n2, … , nk개 씩 들어있다. 가게 주인은 명보에게 T원의 지폐를 동전으로 바꿔 주려고 한다. 이때, 동전 교환 방법은 여러 가지가 있을 www.acmicpc.net 코드 #include using namespace std; int n, k; int c[111], m[111]; int dp[11111]; int main() { cin >> n >> k; for (int i = 0; i > c[i] >> m[i]; dp[0] = 1; for (int i = 0; i = 0; j--) { if (dp[j]) { for (int l = 1; l

백준 1041: 주사위

https://www.acmicpc.net/problem/1041 1041번: 주사위 첫째 줄에 N이 주어진다. 둘째 줄에 주사위에 쓰여 있는 수가 주어진다. 위의 그림에서 A, B, C, D, E, F에 쓰여 있는 수가 차례대로 주어진다. N은 1,000,000보다 작거나 같은 자연수이고, 쓰여 있는 수 www.acmicpc.net 코드 #include #include #define ll unsigned long long using namespace std; int N; ll a, b, c, d, e, f; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> N; cin >> a >> b >> c >> d >> e >> f; ll m..

백준 23832: 서로소 그래프

https://www.acmicpc.net/problem/23832 23832번: 서로소 그래프 우석이는 심심할 때마다 그래프를 그린다. 우석이는 매달 새로운 그래프를 그리는데, 이번 달에는 서로소 그래프를 그린다. 서로소 그래프는 $1$부터 $N$까지의 번호를 가진 $N$ 개의 정점으로 이 www.acmicpc.net 코드 #include using namespace std; #define ull unsigned long long int ull Power(__int128 x, __int128 y, __int128 mod) { x %= mod; ull ret = 1; while(y > 0) { if(y%2 == 1) ret = (ret*x)%mod; x = (x*x)%mod; y /= 2; } retur..

백준 12904: A와 B [C/C++]

https://www.acmicpc.net/problem/12904 12904번: A와 B 수빈이는 A와 B로만 이루어진 영어 단어가 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수 www.acmicpc.net 코드 #include #include #include #define fastio() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; string s, t; int ss, tt; int main() { fastio(); cin >> s >> t; ss = s.size() - 1; tt =..

백준 2015: 수들의 합 4 [C/C++]

https://www.acmicpc.net/problem/2015 2015번: 수들의 합 4 첫째 줄에 정수 N과 K가 주어진다. (1 ≤ N ≤ 200,000, |K| ≤ 2,000,000,000) N과 K 사이에는 빈칸이 하나 있다. 둘째 줄에는 배열 A를 이루는 N개의 정수가 빈 칸을 사이에 두고 A[1], A[2], ..., A[N]의 순서로 www.acmicpc.net #include #include #define fastio() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; long long n, k, cnt, lis[202020], acc[202020]; map m; int main() { fastio(); cin ..

백준 1405: 미친 로봇 [C/C++]

https://www.acmicpc.net/problem/1405 1405번: 미친 로봇 첫째 줄에 N, 동쪽으로 이동할 확률, 서쪽으로 이동할 확률, 남쪽으로 이동할 확률, 북쪽으로 이동할 확률이 주어진다. N은 14보다 작거나 같은 자연수이고, 모든 확률은 100보다 작거나 같은 자 www.acmicpc.net #include #define fastio() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; long double N, w[4]; // 동, 서, 남, 북 int visited[30][30]; // 방문 여부 확인 int dy[4] = {0, 0, 1, -1}; // 동서남북 int dx[4] = {1, -1, 0, ..

백준 1744: 수 묶기 [C/C++], 다이나믹 프로그래밍

https://www.acmicpc.net/problem/1744 1744번: 수 묶기 길이가 N인 수열이 주어졌을 때, 그 수열의 합을 구하려고 한다. 하지만, 그냥 그 수열의 합을 모두 더해서 구하는 것이 아니라, 수열의 두 수를 묶으려고 한다. 어떤 수를 묶으려고 할 때, 위치에 www.acmicpc.net #include #include #include #define fastio() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; int N; vector lis; vector dp; void input(); long long dfs(int i, int val); int main() { fastio(); input(); co..