結果

問題 No.2746 Bicolor Pyramid
ユーザー otoshigootoshigo
提出日時 2024-04-20 14:37:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,093 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 197,148 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 14:37:52
合計ジャッジ時間 3,442 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

vector<int>A={0,1,4,5,9,10,13,14,16,17,20,21,25,26,29,30,34,35,36,37,38,39,40,41,42,45,46,49,50,51,52,53,54,55,56,57,58,59,61,62,63,64,65,66,68,69,70,71,73,74,75,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,93,94,95,97,98,99,100,101,102,103,104,105,106,107,109,110,111,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,129};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll R,B;
    cin>>R>>B;
    ll ok=0,ng=1817121;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        if(mid*(mid+1)>(__int128_t)(R+B+2*mid)/(2*mid+1)*6)ng=mid;
        else{
            ll al=(__int128_t)mid*(mid+1)*(2*mid+1)/6;
            if(mid>=15){
                if(R>=129&&al-R>=129){
                    if(al-R<=B)ok=mid;
                    else ng=mid;
                }
                else{
                    int d=min(R,al-R);
                    auto id=lower_bound(all(A),d);
                    if(R<129){
                        if(*id!=d)id--;
                        if(al-*id<=B)ok=mid;
                        else ng=mid;
                    }else{
                        if(al-(al-*id)<=B)ok=mid;
                        else ng=mid;
                    }
                }
            }else{
                int mx=0;
                for(int bit=0;bit<1<<mid;bit++){
                    int cnt=0;
                    for(int i=0;i<mid;i++){
                        if(bit>>i&1){
                            cnt+=(i+1)*(i+1);
                        }
                    }
                    if(cnt<=R)chmax(mx,cnt);
                }
                if(al-mx<=B)ok=mid;
                else ng=mid;
            }
        }
    }
    cout<<ok<<"\n";
}
0