QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#342234 | #8278. Secret Poems | Gen1us | RE | 0ms | 0kb | C++14 | 3.5kb | 2024-03-01 09:56:35 | 2024-03-01 09:56:35 |
answer
// Online C++ compiler to run C++ program online
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main() {
int n;
int s=0;
cin >> n;
vector<vector<char>> a(n+1, vector<char>(n+1));
char *b = new char[n*n+1];
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cin >> a[i][j];
}
}
for(int i=0; i<=n+1; i++) {
a[0][i]=' ';
a[n+1][i]=' ';
a[i][0]=' ';
a[i][n+1]=' ';
}
bool right=true, bottom_left=false, bottom=false, top_right=false;
int i=1, j=1;
b[1]=a[1][1];
int element=2;
while(element<=(n*(n+1)/2)) {
if(right) j++;
if(bottom_left) {
i++;
j--;
}
if(bottom) i++;
if(top_right) {
i--;
j++;
}
b[element]=a[i][j];
element++;
if(right) {
right=false;
bottom_left=true;
goto next;
}
if(bottom_left && a[i+1][j-1]==' ') {
bottom_left=false;
bottom=true;
goto next;
}
if(bottom) {
bottom=false;
top_right=true;
goto next;
}
if(top_right && a[i-1][j+1]==' ') {
top_right=false;
right=true;
goto next;
}
next:
s++;
}
if(n%2) {
right=false;
bottom=true;
}
if(n%2==0) {
bottom=false;
right=true;
}
while(element<=n*n) {
if(right) j++;
if(bottom_left) {
i++;
j--;
}
if(bottom) i++;
if(top_right) {
i--;
j++;
}
b[element]=a[i][j];
element++;
if(right) {
right=false;
top_right=true;
goto end;
}
if(bottom_left && a[i+1][j-1]==' ') {
bottom_left=false;
right=true;
goto end;
}
if(bottom) {
bottom=false;
bottom_left=true;
goto end;
}
if(top_right && a[i-1][j+1]==' ') {
top_right=false;
bottom=true;
goto end;
}
end:
s++;
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
a[i][j]=0;
}
}
for(int i=0; i<=n+1; i++) {
a[0][i]=1;
a[n+1][i]=1;
a[i][0]=1;
a[i][n+1]=1;
}
right=true;
bool left=false;
bottom=false;
bool top=false;
i=1, j=0;
element=1;
while(element<=n*n) {
if(right) j++;
if(left) j--;
if(bottom) i++;
if(top) i--;
a[i][j]=b[element];
element++;
if(right && a[i][j+1]) {
right=false;
bottom=true;
goto hi;
}
if(left && a[i][j-1]) {
left=false;
top=true;
goto hi;
}
if(bottom && a[i+1][j]) {
bottom=false;
left=true;
goto hi;
}
if(top && a[i-1][j]) {
top=false;
right=true;
goto hi;
}
hi:
s++;
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cout << a[i][j];
}
cout << "\n";
}
a.clear();
delete [] b;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 THSAD IIVOP SEOOH RGETI YMINK