結果

問題 No.2746 Bicolor Pyramid
ユーザー Nzt3Nzt3
提出日時 2024-04-17 17:39:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 198,296 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-17 17:39:33
合計ジャッジ時間 6,111 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,448 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
https://yukicoder.me/submissions/973056
C++移植
*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll B,R;
  cin>>R>>B;
  if(R<B)swap(R,B);
  if(B>128){
    ll ans=0,S=0;
    while(S+(ans+1)*(ans+1)<=R+B){
      ans+=1;
      S+=ans*ans;
    }
    cout<<ans<<'\n';
  }else{
    vector dp(B+1,0);
    dp[0]=1;
    ll k=1,z=0;
    while(1){
      bool flag=0;
      vector ndp(B+1,0);
      swap(dp,ndp);
      for(int i=0;i<=B;i++){
        if(!ndp[i])continue;
        int j=z-i;
        if(i+k*k<=B && j+k*k<=R){
          dp[i+k*k]=1;
          flag=1;
        }
        if(i<=B && j+k*k<=R){
          dp[i]=1;
          flag=1;
        }
      }
      if(flag){
        z+=k*k;
        k+=1;
      }else{
        break;
      }
    }
    cout<<k-1<<'\n';
  }
}
0