-
[BOJ] 11277 : 2-SAT - 1
11277 : 2-SAT - 1 풀이 참 아프다 네가 너무 아프다 너를 닮은 이 시린 가을이 오면 보고 싶어서 너를 안고 싶어서 가슴이 너를 앓는다 코드 #include <cstdio> #include <stack> #include <vector> #include <algorithm> using namespace std; typedef vector<int> vi; const int n_ = 20*2+2; int n, m, cnt, scc[n_], chk[n_], ans[n_]; vi gph[n_]; vector<vi> res; stack<int> stk; int getSCC(int now) { chk[now] = ++cnt; int ret = chk[now]; stk.push(now); for (int nxt : gph[now])...
-
[BOJ] 3648 : 아이돌
3648 : 아이돌 풀이 사랑도 그러게 별 수 없나봐 언제 그랬냐는 듯 계절처럼 변해가 그리워져 미치도록 사랑한 그날들이 내 잃어버린 날들이 참 많이 웃고 울었던 그때 그 시절의 우리 네가 떠올라 밤새 코드 #include <cstdio> #include <stack> #include <vector> #include <algorithm> using namespace std; typedef vector<int> vi; const int n_ = 1000*2+2; int n, m, cnt, scc[n_], chk[n_], ans[n_]; vi gph[n_]; vector<vi> res; stack<int> stk; int getSCC(int now) { chk[now] = ++cnt; int ret =...
-
[BOJ] 2207 : 가위바위보
2207 : 가위바위보 풀이 어떠니 잘 지냈니 지난 여름 유난히도 힘에 겹더라 올핸 새벽녘엔 제법 쌀쌀한 바람이 어느덧 네가 좋아하던 그 가을이 와 코드 #include <cstdio> #include <stack> #include <vector> #include <algorithm> using namespace std; typedef vector<int> vi; const int n_ = 10000*2+2; int n, m, cnt, scc[n_], chk[n_], ans[n_]; vi gph[n_]; vector<vi> res; stack<int> stk; int getSCC(int now) { chk[now] = ++cnt; int ret = chk[now]; stk.push(now); for (int nxt : gph[now]) { if...
-
[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({...