結果

問題 No.2493 K-th in L2 with L1
ユーザー tnakao0123tnakao0123
提出日時 2023-10-08 16:40:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 52,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-08 16:40:25
合計ジャッジ時間 1,521 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2493.cc:  No.2493 K-th in L2 with L1 - yukicoder
 */

#include<cstdio>
#include<tuple>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_D = 100;

/* typedef */

typedef tuple<int,int,int> trpl;

/* global variables */

trpl ps[MAX_D * 4];

/* subroutines */

/* main */

int main() {
  int qn;
  scanf("%d", &qn);

  while (qn--) {
    int di, ki;
    scanf("%d%d", &di, &ki), ki--;

    int n = 0;
    if (di == 0)
      ps[n++] = {0, 0, 0};
    else {
      for (int y = -di; y <= di; y++) {
	int x0 = di - abs(y), x1 = -x0;
	int d2 = x0 * x0 + y * y;
	ps[n++] = {d2, x0, y};
	if (x1 != x0) ps[n++] = {d2, x1, y};
      }
      sort(ps, ps + n);
    }

    if (ki < n)
      printf("Yes\n%d %d\n", get<1>(ps[ki]), get<2>(ps[ki]));
    else
      puts("No");
  }
  
  return 0;
}
0