結果

問題 No.1159 Sashiming String
ユーザー Konton7Konton7
提出日時 2020-08-14 00:35:20
言語 Rust
(1.77.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,606 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 154,384 KB
実行使用メモリ 8,404 KB
最終ジャッジ日時 2024-04-18 01:56:39
合計ジャッジ時間 1,266 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 8 ms
8,404 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 7 ms
7,216 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 8 ms
8,400 KB
testcase_09 AC 7 ms
8,400 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::fs::File;
use std::io::Read;

fn main() {
    let inputstatus = 1;
    let mut buf = String::new();

    let filename = "inputrust.txt";

    if inputstatus == 0 {
        let mut f = File::open(filename).expect("file not found");
        f.read_to_string(&mut buf)
            .expect("something went wrong reading the file");
    } else {
        std::io::stdin().read_to_string(&mut buf).unwrap();
    }

    let s: &str = &buf;

    let mut s_list: Vec<i64> = Vec::new();
    let mut i_list: Vec<i64> = Vec::new();
    let mut n_list: Vec<i64> = Vec::new();
    let mut g_list: Vec<i64> = Vec::new();

    for (i, c) in s.chars().enumerate() {
        if i == 0 {
            s_list.push(0);
            i_list.push(0);
            n_list.push(0);
            g_list.push(0);
        } else {
            s_list.push(s_list[i - 1]);
            i_list.push(0);
            n_list.push(0);
            g_list.push(g_list[i - 1]);
        }
        if c == 'S' {
            s_list[i] += 1;
        } else if c == 'i' {
            i_list[i] += s_list[i];
        } else if c == 'n' {
            n_list[i] += i_list[i-1];
        } else if c == 'g' {
            g_list[i] += n_list[i-1];
        }
    }

    // for v in s_list {
    //     print!("{} ", v);
    // }
    // println!("\n");
    // for v in i_list {
    //     print!("{} ", v);
    // }
    // println!("\n");
    // for v in n_list {
    //     print!("{} ", v);
    // }
    // println!("\n");
    // for v in g_list {
    //     print!("{} ", v);
    // }
    // println!("\n");

    println!("{}", g_list[s.len() - 1]);
}
0