結果
問題 |
No.2510 Six Cube Sum Counting
|
ユーザー |
|
提出日時 | 2023-10-21 17:19:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 762 ms / 4,000 ms |
コード長 | 1,227 bytes |
コンパイル時間 | 1,888 ms |
コンパイル使用メモリ | 180,304 KB |
実行使用メモリ | 134,504 KB |
最終ジャッジ日時 | 2024-09-21 18:35:29 |
合計ジャッジ時間 | 24,384 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
コンパイルメッセージ
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); | ^
ソースコード
#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; }