QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#342213#8278. Secret PoemsGen1usRE 1ms3684kbC++143.4kb2024-03-01 09:46:232024-03-01 09:46:23

Judging History

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

  • [2024-03-01 09:46:23]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3684kb
  • [2024-03-01 09:46:23]
  • 提交

answer

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
THSAD
IIVOP
SEOOH
RGETI
YMINK

output:

THISI
POEMS
DNKIA
OIHTV
OGYRE

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3632kb

input:

2
AB
CD

output:

AB
DC

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

4
ABCD
EFGH
IJKL
MNOP

output:

ABEI
KHLF
NPOC
MJGD

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 3552kb

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: 0
Accepted
time: 1ms
memory: 3552kb

input:

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

output:

ABEIFCDGJEIFKHEFILGJ
GJEIFKHEJLAANKPEFKLI
DLENELILKNIJKLMJIIOJ
IAAKIDGJIJKHEJLAAOJJ
KJAPILGNAEEWEEAKNFAK
AIMKLMJIIOFMAAKHKMEH
ALJJKKPELLLEEEAMPAKI
MLOEJEWEEAKHMWNJEKFJ
JFHLFLELLIEEJEGKLAIG
OAKGAJEKEWEKEFPLLILH
HEKJEOAJAJAWKEJKLIGK
GKKIAHNFJEFLKEJEEGJA
NKLLEKGAEAEINIKMEBII
ALKKIKLIEELKFMNHEEJL
LIELNK...

result:

ok 20 lines

Test #6:

score: -100
Runtime Error

input:

100
XIZRFKBGIFYHQYTINRAKHBPJVQGJIJQXTBLLBVNQQQTSAKPIXTORIREMDTGNDFTOZGUZICOMGINGXDXQXYQEWRNCYEDQCQZHKOIB
DNOXVOJOCZMMMAVEWUBXSRPTRNQYWWNGIPKSSRRSBJVKJTAFHQTLJXRWEAZIPYYHSOOTJNJWROQLKUUXBDYKEWKCGGVKFYUWEJWA
MIJFNAGSVCXQVEUKOKADMISAQIUNIRHMOVQUPREHRYLSVCTDMTDBEUOYEDJNAQGAMDPLLVAMNARRTYQQERKKBOMPGEEYBC...

output:


result: