답안 #377588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377588 2021-03-14T10:41:20 Z ne4eHbKa Specijacija (COCI20_specijacija) C++17
0 / 110
423 ms 351980 KB
#include <bits/stdc++.h>
using namespace std;
#ifndef _LOCAL
//#pragma GCC optimize("O3,Ofast")
#else
#pragma GCC optimize("O0")
#endif
template<typename t> inline void umin(t &a, const t b) {a = min(a, b);}
template<typename t> inline void umax(t &a, const t b) {a = max(a, b);}
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef int8_t byte;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
#define ft first
#define sd second
#define len(f) int((f).size())
#define bnd(f) (f).begin(), (f).end()
#define _ <<' '<<
const int inf = 1e9 + 5;
const ll inf64 = 4e18 + 5;
const int md = 998244353;
namespace MD {
    void add(int &a, const int b) {if((a += b) >= md) a -= md;}
    void sub(int &a, const int b) {if((a -= b) < 0) a += md;}
    int prod(const int a, const int b) {return ll(a) * b % md;}
};

const int N = 1e3 + 5;
const int NN = 2e3 + 5;
const int K = 4e6 + 5;

int n, m, nn, mm, d;
int a[NN][NN], z[NN][NN];
int fst[K], lst[K], nxt[K], vl[K], t, e[K], ne;

inline void add(const int &i, const int &j) {
    umax(d, i + 1);
    if(fst[i] < 0) {
        fst[i] = lst[i] = t;
    } else {
        nxt[lst[i]] = t;
        lst[i] = t;
    }
    vl[t++] = j;
}

inline void iterate(const int &i) {
    if(fst[i] < 0) return;
    for(int j = fst[i]; ; j = nxt[j]) {
        e[ne++] = vl[j];
        if(j == lst[i]) {
            fst[i] = -1;
            return;
        }
    }
}

typedef pair<pii, pii> ppp;
ppp f[K]; int nf;

void doub(int a[NN][NN], int dx, int dy) {
    nf = 0;
    for(int i = 0; i + dx < nn; ++i)
        for(int j = 0; j + dy < mm; ++j)
            f[nf++] = {{a[i][j], a[i + dx][j + dy]}, {i, j}};

    d = t = 0;
    for(int i = 0; i < nf; ++i)
        add(f[i].ft.sd, i);
    ne = 0;
    for(int i = 0; i < d; ++i)
        iterate(i);

    d = t = 0;
    for(int i = 0; i < ne; ++i)
        add(f[e[i]].ft.ft, e[i]);
    ne = 0;
    for(int i = 0; i < d; ++i)
        iterate(i);

    for(int i = 0, j = 0; i < nf; ++i) {
        auto &g = f[e[i]];
        if(i && g.ft != f[e[i - 1]].ft)
            ++j;
        a[g.sd.ft][g.sd.sd] = j;
    }
}

void solve() {
    memset(fst, -1, sizeof fst);
    cin >> n >> m;
    nn = n << 1;
    mm = m << 1;
    for(int i = 0; i < NN; ++i) {
        for(int j = 0; j < NN; ++j) {
            if(i < n && j < m) {
                char c; cin >> c;
                a[i][j] = c == '.';
            } else
                a[i][j] = a[i % n][j % m];
        }
    }
    memcpy(z, a, sizeof z);
    for(int i = 1; ; ++i) {
        doub(a, 0, 1 << i - 1);
        if(1 << i + 1 >= m) {
            doub(a, 0, m - (1 << i));
            break;
        }
    }
    for(int i = 1; ; ++i) {
        doub(a, 1 << i - 1, 0);
        if(1 << i + 1 >= n) {
            doub(a, n - (1 << i), 0);
            break;
        }
    }
    int x = 0, y = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            if(a[i][j] < a[x][y])
                x = i, y = j;
    for(int i = 0; i < n; ++i, cout << '\n')
        for(int j = 0; j < m; ++j)
            cout << (z[x + i][y + j] ? '.' : '*');
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef _LOCAL
//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);
#else
    system("color a");
    freopen("in.txt", "r", stdin);
    int t; cin >> t;
    while(t--)
#endif
    solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:107:27: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  107 |         doub(a, 0, 1 << i - 1);
      |                         ~~^~~
Main.cpp:108:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  108 |         if(1 << i + 1 >= m) {
      |                 ~~^~~
Main.cpp:114:24: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  114 |         doub(a, 1 << i - 1, 0);
      |                      ~~^~~
Main.cpp:115:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  115 |         if(1 << i + 1 >= n) {
      |                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 95980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 95980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 145 ms 95980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 423 ms 351980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -