結果

問題 No.2746 Bicolor Pyramid
ユーザー Nzt3Nzt3
提出日時 2024-04-17 17:45:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 2,653 ms
コンパイル使用メモリ 197,460 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 17:45:31
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 24 ms
6,944 KB
testcase_17 AC 36 ms
6,940 KB
testcase_18 AC 71 ms
6,944 KB
testcase_19 AC 19 ms
6,940 KB
testcase_20 AC 16 ms
6,944 KB
testcase_21 AC 43 ms
6,940 KB
testcase_22 AC 52 ms
6,940 KB
testcase_23 AC 38 ms
6,944 KB
testcase_24 AC 54 ms
6,944 KB
testcase_25 AC 15 ms
6,944 KB
testcase_26 AC 81 ms
6,940 KB
testcase_27 AC 218 ms
6,940 KB
testcase_28 AC 189 ms
6,940 KB
testcase_29 AC 63 ms
6,940 KB
testcase_30 AC 102 ms
6,940 KB
testcase_31 AC 79 ms
6,940 KB
testcase_32 AC 90 ms
6,944 KB
testcase_33 AC 50 ms
6,944 KB
testcase_34 AC 50 ms
6,944 KB
testcase_35 AC 116 ms
6,944 KB
testcase_36 AC 385 ms
6,940 KB
testcase_37 AC 365 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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]==0)continue;
        ll j=z-i;
        if(i+k*k<=B && j<=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