結果
| 問題 |
No.2746 Bicolor Pyramid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-17 17:45:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 317 ms / 2,000 ms |
| コード長 | 878 bytes |
| コンパイル時間 | 2,119 ms |
| コンパイル使用メモリ | 194,412 KB |
| 最終ジャッジ日時 | 2025-02-21 02:51:15 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
/*
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';
}
}