/* nya */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma")
#include <bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int long long
#define INF (int)(1e18)
#define MOD (int)(1000000007)
// #define MOD (int)(998244353)
using namespace std;
using LL = long long;
using LLL = __int128_t;
using pii = pair<int, int>;
#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
namespace {
const int MAXN = 1024;
pii i2p(int id) {
return pii(id >> 10, id & 1023);
}
int p2i(int a, int b) {
return (a << 10) | b;
}
int n, m;
char g[MAXN][MAXN];
int val[MAXN][MAXN];
int sa[MAXN * MAXN];
int rk[MAXN * MAXN];
int tmp[MAXN * MAXN];
void getSA(function<int(int, int)> nxt) {
int nm = n * m;
int *r = rk;
int *r2 = tmp;
For(i, 0, n - 1) For(j, 0, m - 1) {
sa[i * m + j] = p2i(i, j);
r[p2i(i, j)] = val[i][j];
}
for(int len = 1; len < 1024; len <<= 1) {
auto cmp = [&](int a, int b) {
if(r[a] != r[b]) return r[a] < r[b];
a = nxt(a, len); b = nxt(b, len);
return r[a] < r[b];
};
sort(sa, sa + nm, cmp);
r2[sa[0]] = 0;
For(i, 1, nm - 1) r2[sa[i]] = r2[sa[i - 1]] + cmp(sa[i - 1], sa[i]);
swap(r, r2);
}
if(r != rk) {
For(i, 0, nm - 1) rk[i] = tmp[i];
}
}
int nxt1(int id, int len) {
pii p = i2p(id);
return p2i(p.F, (p.S + len) % m);
}
int nxt2(int id, int len) {
pii p = i2p(id);
return p2i((p.F + len) % n, p.S);
}
inline void in(int &x) {
x = 0;
for(char ch; (ch = getchar()) <= '9' && ch >= '0';)
x = x * 10 + ch - '0';
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// OAO
in(n); in(m);
For(i, 0, n - 1) For(j, 0, m - 1) {
char ch = getchar();
val[i][j] = (ch == '.');
g[i][j] = ch;
if(j == m - 1) ch = getchar();
}
getSA(nxt1);
For(i, 0, n - 1) For(j, 0, m - 1) {
auto id = p2i(i, j);
val[i][j] = rk[id];
}
getSA(nxt2);
auto p = i2p(sa[0]);
int x = p.F, y = p.S;
For(i, 0, n - 1) {
For(j, 0, m - 1) putchar(g[(x + i) % n][(y + j) % m]);
putchar('\n');
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
948 KB |
Output is correct |
5 |
Correct |
3 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
948 KB |
Output is correct |
5 |
Correct |
3 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
980 KB |
Output is correct |
8 |
Correct |
144 ms |
4468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
216 ms |
4448 KB |
Output is correct |
12 |
Correct |
221 ms |
4588 KB |
Output is correct |
13 |
Correct |
211 ms |
4704 KB |
Output is correct |
14 |
Correct |
200 ms |
4696 KB |
Output is correct |
15 |
Correct |
186 ms |
4772 KB |
Output is correct |
16 |
Correct |
177 ms |
4692 KB |
Output is correct |
17 |
Correct |
224 ms |
4688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
5 ms |
948 KB |
Output is correct |
5 |
Correct |
3 ms |
980 KB |
Output is correct |
6 |
Correct |
3 ms |
980 KB |
Output is correct |
7 |
Correct |
5 ms |
980 KB |
Output is correct |
8 |
Correct |
144 ms |
4468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
216 ms |
4448 KB |
Output is correct |
12 |
Correct |
221 ms |
4588 KB |
Output is correct |
13 |
Correct |
211 ms |
4704 KB |
Output is correct |
14 |
Correct |
200 ms |
4696 KB |
Output is correct |
15 |
Correct |
186 ms |
4772 KB |
Output is correct |
16 |
Correct |
177 ms |
4692 KB |
Output is correct |
17 |
Correct |
224 ms |
4688 KB |
Output is correct |
18 |
Correct |
2184 ms |
19108 KB |
Output is correct |
19 |
Correct |
28 ms |
13396 KB |
Output is correct |
20 |
Correct |
25 ms |
684 KB |
Output is correct |
21 |
Execution timed out |
3061 ms |
18336 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |