QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#342218#8278. Secret PoemsGen1usRE 0ms3860kbC++143.5kb2024-03-01 09:49:132024-03-01 09:49:13

Judging History

你现在查看的是最新测评结果

  • [2024-03-01 09:49:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3860kb
  • [2024-03-01 09:49:13]
  • 提交

answer

// Online C++ compiler to run C++ program online
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    int s=0;
    cin >> n;
    char a[n+1][n+1];
    vector<char> b(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";
    }
    b.clear();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3860kb

input:

5
THSAD
IIVOP
SEOOH
RGETI
YMINK

output:

THISI
POEMS
DNKIA
OIHTV
OGYRE

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

2
AB
CD

output:

AB
DC

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4
ABCD
EFGH
IJKL
MNOP

output:

ABEI
KHLF
NPOC
MJGD

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

8
ABCEFDWL
ABCEFDWL
ABCEFDWL
ABCEFDWL
ABCEFDWL
ABCEFDWL
ABCEFDWL
ABCEFDWL

output:

ABAABCEC
WLWDFECB
DECEFDBA
FFWLLWAA
EDDLWLBB
CWFDWLCC
BLLWDFEE
AABCEFDF

result:

ok 8 lines

Test #5:

score: -100
Runtime Error

input:

20
ABCDEFGHEFGHEFGHIJKL
EFGHIJKLMNOPKLMNKEFW
IJKLIAAAAJKLIJKLEEEE
EFGHIJKLMNOPKLMNKEFW
IJKLIAAAAJKLIJKLEEEE
IJKLIAAAAJKLIJKLEEEE
JKLIJKLEEEEIJKLIAAAA
EFGHIJKLMNOPKLMNKEFW
ABCDEFGHEFGHEFGHIJKL
EFGHIJKLMNOPKLMNKEFW
IJKLIAAAAJKLIJKLEEEE
EFGHIJKLMNOPKLMNKEFW
IJKLIAAAAJKLIJKLEEEE
IJKLIAAAAJKLIJKLEEEE
JKL...

output:


result: