From: Skullheadx <704277@pdsb.net> Date: Fri, 6 Jan 2023 20:38:07 +0000 (-0500) Subject: 2020 S2 attempt 1 X-Git-Url: http://git.skullheadx.com/tech/index.html?a=commitdiff_plain;h=8e3fab2aee251e46f3a005cb8b98b127f6f83533;p=CCC.git 2020 S2 attempt 1 --- diff --git a/Main/C++/2020/S2.cpp b/Main/C++/2020/S2.cpp new file mode 100644 index 0000000..42873dd --- /dev/null +++ b/Main/C++/2020/S2.cpp @@ -0,0 +1,90 @@ +#include +using namespace std; + + +vector get_factors(int n) +{ + vector output; + for (int i = 1; i < 1 + sqrt(n); i++) + { + if (n % i == 0) + { + output.push_back(i); + } + } + return output; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int M, N; + cin >> M; + cin >> N; + + vector> room; + int temp; + + for (int i = 0; i < M;i++) + { + vector v; + for (int j = 0; j < N; j++) + { + cin >> temp; + v.push_back(temp); + } + room.push_back(v); + } + + queue> q; + q.push({0,0}); + vector> seen; + + while (!q.empty()) + { + vector current = q.front(); + q.pop(); + + if (find(seen.begin(), seen.end(), current) != seen.end()) + { + continue; + } + else + { + seen.push_back(current); + } + + int r = current[0]; + int c = current[1]; + + if (r == M -1 && c == N-1) + { + cout << "yes" << endl; + return 0; + } + + int n = room[r][c]; + vector factors = get_factors(n); + + + for (int i = 0; i < factors.size(); i++) + { + int row = factors[i] - 1; + int col = n / factors[i] - 1; + if ( 0 <= row && row < M && 0 <= col && col < N) + { + q.push({row, col}); + } + if ( 0 <= col && col < M && 0 <= row && row < N) + { + q.push({col, row}); + } + + } + + + } + cout << "no" << endl; + return 0; +} diff --git a/Main/Python/2020/S2.py b/Main/Python/2020/S2.py new file mode 100644 index 0000000..83c852d --- /dev/null +++ b/Main/Python/2020/S2.py @@ -0,0 +1,51 @@ +from queue import Queue +from math import sqrt +# from functools import lru_cache + + +# @lru_cache() +def get_factors(n): + output = [] + for i in range(1, 1 + int(sqrt(n))): + if n % i == 0: + output.append(i) + # output.append(n / i) + return output + + +M = int(input()) +N = int(input()) + +room = [] +for i in range(M): + room.append(tuple(map(int, input().split()))) + +q = Queue() + +q.put((0, 0)) + +seen = set() + +while not q.empty(): + r, c = q.get() + + if (r, c) in seen: + continue + else: + seen.add((r, c)) + + if r == M - 1 and c == N - 1: + print("yes") + quit() + + n = room[r][c] + for factor in get_factors(n): + row, col = int(factor - 1), int(n / factor - 1) + if 0 <= row < M and 0 <= col < N: + q.put((row, col)) + + if 0 <= col < M and 0 <= row < N: + q.put((col, row)) + + +print("no") diff --git a/Main/Python/2021/S2.py b/Main/Python/2021/S2.py new file mode 100644 index 0000000..d6d1262 --- /dev/null +++ b/Main/Python/2021/S2.py @@ -0,0 +1,26 @@ +M = int(input()) +N = int(input()) +K = int(input()) + +commands = set() + +rows = 0 +cols = 0 + +for i in range(K): + a, b = input().split() + c = (a, int(b)) + if c in commands: + commands.remove(c) + if a == "R": + rows -= 1 + elif a == "C": + cols -= 1 + else: + commands.add(c) + if a == "R": + rows += 1 + elif a == "C": + cols += 1 + +print(rows * N + (M - rows) * cols - rows * cols)