結果

問題 No.2510 Six Cube Sum Counting
ユーザー GOTKAKOGOTKAKO
提出日時 2023-10-21 17:19:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 721 ms / 4,000 ms
コード長 1,227 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 180,528 KB
実行使用メモリ 134,984 KB
最終ジャッジ日時 2023-10-21 17:19:52
合計ジャッジ時間 24,141 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 637 ms
134,984 KB
testcase_01 AC 656 ms
134,984 KB
testcase_02 AC 678 ms
134,984 KB
testcase_03 AC 641 ms
134,984 KB
testcase_04 AC 656 ms
134,984 KB
testcase_05 AC 639 ms
134,984 KB
testcase_06 AC 671 ms
134,984 KB
testcase_07 AC 637 ms
134,984 KB
testcase_08 AC 665 ms
134,984 KB
testcase_09 AC 638 ms
134,984 KB
testcase_10 AC 662 ms
134,984 KB
testcase_11 AC 637 ms
134,984 KB
testcase_12 AC 659 ms
134,984 KB
testcase_13 AC 640 ms
134,984 KB
testcase_14 AC 665 ms
134,984 KB
testcase_15 AC 636 ms
134,984 KB
testcase_16 AC 661 ms
134,984 KB
testcase_17 AC 633 ms
134,984 KB
testcase_18 AC 658 ms
134,984 KB
testcase_19 AC 635 ms
134,984 KB
testcase_20 AC 701 ms
134,984 KB
testcase_21 AC 680 ms
134,984 KB
testcase_22 AC 721 ms
134,984 KB
testcase_23 AC 685 ms
134,984 KB
testcase_24 AC 684 ms
134,984 KB
testcase_25 AC 666 ms
134,984 KB
testcase_26 AC 654 ms
134,984 KB
testcase_27 AC 695 ms
134,984 KB
testcase_28 AC 636 ms
134,984 KB
testcase_29 AC 710 ms
134,984 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:21:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   21 |         auto &[cube1,a1,b1,c1] = abc.at(l);
      |               ^
main.cpp:26:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   26 |             auto &[cube2,a2,b2,c2] = abc.at(r);
      |                   ^
main.cpp:30:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   30 |         auto &[cube2,a2,b2,c2] = abc.at(r);
      |               ^
main.cpp:35:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   35 |             auto &[cube3,a3,b3,c3] = abc.at(rl);
      |                   ^
main.cpp:42:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   42 |             auto &[cube3,a3,b3,c3] = abc.at(i);
      |                   ^

ソースコード

diff #

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

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

    int X; cin >> X;
    vector<int> C(301);
    vector<tuple<int,int,int,int>> abc;
    for(int i=0; i<301; i++) C.at(i) = i*i*i;
    for(int a=0; a<=300; a++) for(int b=a; b<=300; b++) for(int c=b; c<=300; c++){
        int cube = C.at(a)+C.at(b)+C.at(c);
        abc.push_back({cube,a,b,c});
    }
    sort(abc.begin(),abc.end());
    
    int answer = 0;
    int l = 0,r = abc.size()-1;
    while(l < abc.size()){
        auto &[cube1,a1,b1,c1] = abc.at(l);
        if(cube1 > X) break;
        l++;
        
        while(r >= 0){
            auto &[cube2,a2,b2,c2] = abc.at(r);
            if(cube1+cube2 > X) r--;
            else break;
        }
        auto &[cube2,a2,b2,c2] = abc.at(r);
        if(cube1+cube2 != X) continue;

        int rl = r;
        while(true){
            auto &[cube3,a3,b3,c3] = abc.at(rl);
            if(cube2 == cube3) rl--;
            else{rl++; break;}
            if(rl < 0){rl++; break;}
        }

        for(int i=rl; i<=r; i++){
            auto &[cube3,a3,b3,c3] = abc.at(i);
            if(c1 <= a3) answer++;
        }
    }
    cout << answer << endl;
}
0