QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#337068#8278. Secret Poemsucup-team2000#AC ✓1ms3908kbC++203.4kb2024-02-25 02:45:552024-02-25 02:45:55

Judging History

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

  • [2024-02-25 02:45:55]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3908kb
  • [2024-02-25 02:45:55]
  • 提交

answer

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

const int maxn = 105;
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
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

2
AB
CD

output:

AB
DC

result:

ok 2 lines

Test #3:

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

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

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

input:

100
XIZRFKBGIFYHQYTINRAKHBPJVQGJIJQXTBLLBVNQQQTSAKPIXTORIREMDTGNDFTOZGUZICOMGINGXDXQXYQEWRNCYEDQCQZHKOIB
DNOXVOJOCZMMMAVEWUBXSRPTRNQYWWNGIPKSSRRSBJVKJTAFHQTLJXRWEAZIPYYHSOOTJNJWROQLKUUXBDYKEWKCGGVKFYUWEJWA
MIJFNAGSVCXQVEUKOKADMISAQIUNIRHMOVQUPREHRYLSVCTDMTDBEUOYEDJNAQGAMDPLLVAMNARRTYQQERKKBOMPGEEYBC...

output:

XIDMNZROISHWJXFKVFOMPBLMSNOBGJANSFUSGKDSGMGOIFCSFFMKRXJLQYULMBGVZYHMCIYDVHARLNXOHNCRFLUQXMQYMQBMZUGI
VXJKKIEEMEBNESRILIGJZXDTTPBGTLEFJMJIRUYIJWNXRTNIBFPKEMPYDRHWRMJMDRBGRFWXIOYGRKJVXIMZUCWBZTHSJHOJWIIP
GUWMZUKXPUVAMPLTZXTDHTRJKWJWUDGAHTRLUVBQOWXPZHWGVAORKJKTPZWOLWQSFSVQQKTQBRZUESQQBHIEEBUBSRGTQRHIGL...

result:

ok 100 lines

Test #7:

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

input:

99
KQAUNRTKSNBKSOZMISHVIOTCGFRXRTSERIDJIRBWSUBUSHDCYSRJRGFUAEDPPSSYICZTADUFWNQWOYJXSIWPKORVPXNNIATPFMI
TYVXVKQOAHAAZHKIBRXTQMPAGYJRILVGWJIWSAKLVUFDMWXTWPXNDSUMKKNAXDIOKHMOBYCFEXHWQDQHPRAYKDOPDJZZAJVNNAL
PHPSTAHBZPCVMEFZJYRIOEZFBYVEVUEXNFEQBONIRFGGKPJXOMHVVRWJWOQFCKLQWBRZUVPSUVNKMDGNFMMENZDWPCZZXNXSI...

output:

KQTPYAUVHCPCPXNRVSHVOOXGPTKTKQARHSKDXDRRDWHOSNABFPUDNTFLEFXSJBFZHBKAPYBNETSZYWKAWFTXPBQACASOZVKUZEK
MFXDKJWJFYDGYLNSEVKRYOAYTWVROFEDJZEJXNWKRVRRTIERMPSIRXQMIXFZRFUBRILBNGQJROPQBAXKCTCOKYRAOLTPECOXBTC
GZXBABWKOCZAOQBKENWFFRFBXOOCQZAXONHAWHXLJPZDLDBYAFKPZBLXVZQUJWTPNGRCDKYRJRWNIIUECLMBNLSUVIEMGJPGBVG
...

result:

ok 99 lines

Test #8:

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

input:

98
AWIITUWKFFFFJJAFYGXBSDMHLXUENBIGWUUXSQMWRIOOFYIECDJVUCRUUFWXDRQMJPUPJVJOIRVCURIVIAJPPWDSCYLZBNSRRL
OVLTIENSFNUSITTHGHASWIHFEQSDYSFFSASKUUJZSMKNKGBDXZGTHPVRNQWDGTYNXMDLZICESKPMOCSLSVLELDVKYWOQFPUNRH
RZGYHTYLPROGTRHSTZOJKRHQGJOQRHZUCGPJQBRUKHBMPUEIVMILPRUKKYFOUJWUYBCNNVHJHWRKAANOCOABIMZCJLGMFJAJDU
...

output:

AWORVIILZUVZGTTUIYHZXJAAHHEWKNTKQKWGMXZMRKYSFFFLNEWCSKTDNUODOLXPNFFURVHEUDXQMZYPRFQLIKQOOSJJIGTZKN
TCGXALVYNTYWRQKMDYFQCWVCLLIWAEHGXAMDVBGDFTTFXODNBYQCTFRTNAENUSLKKIMBHFWVGJJCGPBMPSECFDCIDQFIAASLWT
BMNDJLLRQKLQUMWJBZOKXODRSJCXAITJNLGFZJCHJULZQQUFAFUKBAVUPIMFTWLEPAISOLMLDXZLHGFXSALVXGOHZBQSRZRINR
KBP...

result:

ok 98 lines

Test #9:

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

input:

96
GTHPKKJKUAIXLVQNDZGHHPPURUOMMYWDZVHHNCPIIDOFYXREYSUKPDHPINGMVXWPOWAAJJKIUKIVCIKDZDHUTZDNETZEZJFU
HBORTXEIITFJNMZFIQMNVPRXAEMGGHCFKGEAUELEICWYIFUCMKEJHVURPDMQUOWPRDCHQEAKOUHLCEHJSMMTDGLVJRNXQPTO
TLKETIQMYASQZUMUFBUYONKMGEEBMIBKGEGTYVDWTGAFFQAFQJDUKIVDHOSTKCDCKZMGKRMRBFUVFMREQWBFLVHQLUFLMTYV
GHQSRN...

output:

GTHTBHPOLGXHKRKKTEQKNKOZSTXJKEIRQLSIYWKJWNQIUAIMBRMHDWBPABSPOQFYTIXFAFTUFYNEWMTQGPOSXOLPSJLVNQWL
MEGBWAZQHNVNOTUJCDSRXCPHGPWNYKZDCCKKQTWVYUMQWVSRIGGDGEGMYGBDYHPGZXVLBDEESUJNCJTUZMKGJJUQAMHDMKIQ
MCDLTVHGEKWZZVPPXJEPLOYKBWPYEPILVNNEMINITOFHFACKCKUNFXZFUUBQYPHOCKOCOIMBMLXNAAWMKEUBBVMAXCBVFALP
OWATAXAFB...

result:

ok 96 lines

Test #10:

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

input:

90
QVRHBGLGFBQQJZYICUKIXNUZRZXJWRHQRDKOPEXGBQXGFTTQCNOPALCXPTYDZWTQTKCECRTKEWGYTWMXHIURMLUYDP
YHPXNNJDKHMYRUKHLPKOMEWODYRMOJNEHDJMDHEZVKQXTYBWVKCOJWHEYKNQIQJYUIHCNUDGNOVTDOQZAHRGWZOAXP
BWGPZHSHHSEBWWGRTUVQEUZWUKCBWMQYOBPHPQTZYAGBNPMDDOTEPTVAZYTRSROQWXFLHMCRZAYIPAOHFQSLLQUAAW
PSKKELFITHSHHGKIVZEEBLRZ...

output:

QVYBHRHPWPWSGXBGNPKKXRAPKZNLGJHEDGMMJWZMHLSDFBKHFTRFNGBYVDHIZRIHHQQMSTZUDZHREEZOWPZISKWHEY
EBOYLFKUXQQASLTXBLTZUYXJRKAXOREIUEZRWMRUBZGEMBCTVNSSNZRBSCEVJIXTIWIKXODQAIRADCMWROBFAWCEZJ
JEDHKPJQVVCMEURZCADOVJTRIVQDXTUECSVIJWFOBABSVBFIZCRKUQHUKNUMJBUMWLWNKWRSLVXPHXGEQIOFIXGSVZ
FPNVQBHBYCPIHKIEPBTJUAJNLPX...

result:

ok 90 lines

Extra Test:

score: 0
Extra Test Passed