QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185263#4195. Looking for Waldorgnerdplayer#AC ✓155ms5740kbC++202.1kb2023-09-21 20:13:262023-09-21 20:13:26

Judging History

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

  • [2023-09-21 20:13:26]
  • 评测
  • 测评结果:AC
  • 用时:155ms
  • 内存:5740kb
  • [2023-09-21 20:13:26]
  • 提交

answer

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

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    auto solve = [&]() {
        int n, m;
        cin >> n >> m;

        bool trans = false;

        if (n > m) {
            trans = true;
            swap(n, m);
        }

        vector a(n, string(m, '?'));
        for (int i = 0; i < (trans ? m : n); i++) {
            for (int j = 0; j < (trans ? n : m); j++) {
                if (!trans) {
                    cin >> a[i][j];
                } else {
                    cin >> a[j][i];
                }
            }
        }

        string code = "WALDO";
        vector f(5, vector(n + 1, vector<int>(m + 1)));
        
        for (int c = 0; c < 5; c++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    f[c][i + 1][j + 1] = f[c][i + 1][j] + f[c][i][j + 1] - f[c][i][j] + (a[i][j] == code[c]);
                }
            }
        }

        auto sum = [&](int c, int x1, int y1, int x2, int y2) {
            return f[c][x2 + 1][y2 + 1] - f[c][x1][y2 + 1] - f[c][x2 + 1][y1] + f[c][x1][y1];
        };

        auto check = [&](int x1, int y1, int x2, int y2) {
            for (int c = 0; c < 5; c++) {
                if (sum(c, x1, y1, x2, y2) == 0) {
                    return false;
                }
            }
            return true;
        };

        constexpr int INF = 1e9;
        int ans = INF;

        for (int x1 = 0; x1 < n; x1++) {
            for (int x2 = x1; x2 < n; x2++) {
                for (int y1 = 0, y2 = 0; y1 < m; y1++) {
                    y2 = max(y2, y1);
                    while (y2 < m && !check(x1, y1, x2, y2)) {
                        y2++;
                    }
                    if (y2 < m) {
                        ans = min(ans, (x2 - x1 + 1) * (y2 - y1 + 1));
                    }
                }
            }
        }

        if (ans == INF) {
            cout << "impossible\n";
        } else {
            cout << ans << '\n';
        }
    };

    solve();

    return 0;
}


詳細信息

Test #1:

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

input:

5 5
ABCDE
FGHIJ
KLMNO
PQRST
VWXYZ

output:

25

result:

ok single line: '25'

Test #2:

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

input:

5 10
ABCDEABCDE
FGHIJFGHIJ
KLMNOKLMNO
PQRSTPQRST
VWXYZVWXYZ

output:

20

result:

ok single line: '20'

Test #3:

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

input:

5 10
WAALDLODOW
AWWLAOODOW
LOLADOWALO
ADALLLWWOL
WWOOAAAALO

output:

5

result:

ok single line: '5'

Test #4:

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

input:

2 3
WAL
TER

output:

impossible

result:

ok single line: 'impossible'

Test #5:

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

input:

1 260
AWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWLDO

output:

260

result:

ok single line: '260'

Test #6:

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

input:

1 5
WALDO

output:

5

result:

ok single line: '5'

Test #7:

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

input:

5 5
WXXAL
XALDO
XDOXX
ALXXX
DOXXX

output:

9

result:

ok single line: '9'

Test #8:

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

input:

7 115
DVGTNMMOMTPGLREEHPNWWOVARKFSSAQNWBBSUIUXDTRLZXHJAVOQPZWNJDMCBJRVSJNTUSOGUYKBWVUEDGJJJZRIJAJONHUSUJVGMYRDNRKZZLYOKRB
VVPSQMSDLFLEHIBTFMMRAWJFZTRVXOQJCNMPLYMWAXRXPXQWEDMWYTCQQBDGUACGWIQBIIRMTCYBQPKNWPYIRPHEIFHCPKYTVRSBBXUXVOCSLPJFRWM
DUSXXJPYFRNCGGDJPDVDXGKLDBABDGMWBELWYWMQMQCRAHINEYSMTLXGUOBGAC...

output:

8

result:

ok single line: '8'

Test #9:

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

input:

43 6
MSKXQI
PGFKAO
YZSLPS
LVMBUX
QQJWVW
GWVLPM
HDBTRG
WKHMGP
RLGDEB
TXYZEY
LQRDJI
IFIJZU
STLLPN
HDJOID
NTIAZG
KHQVHO
UBUERZ
PWBOBI
UTIEJW
KWEPPZ
TVWEBQ
JVFXYB
QHKYCG
DXJXMD
BZGFOV
RRHFKI
PZUCBJ
NUOPLE
ZWVFVP
NACTWZ
XAJRUG
XOBZIC
EGHUGF
TODGGA
AYQHYD
QPVLIQ
HJLKOV
WTRZJJ
AXSPON
LWRXIG
VPUZOR
ZDZQXK
C...

output:

11

result:

ok single line: '11'

Test #10:

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

input:

2 461
ZOXPGJHVSWLVZYOPKFWBPPMFSEHNPDFUAPHPJMXDFNAOEVGFLUZLHLOUMCSYYTHNKNYXAHHJXCSXHVEONVWYKTZCYUKWRBLIRFTCWHSGWNSULYTMNQSFQQKGXTUUPRYZMDBPPEYNSTCXFCUREDPGHSIGHJGDRCIQJUNUHTCNHFLHMEEPDIXSRRDBYIJSWGJCDAVIPCUYPARKSSXHDSLYDNHZJSYXWDTBCKFYILISHVJXFLSGPVPEEICHWKENYXBAACFXLNVTNQMUENNYCSUZSWHBYXFPYPGUTFEUAR...

output:

7

result:

ok single line: '7'

Test #11:

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

input:

10 62
MEBVDGFNDFAVGQOYMVVJPUOPIUXNJZBVTPGMNDYKVEFITSAEKRFIGVOZSEPAFU
JYIRCBPVQCIUAMGHUTVOEDNLVDTNBXUAMMJFZQPVUOKYGILFEVEKRYOKJCZKSX
IVNCDWFOUQKLEBOKKDKAXOKHFKPRUUAMSUDIBBWRICUALRRGAKMADEKSRWASKK
EVUMONXCMASAGLDEQAKFFJYPMVLNRRDXVFJJLBUYAUCRLUXBQWCVHNLSGZOIUW
XFKUOZQJHLAWSUPLBRBFJQXHAFMSBCMFUVDLKEFDLN...

output:

6

result:

ok single line: '6'

Test #12:

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

input:

24 4
PTLR
CFSQ
WJRS
KMOA
UTUI
LLBX
OMJV
VAPR
OHEA
ETZA
YGJA
XWYF
AHYC
ZRXT
WBQG
QSQR
JBWY
VQTC
ZGFF
USJI
APJH
TTGF
PVKC
JNOU

output:

impossible

result:

ok single line: 'impossible'

Test #13:

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

input:

9 8
WSWLWZTQ
SEIXFVUV
VRBEKFKR
EAKHTYEP
CIYZFNNE
XHFBOKWE
DXFWSGRK
ONFJKUQY
KUJQCJME

output:

32

result:

ok single line: '32'

Test #14:

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

input:

29 6
BVROIF
KSZROD
RWYYFV
CHKFXG
NANVXJ
KSCOCH
QIDLUT
KPPHPF
HGWTTN
CCOJEV
QZPPHL
LZAUXY
XICHTP
RSMYEI
MJEWDF
IYRXBW
GLJVXM
DOONIH
OPMUZW
YYYLSE
SGSPVZ
WVORGQ
BTWOIS
NPIQKT
CORXPN
KMNLGT
QTMVSW
WFOJNS
GQQZKO

output:

12

result:

ok single line: '12'

Test #15:

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

input:

6 30
YIEWUARANVJHLMMFIBBGKNDINMKCIH
MYGXZOGUNRHSICKEECSLTIFSEDFDYO
OENJCWJZMAEUJLJOEHPBSCKUCGMBPO
GCETCKSYVVOFSTAIODZDVDHYGBHQPP
RTKBTULQAGCFHEIYSYKGJNPCYFNNTD
UTBYRFXJGQIBREELOWWVMKUBEQDINX

output:

12

result:

ok single line: '12'

Test #16:

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

input:

27 6
DXKWIJ
SQFIKD
ZOBIUI
UTQRJN
TUVCQZ
CBRXHF
ULHYRV
QEQYBE
LVJZNT
NDAJAQ
NTTRSY
ETAYBI
LWLWHA
DCXBVH
HKLOQT
DLICSA
ZNIROE
MJRAVY
RZBDOE
TIIQDG
OTZAOV
WZNBBN
GXSSXT
NBXKTJ
VTWNAU
LXHDLS
PBTUCR

output:

14

result:

ok single line: '14'

Test #17:

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

input:

21 8
OZSOIHXZ
HMQRLUXE
HIVETDEP
DQJCTXNE
SXDOHCYG
TFYKEFJW
TJGXULLS
PMEJGSEF
UYAHBHKS
WALAUWUJ
DQXLTFVG
NVHTNPNA
ILITJIOS
NNFUIMPX
BCUYEIFL
VJWISWVQ
HZNPZZJF
HIJPMRJI
FCXYRPSA
WVOKEXQB
GHYDZKBM

output:

16

result:

ok single line: '16'

Test #18:

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

input:

5 5
LAXXW
ODLAX
XXODX
XXXLA
XXXOD

output:

9

result:

ok single line: '9'

Test #19:

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

input:

5 5
XXXOD
XXXLA
XXODX
ODLAX
LAXXW

output:

9

result:

ok single line: '9'

Test #20:

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

input:

5 5
DOXXX
ALXXX
XDOXX
XALDO
WXXAL

output:

9

result:

ok single line: '9'

Test #21:

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

input:

9 9
XXXODOXXX
XXXLALXXX
XXODXDOXX
ODLAXALDO
LAXXWXXAL
ODLAXALDO
XXODXDOXX
XXXLALXXX
XXXODOXXX

output:

9

result:

ok single line: '9'

Test #22:

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

input:

1 1
W

output:

impossible

result:

ok single line: 'impossible'

Test #23:

score: 0
Accepted
time: 105ms
memory: 5196kb

input:

176 472
KUMYIMXYCXUKCQXPDEOURBXYMTQVXOCYNZYCPKNAYWZMKMKBDYCCLJCWHRWKFAVYRDDQBNONSIQEKWJVUUGICMHFXTRUGLVHELGGSSFMEWXMWKUVMJHBSECGUFVXPKHJGDLNCYWPAAAOAVNKUXXKMLXJSLTJUAJJWVZMJCKTLDRELSUACYKBNRFFZMJODJQQYRTAFUJVENRLBFCQHKCSDBYSMYOYBUAXNDYCSSFYRGTLSMDOEVOWPXPBFBAQWFWEIGOEPUQTGTXTCLOCTUXKEWKFRKVSEPVIMFUA...

output:

5

result:

ok single line: '5'

Test #24:

score: 0
Accepted
time: 155ms
memory: 5664kb

input:

398 244
QUHZAOKHAAFETIKDGMDIOXCZTCNQGQOVKSVMGHWDBJJPZCGFVZOEVWEZQTGOTYHARAKLXBCBTONLOHBPSULLPTZPGLAFMIMFQWTWXZHDJVBEJVQRLCRDTWWDLHCLPQBFWFHOJAMSUHVQIUOKADYJXWCLPVJMULBAHOCXCKLTCIHZRANLLUPPENLIIVVDQSAQIJQPFMWQZEEKELEZTHOPIKOTUJOWPWSFXBENJNPOOWYRCPCGGZCP
GZESAWOKTMDKVDBKPVDXIYXVCWVKSUSUQVUDBMWCWTFFMJR...

output:

6

result:

ok single line: '6'

Test #25:

score: 0
Accepted
time: 65ms
memory: 4516kb

input:

238 211
CORYOZFTAYVYKDDVPCNFQXWJNVKWJRVQNXGCIFBRIUVBKBJDERPYCJLDXLSGKNZKHHJWYEDPODCKAYFIJELZXJVKKWQICLXSUZRTZQNPGRQCOFCPGENFNZBRUZWKBNTMUNZEPAUMMAMWMTJWPBZKMENDJPMFFEEMTKITMKGOZXRYGGCGUTWMQEAMGKZFACJREXAXOLCPMLUFGHRBBDH
HXRBZJEGCZKYRNJXNUIVJWROYDAPATLOJNJDPYYLHZCGBQDTGAPWIVNGIUZDLSOTWKBLWJELJWIFORGV...

output:

5

result:

ok single line: '5'

Test #26:

score: 0
Accepted
time: 5ms
memory: 3792kb

input:

293 43
HJXILPOWPUYLDYHSQHPDKCRVUSVROIQPJUJHOVOUDXR
QFUEWEYZLSXJKPUNXGDUCVPGIZJUAXJUMIOAFIBSZJT
BJFTQUWPOTLSPPRRMGQPRQYZDPSSORDIBYIKKRMQHUP
BXCPCTEDPRPYZRNUQYLMKHNVCAGVAOPIGBKDWGJIIKV
NQUYAFZEZSTUGYOVRYIISVGVKEVXDKBLTYBHDZNZTRQ
VQHJKXGJZYNDBCNTYRPMOHOWVZBJXLDXXVKYOZQUVLU
KJVRYGHWMJEYQVGHTNJQJWKOLFRFZ...

output:

6

result:

ok single line: '6'

Test #27:

score: 0
Accepted
time: 14ms
memory: 4076kb

input:

445 58
KGVWGWIMIGQVKDWAQXZCYKSEEXIXXBWHGPAJWXKCMXNTRRLEICEPLZJHQX
TMPIZUDRGKATXPLULHFFTIDEHAWNWGHYCOTRIWGJIUDOAZUVBESNEQMGQM
GEDWKZHNFVTRPPGGPYUJCISCENNROWSRBTWROXTEDOGGFHRTQCCDIITWCQ
XPHWSDWZHEZBCIXQREGTYCAJLGBUQADEQMPHRYURLYTMATMRGYKSYTHMKY
YWMMNBDNIIAUOUWEWLMNQYQRCREDBOGXDEXOAEMPCZBQEKCTDYVKWOGFO...

output:

6

result:

ok single line: '6'

Test #28:

score: 0
Accepted
time: 41ms
memory: 4496kb

input:

544 95
ZFVLAMXMQPASGTJZSABPYDSOQDVIXDUWJRJUAQKEBHCNHFZNIOTGZXUQIJHEHLICCEENVBZEJKBQBZFOLRKSJFZELDQEWUJ
XZYESFYFLDFSBPAWVOPWEUOPLKZYFOFLWKWHHMVLGSSCPYEHUBOGRWRDXQLQLVGMOAALAIRCBXWUHKMEENNHVHMAZEDEECQ
ODJUZXZOGXVSSSKWTCTJNVKZYDRWPBWFFAJVESWDEOQLOYAYFXNCDCMCFCOTHRWANPVSKCGAOFFCZCALAOVBHBOPWYDEJVY
DKOKG...

output:

5

result:

ok single line: '5'

Test #29:

score: 0
Accepted
time: 33ms
memory: 4664kb

input:

61 950
ESBJPSCSQAEXMVGEVQUFMVAFHVXTPYQFWNJNLBZBAJXRNWIGQUUBBZHJKVFNRJHRVOLFGXNCXOPUZAXQZDYPHQICOGACPJUBLZJININNZPNNVCIAIZRWGKDZXOYAGLWQNXSRKHMAKJPAHNKIOHYGGOISXGSIFQBIJKWXDUDVLQSKGZUZJSXFYSJTSFEDIOQITYMFIPMCTJLHDFYFLVHGLLNCFNGDNLSINXSUEBAJSRRZEOACSTSOVPQJUCYGKYNRAAQGMNTZXIXLMAANUXXJGSPIPQCDROHLSXRDO...

output:

6

result:

ok single line: '6'

Test #30:

score: 0
Accepted
time: 101ms
memory: 4848kb

input:

283 234
ADHGGMRRPRGHQBLDXQDQBGUSXXFLPDQCDEBUSHAPDXRTSRCUKYTQYIPQMKFNPRTIJWFPSJPKPXDFKIGBBAZGPKLANSVTHLDOJNJNWGCLRTKAAIRYGPCNZZPTYUSYIQZZHEDOMHMANKKPCIPACNCMNRAHMAIBZKVPWEILETCCVMKUNFDTHGBHIKBMFDWTFKMYJWKMBSATOHQKVRHEGNCPQRSEBTEHIVZQEDSVOZMTUT
CJWXZVIVIYZGENJMMXBZSGYHMYFDJBZKNJUVJIIDOTRCOFJYLXGHKOAIP...

output:

5

result:

ok single line: '5'

Test #31:

score: 0
Accepted
time: 3ms
memory: 3780kb

input:

46 122
WPQFCTULEZOUZQTUOQBFGBMGCVQCXUCAZHICDJYELAOQCHUWEIZCPBDBSQGGFXYINHOLZZJBOVDZQWHFCSXSIASTLRMJOWICVDLECOZBZGSNKDCSZPGGHJDMTK
CEFHGGTJOHWBLZHOMUGGRRIUBVOPPGCFNWOFCRAANAYUSJWGKQMEICCRBOHDNYXXDQGQBFJVSTIYXTRZBTEZUGTDDBPRXRABYPGHYTPNUSCXWWNKKIGMWHQFUI
TPEKCTRPXJEDFPDYLAGRFDHZDMOKXLYEBELAMGOHDJJGRQV...

output:

5

result:

ok single line: '5'

Test #32:

score: 0
Accepted
time: 21ms
memory: 4324kb

input:

46 1003
LFUCKMVFUPVHECFGASOYVWPPRYFRDQINNSGXSAJOTEXPQKXTBGYEQWKRGEWRAIBRKIWRVGYYNIAZRWGXAWSIHFNSLPGYELNFATKTOLFUQIDKMZTZUCIYHZIKKNZQUCIIWKZFMMWZMGPQUYBWTRBVUBYJWNMJXKBJIZNYFZCIETXBVUFCRUVKUBSNMTLZSIUPDYNMHRNFLINKOIBBMFEETHXRMSMQJZCFSMGDZCBNIRHUOKNUPQTFRLJBGJEMIPKLNOFMJWUJWUBAAMUZGXZLHPJKKBATXROMKGHY...

output:

6

result:

ok single line: '6'

Test #33:

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

input:

5 5
WALDO
ALODW
LODWA
ODWAL
DWALO

output:

5

result:

ok single line: '5'

Test #34:

score: 0
Accepted
time: 35ms
memory: 5740kb

input:

316 316
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLXXXDXXX...

output:

80264

result:

ok single line: '80264'

Test #35:

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

input:

5 5
XXXXX
XXWXX
XALDX
XXOXX
XXXXX

output:

9

result:

ok single line: '9'

Test #36:

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

input:

5 5
XXXXX
XWXAX
XXLXX
XDXOX
XXXXX

output:

9

result:

ok single line: '9'

Test #37:

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

input:

49 49
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

25

result:

ok single line: '25'