結果

問題 No.2493 K-th in L2 with L1
ユーザー planesplanes
提出日時 2023-11-12 17:13:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 169,824 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-12 17:14:02
合計ジャッジ時間 2,051 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll Q;cin>>Q;
  for(ll i=0;i<Q;i++) {
    ll D,K;cin>>D>>K;
if(D==0) {
  if(K==1) {
    cout<<"Yes"<<endl;
     cout<<0<<" "<<0<<endl;
  }
  else cout<<"No"<<endl;
continue;
}

    vector<ll> yu(20000+10);
    for(ll j=-100;j<=100;j++) {
      ll noko=D-abs(j);
      if(noko>=0) {
        ll x=j;ll y=noko;
        yu[x*x+y*y]++;
        if(noko>0) yu[x*x+y*y]++;
      }
    }

    for(ll j=1;j<yu.size();j++) {
      yu[j]+=yu[j-1];
    }
  
  bool ok=false;
  for(ll j=-100;j<=100;j++) {
    ll noko=D-abs(j);
    if(noko>=0) {
     ll k=noko*noko+j*j;
     if(yu[k-1]<K&&yu[k]>=K) {
      cout<<"Yes"<<endl;
      cout<<j<<" "<<noko<<endl;
      ok=true;
      break;
     }
    }
  }

  if(!ok) cout<<"No"<<endl;
  }

}



0