QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#54679#4195. Looking for WaldoT3alaadl3k2olyehymn3kAC ✓138ms7344kbC++2.5kb2022-10-10 03:50:252022-10-10 03:50:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-10 03:50:26]
  • 评测
  • 测评结果:AC
  • 用时:138ms
  • 内存:7344kb
  • [2022-10-10 03:50:25]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define gtr(T) vector<T>,greater<T>
#define int long long
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void err(istream_iterator<string> it) { cerr << endl; }

template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

#define S second
#define F first
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int N = 2005;
const string TARGET = "WALDO";

vector<vector<char> > a;
vector<vector<int> > pref[5];
int n, m;

vector<vector<int> > build(char c) {
    vector<vector<int> > pref(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            pref[i][j] = (a[i][j] == c) + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
        }
    }
    return pref;
}

int get(int r, int r2, int c, int c2, int idx) {
    return pref[idx][r2][c2] - pref[idx][r - 1][c2] - pref[idx][r2][c - 1] + pref[idx][r - 1][c - 1];
}

bool check(int r, int r2, int c, int c2) {
    for (int i = 0; i < 5; i++) {
        if (get(r, r2, c, c2, i) == 0) return 0;
    }
    return 1;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    a = vector<vector<char>>(min(n + 1, m + 1), vector<char>(max(n + 1, m + 1)));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (n < m) cin >> a[i][j];
            else cin >> a[j][i];
        }
    }
    if (n > m) swap(n, m);
    for (int i = 0; i < 5; i++) pref[i] = build(TARGET[i]);
    ll ans = n * m + 1;
    for (int r1 = 1; r1 <= n; r1++)
        for (int r2 = r1; r2 <= n; r2++)
            for (int c1 = 1, c2 = 1; c1 <= m; c1++) {
                while (c2 <= m && !check(r1, r2, c1, c2))c2++;
                if (c2 <= m) {
                    ans = min(ans, (r2 - r1 + 1) * (c2 - c1 + 1));
                }
            }

    if (ans > n * m) cout << "impossible\n";
    else
        cout << ans << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3564kb

input:

5 5
ABCDE
FGHIJ
KLMNO
PQRST
VWXYZ

output:

25

result:

ok single line: '25'

Test #2:

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

input:

5 10
ABCDEABCDE
FGHIJFGHIJ
KLMNOKLMNO
PQRSTPQRST
VWXYZVWXYZ

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3644kb

input:

5 10
WAALDLODOW
AWWLAOODOW
LOLADOWALO
ADALLLWWOL
WWOOAAAALO

output:

5

result:

ok single line: '5'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3564kb

input:

2 3
WAL
TER

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3576kb

input:

1 260
AWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWLDO

output:

260

result:

ok single line: '260'

Test #6:

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

input:

1 5
WALDO

output:

5

result:

ok single line: '5'

Test #7:

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

input:

5 5
WXXAL
XALDO
XDOXX
ALXXX
DOXXX

output:

9

result:

ok single line: '9'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

7 115
DVGTNMMOMTPGLREEHPNWWOVARKFSSAQNWBBSUIUXDTRLZXHJAVOQPZWNJDMCBJRVSJNTUSOGUYKBWVUEDGJJJZRIJAJONHUSUJVGMYRDNRKZZLYOKRB
VVPSQMSDLFLEHIBTFMMRAWJFZTRVXOQJCNMPLYMWAXRXPXQWEDMWYTCQQBDGUACGWIQBIIRMTCYBQPKNWPYIRPHEIFHCPKYTVRSBBXUXVOCSLPJFRWM
DUSXXJPYFRNCGGDJPDVDXGKLDBABDGMWBELWYWMQMQCRAHINEYSMTLXGUOBGAC...

output:

8

result:

ok single line: '8'

Test #9:

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

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: 2ms
memory: 3684kb

input:

2 461
ZOXPGJHVSWLVZYOPKFWBPPMFSEHNPDFUAPHPJMXDFNAOEVGFLUZLHLOUMCSYYTHNKNYXAHHJXCSXHVEONVWYKTZCYUKWRBLIRFTCWHSGWNSULYTMNQSFQQKGXTUUPRYZMDBPPEYNSTCXFCUREDPGHSIGHJGDRCIQJUNUHTCNHFLHMEEPDIXSRRDBYIJSWGJCDAVIPCUYPARKSSXHDSLYDNHZJSYXWDTBCKFYILISHVJXFLSGPVPEEICHWKENYXBAACFXLNVTNQMUENNYCSUZSWHBYXFPYPGUTFEUAR...

output:

7

result:

ok single line: '7'

Test #11:

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

input:

10 62
MEBVDGFNDFAVGQOYMVVJPUOPIUXNJZBVTPGMNDYKVEFITSAEKRFIGVOZSEPAFU
JYIRCBPVQCIUAMGHUTVOEDNLVDTNBXUAMMJFZQPVUOKYGILFEVEKRYOKJCZKSX
IVNCDWFOUQKLEBOKKDKAXOKHFKPRUUAMSUDIBBWRICUALRRGAKMADEKSRWASKK
EVUMONXCMASAGLDEQAKFFJYPMVLNRRDXVFJJLBUYAUCRLUXBQWCVHNLSGZOIUW
XFKUOZQJHLAWSUPLBRBFJQXHAFMSBCMFUVDLKEFDLN...

output:

6

result:

ok single line: '6'

Test #12:

score: 0
Accepted
time: 2ms
memory: 3652kb

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: 2ms
memory: 3568kb

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: 2ms
memory: 3512kb

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: 2ms
memory: 3572kb

input:

6 30
YIEWUARANVJHLMMFIBBGKNDINMKCIH
MYGXZOGUNRHSICKEECSLTIFSEDFDYO
OENJCWJZMAEUJLJOEHPBSCKUCGMBPO
GCETCKSYVVOFSTAIODZDVDHYGBHQPP
RTKBTULQAGCFHEIYSYKGJNPCYFNNTD
UTBYRFXJGQIBREELOWWVMKUBEQDINX

output:

12

result:

ok single line: '12'

Test #16:

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

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

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

input:

5 5
LAXXW
ODLAX
XXODX
XXXLA
XXXOD

output:

9

result:

ok single line: '9'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3568kb

input:

5 5
XXXOD
XXXLA
XXODX
ODLAX
LAXXW

output:

9

result:

ok single line: '9'

Test #20:

score: 0
Accepted
time: 2ms
memory: 3728kb

input:

5 5
DOXXX
ALXXX
XDOXX
XALDO
WXXAL

output:

9

result:

ok single line: '9'

Test #21:

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

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: 2ms
memory: 3560kb

input:

1 1
W

output:

impossible

result:

ok single line: 'impossible'

Test #23:

score: 0
Accepted
time: 95ms
memory: 6668kb

input:

176 472
KUMYIMXYCXUKCQXPDEOURBXYMTQVXOCYNZYCPKNAYWZMKMKBDYCCLJCWHRWKFAVYRDDQBNONSIQEKWJVUUGICMHFXTRUGLVHELGGSSFMEWXMWKUVMJHBSECGUFVXPKHJGDLNCYWPAAAOAVNKUXXKMLXJSLTJUAJJWVZMJCKTLDRELSUACYKBNRFFZMJODJQQYRTAFUJVENRLBFCQHKCSDBYSMYOYBUAXNDYCSSFYRGTLSMDOEVOWPXPBFBAQWFWEIGOEPUQTGTXTCLOCTUXKEWKFRKVSEPVIMFUA...

output:

5

result:

ok single line: '5'

Test #24:

score: 0
Accepted
time: 138ms
memory: 7216kb

input:

398 244
QUHZAOKHAAFETIKDGMDIOXCZTCNQGQOVKSVMGHWDBJJPZCGFVZOEVWEZQTGOTYHARAKLXBCBTONLOHBPSULLPTZPGLAFMIMFQWTWXZHDJVBEJVQRLCRDTWWDLHCLPQBFWFHOJAMSUHVQIUOKADYJXWCLPVJMULBAHOCXCKLTCIHZRANLLUPPENLIIVVDQSAQIJQPFMWQZEEKELEZTHOPIKOTUJOWPWSFXBENJNPOOWYRCPCGGZCP
GZESAWOKTMDKVDBKPVDXIYXVCWVKSUSUQVUDBMWCWTFFMJR...

output:

6

result:

ok single line: '6'

Test #25:

score: 0
Accepted
time: 62ms
memory: 5276kb

input:

238 211
CORYOZFTAYVYKDDVPCNFQXWJNVKWJRVQNXGCIFBRIUVBKBJDERPYCJLDXLSGKNZKHHJWYEDPODCKAYFIJELZXJVKKWQICLXSUZRTZQNPGRQCOFCPGENFNZBRUZWKBNTMUNZEPAUMMAMWMTJWPBZKMENDJPMFFEEMTKITMKGOZXRYGGCGUTWMQEAMGKZFACJREXAXOLCPMLUFGHRBBDH
HXRBZJEGCZKYRNJXNUIVJWROYDAPATLOJNJDPYYLHZCGBQDTGAPWIVNGIUZDLSOTWKBLWJELJWIFORGV...

output:

5

result:

ok single line: '5'

Test #26:

score: 0
Accepted
time: 7ms
memory: 3868kb

input:

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

output:

6

result:

ok single line: '6'

Test #27:

score: 0
Accepted
time: 24ms
memory: 4388kb

input:

445 58
KGVWGWIMIGQVKDWAQXZCYKSEEXIXXBWHGPAJWXKCMXNTRRLEICEPLZJHQX
TMPIZUDRGKATXPLULHFFTIDEHAWNWGHYCOTRIWGJIUDOAZUVBESNEQMGQM
GEDWKZHNFVTRPPGGPYUJCISCENNROWSRBTWROXTEDOGGFHRTQCCDIITWCQ
XPHWSDWZHEZBCIXQREGTYCAJLGBUQADEQMPHRYURLYTMATMRGYKSYTHMKY
YWMMNBDNIIAUOUWEWLMNQYQRCREDBOGXDEXOAEMPCZBQEKCTDYVKWOGFO...

output:

6

result:

ok single line: '6'

Test #28:

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

input:

544 95
ZFVLAMXMQPASGTJZSABPYDSOQDVIXDUWJRJUAQKEBHCNHFZNIOTGZXUQIJHEHLICCEENVBZEJKBQBZFOLRKSJFZELDQEWUJ
XZYESFYFLDFSBPAWVOPWEUOPLKZYFOFLWKWHHMVLGSSCPYEHUBOGRWRDXQLQLVGMOAALAIRCBXWUHKMEENNHVHMAZEDEECQ
ODJUZXZOGXVSSSKWTCTJNVKZYDRWPBWFFAJVESWDEOQLOYAYFXNCDCMCFCOTHRWANPVSKCGAOFFCZCALAOVBHBOPWYDEJVY
DKOKG...

output:

5

result:

ok single line: '5'

Test #29:

score: 0
Accepted
time: 30ms
memory: 5612kb

input:

61 950
ESBJPSCSQAEXMVGEVQUFMVAFHVXTPYQFWNJNLBZBAJXRNWIGQUUBBZHJKVFNRJHRVOLFGXNCXOPUZAXQZDYPHQICOGACPJUBLZJININNZPNNVCIAIZRWGKDZXOYAGLWQNXSRKHMAKJPAHNKIOHYGGOISXGSIFQBIJKWXDUDVLQSKGZUZJSXFYSJTSFEDIOQITYMFIPMCTJLHDFYFLVHGLLNCFNGDNLSINXSUEBAJSRRZEOACSTSOVPQJUCYGKYNRAAQGMNTZXIXLMAANUXXJGSPIPQCDROHLSXRDO...

output:

6

result:

ok single line: '6'

Test #30:

score: 0
Accepted
time: 114ms
memory: 5876kb

input:

283 234
ADHGGMRRPRGHQBLDXQDQBGUSXXFLPDQCDEBUSHAPDXRTSRCUKYTQYIPQMKFNPRTIJWFPSJPKPXDFKIGBBAZGPKLANSVTHLDOJNJNWGCLRTKAAIRYGPCNZZPTYUSYIQZZHEDOMHMANKKPCIPACNCMNRAHMAIBZKVPWEILETCCVMKUNFDTHGBHIKBMFDWTFKMYJWKMBSATOHQKVRHEGNCPQRSEBTEHIVZQEDSVOZMTUT
CJWXZVIVIYZGENJMMXBZSGYHMYFDJBZKNJUVJIIDOTRCOFJYLXGHKOAIP...

output:

5

result:

ok single line: '5'

Test #31:

score: 0
Accepted
time: 4ms
memory: 3880kb

input:

46 122
WPQFCTULEZOUZQTUOQBFGBMGCVQCXUCAZHICDJYELAOQCHUWEIZCPBDBSQGGFXYINHOLZZJBOVDZQWHFCSXSIASTLRMJOWICVDLECOZBZGSNKDCSZPGGHJDMTK
CEFHGGTJOHWBLZHOMUGGRRIUBVOPPGCFNWOFCRAANAYUSJWGKQMEICCRBOHDNYXXDQGQBFJVSTIYXTRZBTEZUGTDDBPRXRABYPGHYTPNUSCXWWNKKIGMWHQFUI
TPEKCTRPXJEDFPDYLAGRFDHZDMOKXLYEBELAMGOHDJJGRQV...

output:

5

result:

ok single line: '5'

Test #32:

score: 0
Accepted
time: 17ms
memory: 5136kb

input:

46 1003
LFUCKMVFUPVHECFGASOYVWPPRYFRDQINNSGXSAJOTEXPQKXTBGYEQWKRGEWRAIBRKIWRVGYYNIAZRWGXAWSIHFNSLPGYELNFATKTOLFUQIDKMZTZUCIYHZIKKNZQUCIIWKZFMMWZMGPQUYBWTRBVUBYJWNMJXKBJIZNYFZCIETXBVUFCRUVKUBSNMTLZSIUPDYNMHRNFLINKOIBBMFEETHXRMSMQJZCFSMGDZCBNIRHUOKNUPQTFRLJBGJEMIPKLNOFMJWUJWUBAAMUZGXZLHPJKKBATXROMKGHY...

output:

6

result:

ok single line: '6'

Test #33:

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

input:

5 5
WALDO
ALODW
LODWA
ODWAL
DWALO

output:

5

result:

ok single line: '5'

Test #34:

score: 0
Accepted
time: 24ms
memory: 7344kb

input:

316 316
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLXXXDXXX...

output:

80264

result:

ok single line: '80264'

Test #35:

score: 0
Accepted
time: 2ms
memory: 3656kb

input:

5 5
XXXXX
XXWXX
XALDX
XXOXX
XXXXX

output:

9

result:

ok single line: '9'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3652kb

input:

5 5
XXXXX
XWXAX
XXLXX
XDXOX
XXXXX

output:

9

result:

ok single line: '9'

Test #37:

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

input:

49 49
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...

output:

25

result:

ok single line: '25'