답안 #377403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377403 2021-03-14T07:14:31 Z VEGAnn Sateliti (COCI20_satellti) C++14
110 / 110
518 ms 124416 KB
#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int N = 2010;
const int M = 11;
const int PW = 10;
const int HPW = 233;
const int md = int(1e9) + 7;
bool mat[N][N];
int n, m, hsh[N][N];
int sms[N][N][PW], prec[N * N];

int sum(int x, int y){
    x += y;
    if (x >= md)
        x -= md;
    return x;
}

int sub(int x, int y){
    x -= y;
    if (x < 0)
        x += md;
    return x;
}

int mult(int x, int y) { return (1ll * x * y) % md; }

int get_hsh(int id, int lf, int rt){
    return sub(hsh[id][lf], mult(hsh[id][rt + 1], prec[rt - lf + 1]));
}

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    prec[0] = 1;

    for (int i = 1; i < N * N; i++)
        prec[i] = mult(prec[i - 1], HPW);

    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++){
        char c; cin >> c;

        mat[i][j] = bool(c == '*');
    }

    for (int i = 0; i < n + n; i++)
    for (int j = 0; j < m + m; j++)
        mat[i][j] = mat[(i % n)][(j % m)];

    for (int i = 0; i < n + n; i++){
        hsh[i][m + m] = 0;

        for (int j = m + m - 1; j >= 0; j--)
            hsh[i][j] = sum(mult(hsh[i][j + 1], HPW), mat[i][j] + 1);

        for (int j = 0; j < m; j++)
            sms[i][j][0] = get_hsh(i, j, j + m - 1);
    }

    for (int po = 1; po < PW; po++)
    for (int i = 0; ; i++){
        if (i + (1 << po) > n + n) break;

        int NOW = prec[m * (1 << (po - 1))];

        for (int j = 0; j < m; j++)
            sms[i][j][po] = sum(sms[i][j][po - 1], mult(NOW, sms[i + (1 << (po - 1))][j][po - 1]));
    }

    int bx = 0, by = 0;

    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++){
        if (i == 0 && j == 0) continue;

        int len = 0;

        for (int po = PW - 1; po >= 0; po--){
            if (len + (1 << po) > n) continue;

            if (sms[i + len][j][po] != sms[bx + len][by][po]) continue;

            len += (1 << po);
        }

        if (len == n) continue;

        int l = 0, r = m - 1;

        while (l < r){
            int md = (l + r) >> 1;

            if (get_hsh(i + len,  j,  j + md) !=
                get_hsh(bx + len, by, by + md))
                r = md;
            else l = md + 1;
        }

        assert(mat[i + len][j + l] != mat[bx + len][by + l]);

        if (mat[i + len][j + l] > mat[bx + len][by + l]){
            bx = i;
            by = j;
        }
    }

    for (int i = bx; i < bx + n; i++){
        for (int j = by; j < by + m; j++)
            cout << (mat[i][j] ? '*' : '.');
        cout << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 17388 KB Output is correct
2 Correct 34 ms 17260 KB Output is correct
3 Correct 34 ms 17260 KB Output is correct
4 Correct 33 ms 17388 KB Output is correct
5 Correct 33 ms 17388 KB Output is correct
6 Correct 33 ms 17388 KB Output is correct
7 Correct 33 ms 17388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 17388 KB Output is correct
2 Correct 34 ms 17260 KB Output is correct
3 Correct 34 ms 17260 KB Output is correct
4 Correct 33 ms 17388 KB Output is correct
5 Correct 33 ms 17388 KB Output is correct
6 Correct 33 ms 17388 KB Output is correct
7 Correct 33 ms 17388 KB Output is correct
8 Correct 73 ms 30444 KB Output is correct
9 Correct 34 ms 16620 KB Output is correct
10 Correct 35 ms 22252 KB Output is correct
11 Correct 72 ms 30444 KB Output is correct
12 Correct 75 ms 30700 KB Output is correct
13 Correct 84 ms 30836 KB Output is correct
14 Correct 72 ms 30828 KB Output is correct
15 Correct 74 ms 30828 KB Output is correct
16 Correct 74 ms 30956 KB Output is correct
17 Correct 76 ms 30828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 17388 KB Output is correct
2 Correct 34 ms 17260 KB Output is correct
3 Correct 34 ms 17260 KB Output is correct
4 Correct 33 ms 17388 KB Output is correct
5 Correct 33 ms 17388 KB Output is correct
6 Correct 33 ms 17388 KB Output is correct
7 Correct 33 ms 17388 KB Output is correct
8 Correct 73 ms 30444 KB Output is correct
9 Correct 34 ms 16620 KB Output is correct
10 Correct 35 ms 22252 KB Output is correct
11 Correct 72 ms 30444 KB Output is correct
12 Correct 75 ms 30700 KB Output is correct
13 Correct 84 ms 30836 KB Output is correct
14 Correct 72 ms 30828 KB Output is correct
15 Correct 74 ms 30828 KB Output is correct
16 Correct 74 ms 30956 KB Output is correct
17 Correct 76 ms 30828 KB Output is correct
18 Correct 500 ms 124012 KB Output is correct
19 Correct 47 ms 37376 KB Output is correct
20 Correct 39 ms 18284 KB Output is correct
21 Correct 513 ms 124408 KB Output is correct
22 Correct 507 ms 124396 KB Output is correct
23 Correct 512 ms 124288 KB Output is correct
24 Correct 505 ms 124284 KB Output is correct
25 Correct 518 ms 124416 KB Output is correct
26 Correct 507 ms 124396 KB Output is correct
27 Correct 506 ms 124004 KB Output is correct