結果
| 問題 | No.1225 I hate I hate Matrix Construction | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-09-11 21:55:47 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 3,465 bytes | 
| コンパイル時間 | 16,705 ms | 
| コンパイル使用メモリ | 378,772 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-27 12:00:41 | 
| 合計ジャッジ時間 | 14,674 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 35 | 
コンパイルメッセージ
warning: variable does not need to be mutable
  --> src/main.rs:13:9
   |
13 |     let mut s = read!([usize]);
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default
warning: variable does not need to be mutable
  --> src/main.rs:8:338
   |
8  | ...read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::<Vec <_ >>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =l...
   |                                                                                                                                                                                                                                                                                                                                        ----^^
   |                                                                                                                                                                                                                                                                                                                                        |
   |                                                                                                                                                                                                                                                                                                                                        help: remove this `mut`
...
13 | ... = read!([usize]);
   |       -------------- in this macro invocation
   |
   = note: this warning originates in the macro `read` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: variable does not need to be mutable
  --> src/main.rs:8:338
   |
8  | ...read {($($t :tt ) ,*;$n :ex
            
            ソースコード
pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin()
        .read_line(&mut line)
        .unwrap_or_else(|e| panic!("{}", e));
    line
}
macro_rules !read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::<Vec <_ >>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } } ;}
macro_rules !_read {($it :ident ;[char ] ) =>{_read !($it ;String ) .chars () .collect ::<Vec <_ >>() } ;($it :ident ;[u8 ] ) =>{Vec ::from (_read !($it ;String ) .into_bytes () ) } ;($it :ident ;usize1 ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<usize >() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 } ;($it :ident ;[usize1 ] ) =>{$it .map (|s |s .parse ::<usize >() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 ) .collect ::<Vec <_ >>() } ;($it :ident ;[$t :ty ] ) =>{$it .map (|s |s .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) ) .collect ::<Vec <_ >>() } ;($it :ident ;$t :ty ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) } ;($it :ident ;$($t :tt ) ,+) =>{($(_read !($it ;$t ) ) ,*) } ;}
fn main() {
    let n = read!(usize);
    let mut s = read!([usize]);
    let mut t = read!([usize]);
    {
        let mut zero = 0;
        let mut two = 0;
        for i in 0..n {
            if s[i] == 0 {
                zero += 1;
            }
            if s[i] == 2 {
                two += 1;
            }
        }
        if zero > 0 && two > 0 {
            println!("{}", two * n + (n - zero - two));
            return;
        }
    }
    {
        let mut zero = 0;
        let mut two = 0;
        for i in 0..n {
            if t[i] == 0 {
                zero += 1;
            }
            if t[i] == 2 {
                two += 1;
            }
        }
        if zero > 0 && two > 0 {
            println!("{}", two * n + (n - zero - two));
            return;
        }
    }
    let mut a = vec![vec![0; n]; n];
    for i in 0..n {
        for j in 0..n {
            if s[i] == 0 || t[j] == 0 {
                a[i][j] = 0;
            }
            if s[i] == 2 || t[j] == 2 {
                a[i][j] = 1;
            }
        }
    }
    let mut ans = 0;
    for i in 0..n {
        if s[i] == 1 {
            let mut f = false;
            for j in 0..n {
                if a[i][j] == 1 {
                    f = true;
                    break;
                }
            }
            if f {
                continue;
            }
            for j in 0..n {
                if t[j] == 1 {
                    t[j] = 0;
                    a[i][j] = 1;
                    f = true;
                    break;
                }
            }
            if !f {
                ans += 1;
            }
        }
    }
    for j in 0..n {
        if t[j] == 1 {
            let mut f = false;
            for i in 0..n {
                if a[i][j] == 1 {
                    f = true;
                    break;
                }
            }
            if !f {
                ans += 1;
            }
        }
    }
    for i in 0..n {
        for j in 0..n {
            ans += a[i][j];
        }
    }
    println!("{}", ans);
}
            
            
            
        