목록알고리즘 풀이 (63)
하다보니
n=int(input()) board=[] num=[0]*3 for _ in range(n): board.append(list(map(int,input().split()))) def check(x,y,n): for i in range(x,x+n): for j in range(y,y+n): if board[x][y]!=board[i][j]: return False return True def func(x,y,z): if check(x,y,z): num[board[x][y]+1]+=1 return n=z//3 for i in range(3): for j in range(3): func(x+n*i,y+n*j,n) func(0,0,n) for i in range(3): print(num[i]) - c++ /* ..
와...이 문제는 진짜 간단해 보였고 코드도 짰는데 이상할정도로 로직이 이해가 안가서 며칠 답답했음..휴....그래도 좀 감이 잡혀서 코드 작성하고 제출했따.... - c++ #include #include #define X first #define Y second using namespace std; int main() { int n; long long ans = 0; cin >> n; stack S; while (n--) { int height; cin >> height; int cnt = 1; while (!S.empty() && S.top().X
n=int(input()) stack=[] ans=0 for i in range(n): h=int(input()) while stack!=[] and stack[-1]
#include using namespace std; int func(int n,int r,int c) { if (n == 0)return 0; int half = 1 = half)return half*half+func(n - 1, r, c - half); if (r >= half && c = half && c >= half)return half * half * 3 + func(n - 1, r - half, c - half); } int main() { int n, r, c; cin >> n >> r >> c; cout
#include using namespace std; void func(int i,int j, int n) { if (n == 1) { cout
처음에 제출한 코드 /* F층으로 이루어진 고층 건물, S는 현재 강호 위치, G는 도착지, U는 위로 U층 가는 버튼, D는 아래로 D층 가는 버튼. U와 D버튼만으로 도착지까지 이동을 한다.최소 몇 번을 눌러야 하는가? */ #include using namespace std; int vis[1000002]; int main() { int f, s, g, u, d; cin >> f >> s >> g >> u >> d; if (s == g) { cout f || dx 0)continue; Q.push(dx); vis[dx] = vis[cur]+1; } cout > f >> s >> g >> u >> d; queue q; fill(vis+1, vis + f+1, -1); q..
#include #define X first #define Y second using namespace std; int board[1002][1002]; int dist_f[1002][1002]; int dist_s[1002][1002]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while (n--) { queue Qf = {}; queue Qs = {}; bool flag = false; int w, h; cin >> w >> h; for (int i = 0; i < h; i++) { fill(dist_f[i], dist_f[i] +..
- c++ #include using namespace std; using li = long long; li pow(li a, li b, li c) { if (b == 1)return a % c; li val = pow(a, b / 2, c); val = val * val%c; if (b % 2 == 0)return val; return val * a%c; } int main() { ios::sync_with_stdio(0); cin.tie(0); li a, b, c; cin >> a >> b >> c; cout
#include #define X first #define Y second using namespace std; int board[102][102]; int vis[102][102]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; int main() { ios::sync_with_stdio(0); cin.tie(0); int m, n, k;//m은 세로, n은 가로, k는 사각형 개수 queue Q; vector v; cin >> m >> n >> k; while (k--) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; for (int i = x1; i < x2; i++) { for (int j = y1; j < ..
#include #define X first #define Y second using namespace std; int dx[8] = { 2,-2,1,-1,2,-2,1,-1 }; int dy[8] = { 1,1,2,2,-1,-1,-2,-2 }; int board[302][302]; int vis[302][302]; int main() { int n;//테스트 케이스 cin >> n; while (n--) { queue Q; int l;//체스판의 한 변의 길이 cin >> l; for (int i = 0; i > a >> b;//출발지 cin >> c >> d;//도착지 Q.push({ a,b });..