μκ³ λ¦¬μ¦
λ°±μ€_12886_λκ·Έλ£Ή
shj718
2022. 6. 24. 16:47
πβοΈ λ¬Έμ
https://www.acmicpc.net/problem/12886
12886λ²: λ κ·Έλ£Ή
μ€λ κ°νΈλ λμ μ΄μ©ν΄ μ¬λ―Έμλ κ²μμ νλ €κ³ νλ€. λ¨Όμ , λμ μΈ κ°μ κ·Έλ£ΉμΌλ‘ λλμ΄μ Έ μμΌλ©° κ°κ°μ κ·Έλ£Ήμλ λμ΄ A, B, Cκ°κ° μλ€. κ°νΈλ λͺ¨λ κ·Έλ£Ήμ μλ λμ κ°μλ₯Ό κ°κ² λ§λ€λ €
www.acmicpc.net
π§© μκ³ λ¦¬μ¦
DFS / BFS μκ³ λ¦¬μ¦ λλ€ μ¬μ© κ°λ₯ (μ΄λ²μλ DFSλ‘ νμ΄λ΄€λ€.)
π‘ μμ΄λμ΄
μ μ : (a,b,c) = λμ κ°μ μν
κ°μ : (a,b,c) → (a´,b´,c´) = ν λ¨κ³μμ λμ μ΄λ
μ 체 λμ κ°μλ λ³νμ§ μλλ€λ μ μ μ΄μ©ν΄μ 곡κ°λ³΅μ‘λλ₯Ό μ€μΈλ€. (dfs ν¨μμ λ§€κ°λ³μλ‘ 2κ°μ λ κ·Έλ£Ήλ§ νμ)
π©π» μ½λ
#include <iostream>
using namespace std;
int sum;
bool visited[1501][1501];
void dfs(int a, int b) {
if (visited[a][b]) return;
visited[a][b] = true;
int arr[3] = { a,b,sum - a - b };
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (arr[i] < arr[j]) {
int changed[3] = { a,b,sum - a - b };
changed[i] += arr[i];
changed[j] -= arr[i];
dfs(changed[i], changed[j]);
}
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int a, b, c;
cin >> a >> b >> c;
sum = a + b + c;
if (sum % 3 != 0) {
cout << 0 << '\n';
return 0;
}
dfs(a, b);
if (visited[sum / 3][sum / 3]) {
cout << 1 << '\n';
}
else {
cout << 0 << '\n';
}
return 0;
}