2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Atcoder Beginner Contest 351 [Rust]

Posted at

A問題

チーム青木の得点が、チーム高橋の得点を上回るための最小値を求める問題。
よって、
$$チーム高橋の得点 - チーム青木の得点 + 1$$
が答えとなる。

解答

use proconio::input;
use std::cmp;
use proconio::marker::Chars;
use std::collections::VecDeque;
use std::collections::HashSet;
use permutohedron::LexicalPermutation;
use std::num;

fn main() {

    input! {
        a: [usize; 9],
        b: [usize; 8],
    }
    
    let mut ans =0;
    let mut asum =0;
    let mut bsum =0;
    for i in 0..9 {
        asum += a[i];
    }
    for i in 0..8 {
        bsum += b[i];
    }
    ans = asum-bsum+1;
    println!("{}",ans);

}

B問題

グリッドA、Bの入力を受け取り、文字が異なる箇所の座標(i,j)を出力する。

解答

use proconio::input;
use std::cmp;
use proconio::marker::Chars;
use std::collections::VecDeque;
use std::collections::HashSet;
use permutohedron::LexicalPermutation;
use std::num;

fn main() {

    input! {
        n: usize,
        a: [Chars; n],
        b: [Chars; n],
    }

    for i in 0..n {
        for j in 0..n {
            if a[i][j] != b[i][j] {
                println!("{} {}", i+1,j+1);
            }
        }
    }

}

C問題

スタックにボールを一つ入れ、後ろ二つのボールが同じ大きさなら、+1した大きさのボールを入れる。
異なるなら二つのボールを入れ直す。
N個のボールにおいてこれを行うが、上記のスタックの計算量は0(1)なので、愚直に実装して良い。

解答

use proconio::input;
use std::cmp;
use proconio::marker::Chars;
use std::collections::VecDeque;
use std::collections::HashSet;
use permutohedron::LexicalPermutation;
use std::num;

fn main() {

    input! {
        n: usize,
        a: [usize; n],
    }
    let mut deque = VecDeque::new();
    deque.push_back(a[0]);

    for i in 1..n {
        deque.push_back(a[i]);
        while deque.len()>1{
            let mut back1 = deque.pop_back().unwrap();
            let mut back2 = deque.pop_back().unwrap();
            if back1 == back2 {
                deque.push_back(back1+1);
            } else {
                deque.push_back(back2);
                deque.push_back(back1);
                break;
            }
        }
    }

    println!("{}",deque.len());

}

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?