結果

問題 No.441 和か積
ユーザー happy-beanshappy-beans
提出日時 2017-03-14 21:28:40
言語 PHP
(8.3.4)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 1,370 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 12,048 KB
実行使用メモリ 12,332 KB
最終ジャッジ日時 2023-09-09 10:38:46
合計ジャッジ時間 1,884 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,288 KB
testcase_01 AC 7 ms
12,236 KB
testcase_02 AC 7 ms
12,288 KB
testcase_03 AC 7 ms
12,320 KB
testcase_04 AC 7 ms
12,328 KB
testcase_05 AC 7 ms
12,284 KB
testcase_06 AC 7 ms
12,332 KB
testcase_07 AC 7 ms
12,324 KB
testcase_08 AC 7 ms
12,172 KB
testcase_09 AC 7 ms
12,176 KB
testcase_10 AC 7 ms
12,332 KB
testcase_11 AC 7 ms
12,264 KB
testcase_12 AC 7 ms
12,324 KB
testcase_13 AC 7 ms
12,288 KB
testcase_14 AC 7 ms
12,312 KB
testcase_15 AC 6 ms
12,228 KB
testcase_16 AC 7 ms
12,288 KB
testcase_17 AC 6 ms
12,276 KB
testcase_18 AC 7 ms
12,196 KB
testcase_19 AC 7 ms
12,220 KB
testcase_20 AC 7 ms
12,200 KB
testcase_21 AC 6 ms
12,320 KB
testcase_22 AC 6 ms
12,324 KB
testcase_23 AC 7 ms
12,248 KB
testcase_24 AC 7 ms
12,312 KB
testcase_25 AC 7 ms
12,304 KB
testcase_26 AC 6 ms
12,240 KB
testcase_27 AC 7 ms
12,176 KB
testcase_28 AC 6 ms
12,284 KB
testcase_29 AC 7 ms
12,308 KB
testcase_30 AC 7 ms
12,280 KB
testcase_31 AC 7 ms
12,320 KB
testcase_32 AC 7 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
// No. 441

$args = explode(" ", trim(fgets(STDIN)));
$a = $args[0];
$b = $args[1];

/*
 * A + B = A * B と仮定したとき
 * A = 0 とすると、条件から B = 0 となり、これは常に成り立つ。
 * -> A = AB - B
 * -> A = B(A - 1)
 * -> B = A / (A - 1)
 * A,Bは非負整数なので、A / (A - 1) が正の整数になるのは A = 2 のときのみ。
 * A = 2 のとき、B = 2
 *
 * A + B > A * B と仮定したとき
 * A = 0 とすると、条件から B > 0 となり、Bが1以上のとき常に成り立つ。B = 0 のときも同様。
 * A = 1 とすると、条件から 1 + B > B となり、これは常に成り立つ。B = 1 のときも同様。
 * A >= 2 のとき
 * -> A > AB - B
 * -> A > B(A - 1)
 * -> 1 > B(A - 1) / A
 * これを満たす、 A (>=2), B (>2) のペアは存在しない。
 */

$a = check($a);
$b = check($b);

if (($a == 0) && ($b == 0)) {
  echo "E".PHP_EOL;
} else if (($a == 2) && ($b == 2)) {
  echo "E".PHP_EOL;
}
else if (($a * $b) == 0) {
  echo "S".PHP_EOL;
}
else if (($a == 1) || ($b == 1)) {
  echo "S".PHP_EOL;
}
else {
  echo "P".PHP_EOL;
}

function check($i)
{
  if (strlen($i) > 2) {
    // 2桁以上の場合はどれでも同じなので、計算可能な数値に置き換え
    return (int) 10;
  }
  else {
    // 1桁の数値はそのまま返す
    return (int) $i;
  }
}
0