結果

問題 No.482 あなたの名は
ユーザー 💕💖💞💕💖💞
提出日時 2017-07-22 23:35:00
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,110 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 179,516 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-17 16:00:33
合計ジャッジ時間 23,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `HashMap`, `LinkedList`
 --> main.rs:2:24
  |
2 | use std::collections::{HashMap, LinkedList};
  |                        ^^^^^^^  ^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unnecessary parentheses around `for` iterator expression
  --> main.rs:16:12
   |
16 |   for i in (0..v.len()) {
   |            ^          ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
16 -   for i in (0..v.len()) {
16 +   for i in 0..v.len() {
   |

warning: unnecessary parentheses around `for` iterator expression
  --> main.rs:19:16
   |
19 |       for j in (i..v.len()) {
   |                ^          ^
   |
help: remove these parentheses
   |
19 -       for j in (i..v.len()) {
19 +       for j in i..v.len() {
   |

warning: unused variable: `n`
 --> main.rs:9:8
  |
9 |   let (n, k) = (v[0], v[1]);
  |        ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 4 warnings emitted

ソースコード

diff #

use std::io::{self, BufRead};
use std::collections::{HashMap, LinkedList};

fn main() {
  let stdin  = io::stdin();
  let line   = stdin.lock().lines().next().unwrap().unwrap();
  let v      = line.split(" ").collect::<Vec<&str>>()
                .iter().map( |x| x.to_string()).map(|x| x.parse::<i32>().unwrap() ).collect::<Vec<i32>>();
  let (n, k) = (v[0], v[1]);
  let line   = stdin.lock().lines().next().unwrap().unwrap();
  let mut v  = line.split(" ").collect::<Vec<&str>>()
                .iter().map( |x| x.to_string()).map(|x| x.parse::<i32>().unwrap() ).collect::<Vec<i32>>();
  let mut va = v.clone();
  va.sort();
  let mut cnt = 0;
  for i in (0..v.len()) {
    if v[i] != va[i] {
      let mut toswap = 0;
      for j in (i..v.len()) {
        if v[j] == va[i] {
          toswap = j;
          cnt += 1;
          break;
        }
      } 
      let tmp = v[toswap].clone();
      v[toswap] = v[i];
      v[i] = tmp;
      if v == va {
        break;
      }
    }
  }
  if k < cnt {
    println!("NO");
  }else if (k - cnt)%2 == 0 { 
    println!("YES");
  }else {
    println!("NO");
  }
}
0