結果

問題 No.2358 xy+yz+zx=N
ユーザー simansiman
提出日時 2023-06-25 01:14:35
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 7,761 ms
コンパイル使用メモリ 110,168 KB
実行使用メモリ 7,284 KB
最終ジャッジ日時 2023-09-14 20:48:11
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 84 ms
7,256 KB
testcase_09 AC 90 ms
7,284 KB
testcase_10 AC 44 ms
4,640 KB
testcase_11 AC 52 ms
5,208 KB
testcase_12 AC 28 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

string to_s(int x, int y, int z) {
  return to_string(x) + " " + to_string(y) + " " + to_string(z);
}

int main() {
  int N;
  cin >> N;
  vector<string> ans;

  map<int, map<int, bool>> checked;

  int x = 0;
  while (x * x <= N) {
    int y = x;
    while (y * y <= N) {
      if (x + y != 0) {
        if ((N - x * y) % (x + y) == 0) {
          int z = (N - x * y) / (x + y);

          if (not checked[x][y]) {
            checked[x][y] = true;
            ans.push_back(to_s(x, y, z));
          }
          if (not checked[x][z]) {
            checked[x][z] = true;
            ans.push_back(to_s(x, z, y));
          }
          if (not checked[y][x]) {
            checked[y][x] = true;
            ans.push_back(to_s(y, x, z));
          }
          if (not checked[y][z]) {
            checked[y][z] = true;
            ans.push_back(to_s(y, z, x));
          }
          if (not checked[z][x]) {
            checked[z][x] = true;
            ans.push_back(to_s(z, x, y));
          }
          if (not checked[z][y]) {
            checked[z][y] = true;
            ans.push_back(to_s(z, y, x));
          }
        }
      }

      ++y;
    }

    ++x;
  }

  cout << ans.size() << endl;
  for (string s : ans) {
    cout << s << endl;
  }

  return 0;
}
0