結果

問題 No.1624 三角形の反射
ユーザー tnakao0123tnakao0123
提出日時 2021-07-24 19:15:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,491 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 92,124 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 04:51:46
合計ジャッジ時間 1,813 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1624.cc:  No.1624 三角形の反射 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

char s[16];

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m > 0, n > 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

int main() {
  scanf("%s", s);

  int gx = 1, gy = 0, pt = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '.') pt = 1;
    else {
      gy = gy * 10 + (s[i] - '0');
      if (pt) gx *= 10;
    }
  }

  int g = gcd(gx, gy);
  gx /= g, gy /= g;
  //printf("%d,%d\n", gx, gy);

  int k = (gx - 1) + (gy - 1) + (gx + gy) / 2;

  for (int z = 1; z < gy; z += 2) {
    // y=x+z, y=(gy/gx)x
    // x=0 -> (0,z),(0,0), x=gx -> (gx,gx+z),(gx,gy)
    if (gx + z < gy) k++;
  }
  for (int z = -1; z > -gx; z -= 2) {
    if (gx + z > gy) k++;
  }

  int p = (gx + gy) & 1;

  // +C+C+C+
  // B/C\B/C
  // +B+B+B+
  // B\C/B\C
  // +C+C+C+

  char c;
  if (p == 0) c = 'A';
  else if (gx > gy)
    c = (gx & 1) ? 'B' : 'C';
  else
    c = (gy & 1) ? 'C' : 'B';

  printf("%c %d\n", c, k);
  return 0;
}
0