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 <stdio.h>
#define N 2000
int di[] = { -1, 0, 1, 0 };
int dj[] = { 0, 1, 0, -1 };
int ej[(N + 2) * (N + 2)][4];
int nxt(int u, int v, int r) {
int h;
for (h = 0; h < 4; h++)
if (ej[v][h] == u)
return ej[v][(h + 2 + r) % 4];
return -1;
}
void reattach(int u, int v, int w) {
int h;
for (h = 0; h < 4; h++)
if (ej[u][h] == v) {
ej[u][h] = w;
return;
}
}
int main() {
static char cc[N][N + 1], cc_[N][N + 1];
int n, q, h, i, j, i_, j_, k, l, u, v, w, x, y;
scanf("%d%d", &n, &q);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
for (i = 0; i <= n + 1; i++)
for (j = 0; j <= n + 1; j++) {
u = i * (n + 2) + j;
for (h = 0; h < 4; h++) {
i_ = i + di[h], j_ = j + dj[h], v = i_ * (n + 2) + j_;
ej[u][h] = i_ >= 0 && i_ <= n + 1 && j_ >= 0 && j_ <= n + 1 ? v : -1;
}
}
while (q--) {
static int qu1[N * 4], qu2[N * 4];
scanf("%d%d%d", &i, &j, &l);
u = 0 * (n + 2) + 0, v = 0 * (n + 2) + 1;
for (k = 2; k <= j; k++)
w = nxt(u, v, 0), u = v, v = w;
u = nxt(u, v, -1);
for (k = 1; k <= i; k++)
w = nxt(u, v, 0), u = v, v = w;
for (h = 0; h < 4; h++) {
for (k = 1; k <= l; k++) {
qu1[h * l + k - 1] = v, qu2[h * l + k - 1] = nxt(u, v, 1);
if (k < l)
w = nxt(u, v, 0), u = v, v = w;
}
u = nxt(u, v, 1);
}
for (h = 0; h < 4; h++)
for (k = 1; k <= l; k++) {
reattach(qu1[h * l + k - 1], qu2[h * l + k - 1], qu2[(h + 1) % 4 * l + k - 1]);
reattach(qu2[h * l + k - 1], qu1[h * l + k - 1], qu1[(h + 3) % 4 * l + k - 1]);
}
}
u = 0 * (n + 2) + 0, v = 1 * (n + 2) + 0;
for (i = 1; i <= n; i++) {
x = nxt(u, v, 1), y = v;
for (j = 1; j <= n; j++) {
w = nxt(x, y, 0), x = y, y = w;
cc_[i - 1][j - 1] = cc[w / (n + 2) - 1][w % (n + 2) - 1];
}
if (i < n)
w = nxt(u, v, 0), u = v, v = w;
}
for (i = 0; i < n; i++)
printf("%s\n", cc_[i]);
return 0;
}
Compilation message (stderr)
rotate.c: In function 'main':
rotate.c:33:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d%d", &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~
rotate.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%s", cc[i]);
| ^~~~~~~~~~~~~~~~~~
rotate.c:47:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d%d", &i, &j, &l);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |