SSENI's
search
sseni
말하는 감자에서 자라기
Today
Yesterday
전체 글 (290)
#include #include using namespace std; int n, x; priority_queue pq; // 우선순위 큐 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; while (n--) { cin >> x; if (x == 0) { // pq.size() 로도 가능 if (pq.empty()) cout
#include #include using namespace std; const int MAX = 1001; queue Q; int map[MAX][MAX] = { 0, }; bool visit[MAX] = { 0, }; int n, m, cnt = 0; int s, f; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i > s >> f; map[s][f] = 1; map[f][s] = 1; } for (int i = 1; i
#include #include using namespace std; int n, x; priority_queue pq; // 우선순위 큐 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; while (n--) { cin >> x; if (x == 0) { if (pq.empty()) cout
#include #include #include using namespace std; int n, s, f; vector v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i > s >> f; v.push_back(make_pair(f, s)); // (끝, 시작) } sort(v.begin(), v.end()); int t = v[0].first; // 끝나는 시간 int cnt = 1; for (int i = 1; i < n; i++) { if (t
#include using namespace std; int n; int paper[128][128]; int p1, p2; void f(int x, int y, int size) { int check = paper[x][y]; for (int i = x; i < x + size; i++) { for (int j = y; j < y + size; j++) { if (check == 0 && paper[i][j] == 1) check = 2; else if (check == 1 && paper[i][j] == 0) check = 2; if (check == 2) { f(x, y, size / 2); f(x, y + size / 2, size / 2); f(x + size / 2, y, size / 2); ..
#include #include using namespace std; int n, time; int arr[1001]; //사람 번호, 걸리는 시간 int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i > tmp; arr[i] = tmp; } sort(arr, arr+n); for (int i = 0; i < n; i++) { time += arr[i] * (n-i); } cout
#include #include using namespace std; // 걷기 : 1초 후에 x-1 or x+1 이동 // 순간이동 : 1초 후에 2*x 이동 const int Max = 100001; int n, k, fl, fs; bool isVisit[Max]; queue Q; int main(void) { cin >> n >> k; Q.push(make_pair(n, 0)); isVisit[n] = true; while (!Q.empty()) { fl = Q.front().first; fs = Q.front().second; Q.pop(); if (fl == k) break; if (fl + 1 < Max && !isVisit[fl + 1]) { // +1 Q.push(make_pair(fl +..
import sys from collections import deque limit = 100001 def solve(arr, n, k): q = deque() q.append(n) while q: i = q.popleft() if i == k: return arr[i] for j in (i+1, i-1, 2*i): if (0
보관 후, 하루가 지나면 익은 토마토의 인접한 곳에 익지 않은 토마토들은 익게 됨 (인접한 곳 - 왼, 오, 앞, 뒤) 혼자 저절로 익는 경우는 없음 며칠이 지나면 다 익게 되는가? m,n - 상자 가로, 세로 1 - 익은 토마토 0 - 익지 않은 토마토 -1 - 토마토가 들어있지 않음 최소 날짜 출력 (모든 토마토 익어있음 = 0, 모두 익지 못함 = -1) #include #include using namespace std; int m, n, cnt; int map[1001][1001]; bool isVisit[1001][1001]; int dr[4] = { -1,1,0,0 }; int dc[4] = { 0,0,-1,1 }; queue Q; int main(void) { ios::sync_with_s..
## BFS (너비 우선 탐색) - Queue 이용 #include #include using namespace std; int virus[101][101]; int visit[101]; int c, n, cnt; int main(void) { cin >> c; cin >> n; for (int i = 0; i > s >> f; virus[s][f] = 1; virus[f][s] = 1; } visit[1] = 1; queue Q; Q.push(1); while (!Q.empty()) { int node = Q.front(); Q.pop(); for (int i = 1; i
#include using namespace std; long long fibo[50] = { 0,1, }; // 0 개수 : 1 0 1 1 2 3 5 ... = 맨 앞이 1이고 다음부터 0부터 시작하는 피보나치 // 1 개수 : 0 1 1 2 3 5 ... = 0부터 시작하는 피보나치 int fibonacci(int n) { if (n == 0 || n == 1) return fibo[n]; if (fibo[n] == 0) return fibo[n] = fibonacci(n - 1) + fibonacci(n - 2); else return fibo[n]; } int main(void) { int t; cin >> t; while (t--) { int n; cin >> n; if (n == 0) cout
#include #include #include using namespace std; int n, m; vector v; bool binary_search(int low, int high, string name) { if (low > high) return false; else { int mid = (low + high) / 2; if (name == v[mid]) return true; else if (v[mid] > name) return binary_search(low, mid - 1, name); else return binary_search(mid + 1, high, name); } } int main(void) { cin >> n >> m; for (int i = 0; i < n; i++) {..
#include #include #include #include #include using namespace std; int n, m; int result; char str[21]; map mp1; // 문자열 기준 정렬 string mp2[100001]; // 번호 기준 정렬 int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // 포켓몬 입력 cin >> n >> m; for (int i = 0; i > tmp; mp1.insert(pair(tmp, i)); mp2[i] = tmp; } // 문자열 또는 번호 검색 for (int i = 0; i < m; ..
#include #include using namespace std; /* 비트 마스킹 문제 bit | (1 cal; if (cal == "add") { cin >> x; bit |= (1 > x; bit &= ~(1 > x; if (bit & (1
#include #include using namespace std; //가로길이 m = 열, 세로길이 n = 행 //BFS(Breadth-first search) : 너비우선탐색 - 인접한 노드 먼저(얕은 노드 -> 깊은 노드) //DFS(Depth-First Search) : 깊이우선탐색 - //큐 - FIFO 이용 //1. 타겟 발견 //2. 맵 벗어났나 //3. 이미 방문한 타겟인가 int t; int m, n, k; int map[50][50]; bool visit[50][50]; int result; queue Q; int dr[4] = { -1,1,0,0 }; int dc[4] = { 0,0,-1,1 }; int main() { cin >> t; while (t--) { cin >> m >>..
import sys t = int(sys.stdin.readline()) dr = [1, -1, 0, 0] dc = [0, 0, -1, 1] for i in range(t): m, n, k = map(int, sys.stdin.readline().split()) cabbage = [[0] * m for cb in range(n)] cnt = 0 for j in range(k): c, r = map(int, sys.stdin.readline().split()) cabbage[r][c] = 1 for q in range(n): for w in range(m): if cabbage[q][w] == 1: queue = [[q, w]] while queue: fr, fc = queue[0][0], queue[0]..
import sys from collections import defaultdict n, m, b = map(int, sys.stdin.readline().split()) dic = defaultdict(int) # default값이 int인 딕셔너리 for i in range(n): for j in list(map(int, input().split())): dic[j] += 1 print(dic) key = list(dic.keys()) bot = min(key) top = max(key) cnt = int(1e9) h = 0 for x in range(bot, top+1): count, have = 0, b for y in dic.keys(): if x > y: count += (x - y) * di..
import sys n = int(sys.stdin.readline()) arr = [int(sys.stdin.readline()) for _ in range(n)] negative = [] positive = [] ans = 0 for a in arr: if a 1: positive.append(a) negative.sort() positive.sort(reverse=True) for i in range(0,len(negative), 2): if i+1 < len(negative): ans += negative[i] * negative[i+1] else: ans += negative[i] for i in range(0,len(positive), 2): if i+1 < len(positive): ans ..
N = int(input()) f = 1 for i in range(1, N+1): f *= i f %= 1000000000000 while f % 10 == 0: f /= 10 print(int(f % 10))