-
[BOJ] 4485 : 녹색 옷 입은 애가 젤다지?
4485 : 녹색 옷 입은 애가 젤다지? 풀이 lulu lala 코드 #include <cstdio> #include <queue> #include <algorithm> using namespace std; const int dx[] = { 0,0,-1,1 }; const int dy[] = { -1,1,0,0 }; int n, t, x, a[133][133], d[133][133]; struct abc { int x, y, c; bool operator <(abc a)const { return c > a.c; } }; int main() { for (scanf("%d", &n); n; scanf("%d", &n)) { for (int i = 1; i <=...
-
[BOJ] 10986 : 나머지 합
10986 : 나머지 합 풀이 (a[i] + ... + a[j]) % m = 0의 필요충분조건은 (a[1]+...+a[j]) % m = (a[1]+...+a[i-1]) % m이다. 오잉? 주어진 문제가 나머지가 x인 prefix sum의 개수를 k라고 할 때, k에서 2개를 고르는 경우의 수들의 합을 구하는 문제로 바뀌었다. 코드 #include <cstdio> typedef long long ll; int n, m, x; ll r, s, a[1002]={1}; int main() { scanf("%d %d", &n, &m); while (n--) scanf("%d", &x), a[s=(s+x)%m]++; while (m--) r+=(a[m]*(a[m]-1))/2; printf("%lld", r); return...
-
[BOJ] 14585 : 사수빈탕
14585 : 사수빈탕 풀이 코드 #include <cstdio> typedef long long ll; int n, m, x; ll r, s, a[1002]={1}; int main() { scanf("%d %d", &n, &m); while (n--) scanf("%d", &x), a[s=(s+x)%m]++; while (m--) r+=(a[m]*(a[m]-1))/2; printf("%lld", r); return 0; } 아무말 백준, 백준 온라인 저지, BOJ, Baekjoon Online Judge, C, C++, 씨, 씨쁠쁠, JAVA, algorithm, 자바, 알고리즘, 자료구조, 문제, 문제 풀이, 풀이
-
[BOJ] 10282 : 해킹
10282 : 해킹 풀이 안녕하세요 다욱스트라입니다 코드 #include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; int n, m, s; struct edg { int idx, dst; bool operator <(edg A)const { return dst > A.dst; } }; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int tc; for (cin >> tc; tc; tc--) { cin >> n >> m >> s; vector<vector<edg> > gph(n+1); vector<int> dst(n+1, 1e9); priority_queue<edg> pq; for (int i = 0, u, v,...
-
[BOJ] 2056 : 작업
2056 : 작업 풀이 간단한 다이나믹으로 풀어도 되고 위상정렬스럽게 풀어도 된다 코드 #include <cstdio> #include <algorithm> using namespace std; int n, res, dp[10001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int c, m, x; scanf("%d %d", &c, &m); for (int j = 0; j < m; j++) { scanf("%d", &x); dp[i] = max(dp[i], dp[x]); } res = max(res, dp[i] += c); } printf("%d", res); return 0; }...
-
[BOJ] 2344 : 거울
2344 : 거울 풀이 매일 가슴이 갈라져요 숨이 다 끊어질만큼 울어요 수 천 번 잊었다 외쳐봐도 내 삶은 어느새 벼랑 끝에 서있네요 코드 #include <cstdio> #include <cstring> #define R(N) for(int i=1;i<=N;i++) int n, m, a[1002][1002], num[1002][1002], res[4004]; void go(int x, int y, int s, int d, int cnt) { int dx[] = { -1*s,0 }, dy[] = { 0,+1*s }; while (a[x][y] != -1) { if (a[x][y] == 1) d = (d+1)%2; x += dx[d],...
-
[BOJ] 15686 : 치킨 배달
15686 : 치킨 배달 풀이 삼성 인사 담당자님, 모든 경우의 수를 다 돌려보면 된답니다. 코드 #include <cstdio> #include <vector> #include <algorithm> using namespace std; int n, m, x, chk[14]; vector<pair<int, int> > a, b; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &x); if (x == 1) a.push_back({ i,j }); if (x == 2) b.push_back({...
-
[BOJ] 2234 : 성곽
2234 : 성곽 풀이 안 돼요 더는 못해요 그대 없이 사는 일 나 때문에 그대 망가진다며 이별을 원한 건 나인데 코드 #include <cstdio> const int dx[] = { 0,-1,0,1 }; const int dy[] = { -1,0,1,0 }; int n, m, a[55][55], c[55][55], cnt[55*55]; int dfs(int x, int y, int num) { int ret = 1; c[x][y] = num; for (int i = 0; i < 4; i++) { int nx = x+dx[i], ny = y+dy[i];...
-
[BOJ] 5214 : 환승
5214 : 환승 풀이 이번 역은 욱제 욱제 역입니다. 수찬이나 사과역으로 갈아타실 고객께서는 이번 역에서 내리시기 바랍니다. 코드 #include <stdio.h> #include <vector> #include <algorithm> #include <queue> using namespace std; const int n_ = 1e5 + 1e3 + 1; int n, k, m, a, i, j, chk[n_]; queue<int> que; vector<int> gph[n_]; int main() { scanf("%d %d %d", &n, &k, &m); for (i = n + 1; i <= n + m; i++) { for (j =...
-
[BOJ] 14465 : 소가 길을 건너간 이유 5
14465 : 소가 길을 건너간 이유 5 풀이 졸리당 코드 #include <cstdio> int n, m, k, cnt, res = 1e9, a[200001]; int main() { scanf("%d %d %d", &n, &m, &k); while (k--) { int x; scanf("%d", &x); a[x+m] = 1; } for (int i = 1; i <= n; i++) { cnt += a[i+m], cnt -= a[i]; if (i >= m && cnt < res) res = cnt; } printf("%d", res); return 0; } 아무말...