QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#343285 | #8278. Secret Poems | mendicillin2# | WA | 0ms | 8372kb | C++17 | 2.0kb | 2024-03-02 13:21:13 | 2024-03-02 13:21:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0' || c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0' && c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
char ch[1100][1100], ans[1100];
int vis[1100][1100];
int main()
{
int n = read();
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++) {
cin >> ch[i][j];
}
int si = 1, sj = 1, f = 0;
for (int i = 1; i <= n * n; i ++) {
cout << si << ' ' << sj << endl;
ans[i] = ch[si][sj];
vis[si][sj] = 1;
if (si == 1 && sj + 1 <= n && !f) {
sj ++;
f = 1;
continue;
}
if (sj == 1 && si + 1 <= n && !f) {
si ++;
f = 1;
continue;
}
if (sj == n && si + 1 <= n && !f) {
si ++;
f = 1;
continue;
}
if (si == n && sj + 1 <= n && !f) {
sj ++;
f = 1;
continue;
}
f = 0;
if (!vis[si + 1][sj - 1] && si + 1 <= n && sj - 1 >= 1) {
++si;
--sj;
continue;
}
if (!vis[si - 1][sj + 1] && si - 1 >= 1 && sj + 1 <= n) {
--si;
++sj;
continue;
}
}
si = 1; sj = 1; f = 0;
memset(vis, 0, sizeof(vis));
for (int i = 0; i <= n + 1; i ++)
for (int j = 0; j <= n + 1; j ++)
vis[i][j] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j ++)
vis[i][j] = 0;
for (int i = 1; i <= n * n; i ++) {
ch[si][sj] = ans[i];
vis[si][sj] = 1;
if (f == 0 && !vis[si][sj + 1]) {
sj ++;
continue;
}
if (f == 0 && vis[si][sj + 1]) f = 1;
if (f == 1 && !vis[si + 1][sj]) {
si ++;
continue;
}
if (f == 1 && vis[si + 1][sj]) {
f = 2;
}
if (f == 2 && !vis[si][sj - 1]) {
sj --;
continue;
}
if (f == 2 && vis[si][sj - 1]) {
f = 3;
}
if (f == 3 && !vis[si - 1][sj]) {
si --;
continue;
}
if (f == 3 && vis[si - 1][sj]) {
f = 0;
}
if (f == 0 && !vis[si][sj + 1]) {
sj ++;
continue;
}
}
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++)
cout << ch[i][j];
cout <<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 8372kb
input:
5 THSAD IIVOP SEOOH RGETI YMINK
output:
1 1 1 2 2 1 3 1 2 2 1 3 1 4 2 3 3 2 4 1 5 1 4 2 3 3 2 4 1 5 2 5 3 4 4 3 5 2 5 3 4 4 3 5 4 5 5 4 5 5 THISI POEMS DNKIA OIHTV OGYRE
result:
wrong answer 1st lines differ - expected: 'THISI', found: '1 1'