結果

問題 No.2746 Bicolor Pyramid
ユーザー GOTKAKO
提出日時 2024-04-20 16:40:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 2,720 ms
コンパイル使用メモリ 200,932 KB
最終ジャッジ日時 2025-02-21 06:52:45
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

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);
    
    int limit = upper_bound(N2.begin(),N2.end(),R+B)-N2.begin();

    long long n = min(18,limit),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;
    }
    else{
        long long maxs = 0;
        for(auto s : Se){
            if(s > R) break;
            maxs = s;
        }
        R = maxs; sum = R+B;
        int ans = upper_bound(N2.begin(),N2.end(),sum)-N2.begin();
        cout << ans << endl;
    }
}
0