結果
| 問題 | No.2493 K-th in L2 with L1 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-08-31 23:14:34 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,052 bytes | 
| コンパイル時間 | 4,533 ms | 
| コンパイル使用メモリ | 255,536 KB | 
| 最終ジャッジ日時 | 2025-02-16 15:53:51 | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 4 | 
ソースコード
#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";
      }
    }
  }
}
            
            
            
        