QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#337067#8278. Secret Poemsucup-team2000#RE 1ms3860kbC++203.4kb2024-02-25 02:44:282024-02-25 02:44:28

Judging History

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

  • [2024-02-25 02:44:28]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3860kb
  • [2024-02-25 02:44:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int maxn = 15;
int n;
char grid[maxn][maxn], ans[maxn][maxn];
char dir[] = {'R', 'D', 'L', 'U'};

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) { 
            cin >> grid[i][j];
            ans[i][j] = '.';
        }
    }
    if (n == 1) {
        cout << grid[0][0];
    } else {
        string res;
        res.push_back(grid[0][0]);
        for (int i = 1; i < n; ++i) {
            bool same = i&1;
            string tmp;
            for (int j = i; j >= 0; --j) {
                tmp.push_back(grid[i - j][j]);
            }
            if (!same) reverse(tmp.begin(), tmp.end());
            res += tmp;
        }
        for (int i = 1; i < n; ++i) {
            bool same = (n&1 ? i&1 : !(i&1));
            string tmp;
            for (int j = 1; j <= n - i; ++j) {
                tmp.push_back(grid[i + j - 1][n - j]);
            }
            if (!same) reverse(tmp.begin(), tmp.end());
            res += tmp;
        }
        // cout << res << endl;
        int cnt = 0, cnt1 = 0, row = 0, col = 0;
        for (int i = 0; i < res.size();) {
            if (dir[cnt % 4] == 'R') {
                while (i < res.size() && row < n && col < n && ans[row][col] == '.') {
                    // cout << "R: " << row << " " << col << " " << res[i] << " " << cnt1 << endl;
                    ans[row][col] = res[i++];
                    col++;
                    cnt1++;
                }
                row++;
                col--;
                cnt++;
            } else if (dir[cnt % 4] == 'D') {
                while (i < res.size() && row < n && col < n && ans[row][col] == '.') {
                    // cout << "D: " << row << " " << col << " " << res[i] << " " << cnt1 << endl;
                    ans[row][col] = res[i++];
                    row++;
                    cnt1++;
                }
                col--;
                row--;
                cnt++;
            } else if (dir[cnt % 4] == 'L') {
                while (i < res.size() && row < n && col >= 0 && ans[row][col] == '.') {
                    // cout << "L: " << row << " " << col << " " << res[i] << " " << cnt1 << endl;
                    ans[row][col] = res[i++];
                    col--;
                    cnt1++;
                }
                row--;
                col++;
                cnt++;
            } else {
                while (i < res.size() && row >= 0 && col < n && ans[row][col] == '.') {
                    // cout << "U: " << row << " " << col << " " << res[i] << " " << cnt1 << endl;
                    ans[row][col] = res[i++];
                    row--;
                    cnt1++;
                }
                col++;
                row++;
                cnt++;
            }
            cnt1 = 0;
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) cout << ans[i][j];
            cout << endl;
        }
    }
}

int main() {
    solve();
    return 0;
}
/*
R: 0 0 T 0
R: 0 1 H 1
R: 0 2 I 2
R: 0 3 S 3
R: 0 4 I 4
D: 1 5 S 0
D: 2 5 A 1
D: 3 5 V 2
D: 4 5 E 3
D: 5 5 R 4
L: 6 4 Y 0
L: 6 3 G 1
L: 6 2 O 2
L: 6 1 O 3
L: 6 0 D 4
U: 5 -1 P 0
U: 4 -1 O 1
U: 3 -1 E 2
U: 2 -1 M 3
U: 1 -1 I 4
R: 0 0 T 0
R: 0 1 H 1
R: 0 2 I 2
R: 0 3 N 3
R: 0 4 K 4
THINK
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3632kb

input:

2
AB
CD

output:

AB
DC

result:

ok 2 lines

Test #3:

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

input:

4
ABCD
EFGH
IJKL
MNOP

output:

ABEI
KHLF
NPOC
MJGD

result:

ok 4 lines

Test #4:

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

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: