This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e3+5;
const int ALPH = 26;
const int LGN = 25;
const int MOD = 1e9+7;
array<int,2> bases = {3,5};
vector<int> pows[2];
int n,m,q;
vector<vector<int> > grid, pref;
array<int,2> res;
int mult(int x, int y) {
return (x*y)%MOD;
}
int add(int x, int y) {
return(((x+y)%MOD) + MOD) %MOD;
}
int get_hash(array<int,2> a1, array<int,2> a2) {
if(a2[0] < a1[0] || a2[1] < a1[1]) return 0;
int ret = pref[a2[0]][a2[1]];
if(a1[0] > 0) {
ret = add(ret , -pref[a1[0] - 1][a2[1]]);
}
if(a1[1] > 0) {
ret = add(ret , -pref[a2[0]][a1[1] - 1]);
}
if(a1[1] > 0 && a1[0] > 0) {
ret = add(ret , pref[a1[0] - 1][a1[1] - 1]);
}
return ret;
}
bool isEqual(array<int,2> a1, array<int,2> a2, array<int,2> b1, array<int,2> b2) {
int mxx = max(a1[0], b1[0]), mxy = max(a1[1], b1[1]);
int tmpa = get_hash(a1, a2), tmpb = get_hash(b1, b2);
tmpa = mult(tmpa , mult(pows[0][mxx - a1[0]] , pows[1][mxy - a1[1]] ) );
tmpb = mult(tmpb , mult(pows[0][mxx - b1[0]] , pows[1][mxy - b1[1]] ) );
return tmpa == tmpb;
}
bool comp(array<int,2> x, array<int,2> y) {
int l = 0, r = n;
if(!isEqual(x, {x[0], x[1] + m - 1}, y, {y[0], y[1] + m - 1})) {
r = 0;
l = -1;
}
while(l + 1 < r) {
int tm = (l+r) / 2;
array<int,2> a2 = {x[0] + tm, x[1] + m - 1}, b2 = {y[0] + tm, y[1] + m - 1};
if(!isEqual(x, a2, y, b2)) {
r = tm;
}
else {
l = tm;
}
}
int row = r;
if(row == n) return 0;
l = 0, r = m;
if(!isEqual(x, {x[0] + row, x[1]}, y, {y[0] + row, y[1]})) {
l = -1;
r = 0;
}
while(l + 1 < r) {
int tm = (l+r) / 2;
array<int,2> a2 = {x[0] + row, x[1] + tm}, b2 = {y[0] + row, y[1] + tm};
if(!isEqual(x, a2, y, b2)) {
r = tm;
}
else {
l = tm;
}
}
int column = r;
if(column == m) return 0;
return grid[x[0] + row][x[1] + column] < grid[y[0] + row][y[1] + column];
}
void calc_pref() {
pref[0][0] = 1 * grid[0][0];
for(int i = 1; i<grid.size(); i++) {
pref[i][0] = add(pref[i-1][0], mult(grid[i][0] , pows[0][i]));
}
for(int j = 1; j<grid[0].size(); j++) {
pref[0][j] = add(pref[0][j-1], mult(grid[0][j], pows[1][j]));
}
for(int i = 1; i<grid.size(); i++) {
for(int j = 1; j<grid[i].size(); j++) {
pref[i][j] = add(pref[i][j-1] , add(pref[i-1][j] , -pref[i-1][j-1]));
pref[i][j] = add(pref[i][j] , mult(grid[i][j], mult(pows[0][i], pows[1][j]) ) );
}
}
}
inline void solve() {
cin>>n>>m;
grid.resize(2*n+1, vector<int> (2*m+1));
pref.resize(2*n+1, vector<int> (2*m+1));
REP(i,n) {
REP(j,m) {
char tmp;
cin>>tmp;
grid[i][j] = (tmp == '.');
grid[i][j+m] = grid[i+n][j] = grid[i+n][j+m] = grid[i][j];
}
}
calc_pref();
for(int i = 0; i<n; i++) {
for(int j = 0; j<m; j++) {
array<int,2> cur = {i,j};
if(!comp(res, cur) ) {
res = cur;
}
}
}
for(int i = res[0]; i<res[0] + n; i++) {
for(int j = res[1]; j<res[1] + m; j++) {
if(grid[i][j]) {
cout<<".";
}
else {
cout<<"*";
}
}
cout<<"\n";
}
}
signed main() {
//freopen("milkvisits.in", "r", stdin);
//freopen("milkvisits.out", "w", stdout);
//fastio();
for(int i = 0; i<2; i++) {
pows[i].resize(N);
pows[i][0] = 1;
for(int j = 1; j<N; j++) {
pows[i][j] = mult(pows[i][j-1], bases[i]);
}
}
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
Compilation message (stderr)
Main.cpp: In function 'std::string to_string(std::string, int, int)':
Main.cpp:7:208: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
| ~~~^~~~~~~~~~
Main.cpp: In function 'void calc_pref()':
Main.cpp:110:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i = 1; i<grid.size(); i++) {
| ~^~~~~~~~~~~~
Main.cpp:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int j = 1; j<grid[0].size(); j++) {
| ~^~~~~~~~~~~~~~~
Main.cpp:116:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for(int i = 1; i<grid.size(); i++) {
| ~^~~~~~~~~~~~
Main.cpp:117:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for(int j = 1; j<grid[i].size(); j++) {
| ~^~~~~~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:14:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
14 | #define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
| ^
Main.cpp:129:5: note: in expansion of macro 'REP'
129 | REP(i,n) {
| ^~~
Main.cpp:14:26: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
14 | #define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
| ^
Main.cpp:130:9: note: in expansion of macro 'REP'
130 | REP(j,m) {
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |