結果

問題 No.2493 K-th in L2 with L1
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-08-31 23:14:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 4,422 ms
コンパイル使用メモリ 266,760 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 21:43:39
合計ジャッジ時間 4,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++)

using P = pair<int, int>;
using IP = pair<int, P>;

int main() {
  int q;
  cin >> q;
  while (q--) {
    int d, k;
    cin >> d >> k;
    if (d == 0) {
      if (k == 1)
        cout << "Yes\n0 0\n";
      else
        cout << "No\n";
    } else {
      if (k > 4 * d) {
        cout << "No\n";
      } else {
        vector<IP> pts;
        rep(x, 0, d) {
          int y = d - x;
          int z = x * x + y * y;
          pts.push_back(IP(z, P(x, y)));
          pts.push_back(IP(z, P(-y, x)));
          pts.push_back(IP(z, P(-x, -y)));
          pts.push_back(IP(z, P(y, -x)));
        }
        sort(pts.begin(), pts.end());
        auto p = pts[k - 1].second;
        cout << "Yes\n";
        cout << p.first << " " << p.second << "\n";
      }
    }
  }
}
0