답안 #377738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377738 2021-03-14T21:49:41 Z Vimmer Sateliti (COCI20_satellti) C++14
0 / 110
1 ms 1004 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

#define N 2051
#define NN 1005000
#define PB push_back
#define M ll(998244353)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pri(x) cout << x << endl
#define endl '\n'
#define _ << " " <<
#define F first
#define S second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef short int si;

ll pw[N][2], pr[N][N];

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

//    freopen("1.in", "r", stdin);
//    freopen("1.out", "w", stdout);

    pw[0][0] = 1;

    for (int i = 1; i < N; i++)
        pw[i][0] = (pw[i - 1][0] * 2) % M;

    pw[0][1] = 1;

    for (int i = 1; i < N; i++)
        pw[i][1] = (pw[i - 1][1] * 3) % M;

    int n, m;

    cin >> n >> m;

    string s[n + n];

    for (int i = 0; i < n; i++)
        cin >> s[i];

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

            s[i + n] = s[i];
        }

    int a[n + n][m + m];

    for (int i = 0; i < n + n; i++)
        for (int j = 0; j < m + m; j++)
        {
            if (s[i][j] == '*')
                    a[i][j] = 1;
                    else a[i][j] = 0;
        }

    for (int i = 0; i < n + n; i++)
        for (int j = 0; j < m + m; j++)
        {
            pr[i][j] = (pw[j][0] * a[i][j] + a[i][j] * pw[i][1]) % M;

            if (i != 0)
                pr[i][j] += pr[i - 1][j];

            if (j != 0)
                pr[i][j] += pr[i][j - 1];

            if (i != 0 && j != 0)
                pr[i][j] -= pr[i - 1][j - 1];

            pr[i][j] = (pr[i][j] + 10 * M) % M;
        }

    int x = 0, y = 0;

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

            int l = 0, r = n - 1;

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

                bool ft = 1;

                ll h = pr[i + md][j + m];

                if (i != 0)
                    h -= pr[i - 1][j + m];

                if (j != 0)
                    h -= pr[i + md][j - 1];

                if (i != 0 && j != 0)
                    h += pr[i - 1][j - 1];

                h = (h + 10 * M) % M;

                    ll p = pr[x + md][y + m];

                    if (x != 0)
                        p -= pr[x - 1][y + m];

                    if (y != 0)
                        p -= pr[x + md][y - 1];

                    if (x != 0 && y != 0)
                        p += pr[x - 1][y - 1];

                    p = (p + 10 * M) % M;

                ft = (p == h);

                if (ft)
                    l = md + 1;
                        else r = md;
            }

            int lt = 0, rt = m - 1;

            while (lt < rt)
            {
                int md = (lt + rt) >> 1;

                ll h = pr[i + l][j + md];

                if (i + l != 0)
                    h -= pr[i + l - 1][j + md];

                if (j != 0)
                    h -= pr[i + l][j - 1];

                if (i + l != 0 && j != 0)
                    h += pr[i + l - 1][j - 1];

                h = (h + 10 * M) % M;

                    ll p = pr[x + l][y + md];

                    if (x + l != 0)
                        p -= pr[x + l - 1][y + md];

                    if (y != 0)
                        p -= pr[x + l][y - 1];

                    if (x + l != 0 && y != 0)
                        p += pr[x + l - 1][y - 1];

                    p = (p + 10 * M) % M;

                if (h == p)
                    lt = md + 1;
                        else rt = md;
            }

            if (a[x + l][y + lt] < a[i + l][j + lt])
            {
                x = i; y = j;
            }
        }

    for (int i = x; i < x + n; i++)
    {
        for (int j = y; j < y + m; j++)
            cout << s[i][j];

        cout << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -