fork download
  1. //
  2. // 돌_그룹_12886.cpp
  3. // BFS
  4. //
  5. // Created by jiho park on 2020/01/25.
  6. // Copyright © 2020 jiho park. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <queue>
  11. #include <tuple>
  12.  
  13. using namespace std;
  14.  
  15. bool check[501][501][501];
  16. int a[3];
  17.  
  18. pair<int,int> cal(int x, int y){
  19. if(x<y){
  20. y=y-x;
  21. x=x+x;
  22. }else{
  23. x=x-y;
  24. y=y+y;
  25. }
  26. return make_pair(x,y);
  27. }
  28.  
  29. int main(){
  30. cin >> a[0] >> a[1] >> a[2];
  31. if(a[0]==a[1] && a[1]==a[2]){
  32. cout << "1";
  33. return 0;
  34. }
  35.  
  36. queue<tuple<int,int,int>> q;
  37. check[a[0]][a[1]][a[2]]=true;
  38. q.emplace(a[0],a[1],a[2]);
  39.  
  40. while(!q.empty()){
  41. int x[3];
  42. tie(x[0],x[1],x[2]) = q.front();
  43. q.pop();
  44. for(int i=0; i<2; i++){
  45. for(int j=i+1; j<3; j++){
  46. if(x[i] != x[j]){
  47. int nx, ny;
  48. tie(nx,ny) = cal(x[i], x[j]);
  49. if(i==0 && j==1 && !check[nx][ny][x[2]]){
  50. if(nx==ny && ny==x[2]){
  51. cout << "1";
  52. return 0;
  53. }
  54. q.emplace(nx,ny,x[2]);
  55. check[nx][ny][x[2]]=true;
  56. }
  57. else if(i==0 && j==2 && !check[nx][x[1]][ny]){
  58. if(nx==x[1] && x[1]==ny){
  59. cout << "1";
  60. return 0;
  61. }
  62. q.emplace(nx,x[1],ny);
  63. check[nx][x[1]][ny]=true;
  64. }
  65. else if(i==1 && j==2 && !check[x[0]][nx][ny]){
  66. if(x[0]==nx && nx==ny){
  67. cout << "1";
  68. return 0;
  69. }
  70. q.emplace(x[0],nx,ny);
  71. check[x[0]][nx][ny]=true;
  72. }
  73. }
  74. }
  75. }
  76. }
  77.  
  78. cout << "0";
  79.  
  80. return 0;
  81. }
  82.  
Success #stdin #stdout 0s 4296KB
stdin
10 15 35
stdout
1