結果

問題 No.459 C-VS for yukicoder
ユーザー imulanimulan
提出日時 2016-12-10 02:45:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,852 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 179,868 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-11-28 21:17:17
合計ジャッジ時間 4,605 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    cin.tie(0);ios::sync_with_stdio(false);

    int h,w,n;
    cin >>h >>w >>n;

    vector<string> s(h);
    rep(i,h) cin >>s[i];

    vector<pi> c(n);
    rep(i,n)
    {
        int x;
        cin >>x;
        c[i]=pi(x,i);
    }
    sort(all(c));


    // その列に積み上がっているブロックの個数
    vector<int> num(w);
    rep(x,w)
    {
        rep(y,h)
        {
            if(s[y][x]=='#')
            {
                num[x]=h-y;
                break;
            }
        }
    }

    // その列にブロックを落とせる回数
    vector<int> ct(w,0);
    rep(i,n)rep(j,3) ++ct[c[i].fi+j];

    vector<vector<string>> ans(n,vector<string>(3,string(3,'.')));

    rep(i,n)
    {
        int b[3]={};
        bool all_zero=true;
        rep(j,3)
        {
            if((ct[c[i].fi+j]-1)*3 < num[c[i].fi+j])
            {
                b[j] = num[c[i].fi+j]-(ct[c[i].fi+j]-1)*3;
                all_zero=false;
                assert(b[j]>0);
                assert(b[j]<=3);
            }
        }

        if(all_zero)
        {
            rep(j,3)
            {
                if(num[c[i].fi+j] > 0)
                {
                    b[j]=1;
                    break;
                }
            }
        }

        // output
        rep(j,3)rep(k,3)
        {
            if(j<b[k]) ans[c[i].se][j][k]='#';
        }

        rep(j,3) --ct[c[i].fi+j];
        rep(j,3) num[c[i].fi+j]-=b[j];
    }

    rep(i,n)rep(j,3) cout << ans[i][j] << '\n';

    return 0;
}
0