paiza POH enshura #_poh


(続き http://qiita.com/cielavenir/items/f5c3fcc0553ce0751b29)

今回(の本編)は普通の問題であるばかりか、尺取り法のような工夫も必要でないので、多言語展開はやめときました。

あと、Pythonのスライス機能、強いですね。多分Python3のprint(input()[::2])が最短コード。

paizapoh5_1.py
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input
print(raw_input()[::2])
paizapoh5_2.rb
#!/usr/bin/ruby
puts gets.to_i.times.map{gets.to_i}.each_slice(7).to_a.transpose.map{|e|e.reduce(:+)}

ミッション3は普通に考えてPHPで突破すべきですよねぇ?

paizapoh5_3a.php
MINAMI
paizapoh5_3b.php
RENA

で、本番。IOゲーする必要はなかった気がする。

paizapoh5_4a.cpp
#include <vector>
#include <cstdio>
char z[9999999];
int get(){
    static int input_count=0;
    int r=0;
    for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
    input_count++;
    return r;
}

int main(){
    fread(z,1,sizeof(z),stdin);
    int W=get(),H=get();
    std::vector<std::vector<int> >m(H);
    for(int h=0;h<H;h++){
        m[h].resize(W);
        for(int w=0;w<W;w++){
            m[h][w]=get();
        }
    }
    for(int w=0;w<W;w++){
        int s=0,h=H-1;
        for(;h>=0;h--)s+=m[h][w]==1;
        for(h=H-1;s>0&&h>=0;h--,s--)m[h][w]=1;
        for(;h>=0;h--)m[h][w]=0;
    }
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            printf(w<W-1?"%d ":"%d\n",m[h][w]);
        }
    }
}

C言語互換とすると、こんな感じ。

paizapoh5_4a.c
#include <stdio.h>
char z[9999999];
int get(){
    static int input_count=0;
    int r=0;
    for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
    input_count++;
    return r;
}

int m[100][100];
int main(){
    fread(z,1,sizeof(z),stdin);
    int W=get(),H=get();
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            m[h][w]=get();
        }
    }
    for(int w=0;w<W;w++){
        int s=0,h=H-1;
        for(;h>=0;h--)s+=m[h][w]==1;
        for(h=H-1;s>0&&h>=0;h--,s--)m[h][w]=1;
        for(;h>=0;h--)m[h][w]=0;
    }
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            printf(w<W-1?"%d ":"%d\n",m[h][w]);
        }
    }
}

結論

本編は多分こっちなんだという結論に。
https://paiza.jp/poh/enshura-special

こちらは納得できる答案を書くのに10時間かかりました。辛かったですが、楽しめました。
こちらのコードは締切後の公開な気がします。多分。

追記

ミッションMINAMIは普通の問題でしたが、ミッションRENAは工夫が必要な問題でしたので多言語展開しました。続きの記事からどうぞ。