Submission #421252

# Submission time Handle Problem Language Result Execution time Memory
421252 2021-06-08T23:17:47 Z SirCovidThe19th Sateliti (COCI20_satellti) C++14
110 / 110
899 ms 49472 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll p = 786433, q = 6291469, md = 1e9+7;

int n, m, grid[2010][2010]; ll pPow[2010], qPow[2010], hsh[2010][2010]; 
int ansR = 1, ansC = 1;

ll get(int a, int b, int x, int y){
    return (hsh[x][y] - (hsh[a-1][y]*pPow[x-a+1])%md - (hsh[x][b-1]*qPow[y-b+1])%md + (hsh[a-1][b-1]*((pPow[x-a+1]*qPow[y-b+1])%md))%md + md*2)%md;
}

int main(){
    cin >> n >> m; pPow[0] = 1; qPow[0] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            char x; cin >> x; int v = (x == '*') ? 1 : 2;
            grid[i][j] = v; grid[i+n][j] = v; grid[i][j+m] = v; grid[i+n][j+m] = v;
        }
    for (int i = 1; i <= n; i++) pPow[i] = (pPow[i-1]*p)%md;
    for (int i = 1; i <= m; i++) qPow[i] = (qPow[i-1]*q)%md;
    for (int i = 1; i <= n*2; i++)
        for (int j = 1; j <= m*2; j++)
            hsh[i][j] = (hsh[i-1][j]*p + hsh[i][j-1]*q - (hsh[i-1][j-1]*((p*q)%md))%md + grid[i][j] + md)%md;
    for (int i = 1; i+n-1 <= 2*n; i++)
        for (int j = 1; j+m-1 <= 2*m; j++){
            int r = 0, c = 0, high = n;
            while (r < high){
                int mid = (r+high)/2;
                if (get(ansR, ansC, ansR+mid, ansC+m-1) == get(i, j, i+mid, j+m-1)) r = mid+1;
                else high = mid;
            }high = m;
            while (c < high){
                int mid = (c+high)/2;
                if (get(ansR+r, ansC, ansR+r, ansC+mid) == get(i+r, j, i+r, j+mid)) c = mid+1;
                else high = mid;
            }
            if (grid[i+r][j+c] == 1) ansR = i, ansC = j;
        }    
    for (int i = ansR; i < ansR+n; i++){
        for (int j = ansC; j < ansC+m; j++)
            cout<<((grid[i][j] == 1) ? '*' : '.');
        cout<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1228 KB Output is correct
2 Correct 2 ms 1064 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1196 KB Output is correct
6 Correct 3 ms 1228 KB Output is correct
7 Correct 3 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1228 KB Output is correct
2 Correct 2 ms 1064 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1196 KB Output is correct
6 Correct 3 ms 1228 KB Output is correct
7 Correct 3 ms 1228 KB Output is correct
8 Correct 72 ms 9156 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 67 ms 9140 KB Output is correct
12 Correct 83 ms 9272 KB Output is correct
13 Correct 69 ms 9420 KB Output is correct
14 Correct 75 ms 9456 KB Output is correct
15 Correct 69 ms 9500 KB Output is correct
16 Correct 84 ms 9440 KB Output is correct
17 Correct 69 ms 9452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1228 KB Output is correct
2 Correct 2 ms 1064 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 2 ms 1196 KB Output is correct
6 Correct 3 ms 1228 KB Output is correct
7 Correct 3 ms 1228 KB Output is correct
8 Correct 72 ms 9156 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 67 ms 9140 KB Output is correct
12 Correct 83 ms 9272 KB Output is correct
13 Correct 69 ms 9420 KB Output is correct
14 Correct 75 ms 9456 KB Output is correct
15 Correct 69 ms 9500 KB Output is correct
16 Correct 84 ms 9440 KB Output is correct
17 Correct 69 ms 9452 KB Output is correct
18 Correct 899 ms 49328 KB Output is correct
19 Correct 17 ms 16844 KB Output is correct
20 Correct 14 ms 1240 KB Output is correct
21 Correct 790 ms 49400 KB Output is correct
22 Correct 841 ms 49444 KB Output is correct
23 Correct 798 ms 49440 KB Output is correct
24 Correct 848 ms 49424 KB Output is correct
25 Correct 800 ms 49436 KB Output is correct
26 Correct 851 ms 49472 KB Output is correct
27 Correct 827 ms 49340 KB Output is correct