結果

問題 No.1514 Squared Matching
ユーザー koba-e964koba-e964
提出日時 2021-10-25 19:49:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 574 ms / 4,000 ms
コード長 1,051 bytes
コンパイル時間 4,788 ms
コンパイル使用メモリ 159,040 KB
実行使用メモリ 490,152 KB
最終ジャッジ日時 2024-04-14 16:15:07
合計ジャッジ時間 14,666 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 574 ms
490,132 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 8 ms
9,304 KB
testcase_07 AC 106 ms
95,068 KB
testcase_08 AC 540 ms
472,184 KB
testcase_09 AC 472 ms
413,228 KB
testcase_10 AC 514 ms
447,408 KB
testcase_11 AC 533 ms
466,192 KB
testcase_12 AC 545 ms
478,928 KB
testcase_13 AC 550 ms
485,276 KB
testcase_14 AC 551 ms
488,020 KB
testcase_15 AC 554 ms
489,200 KB
testcase_16 AC 553 ms
489,720 KB
testcase_17 AC 552 ms
490,060 KB
testcase_18 AC 553 ms
490,076 KB
testcase_19 AC 557 ms
490,136 KB
testcase_20 AC 553 ms
490,120 KB
testcase_21 AC 557 ms
490,152 KB
testcase_22 AC 109 ms
99,484 KB
testcase_23 AC 221 ms
197,000 KB
testcase_24 AC 335 ms
294,800 KB
testcase_25 AC 446 ms
392,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
    let n: usize = get();
    let mut repr = vec![0; n + 1];
    for i in 1..7100 {
        for j in 1..n / i / i + 1 {
            repr[j * i * i] = j;
        }
    }
    let mut f = vec![0i16; n + 1];
    for i in 1..n + 1 {
        f[repr[i]] += 1;
    }
    let mut ans = 0i64;
    for i in 1..n + 1 {
        let x = f[i] as i64;
        ans += x * x;
    }
    println!("{}", ans);
}
0