結果

問題 No.5002 stick xor
ユーザー 最新の錆最新の錆
提出日時 2018-05-27 01:03:48
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 203 ms / 1,000 ms
コード長 3,855 bytes
コンパイル時間 9,765 ms
実行使用メモリ 1,200 KB
スコア 29,679
最終ジャッジ日時 2018-05-27 01:03:59
ジャッジサーバーID
(参考情報)
judge7 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
1,192 KB
testcase_01 AC 145 ms
1,196 KB
testcase_02 AC 121 ms
1,200 KB
testcase_03 AC 125 ms
1,196 KB
testcase_04 AC 145 ms
1,196 KB
testcase_05 AC 203 ms
1,192 KB
testcase_06 AC 147 ms
1,200 KB
testcase_07 AC 120 ms
1,196 KB
testcase_08 AC 200 ms
1,196 KB
testcase_09 AC 156 ms
1,192 KB
testcase_10 AC 148 ms
1,200 KB
testcase_11 AC 179 ms
1,196 KB
testcase_12 AC 151 ms
1,196 KB
testcase_13 AC 145 ms
1,196 KB
testcase_14 AC 119 ms
1,196 KB
testcase_15 AC 143 ms
1,196 KB
testcase_16 AC 165 ms
1,192 KB
testcase_17 AC 183 ms
1,192 KB
testcase_18 AC 149 ms
1,200 KB
testcase_19 AC 118 ms
1,192 KB
testcase_20 AC 144 ms
1,192 KB
testcase_21 AC 118 ms
1,192 KB
testcase_22 AC 117 ms
1,200 KB
testcase_23 AC 120 ms
1,196 KB
testcase_24 AC 89 ms
1,192 KB
testcase_25 AC 115 ms
1,192 KB
testcase_26 AC 169 ms
1,196 KB
testcase_27 AC 154 ms
1,192 KB
testcase_28 AC 151 ms
1,188 KB
testcase_29 AC 149 ms
1,192 KB
testcase_30 AC 149 ms
1,200 KB
testcase_31 AC 145 ms
1,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Read, stdin};

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(usize));
    }
    let n = get!();
    let k = get!();
    let mut ls = vec![];
    for _ in 0..k {
        ls.push(get!());
    }
    let mut grid = vec![];
    for _ in 0..n {
        let tmp: Vec<_> =
            get().as_bytes()
                 .iter()
                 .map(|&ch| (ch - b'0') as i32)
                 .collect();
        grid.push(tmp);
    }
    // println!("{:?}", grid);
    let mut ans = vec![];
    for &l in ls.iter() {
        let mut max_sum_i = 0;
        let mut max_sum_j = 0;
        let mut max_i = 0;
        let mut max_j = 0;
        for i in 0..n {
            let mut sum = 0;
            for j in 0..l {
                sum += grid[i][j];
            }
            if sum > max_sum_i {
                max_sum_i = sum;
                max_i = i;
            }
            let mut sum = 0;
            for j in 0..l {
                sum += grid[j][i];
            }
            sum -= sum;
            if sum > max_sum_j {
                max_sum_j = sum;
                max_j = i;
            }
        }
        if max_sum_i >= max_sum_j {
            for j in 0..l {
                grid[max_i][j] = 1 - grid[max_i][j];
            }
            ans.push((true, max_i, l, 0));
        } else {
            for i in 0..l {
                grid[i][max_j] = 1 - grid[i][max_j];
            }
            ans.push((false, max_j, l, 0));
        }
    }
    for _ in 0..20 {
        let mut flag = true;
        for i in 0..ans.len() {
            let (b, j, l, p0) = ans[i];
            if b {
                for p in p0..p0+l {
                    grid[j][p] = 1 - grid[j][p];
                }
            } else {
                for p in p0..p0+l {
                    grid[p][j] = 1 - grid[p][j];
                }
            }
            let mut max_sum_i = 0;
            let mut max_i = 0;
            let mut max_i_p = 0;
            let mut max_sum_j = 0;
            let mut max_j = 0;
            let mut max_j_p = 0;
            for x in 0..n {
                for y in 0..n-l+1 {
                    let mut sum = 0;
                    for z in y..y+l {
                        sum += grid[x][z];
                    }
                    if sum > max_sum_i {
                        max_sum_i = sum;
                        max_i = x;
                        max_i_p = y;
                    }
                    let mut sum = 0;
                    for z in y..y+l {
                        sum += grid[z][x];
                    }
                    sum -= sum;
                    if sum > max_sum_j {
                        max_sum_j = sum;
                        max_j = x;
                        max_j_p = y;
                    }
                }
            }
            let (b, j, p0) = if max_sum_i >= max_sum_j {
                (true, max_i, max_i_p)
            } else {
                (false, max_j, max_j_p)
            };
            if b {
                for p in p0..p0+l {
                    grid[j][p] = 1 - grid[j][p];
                }
            } else {
                for p in p0..p0+l {
                    grid[p][j] = 1 - grid[p][j];
                }
            }
            let a = (b, j, l, p0);
            if ans[i] != a {
                ans[i] = a;
                flag = false;
            }
        }
        if flag { break; }
    }
    for &(b, i, l, p) in ans.iter() {
        if b {
            println!("{0} {1} {0} {2}", i + 1, p + 1, p + l);
        } else {
            println!("{1} {0} {2} {0}", i + 1, p + 1, p + l);
        }
    }
}
0