Submission #377740

# Submission time Handle Problem Language Result Execution time Memory
377740 2021-03-14T22:01:45 Z Vimmer Sateliti (COCI20_satellti) C++14
10 / 110
36 ms 7404 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(1e9 + 7)
#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;

bitset <N> bt[N], lt, rt;

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);

    pw[0][0] = 2;

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

    pw[0][1] = 3;

    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;

                    bt[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] * pw[i][1] * a[i][j]) % 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] + 3 * 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 = m - 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];

                if (x > i)
                    h *= pw[x - i][1];

                if (y > j)
                    h *= pw[y - j][0];

                h = (h + 3 * 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];

                    if (x < i)
                        p *= pw[i - x][1];

                        if (y < j)
                    p *= pw[j - y][0];

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

                ft = (p == h);

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

            lt = bt[x + l];

            rt = bt[i + l];

            lt >>= y;

            rt >>= j;

            int ps = (lt ^ rt)._Find_first();

            if (ps < m && lt[ps] == 0)
            {
                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;
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:143:21: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  143 |                     if (x < i)
      |                     ^~
Main.cpp:146:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  146 |                         if (y < j)
      |                         ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 36 ms 7404 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Incorrect 2 ms 2924 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1004 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 2 ms 1004 KB Output is correct
8 Correct 36 ms 7404 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Incorrect 2 ms 2924 KB Output isn't correct
11 Halted 0 ms 0 KB -