Submission #373352

# Submission time Handle Problem Language Result Execution time Memory
373352 2021-03-04T09:00:30 Z sam571128 Sateliti (COCI20_satellti) C++14
110 / 110
686 ms 77164 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e3+5, MOD = 998244353, p = 11, q = 17;
int grid[N][N], pp[N], qp[N], h[N][N], sum[N][N];

int n,m;
int ansx, ansy;

void precompute(){
	pp[0] = 1;
	qp[0] = 1;
	for(int i = 1;i < N;i++){
		pp[i] = pp[i-1]*p%MOD;
		qp[i] = qp[i-1]*q%MOD;
	}
	for(int i = 0;i < 2*n;i++){
		for(int j = 0;j < 2*m;j++){
			h[i][j] = grid[i%n][j%m]*pp[i]%MOD*qp[j]%MOD;
		}
	}
	for(int i = 0;i < 2*n;i++){
		for(int j = 0;j < 2*m;j++){
			sum[i+1][j+1] = (h[i][j]+sum[i+1][j]+sum[i][j+1]-sum[i][j]);
		}
	}
}

bool check(int x1, int y1, int x2, int y2, int dx, int dy){
	return (((sum[x1+dx][y1+dy]-sum[x1+dx][y1]-sum[x1][y1+dy]+sum[x1][y1])%MOD+MOD)%MOD*pp[x2]%MOD*qp[y2]%MOD == ((sum[x2+dx][y2+dy]-sum[x2+dx][y2]-sum[x2][y2+dy]+sum[x2][y2])%MOD+MOD)%MOD*pp[x1]%MOD*qp[y1]%MOD);
}

signed main(){
	fastio
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			char c;
			cin >> c;
			if(c=='.') grid[i][j] = 1;
		}
	}

	precompute();
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			int l = 0, r = n;
			while(l+1 < r){
				int mid = l+r>>1;
				if(check(i,j,ansx,ansy,mid,m)) l = mid;
				else r = mid;
			}
			int dx = l;
			l = 0, r = m;
			while(l+1 < r){
				int mid = l+r>>1;
				if(check(i+dx,j,ansx+dx,ansy,1,mid)) l = mid;
				else r = mid;
			}
			int dy = l;

			if(grid[(i+dx)%n][(j+dy)%m] <= grid[(ansx+dx)%n][(ansy+dy)%m]){
				ansx = i;
				ansy = j;
			}
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			cout << (grid[(ansx+i)%n][(ansy+j)%m] ? '.' : '*');
		}
		cout << "\n";
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:53:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     int mid = l+r>>1;
      |               ~^~
Main.cpp:60:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |     int mid = l+r>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1516 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1516 KB Output is correct
6 Correct 2 ms 1516 KB Output is correct
7 Correct 2 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1516 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1516 KB Output is correct
6 Correct 2 ms 1516 KB Output is correct
7 Correct 2 ms 1516 KB Output is correct
8 Correct 50 ms 12524 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 4 ms 6252 KB Output is correct
11 Correct 49 ms 12524 KB Output is correct
12 Correct 53 ms 10860 KB Output is correct
13 Correct 51 ms 12908 KB Output is correct
14 Correct 56 ms 11244 KB Output is correct
15 Correct 50 ms 12908 KB Output is correct
16 Correct 54 ms 11904 KB Output is correct
17 Correct 55 ms 11116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1516 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1516 KB Output is correct
6 Correct 2 ms 1516 KB Output is correct
7 Correct 2 ms 1516 KB Output is correct
8 Correct 50 ms 12524 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 4 ms 6252 KB Output is correct
11 Correct 49 ms 12524 KB Output is correct
12 Correct 53 ms 10860 KB Output is correct
13 Correct 51 ms 12908 KB Output is correct
14 Correct 56 ms 11244 KB Output is correct
15 Correct 50 ms 12908 KB Output is correct
16 Correct 54 ms 11904 KB Output is correct
17 Correct 55 ms 11116 KB Output is correct
18 Correct 607 ms 76864 KB Output is correct
19 Correct 17 ms 21248 KB Output is correct
20 Correct 10 ms 1900 KB Output is correct
21 Correct 584 ms 77152 KB Output is correct
22 Correct 671 ms 65388 KB Output is correct
23 Correct 578 ms 77164 KB Output is correct
24 Correct 676 ms 65740 KB Output is correct
25 Correct 575 ms 77036 KB Output is correct
26 Correct 686 ms 68588 KB Output is correct
27 Correct 654 ms 65132 KB Output is correct