Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp] swea1974 #14

Merged
merged 2 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions minjae9610/SWEA/D2/swea1974/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# [[D2] μŠ€λ„μΏ  검증 - 1974](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5Psz16AYEDFAUq)

## μΉ΄ν…Œκ³ λ¦¬

DP

## μ‹œκ°„λ³΅μž‘λ„

μŠ€λ„μΏ  크기가 κ³ μ •λ˜μ–΄ μžˆμœΌλ―€λ‘œ μ‹œκ°„λ³΅μž‘λ„λŠ” O(1)이닀.

## 풀이

λ©”λͺ¨μ΄μ œμ΄μ…˜μ„ μœ„ν•œ 쀑볡 체크 배열을 3가지 λ§Œλ“€μ–΄μ€€λ‹€.

```cpp
bool row_check[9][9] = { false };
bool col_check[9][9] = { false };
bool square_check[9][9] = { false };
bool result = true;
```

μŠ€λ„μΏ μ˜ 각 슬둯의 값을 μž…λ ₯ λ°›μœΌλ©°, 쑰건 체크λ₯Ό μ§„ν–‰ν•œλ‹€.

```cpp
for (int row = 0; row < 9; row++) {
for (int col = 0; col < 9; col++) {
int slot;
cin >> slot;
if (!result)
continue;
int square = (row / 3) * 3 + col / 3;
if (!row_check[row][slot - 1] and !col_check[col][slot - 1] and !square_check[square][slot - 1])
row_check[row][slot - 1] = col_check[col][slot - 1] = square_check[square][slot - 1] = true;
else
result = false;
}
}
```

κ²°κ³Όλ₯Ό 좜λ ₯ν•œλ‹€.

```cpp
cout << '#' << test_case << ' ' << result << '\n';
```

## μ„±λŠ₯ μš”μ•½

gabalja marked this conversation as resolved.
Show resolved Hide resolved
λ©”λͺ¨λ¦¬: 13,536 KB, μ‹œκ°„: 5 ms, μ½”λ“œκΈΈμ΄: 1,033 Bytes
36 changes: 36 additions & 0 deletions minjae9610/SWEA/D2/swea1974/swea1974.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>

using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);

int T;
cin >> T;
for (int test_case = 1; test_case <= T; ++test_case)
{
bool row_check[9][9] = { false };
bool col_check[9][9] = { false };
bool square_check[9][9] = { false };
bool result = true;

for (int row = 0; row < 9; row++) {
for (int col = 0; col < 9; col++) {
int slot;
cin >> slot;
if (!result)
continue;
int square = (row / 3) * 3 + col / 3;
minjae9610 marked this conversation as resolved.
Show resolved Hide resolved
if (!row_check[row][slot - 1] and !col_check[col][slot - 1] and !square_check[square][slot - 1])
minjae9610 marked this conversation as resolved.
Show resolved Hide resolved
row_check[row][slot - 1] = col_check[col][slot - 1] = square_check[square][slot - 1] = true;
else
result = false;
}
}
cout << '#' << test_case << ' ' << result << '\n';
}

return 0;
}