結果

問題 No.3657 Gathering Stones
コンテスト
ユーザー shinchan
提出日時 2026-08-30 13:41:16
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 629µs
コード長 4,047 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,223 ms
コンパイル使用メモリ 344,436 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 13:41:28
合計ジャッジ時間 4,645 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#define all(v) (v).begin(),(v).end()
#define pb emplace_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define foa(e, v) for(auto& e : v)
#define dout(a) cout<<fixed<<setprecision(10)<<a<<'\n';
#define Cout(a) cout<<a<<'\n';

using ll = long long;
using ld = long double;
using Int = __int128;
template <class T> using pqr = priority_queue<T, vector<T>, greater<T>>;

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    bool compare = a < b;
    if(compare) a = b;
    return compare;
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    bool compare = a > b;
    if(compare) a = b;
    return compare;
}
template <typename T> inline T back(std::set<T> &s) {
    return *s.rbegin();
}
template <typename T> inline T back(std::multiset<T> &s) {
    return *s.rbegin();
}
template <typename T> inline T pop_back(std::set<T> &s) {
    auto it = prev(s.end());
    T val = *it;
    s.erase(it); 
    return val;
}
template <typename T> inline T pop_back(std::multiset<T> &s) {
    auto it = prev(s.end());
    T val = *it;
    s.erase(it); 
    return val;
}

const int dy[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
const int dx[8] = {0, -1, 1, 0, -1, -1, 1, 1};

const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (3LL << 59);
const int inf = 1 << 30;
const char br = '\n';

template<class T> std::vector<T> transpose(const std::vector<T> &v) {
    int n = v.size();
    if(n == 0) return v;
    int m = v[0].size();
    std::vector<T> ret(m);
    for(int i = 0; i < m; i ++) {
        ret[i].resize(n);
        for(int j = 0; j < n; j ++) ret[i][j] = v[j][i];
    }
    return ret;
}

template<class T> std::vector<T> rev_lr(std::vector<T> v) {
    int n = v.size();
    for(int i = 0; i < n; i ++) reverse(v[i].begin(), v[i].end());
    return v;
}

template<class T> std::vector<T> rev_ud(std::vector<T> v) {
    reverse(v.begin(), v.end());
    return v;
}

template<class T> std::vector<T> rotate(const std::vector<T> &v, int k) {
    k %= 4;
    if(k == 0) return v;
    if(k < 0) k += 4;
    if(k == 2) return rev_lr(rev_ud(v));
    int n = v.size(); if(n == 0) return v;
    int m = v[0].size();
    std::vector<T> ret(m);
    if(k == 1) {
        for(int i = 0; i < m; i ++) {
            ret[i].resize(n);
            for(int j = 0; j < n; j ++) ret[i][j] = v[n - j - 1][i];
        }
    } else {
        for(int i = 0; i < m; i ++) {
            ret[i].resize(n);
            for(int j = 0; j < n; j ++) ret[i][j] = v[j][m - i - 1];
        }
    }
    return ret;
}

template<class T> std::vector<T> shift(std::vector<T> v, int dy, int dx) {
    int n = v.size();
    if(n == 0) return v;
    int m = v[0].size();
    std::vector<T> ret = v;
    for(int i = 0, ni = dy; i < n; i ++, ni ++) {
        if(ni >= n) ni = 0;
        for(int j = 0, nj = dx; j < m; j ++, nj ++) {
            if(nj >= m) nj = 0;
            ret[ni][nj] = v[i][j];
        }
    }
    return Grid(ret);
}

template<class T> std::vector<T> shift_l(std::vector<T> v, int k) { return shift(v, 0, -k); }
template<class T> std::vector<T> shift_r(std::vector<T> v, int k) { return shift(v, 0, k); }
template<class T> std::vector<T> shift_u(std::vector<T> v, int k) { return shift(v, -k, 0); }
template<class T> std::vector<T> shift_d(std::vector<T> v, int k) { return shift(v, k, 0); }


vector<string> calc(vector<string> s) {
    ll h = s.size();
    ll w = s[0].size();
    vector<ll> cnt(h, 0);
    rep(i, h) rep(j, w) if(s[i][j] == '#') cnt[i] ++;
    vector<string> ret;
    rep(i, h) {
        string le(cnt[i], '#');
        string ri(w - cnt[i], '.');
        ret.pb(le + ri);
    }
    return ret;
}
void solve() {
    ll h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    s = transpose(s);
    s = calc(s);
    s = transpose(s);

    s = calc(s);
    
    foa(e, s) cout << e << endl;
}

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

    int testcase = 1; 
    // cin >> testcase;
    while(testcase --) solve();

    return 0;
}
0