結果
問題 |
No.2510 Six Cube Sum Counting
|
ユーザー |
👑 |
提出日時 | 2023-09-25 08:33:57 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 880 ms / 4,000 ms |
コード長 | 1,155 bytes |
コンパイル時間 | 12,667 ms |
コンパイル使用メモリ | 402,244 KB |
実行使用メモリ | 407,672 KB |
最終ジャッジ日時 | 2024-09-19 12:57:45 |
合計ジャッジ時間 | 36,690 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
use std::io; use std::collections::HashMap; fn solve() -> i32 { // input! { // x: i64, // } let x: i32 = input().parse().unwrap(); let mut cubes: HashMap<i32, u128> = HashMap::new(); for a in 0..=300i32 { for b in a..=300 { for c in b..=300 { let y = a.pow(3) + b.pow(3) + c.pow(3); if let Some(v) = cubes.get_mut(&y) { *v <<= 9; *v |= c as u128; }else { cubes.insert(y, c as u128); } } } } let mut ans = 0; for d in 0..=300i32 { for e in d..=300 { for f in e..=300 { let y = d.pow(3) + e.pow(3) + f.pow(3); if let Some(v) = cubes.get(&(x - y)) { let mut zero = true; let mut u = *v; while u > 0 || zero { let c = (u & 0x1ff) as i32; if c <= d { ans += 1; } u >>= 9; zero = false; } } } } } return ans; } fn input() -> String { let mut buffer = String::new(); io::stdin().read_line(&mut buffer).unwrap(); return buffer.trim().to_string(); } fn main() { println!("{}", solve()); }