結果

問題 No.2746 Bicolor Pyramid
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-20 16:13:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,725 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 201,460 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-20 16:13:50
合計ジャッジ時間 5,257 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 40 ms
19,072 KB
testcase_05 AC 40 ms
18,844 KB
testcase_06 AC 42 ms
18,944 KB
testcase_07 AC 40 ms
18,892 KB
testcase_08 AC 40 ms
18,948 KB
testcase_09 AC 45 ms
18,944 KB
testcase_10 AC 65 ms
18,972 KB
testcase_11 AC 44 ms
18,816 KB
testcase_12 AC 47 ms
19,072 KB
testcase_13 AC 45 ms
18,816 KB
testcase_14 AC 40 ms
18,944 KB
testcase_15 AC 45 ms
18,816 KB
testcase_16 AC 40 ms
18,944 KB
testcase_17 AC 40 ms
18,776 KB
testcase_18 AC 41 ms
18,816 KB
testcase_19 AC 42 ms
19,012 KB
testcase_20 AC 42 ms
18,944 KB
testcase_21 AC 39 ms
19,012 KB
testcase_22 AC 41 ms
18,840 KB
testcase_23 AC 40 ms
18,780 KB
testcase_24 AC 41 ms
18,944 KB
testcase_25 AC 40 ms
18,944 KB
testcase_26 AC 41 ms
18,944 KB
testcase_27 AC 42 ms
18,944 KB
testcase_28 AC 43 ms
18,816 KB
testcase_29 AC 41 ms
18,944 KB
testcase_30 AC 42 ms
19,024 KB
testcase_31 AC 48 ms
18,944 KB
testcase_32 AC 40 ms
18,772 KB
testcase_33 AC 40 ms
18,816 KB
testcase_34 AC 41 ms
19,028 KB
testcase_35 AC 41 ms
18,816 KB
testcase_36 AC 42 ms
18,944 KB
testcase_37 AC 42 ms
18,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int nn2 = 2e6;
    vector<long long> N2(nn2);
    for(long long i=0; i<nn2; i++) N2.at(i) = (i+1)*(i+1);
    for(int i=1; i<nn2; i++)  N2.at(i) += N2.at(i-1);

    long long R,B; cin >> R >> B;
    if(R > B) swap(R,B);
auto solve = [](long long R,long long B) -> long long {
    long long ans1 = -1,border = -1;
    for(long long i=1; ; i++){
        long long need = i*i;
        if(R >= need) R -= need;
        else if(B >= need){
            if(border == -1) border = i; 
            B -= need;
        }
        else{ans1 = i; break;}
    }
    for(long long i=border-1; i>=1; i--){
        long long need = i*i;
        if(B >= need) B -= need,R += need;
    }
    for(;; ans1++){
        long long need= ans1*ans1;
        if(R >= need) R -= need;
        else{ans1--; break;}
    }
    return ans1;
};
    
    long long check = max(solve(R,B),solve(B,R));

    long long n = 18,n2 = 1<<n;
    set<long long> Se;
    for(long long i=0; i<n2; i++){
        long long r = 0,b = 0;
        for(long long k=0; k<n; k++){
            if(i&(1<<k)) r += (k+1)*(k+1);
            else b += (k+1)*(k+1); 
        }
        Se.insert(r);
    }
    long long sum = R+B;
    auto itr = Se.end(); itr--;
    if(*itr < R){
        int ans = upper_bound(N2.begin(),N2.end(),sum)-N2.begin();
        cout << ans << endl;
        assert(ans >= check);
    }
    else{
        long long maxs = 0;
        itr = Se.upper_bound(R);
        itr--;
        maxs = *itr; sum = maxs+B;
        int ans = upper_bound(N2.begin(),N2.end(),sum)-N2.begin();
        cout << ans << endl;
    	assert(ans >= check);
    }
}
0