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>
//#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 1001
#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], nl, cur, cp;
int kl[N];
vector <int> psr[N];
vector <pair <int, int> > vr;
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int n, m;
cin >> n >> m;
string s[n];
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (s[i][j] == '*')
bt[i][j] = 1;
}
int mx = 0;
for (int i = 0; i < n; i++)
{
int sk = 0;
bool ft = 0;
for (int j = 0; j < m; j++)
{
if (s[i][j] == '*')
{
sk++;
if (kl[i] < sk)
{
kl[i] = sk;
}
}
else
{
sk = 0;
}
if (j == m - 1 && !ft && sk != 0 && s[i][0] != '.')
{
j = -1;
ft = 1;
}
}
mx = max(mx, kl[i]);
sk = 0;
ft = 0;
for (int j = 0; j < m; j++)
{
if (s[i][j] == '*')
{
sk++;
if (kl[i] == sk)
{
psr[i].PB((j - sk + 1 + m) % m);
}
}
else
{
sk = 0;
if (ft)
break;
}
if (j == m - 1 && !ft && sk != 0 && s[i][0] != '.')
{
j = -1;
ft = 1;
}
}
}
// pri(mx);
for (int i = 0; i < n; i++)
{
if (kl[i] < mx) continue;
for (auto it : psr[i])
{
vr.PB({i, it});
}
}
vector <pair <int, int> > nx; nx.clear();
int u = 0;
while (sz(vr) > 1 && u < n)
{
nx.clear();
nx.PB(vr[0]);
cur = bt[(vr[0].F + u) % n];
cur <<= (vr[0].S);
for (int t = 1; t < sz(vr); t++)
{
nl = bt[(vr[t].F + u) % n];
nl <<= (vr[t].S);
cp = (nl ^ cur);
int ps = cp._Find_next(-1);
if (ps == N)
{
nx.PB(vr[t]);
}
else if (cur[ps] == 0)
{
nx.clear();
nx.PB(vr[t]);
nl = cur;
}
}
u++;
}
int x = vr[0].F, y = vr[0].S;
// pri(x _ y);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cout << s[(x + i) % n][(y + j) % m];
cout << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |