diff --git a/ICPC/nwerc2022_A/data.zip b/ICPC/nwerc2022_A/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..50956d381d5e4454fdfe8f219e63b5201767ef09 --- /dev/null +++ b/ICPC/nwerc2022_A/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e1b74bb39283545bc56ef173c41b542756db2623c949b79bfa7618c1aedb4b3 +size 34128131 diff --git a/ICPC/nwerc2022_A/init.yml b/ICPC/nwerc2022_A/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..23aafc390d9282a6fce838320bf75d0a995a27ee --- /dev/null +++ b/ICPC/nwerc2022_A/init.yml @@ -0,0 +1,485 @@ +archive: data.zip +test_cases: +- in: 001-all_small_perms.in + out: 001-all_small_perms.ans + points: 1 +- in: 002-all_small_perms.in + out: 002-all_small_perms.ans + points: 1 +- in: 003-all_small_perms.in + out: 003-all_small_perms.ans + points: 1 +- in: 004-all_small_perms.in + out: 004-all_small_perms.ans + points: 1 +- in: 005-all_small_perms.in + out: 005-all_small_perms.ans + points: 1 +- in: 006-all_small_perms.in + out: 006-all_small_perms.ans + points: 1 +- in: 007-all_small_perms.in + out: 007-all_small_perms.ans + points: 1 +- in: 008-all_small_perms.in + out: 008-all_small_perms.ans + points: 1 +- in: 009-all_small_perms.in + out: 009-all_small_perms.ans + points: 1 +- in: 010-all_small_perms.in + out: 010-all_small_perms.ans + points: 1 +- in: 011-all_small_perms.in + out: 011-all_small_perms.ans + points: 1 +- in: 012-all_small_perms.in + out: 012-all_small_perms.ans + points: 1 +- in: 013-all_small_perms.in + out: 013-all_small_perms.ans + points: 1 +- in: 014-all_small_perms.in + out: 014-all_small_perms.ans + points: 1 +- in: 015-all_small_perms.in + out: 015-all_small_perms.ans + points: 1 +- in: 016-all_small_perms.in + out: 016-all_small_perms.ans + points: 1 +- in: 017-all_small_perms.in + out: 017-all_small_perms.ans + points: 1 +- in: 018-all_small_perms.in + out: 018-all_small_perms.ans + points: 1 +- in: 019-all_small_perms.in + out: 019-all_small_perms.ans + points: 1 +- in: 020-all_small_perms.in + out: 020-all_small_perms.ans + points: 1 +- in: 021-all_small_perms.in + out: 021-all_small_perms.ans + points: 1 +- in: 022-all_small_perms.in + out: 022-all_small_perms.ans + points: 1 +- in: 023-all_small_perms.in + out: 023-all_small_perms.ans + points: 1 +- in: 024-all_small_perms.in + out: 024-all_small_perms.ans + points: 1 +- in: 025-all_small_perms.in + out: 025-all_small_perms.ans + points: 1 +- in: 026-all_small_perms.in + out: 026-all_small_perms.ans + points: 1 +- in: 027-all_small_perms.in + out: 027-all_small_perms.ans + points: 1 +- in: 028-all_small_perms.in + out: 028-all_small_perms.ans + points: 1 +- in: 029-all_small_perms.in + out: 029-all_small_perms.ans + points: 1 +- in: 030-all_small_perms.in + out: 030-all_small_perms.ans + points: 1 +- in: 031-all_small_perms.in + out: 031-all_small_perms.ans + points: 1 +- in: 032-all_small_perms.in + out: 032-all_small_perms.ans + points: 1 +- in: 033-minimal.in + out: 033-minimal.ans + points: 1 +- in: 034-minimal.in + out: 034-minimal.ans + points: 1 +- in: 035-minimal.in + out: 035-minimal.ans + points: 1 +- in: 036-minimal.in + out: 036-minimal.ans + points: 1 +- in: 037-random_small.in + out: 037-random_small.ans + points: 1 +- in: 038-random_small.in + out: 038-random_small.ans + points: 1 +- in: 039-random_small.in + out: 039-random_small.ans + points: 1 +- in: 040-random_small.in + out: 040-random_small.ans + points: 1 +- in: 041-random_small.in + out: 041-random_small.ans + points: 1 +- in: 042-random_small.in + out: 042-random_small.ans + points: 1 +- in: 043-random_small.in + out: 043-random_small.ans + points: 1 +- in: 044-random_small.in + out: 044-random_small.ans + points: 1 +- in: 045-random_small.in + out: 045-random_small.ans + points: 1 +- in: 046-random_large.in + out: 046-random_large.ans + points: 1 +- in: 047-random_large.in + out: 047-random_large.ans + points: 1 +- in: 048-random_large.in + out: 048-random_large.ans + points: 1 +- in: 049-random_large.in + out: 049-random_large.ans + points: 1 +- in: 050-random_large.in + out: 050-random_large.ans + points: 1 +- in: 051-random_large.in + out: 051-random_large.ans + points: 1 +- in: 052-random_large.in + out: 052-random_large.ans + points: 1 +- in: 053-random_large.in + out: 053-random_large.ans + points: 1 +- in: 054-random_large.in + out: 054-random_large.ans + points: 1 +- in: 055-random_large.in + out: 055-random_large.ans + points: 1 +- in: 056-random_large.in + out: 056-random_large.ans + points: 1 +- in: 057-random_large.in + out: 057-random_large.ans + points: 1 +- in: 058-random_large.in + out: 058-random_large.ans + points: 1 +- in: 059-random_large.in + out: 059-random_large.ans + points: 1 +- in: 060-random_large.in + out: 060-random_large.ans + points: 1 +- in: 061-binary.in + out: 061-binary.ans + points: 1 +- in: 062-binary.in + out: 062-binary.ans + points: 1 +- in: 063-same.in + out: 063-same.ans + points: 1 +- in: 064-same.in + out: 064-same.ans + points: 1 +- in: 065-increasing.in + out: 065-increasing.ans + points: 1 +- in: 066-increasing.in + out: 066-increasing.ans + points: 1 +- in: 067-decreasing.in + out: 067-decreasing.ans + points: 1 +- in: 068-decreasing.in + out: 068-decreasing.ans + points: 1 +- in: 069-small.in + out: 069-small.ans + points: 1 +- in: 070-small.in + out: 070-small.ans + points: 1 +- in: 071-small.in + out: 071-small.ans + points: 1 +- in: 072-small.in + out: 072-small.ans + points: 1 +- in: 073-small.in + out: 073-small.ans + points: 1 +- in: 074-small.in + out: 074-small.ans + points: 1 +- in: 075-small.in + out: 075-small.ans + points: 1 +- in: 076-small.in + out: 076-small.ans + points: 1 +- in: 077-small.in + out: 077-small.ans + points: 1 +- in: 078-small.in + out: 078-small.ans + points: 1 +- in: 079-small.in + out: 079-small.ans + points: 1 +- in: 080-small.in + out: 080-small.ans + points: 1 +- in: 081-small.in + out: 081-small.ans + points: 1 +- in: 082-small.in + out: 082-small.ans + points: 1 +- in: 083-small.in + out: 083-small.ans + points: 1 +- in: 084-small.in + out: 084-small.ans + points: 1 +- in: 085-small.in + out: 085-small.ans + points: 1 +- in: 086-small.in + out: 086-small.ans + points: 1 +- in: 087-small.in + out: 087-small.ans + points: 1 +- in: 088-binary.in + out: 088-binary.ans + points: 1 +- in: 089-binary.in + out: 089-binary.ans + points: 1 +- in: 090-binary.in + out: 090-binary.ans + points: 1 +- in: 091-binary.in + out: 091-binary.ans + points: 1 +- in: 092-binary.in + out: 092-binary.ans + points: 1 +- in: 093-binary.in + out: 093-binary.ans + points: 1 +- in: 094-one-off.in + out: 094-one-off.ans + points: 1 +- in: 095-max-dist.in + out: 095-max-dist.ans + points: 1 +- in: 096-even-cross.in + out: 096-even-cross.ans + points: 1 +- in: 097-odd-cross.in + out: 097-odd-cross.ans + points: 1 +- in: 098-max-ans-front-even.in + out: 098-max-ans-front-even.ans + points: 1 +- in: 099-max-ans-front-odd.in + out: 099-max-ans-front-odd.ans + points: 1 +- in: 100-max-ans-back-odd.in + out: 100-max-ans-back-odd.ans + points: 1 +- in: 101-max-ans-back-even.in + out: 101-max-ans-back-even.ans + points: 1 +- in: 102-slow_descent_small.in + out: 102-slow_descent_small.ans + points: 1 +- in: 103-slow_descent.in + out: 103-slow_descent.ans + points: 1 +- in: 104-slow_descent.in + out: 104-slow_descent.ans + points: 1 +- in: 105-slow_descent.in + out: 105-slow_descent.ans + points: 1 +- in: 106-slow_descent.in + out: 106-slow_descent.ans + points: 1 +- in: 107-slow_descent.in + out: 107-slow_descent.ans + points: 1 +- in: 108-slow_descent.in + out: 108-slow_descent.ans + points: 1 +- in: 109-slow_descent.in + out: 109-slow_descent.ans + points: 1 +- in: 110-repeated_slow_descent_small.in + out: 110-repeated_slow_descent_small.ans + points: 1 +- in: 111-repeated_slow_descent.in + out: 111-repeated_slow_descent.ans + points: 1 +- in: 112-repeated_slow_descent.in + out: 112-repeated_slow_descent.ans + points: 1 +- in: 113-repeated_slow_descent.in + out: 113-repeated_slow_descent.ans + points: 1 +- in: 114-repeated_slow_descent.in + out: 114-repeated_slow_descent.ans + points: 1 +- in: 115-repeated_slow_descent.in + out: 115-repeated_slow_descent.ans + points: 1 +- in: 116-repeated_slow_descent.in + out: 116-repeated_slow_descent.ans + points: 1 +- in: 117-doubling.in + out: 117-doubling.ans + points: 1 +- in: 118-doubling.in + out: 118-doubling.ans + points: 1 +- in: 119-doubling.in + out: 119-doubling.ans + points: 1 +- in: 120-doubling.in + out: 120-doubling.ans + points: 1 +- in: 121-doubling.in + out: 121-doubling.ans + points: 1 +- in: 122-doubling.in + out: 122-doubling.ans + points: 1 +- in: 123-doubling.in + out: 123-doubling.ans + points: 1 +- in: 124-doubling.in + out: 124-doubling.ans + points: 1 +- in: 125-doubling.in + out: 125-doubling.ans + points: 1 +- in: 126-doubling.in + out: 126-doubling.ans + points: 1 +- in: 127-doubling.in + out: 127-doubling.ans + points: 1 +- in: 128-doubling.in + out: 128-doubling.ans + points: 1 +- in: 129-doubling.in + out: 129-doubling.ans + points: 1 +- in: 130-doubling.in + out: 130-doubling.ans + points: 1 +- in: 131-doubling.in + out: 131-doubling.ans + points: 1 +- in: 132-doubling.in + out: 132-doubling.ans + points: 1 +- in: 133-doubling.in + out: 133-doubling.ans + points: 1 +- in: 134-doubling.in + out: 134-doubling.ans + points: 1 +- in: 135-doubling.in + out: 135-doubling.ans + points: 1 +- in: 136-doubling.in + out: 136-doubling.ans + points: 1 +- in: 137-doubling.in + out: 137-doubling.ans + points: 1 +- in: 138-doubling.in + out: 138-doubling.ans + points: 1 +- in: 139-doubling.in + out: 139-doubling.ans + points: 1 +- in: 140-doubling.in + out: 140-doubling.ans + points: 1 +- in: 141-doubling.in + out: 141-doubling.ans + points: 1 +- in: 142-doubling.in + out: 142-doubling.ans + points: 1 +- in: 143-doubling.in + out: 143-doubling.ans + points: 1 +- in: 144-doubling.in + out: 144-doubling.ans + points: 1 +- in: 145-doubling.in + out: 145-doubling.ans + points: 1 +- in: 146-doubling.in + out: 146-doubling.ans + points: 1 +- in: 147-doubling.in + out: 147-doubling.ans + points: 1 +- in: 148-doubling.in + out: 148-doubling.ans + points: 1 +- in: 149-doubling-backoff.in + out: 149-doubling-backoff.ans + points: 1 +- in: 150-doubling-backoff.in + out: 150-doubling-backoff.ans + points: 1 +- in: 151-doubling-backoff.in + out: 151-doubling-backoff.ans + points: 1 +- in: 152-doubling-backoff.in + out: 152-doubling-backoff.ans + points: 1 +- in: 153-doubling-backoff.in + out: 153-doubling-backoff.ans + points: 1 +- in: 154-doubling-backoff.in + out: 154-doubling-backoff.ans + points: 1 +- in: 155-doubling-backoff.in + out: 155-doubling-backoff.ans + points: 1 +- in: 156-doubling-backoff.in + out: 156-doubling-backoff.ans + points: 1 +- in: 157-doubling-backoff.in + out: 157-doubling-backoff.ans + points: 1 +- in: 158-doubling-backoff.in + out: 158-doubling-backoff.ans + points: 1 +- in: 159-doubling-backoff.in + out: 159-doubling-backoff.ans + points: 1 +- in: 160-doubling-backoff.in + out: 160-doubling-backoff.ans + points: 1 +- in: 161-doubling-backoff.in + out: 161-doubling-backoff.ans + points: 1 diff --git a/ICPC/nwerc2022_B/data.zip b/ICPC/nwerc2022_B/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..7c9fca16fac251d3c707341564828222232bc527 --- /dev/null +++ b/ICPC/nwerc2022_B/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0de8718ad75e9b155afd5c28e97b0008d643a918fa2fd1ab338fb538b9924db6 +size 6051 diff --git a/ICPC/nwerc2022_B/init.yml b/ICPC/nwerc2022_B/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..de490ba017909a68e67b6f90ef016efcfbc18408 --- /dev/null +++ b/ICPC/nwerc2022_B/init.yml @@ -0,0 +1,84 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 01-min.in + out: 01-min.ans + points: 1 +- in: 02-max.in + out: 02-max.ans + points: 1 +- in: 03-max_diff.in + out: 03-max_diff.ans + points: 1 +- in: 04-max_diff.in + out: 04-max_diff.ans + points: 1 +- in: 05-close.in + out: 05-close.ans + points: 1 +- in: 06-close.in + out: 06-close.ans + points: 1 +- in: 07-close.in + out: 07-close.ans + points: 1 +- in: 08-close.in + out: 08-close.ans + points: 1 +- in: 09-close.in + out: 09-close.ans + points: 1 +- in: 10-close.in + out: 10-close.ans + points: 1 +- in: 11-manual.in + out: 11-manual.ans + points: 1 +- in: 12-manual.in + out: 12-manual.ans + points: 1 +- in: 13-manual.in + out: 13-manual.ans + points: 1 +- in: 14-manual.in + out: 14-manual.ans + points: 1 +- in: 15-manual.in + out: 15-manual.ans + points: 1 +- in: 16-manual.in + out: 16-manual.ans + points: 1 +- in: 17-manual.in + out: 17-manual.ans + points: 1 +- in: 18-random.in + out: 18-random.ans + points: 1 +- in: 19-random.in + out: 19-random.ans + points: 1 +- in: 20-random.in + out: 20-random.ans + points: 1 +- in: 21-random.in + out: 21-random.ans + points: 1 +- in: 22-random.in + out: 22-random.ans + points: 1 +- in: 23-random.in + out: 23-random.ans + points: 1 +- in: 24-random.in + out: 24-random.ans + points: 1 +- in: 25-random.in + out: 25-random.ans + points: 1 +- in: 26-random.in + out: 26-random.ans + points: 1 diff --git a/ICPC/nwerc2022_C/data.zip b/ICPC/nwerc2022_C/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..91bfac376c189daa40b7973c3d860bd7d6ac21de --- /dev/null +++ b/ICPC/nwerc2022_C/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9fcc1c2ccef8d81e0db764f9628bf1e0dafa1d3edeb69ef2261170ac1d7201ab +size 7287 diff --git a/ICPC/nwerc2022_C/init.yml b/ICPC/nwerc2022_C/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..57bef66c28e893422d879a03a615d97cd9c4af34 --- /dev/null +++ b/ICPC/nwerc2022_C/init.yml @@ -0,0 +1,102 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 01-min-1.in + out: 01-min-1.ans + points: 1 +- in: 02-min-2.in + out: 02-min-2.ans + points: 1 +- in: 03-min-3.in + out: 03-min-3.ans + points: 1 +- in: 04-min-4.in + out: 04-min-4.ans + points: 1 +- in: 05-max.in + out: 05-max.ans + points: 1 +- in: 06-small.in + out: 06-small.ans + points: 1 +- in: 07-exact.in + out: 07-exact.ans + points: 1 +- in: 08-exact.in + out: 08-exact.ans + points: 1 +- in: 09-exact.in + out: 09-exact.ans + points: 1 +- in: 10-exact.in + out: 10-exact.ans + points: 1 +- in: 11-random.in + out: 11-random.ans + points: 1 +- in: 12-random.in + out: 12-random.ans + points: 1 +- in: 13-random.in + out: 13-random.ans + points: 1 +- in: 14-random.in + out: 14-random.ans + points: 1 +- in: 15-random.in + out: 15-random.ans + points: 1 +- in: 16-random.in + out: 16-random.ans + points: 1 +- in: 17-random.in + out: 17-random.ans + points: 1 +- in: 18-random.in + out: 18-random.ans + points: 1 +- in: 19-random.in + out: 19-random.ans + points: 1 +- in: 20-random.in + out: 20-random.ans + points: 1 +- in: 21-random.in + out: 21-random.ans + points: 1 +- in: 22-random.in + out: 22-random.ans + points: 1 +- in: 23-random.in + out: 23-random.ans + points: 1 +- in: 24-random.in + out: 24-random.ans + points: 1 +- in: 25-random.in + out: 25-random.ans + points: 1 +- in: 26-random.in + out: 26-random.ans + points: 1 +- in: 27-random.in + out: 27-random.ans + points: 1 +- in: 28-random.in + out: 28-random.ans + points: 1 +- in: 29-random.in + out: 29-random.ans + points: 1 +- in: 30-random.in + out: 30-random.ans + points: 1 +- in: 31-random.in + out: 31-random.ans + points: 1 +- in: 32-random.in + out: 32-random.ans + points: 1 diff --git a/ICPC/nwerc2022_D/data.zip b/ICPC/nwerc2022_D/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..210e69e1fe21ae543737328b376dc2c48989860a --- /dev/null +++ b/ICPC/nwerc2022_D/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:067de4df9a960214b3dccb34facbd8b4a88d0d2a08b2635fdc3eff1dae29feea +size 347341 diff --git a/ICPC/nwerc2022_D/init.yml b/ICPC/nwerc2022_D/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..eea4a503b8371f327553aaf32a59b82748748f7d --- /dev/null +++ b/ICPC/nwerc2022_D/init.yml @@ -0,0 +1,222 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 01-small-X.in + out: 01-small-X.ans + points: 1 +- in: 02-small-O.in + out: 02-small-O.ans + points: 1 +- in: 03-small.in + out: 03-small.ans + points: 1 +- in: 04-small.in + out: 04-small.ans + points: 1 +- in: 05-small.in + out: 05-small.ans + points: 1 +- in: 06-row.in + out: 06-row.ans + points: 1 +- in: 07-col.in + out: 07-col.ans + points: 1 +- in: 08-medium.in + out: 08-medium.ans + points: 1 +- in: 09-medium.in + out: 09-medium.ans + points: 1 +- in: 10-medium.in + out: 10-medium.ans + points: 1 +- in: 11-large-x.in + out: 11-large-x.ans + points: 1 +- in: 12-large-few-o.in + out: 12-large-few-o.ans + points: 1 +- in: 13-large-few-o.in + out: 13-large-few-o.ans + points: 1 +- in: 14-large-few-o.in + out: 14-large-few-o.ans + points: 1 +- in: 15-large-equal.in + out: 15-large-equal.ans + points: 1 +- in: 16-large-many-o.in + out: 16-large-many-o.ans + points: 1 +- in: 17-large-many-o.in + out: 17-large-many-o.ans + points: 1 +- in: 18-large-many-o.in + out: 18-large-many-o.ans + points: 1 +- in: 19-large-o.in + out: 19-large-o.ans + points: 1 +- in: 20-tall.in + out: 20-tall.ans + points: 1 +- in: 21-tall.in + out: 21-tall.ans + points: 1 +- in: 22-tall.in + out: 22-tall.ans + points: 1 +- in: 23-tall.in + out: 23-tall.ans + points: 1 +- in: 24-wide.in + out: 24-wide.ans + points: 1 +- in: 25-wide.in + out: 25-wide.ans + points: 1 +- in: 26-wide.in + out: 26-wide.ans + points: 1 +- in: 27-wide.in + out: 27-wide.ans + points: 1 +- in: 28-large.in + out: 28-large.ans + points: 1 +- in: 29-large-o.in + out: 29-large-o.ans + points: 1 +- in: 30-large-x.in + out: 30-large-x.ans + points: 1 +- in: 31-large-few-o.in + out: 31-large-few-o.ans + points: 1 +- in: 32-large-many-o.in + out: 32-large-many-o.ans + points: 1 +- in: 33-max.in + out: 33-max.ans + points: 1 +- in: 34-max-o.in + out: 34-max-o.ans + points: 1 +- in: 35-max-x.in + out: 35-max-x.ans + points: 1 +- in: 36-max-few-o.in + out: 36-max-few-o.ans + points: 1 +- in: 37-max-many-o.in + out: 37-max-many-o.ans + points: 1 +- in: 38-diag.in + out: 38-diag.ans + points: 1 +- in: 39-diag.in + out: 39-diag.ans + points: 1 +- in: 40-diag.in + out: 40-diag.ans + points: 1 +- in: 41-diag.in + out: 41-diag.ans + points: 1 +- in: 42-diag-small.in + out: 42-diag-small.ans + points: 1 +- in: 43-diag-small.in + out: 43-diag-small.ans + points: 1 +- in: 44-diag-small.in + out: 44-diag-small.ans + points: 1 +- in: 45-diag-small.in + out: 45-diag-small.ans + points: 1 +- in: 46-diag-400.in + out: 46-diag-400.ans + points: 1 +- in: 47-diag-400.in + out: 47-diag-400.ans + points: 1 +- in: 48-diag-400.in + out: 48-diag-400.ans + points: 1 +- in: 49-diag-400.in + out: 49-diag-400.ans + points: 1 +- in: 50-diag-700.in + out: 50-diag-700.ans + points: 1 +- in: 51-diag-700.in + out: 51-diag-700.ans + points: 1 +- in: 52-diag-700.in + out: 52-diag-700.ans + points: 1 +- in: 53-diag-700.in + out: 53-diag-700.ans + points: 1 +- in: 54-manual.in + out: 54-manual.ans + points: 1 +- in: 55-manual.in + out: 55-manual.ans + points: 1 +- in: 56-manual.in + out: 56-manual.ans + points: 1 +- in: 57-manual.in + out: 57-manual.ans + points: 1 +- in: 58-manual.in + out: 58-manual.ans + points: 1 +- in: 59-manual.in + out: 59-manual.ans + points: 1 +- in: 60-diag.in + out: 60-diag.ans + points: 1 +- in: 61-diag.in + out: 61-diag.ans + points: 1 +- in: 62-diag.in + out: 62-diag.ans + points: 1 +- in: 63-diag.in + out: 63-diag.ans + points: 1 +- in: 64-diag.in + out: 64-diag.ans + points: 1 +- in: 65-corner1.in + out: 65-corner1.ans + points: 1 +- in: 66-corner2.in + out: 66-corner2.ans + points: 1 +- in: 67-sidel.in + out: 67-sidel.ans + points: 1 +- in: 68-sider.in + out: 68-sider.ans + points: 1 +- in: 69-sideu.in + out: 69-sideu.ans + points: 1 +- in: 70-sided.in + out: 70-sided.ans + points: 1 +- in: 71-moon1.in + out: 71-moon1.ans + points: 1 +- in: 72-moon2.in + out: 72-moon2.ans + points: 1 diff --git a/ICPC/nwerc2022_E/data.zip b/ICPC/nwerc2022_E/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..60979db5c623039290205b53d0105a395aa4c602 --- /dev/null +++ b/ICPC/nwerc2022_E/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:931f1f2c289de53af9c2c4f82799bb43e88e4985ec051891224c306ffe111a88 +size 115467 diff --git a/ICPC/nwerc2022_E/init.yml b/ICPC/nwerc2022_E/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..16c4e6659047220266599cc7e01829794727584b --- /dev/null +++ b/ICPC/nwerc2022_E/init.yml @@ -0,0 +1,319 @@ +archive: data.zip +checker: + args: + files: + - output_validators/output_validator/output_validator.cpp + - output_validators/output_validator/validation.h + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 001-kill-denominator.in + out: 001-kill-denominator.ans + points: 1 +- in: 002-kill-denominator.in + out: 002-kill-denominator.ans + points: 1 +- in: 003-kill-denominator.in + out: 003-kill-denominator.ans + points: 1 +- in: 004-minimal-input.in + out: 004-minimal-input.ans + points: 1 +- in: 005-minimal-ab.in + out: 005-minimal-ab.ans + points: 1 +- in: 006-maximal-input.in + out: 006-maximal-input.ans + points: 1 +- in: 007-maximal-input.in + out: 007-maximal-input.ans + points: 1 +- in: 008-maximal-ab.in + out: 008-maximal-ab.ans + points: 1 +- in: 009-maximal-not-int.in + out: 009-maximal-not-int.ans + points: 1 +- in: 010-maximal-not-int.in + out: 010-maximal-not-int.ans + points: 1 +- in: 011-manual-tricky.in + out: 011-manual-tricky.ans + points: 1 +- in: 012-manual-tricky.in + out: 012-manual-tricky.ans + points: 1 +- in: 013-manual-tricky.in + out: 013-manual-tricky.ans + points: 1 +- in: 014-just-impossible.in + out: 014-just-impossible.ans + points: 1 +- in: 015-just-impossible.in + out: 015-just-impossible.ans + points: 1 +- in: 016-just-impossible.in + out: 016-just-impossible.ans + points: 1 +- in: 017-manual-half.in + out: 017-manual-half.ans + points: 1 +- in: 018-manual-half.in + out: 018-manual-half.ans + points: 1 +- in: 019-manual-half.in + out: 019-manual-half.ans + points: 1 +- in: 020-manual-two.in + out: 020-manual-two.ans + points: 1 +- in: 021-manual-two.in + out: 021-manual-two.ans + points: 1 +- in: 022-manual-two.in + out: 022-manual-two.ans + points: 1 +- in: 023-manual-two.in + out: 023-manual-two.ans + points: 1 +- in: 024-manual-two.in + out: 024-manual-two.ans + points: 1 +- in: 025-manual-two.in + out: 025-manual-two.ans + points: 1 +- in: 026-manual-two.in + out: 026-manual-two.ans + points: 1 +- in: 027-manual-three.in + out: 027-manual-three.ans + points: 1 +- in: 028-manual-three.in + out: 028-manual-three.ans + points: 1 +- in: 029-manual-three.in + out: 029-manual-three.ans + points: 1 +- in: 030-manual-three.in + out: 030-manual-three.ans + points: 1 +- in: 031-manual-three.in + out: 031-manual-three.ans + points: 1 +- in: 032-manual-triangular.in + out: 032-manual-triangular.ans + points: 1 +- in: 033-manual-triangular.in + out: 033-manual-triangular.ans + points: 1 +- in: 034-manual-triangular.in + out: 034-manual-triangular.ans + points: 1 +- in: 035-manual-triangular.in + out: 035-manual-triangular.ans + points: 1 +- in: 036-manual-triangular.in + out: 036-manual-triangular.ans + points: 1 +- in: 037-manual-triangular.in + out: 037-manual-triangular.ans + points: 1 +- in: 038-manual-triangular.in + out: 038-manual-triangular.ans + points: 1 +- in: 039-manual-triangular.in + out: 039-manual-triangular.ans + points: 1 +- in: 040-manual-triangular.in + out: 040-manual-triangular.ans + points: 1 +- in: 041-manual-triangular.in + out: 041-manual-triangular.ans + points: 1 +- in: 042-manual-triangular.in + out: 042-manual-triangular.ans + points: 1 +- in: 043-manual-triangular.in + out: 043-manual-triangular.ans + points: 1 +- in: 044-manual-triangular.in + out: 044-manual-triangular.ans + points: 1 +- in: 045-manual-triangular.in + out: 045-manual-triangular.ans + points: 1 +- in: 046-manual-triangular.in + out: 046-manual-triangular.ans + points: 1 +- in: 047-manual-triangular.in + out: 047-manual-triangular.ans + points: 1 +- in: 048-manual-triangular.in + out: 048-manual-triangular.ans + points: 1 +- in: 049-manual-triangular.in + out: 049-manual-triangular.ans + points: 1 +- in: 050-manual-triangular.in + out: 050-manual-triangular.ans + points: 1 +- in: 051-manual-triangular.in + out: 051-manual-triangular.ans + points: 1 +- in: 052-manual-power.in + out: 052-manual-power.ans + points: 1 +- in: 053-manual-power.in + out: 053-manual-power.ans + points: 1 +- in: 054-manual-power.in + out: 054-manual-power.ans + points: 1 +- in: 055-impossible.in + out: 055-impossible.ans + points: 1 +- in: 056-impossible.in + out: 056-impossible.ans + points: 1 +- in: 057-impossible.in + out: 057-impossible.ans + points: 1 +- in: 058-impossible.in + out: 058-impossible.ans + points: 1 +- in: 059-impossible.in + out: 059-impossible.ans + points: 1 +- in: 060-impossible.in + out: 060-impossible.ans + points: 1 +- in: 061-impossible.in + out: 061-impossible.ans + points: 1 +- in: 062-impossible.in + out: 062-impossible.ans + points: 1 +- in: 063-impossible.in + out: 063-impossible.ans + points: 1 +- in: 064-impossible.in + out: 064-impossible.ans + points: 1 +- in: 065-just-possible.in + out: 065-just-possible.ans + points: 1 +- in: 066-just-possible.in + out: 066-just-possible.ans + points: 1 +- in: 067-just-possible.in + out: 067-just-possible.ans + points: 1 +- in: 068-just-possible.in + out: 068-just-possible.ans + points: 1 +- in: 069-just-possible.in + out: 069-just-possible.ans + points: 1 +- in: 070-just-possible.in + out: 070-just-possible.ans + points: 1 +- in: 071-just-possible.in + out: 071-just-possible.ans + points: 1 +- in: 072-just-possible.in + out: 072-just-possible.ans + points: 1 +- in: 073-just-possible.in + out: 073-just-possible.ans + points: 1 +- in: 074-just-possible.in + out: 074-just-possible.ans + points: 1 +- in: 075-random.in + out: 075-random.ans + points: 1 +- in: 076-random.in + out: 076-random.ans + points: 1 +- in: 077-random.in + out: 077-random.ans + points: 1 +- in: 078-random.in + out: 078-random.ans + points: 1 +- in: 079-random.in + out: 079-random.ans + points: 1 +- in: 080-random.in + out: 080-random.ans + points: 1 +- in: 081-random.in + out: 081-random.ans + points: 1 +- in: 082-random.in + out: 082-random.ans + points: 1 +- in: 083-random.in + out: 083-random.ans + points: 1 +- in: 084-random.in + out: 084-random.ans + points: 1 +- in: 085-random.in + out: 085-random.ans + points: 1 +- in: 086-random.in + out: 086-random.ans + points: 1 +- in: 087-random.in + out: 087-random.ans + points: 1 +- in: 088-random.in + out: 088-random.ans + points: 1 +- in: 089-random.in + out: 089-random.ans + points: 1 +- in: 090-random.in + out: 090-random.ans + points: 1 +- in: 091-random.in + out: 091-random.ans + points: 1 +- in: 092-random.in + out: 092-random.ans + points: 1 +- in: 093-random.in + out: 093-random.ans + points: 1 +- in: 094-large.in + out: 094-large.ans + points: 1 +- in: 095-large.in + out: 095-large.ans + points: 1 +- in: 096-large.in + out: 096-large.ans + points: 1 +- in: 097-large.in + out: 097-large.ans + points: 1 +- in: 098-large.in + out: 098-large.ans + points: 1 +- in: 099-large.in + out: 099-large.ans + points: 1 +- in: 100-large.in + out: 100-large.ans + points: 1 +- in: 101-large.in + out: 101-large.ans + points: 1 +- in: 102-large.in + out: 102-large.ans + points: 1 +- in: 103-large.in + out: 103-large.ans + points: 1 diff --git a/ICPC/nwerc2022_E/output_validators/output_validator/output_validator.cpp b/ICPC/nwerc2022_E/output_validators/output_validator/output_validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c46aedd986220294f4a55ca642649f1f9dc63678 --- /dev/null +++ b/ICPC/nwerc2022_E/output_validators/output_validator/output_validator.cpp @@ -0,0 +1,86 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validation.h" +using std::vector; +using std::string; + +// Output: a list of `n` page flips from `i` to `j`. + +int main(int argc, char **argv) { + // Set up the input and answer streams. + std::ifstream in(argv[1]); + std::ifstream ans(argv[2]); // Only for custom checker. + OutputValidator v(argc, argv); + + long long a,b; + char c; + in >> a >> c >> b; + string s; + ans >> s; + if (s == "impossible"){ + v.test_string("impossible"); + v.newline(); + } + else { + long long n = v.read_integer("n",1,1e6); + v.space(); + long long m = v.read_integer("m",1,1e6); + v.newline(); + vector> graph(n+1,vector{}); + for (long long i=0;i visited(n+1); + vector queue_out, queue_in; + long long distance = 0; + queue_out.push_back(1); + while (queue_out.size() > 0){ + for (long long i : queue_out){ + if (visited[i]) + continue; + total += distance; + visited[i] = true; + for (long long j : graph[i]) + queue_in.push_back(j); + } + queue_out = queue_in; + queue_in = {}; + distance += 1; + } + for (long long i=1;i<=n;i++) v.check(visited[i], "Graph not connected, vertex ", i, " unreachable"); + std::cerr << total << '/' << n << std::endl; + v.check(a*n == total*b, "Wrong average distance, got ", total, "/", n, ", wanted ", a, "/", b); + } +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2022_E/output_validators/output_validator/validation.h b/ICPC/nwerc2022_E/output_validators/output_validator/validation.h new file mode 100644 index 0000000000000000000000000000000000000000..a12961a6605a90b83e02bec0c8f9c0e72626ebb2 --- /dev/null +++ b/ICPC/nwerc2022_E/output_validators/output_validator/validation.h @@ -0,0 +1,1520 @@ +#pragma once +// A header library to safely parse team input. +// It does not support floating points or big integers. +// Author: Ragnar Groot Koerkamp + +// The easiest way to use this is to symlink it from a validator directory, +// so that it will be picked up when creating a contest zip. + +// The default checking behaviour is lenient for both white space and case. +// When validating .in and .ans files, the case_sensitive and +// space_change_sensitive flags should be passed. When validating team output, +// the flags in problem.yaml should be used. + +// Compile with -Duse_source_location to enable +// std::experimental::source_location. This is needed for constraints checking. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef use_source_location +#include +constexpr bool has_source_location = true; +using std::experimental::source_location; +namespace std { +bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +} // namespace std +namespace std::experimental::fundamentals_v2 { +bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +} // namespace std::experimental::fundamentals_v2 +#else +constexpr bool has_source_location = false; +struct source_location { + static source_location current() { return {}; } + [[nodiscard]] int line() const { return 0; } // NOLINT + [[nodiscard]] std::string file_name() const { return ""; } // NOLINT +}; +inline bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +#endif + +inline std::string location_to_string(source_location loc) { + return std::string(loc.file_name()) + ":" + std::to_string(loc.line()); +} + +const std::string_view case_sensitive_flag = "case_sensitive"; +const std::string_view ws_sensitive_flag = "space_change_sensitive"; +const std::string_view constraints_file_flag = "--constraints_file"; +const std::string_view generate_flag = "--generate"; +const std::string_view generate_binary_substring = "generat"; + +inline struct ArbitraryTag { + static constexpr bool unique = false; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Arbitrary; +inline struct UniqueTag : ArbitraryTag { + static constexpr bool unique = true; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Unique; +inline struct IncreasingTag : ArbitraryTag { static constexpr bool increasing = true; } Increasing; +inline struct DecreasingTag : ArbitraryTag { static constexpr bool decreasing = true; } Decreasing; +inline struct StrictlyIncreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool increasing = true; +} StrictlyIncreasing; +inline struct StrictlyDecreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool decreasing = true; +} StrictlyDecreasing; + +template +struct Merge : T... { + static constexpr bool unique = (T::unique || ...); + static constexpr bool strict = (T::strict || ...); + static constexpr bool increasing = (T::increasing || ...); + static constexpr bool decreasing = (T::decreasing || ...); +}; + +template and std::is_base_of_v, int> = 0> +auto operator|(T1 /*unused*/, T2 /*unused*/) { + return Merge(); +} + +enum Separator { Space, Newline }; + +// this contains some specific code which emulates c++20 features +namespace cpp20 { + +constexpr int countl_zero(unsigned long long x) { + int res = 64; + for(int i = 32; i > 0; i >>= 1) { + if((x >> i) > 0) { + res -= i; + x >>= i; + } + } + if(x > 0) res--; + return res; +} + +int popcount(unsigned long long x) { + return static_cast(std::bitset<64>(x).count()); +} + +constexpr long double PI = 3.141592653589793238462643383279502884l; + +} // namespace cpp20 + +namespace Random { + +constexpr unsigned int default_seed = 3141592653; // some digits of PI + +unsigned long long bits64(std::mt19937_64& rng) { + static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull); + static_assert(std::mt19937_64::min() == 0ull); + return rng(); +} + +// generates a uniform real in [0, 1) +long double real64(std::mt19937_64& rng) { + // a long double can represent more than 2^64 values in the range [0, 1)... + // another problem is that real64() < 1.0/3.0 is technically biased. + long double res = bits64(rng) / 0x1.0p64l; + res += bits64(rng) / 0x1.0p128l; + assert(res < 1.0l); + return res; +} + +bool bit(std::mt19937_64& rng) { + return cpp20::popcount(bits64(rng)) & 1; +} + +} // namespace Random + +template +constexpr bool is_number_v = std::is_same_v or std::is_same_v; + +namespace Generators { + +template +struct ConstGenerator { + static_assert(is_number_v or std::is_same_v or std::is_same_v); + static constexpr std::string_view name = "const"; + using Args = std::tuple; + + const T const_; + + explicit ConstGenerator(T val) : const_(std::move(val)) {} + + // For char and string, the constant store has a different type than the min and max length + // passed in. + template + T operator()(U low, U high, std::mt19937_64& rng) const { + return std::clamp(const_, low, high); + } +}; + +struct MinGenerator { + static constexpr std::string_view name = "min"; + using Args = std::tuple<>; + + explicit MinGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return low; + } +}; + +struct MaxGenerator { + static constexpr std::string_view name = "max"; + using Args = std::tuple<>; + + explicit MaxGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return high; + } +}; + +struct UniformGenerator { + static constexpr std::string_view name = "uniform"; + using Args = std::tuple<>; + + explicit UniformGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + if(low == high) return low; + + if constexpr(std::is_same_v) { + assert(low < high); + // Since C++20 we can assume Two's Complement but any sane system used it before anyway. + // Rejection sampling is not as fast as possible but definitely unbiased. + auto ul = static_cast(low); + auto uh = static_cast(high); + int shifts = cpp20::countl_zero(uh - ul); + unsigned long long res; + do { + res = Random::bits64(rng) >> shifts; + } while(res > uh - ul); + return static_cast(res + ul); + } else { + assert(low < high); + return low + Random::real64(rng) * (high - low); + } + } +}; + +template +struct RangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "range"; + using Args = std::tuple; + + const T low_, high_; + + explicit RangeGenerator(T low, T high) : low_(low), high_(high) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng); + } +}; + +template +struct StepRangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "steprange"; + using Args = std::tuple; + + const T low_, high_, step_; + + explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + // round up low to the first multiple of step_. + T start; + if(low <= low_) { + start = low_; + } else { + // first multiple of low_+k*step_ >= low + start = low_ + (long long)((low - low_) / step_) * step_; + if(start < low) start += step_; + assert(low <= start && start < low + step_); + } + long long maxsteps = (std::min(high, high_) - start) / step_; + long long steps = UniformGenerator()(0ll, maxsteps, rng); + return start + steps * step_; + } +}; + +struct NormalDistributionGenerator { + static constexpr std::string_view name = "normal"; + using T = long double; + using Args = std::tuple; + + const T mean_, stddev_; + + explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) { + assert(stddev_ >= 0); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + T u1 = Random::real64(rng); + T u2 = Random::real64(rng); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + } + return v; + } +}; + +struct ExponentialDistributionGenerator { + static constexpr std::string_view name = "exponential"; + using T = long double; + using Args = std::tuple; + + T lambda_; + + explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + v = low - std::log(Random::real64(rng)) / lambda_; + if(v < high) return v; + } + } +}; + +struct GeometricDistributionGenerator { + static constexpr std::string_view name = "geometric"; + using T = long long; + using Args = std::tuple; + + double p_; + + explicit GeometricDistributionGenerator(double p) : p_(p) { + assert(p_ > 0); + assert(p_ < 1); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + T v; + while(true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric + // distribution[...]" + v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_)); + if(v <= high) return v; + } + } +}; + +struct BinomialDistributionGenerator { + static constexpr std::string_view name = "binomial"; + using T = long long; + using Args = std::tuple; + + long long n_; + double p_; + + explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) { + assert(p_ >= 0); + assert(p_ <= 1); + std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!" + << std::endl; + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + // this will be slow for large n + // (a faster implementation requires efficient poisson sampling) + while(true) { + T v = 0; + for(long long i = 0; i < n_; i++) { + v += Random::real64(rng) < p_ ? 1 : 0; + } + if(v >= low && v <= high) return v; + } + } +}; + +template +struct ChoiceGenerator { + using GeneratorType = std::conditional_t< + std::is_same_v, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, GeometricDistributionGenerator, + BinomialDistributionGenerator>, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, NormalDistributionGenerator, + ExponentialDistributionGenerator>>; + + std::vector> generators_; + double total_weight_; + + template + struct Pack {}; + + template + static A parse_number(std::string_view s) { + static_assert(is_number_v); + if constexpr(std::is_same_v) + return stoll(std::string(s)); + else + return stold(std::string(s)); + } + + template + static A parse_argument(std::string_view& s) { + auto end = s.find_first_of(",)"); + assert(end != std::string_view::npos); + auto v = parse_number(s.substr(0, end)); + s.remove_prefix(end); + // Pop the trailing , or ) + s.remove_prefix(1); + return v; + } + + template + static std::tuple parse_arguments(std::string_view& s, + Pack> /*unused*/) { + std::tuple args{parse_argument(s)...}; + return args; + } + + // Try parsing one generator type from the start of s. + template + static void parse_generator(std::string_view& s, std::optional& out) { + if(out) return; + if(s.substr(0, G::name.size()) != G::name) return; + + // Drop the name. + s.remove_prefix(G::name.size()); + if constexpr(std::tuple_size_v == 0) { + out.emplace(std::in_place_type_t{}); + return; + } + + // Drop the ( + assert(not s.empty() and s.front() == '('); + s.remove_prefix(1); + + auto args = parse_arguments(s, Pack{}); + // Construct the resulting generator in-place in the variant.. + std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t{}, _args...); }, + args); + } + + template + static std::optional parse_generators(std::string_view& s, + Pack> /*unused*/) { + std::optional out; + (parse_generator(s, out), ...); + return out; + } + + explicit ChoiceGenerator(std::string_view s) : total_weight_(0) { + // PARSE + while(not s.empty()) { + auto generator = parse_generators(s, Pack{}); + if(!generator) { + // Check for range syntax: + auto comma = s.find_first_of(",:"); + if(comma == std::string::npos) comma = s.size(); + auto dots = s.find(".."); + if(dots != std::string_view::npos and dots < comma) { + auto start = s.substr(0, dots); + auto end = s.substr(dots + 2, comma - dots - 2); + + generator.emplace(std::in_place_type_t>{}, + parse_number(start), parse_number(end)); + s.remove_prefix(comma); + } + + // Fall back to constant. + if(!generator) { + generator.emplace(std::in_place_type_t>{}, + parse_number(s.substr(0, comma))); + s.remove_prefix(comma); + } + } + + // Parse weight if given. + double weight = 1; + if(not s.empty() and s.front() == ':') { + s.remove_prefix(1); + auto comma = s.find(','); + if(comma == std::string_view::npos) comma = s.size(); + weight = parse_number(s.substr(0, comma)); + s.remove_prefix(comma); + } + + // should now be at , or end + assert(s.empty() or s.front() == ','); + if(not s.empty()) s.remove_prefix(1); + generators_.emplace_back(std::move(*generator), weight); + total_weight_ += weight; + } + } + + T operator()(T low, T high, std::mt19937_64& rng) const { + Generators::UniformGenerator uniform; + double x = uniform.operator()(0, total_weight_, rng); + for(size_t i = 0; i < generators_.size(); ++i) { + x -= generators_[i].second; + if(x <= 0) + return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first); + } + assert(false); + } +}; + +struct ParamGenerator { + std::variant, ChoiceGenerator> + generator; + explicit ParamGenerator(std::string_view s) : generator(s) {} + + template + T operator()(T low, T high, std::mt19937_64& rng) { + static_assert(is_number_v); + if(std::holds_alternative(generator)) { + generator = ChoiceGenerator(std::get(generator)); + } + return std::get>(generator)(low, high, rng); + } +}; + +} // namespace Generators + +using Generators::ParamGenerator; + +namespace Random { +template +void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) { + Generators::UniformGenerator uniform; + long long n = last - first; + for(long long i = n - 1; i > 0; i--) { + std::swap(first[i], first[uniform(0ll, i, rng)]); + } +} + +template +void shuffle(std::pair& in, std::mt19937_64& rng) { + if(bit(rng)) std::swap(in.first, in.second); +} + +template +auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) { + assert(first != last); + Generators::UniformGenerator uniform; + long long n = last - first; + return first[uniform(0ll, n - 1, rng)]; +} + +template +const T& select(const std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +template +T& select(std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +} // namespace Random + +class Validator { + protected: + Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "", + std::optional seed = std::nullopt, + std::unordered_map params_ = {}) + : in(in_), ws(ws_), case_sensitive(case_), + constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()), + rng(seed.value_or(Random::default_seed)), params(std::move(params_)) { + + std::ios_base::sync_with_stdio(false); + in.tie(nullptr); + + if(gen) return; + if(ws) + in >> std::noskipws; + else + in >> std::skipws; + + if(!constraints_file_path.empty()) { + assert(has_source_location); // NOLINT + } + } + + public: + // No copying, no moving. + Validator(const Validator&) = delete; + Validator(Validator&&) = delete; + void operator=(const Validator&) = delete; + void operator=(Validator&&) = delete; + + // At the end of the scope, check whether the EOF has been reached. + // If so, return AC. Otherwise, return WA. + ~Validator() { + eof(); + write_constraints(); + AC(); + } + + void space() { + if(gen) { + out << ' '; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected space, found EOF."); + if(c != ' ') + expected("space", std::string("\"") + + ((c == '\n' or c == '\r') ? std::string("newline") + : std::string(1, c)) + + "\""); + } + } + + void newline() { + if(gen) { + out << '\n'; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected newline, found EOF."); + if(c != '\n') { + if(c == '\r') + expected("newline", "DOS line ending (\\r)"); + else + expected("newline", std::string("\"") + c + "\""); + } + } + } + + private: + void separator(Separator s) { + switch(s) { + case Separator::Space: space(); break; + case Separator::Newline: newline(); break; + } + } + + template + auto& seen() { + static std::map> seen; + return seen; + } + template + auto& last_seen() { + static std::map last_seen; + return last_seen; + } + template + auto& integers_seen() { + static std::map, std::vector, bool>> + integers_seen; + return integers_seen; + } + template + void reset(source_location loc) { + seen().erase(loc); + last_seen().erase(loc); + integers_seen().erase(loc); + } + + template + void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/, + source_location loc) { + static_assert(is_number_v); + if(v < low or v > high) { + std::string type_name; + if constexpr(std::is_integral_v) { + type_name = "integer"; + } + if constexpr(std::is_floating_point_v) { + type_name = "float"; + } + expected(name + ": " + type_name + " between " + std::to_string(low) + " and " + + std::to_string(high), + std::to_string(v)); + } + log_constraint(name, low, high, v, loc); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[loc].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else { + auto [it, inserted] = last_seen().emplace(loc, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + template + void check_string(const std::string& name, int low, int high, const std::string& v, + Tag /*unused*/, source_location loc) { + using T = std::string; + if((int) v.size() < low or (int) v.size() > high) { + expected(name + ": " + "string with" + " length between " + std::to_string(low) + + " and " + std::to_string(high), + v); + } + log_constraint(name, low, high, static_cast(v.size()), loc); + if constexpr(Tag::unique) { + // static map> seen; + auto [it, inserted] = seen()[loc].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else if(Tag::increasing or Tag::decreasing) { + // static map last_seen; + auto [it, inserted] = last_seen().emplace(loc, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + // Generate a random integer in [low, high] or float in [low, high). + template + T uniform_number(T low, T high) { + assert(low <= high); + Generators::UniformGenerator uniform; + if constexpr(std::is_integral::value) + return uniform.operator()(low, high, rng); + else + return uniform.operator()(low, high, rng); + } + + template + T gen_number(const std::string& name, T low, T high, Tag /*unused*/, source_location loc) { + static_assert(is_number_v); + T v; + + if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + if constexpr(std::is_integral::value) { + auto& [seen_here, remaining_here, use_remaining] = integers_seen()[loc]; + + if(use_remaining) { + check(!remaining_here.empty(), name, ": no unique values left"); + v = remaining_here.back(); + remaining_here.pop_back(); + } else { + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + + struct CountIterator { + T v; + T& operator*() { return v; } + T& operator++() { return ++v; } + T operator++(int) { return v++; } + bool operator!=(CountIterator r) { return v != r.v; } + }; + + if(seen_here.size() > (high - low) / 2) { + use_remaining = true; + set_difference(CountIterator{low}, CountIterator{high + 1}, + seen_here.begin(), seen_here.end(), + std::back_inserter(remaining_here)); + } + } + } else { + // For floats, just regenerate numbers until success. + auto& seen_here = seen()[loc]; + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + } + + } else { + assert(not Tag::increasing && "Generating increasing sequences is not yet supported!"); + assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!"); + assert((std::is_same::value) && + "Only Unique and Arbitrary are supported!"); + + if(params.find(name) != params.end()) { + v = params.at(name).operator()(low, high, rng); + // This will be checked during input validation of the generated case. + // assert(low <= v and v <= high); + } else { + v = uniform_number(low, high); + } + } + + return v; + } + + std::string gen_string(const std::string& name, long long low, long long high, + std::string_view chars) { + assert(!chars.empty()); + + int len; + if(params.find(name + ".length") != params.end()) + len = params.at(name + ".length").operator()(low, high, rng); + else + len = uniform_number(low, high); + std::string s(len, ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s; + return s; + } + + public: + template + long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_number(name, low, high, tag, loc); + } + + template + long double gen_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}, source_location loc = source_location::current()) { + return gen_number(name, low, high, tag, loc); + } + + private: + template + std::vector gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/, + source_location loc) { + static_assert(is_number_v); + std::vector v; + v.reserve(count); + if constexpr(std::is_same_v) { + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + } else if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + std::set seen_here; + if constexpr(std::is_integral_v) { + if(2 * count < high - low) { + for(int i = 0; i < count; ++i) { + // If density < 1/2: retry. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } else { + // If density >= 1/2, crop a random permutation. + v.resize(high - low + 1); + iota(begin(v), end(v), low); + Random::shuffle(begin(v), end(v), rng); + v.resize(count); + } + } else { + for(int i = 0; i < count; ++i) { + // For floats, just regenerate numbers until success. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + constexpr bool integral_strict = Tag::strict and std::is_integral::value; + if(integral_strict) { + assert(params.find(name) == params.end() && + "Parameters are not supported for strict integer values."); + high = high - count + 1; + } + + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + + sort(begin(v), end(v)); + + if(integral_strict) { + for(int i = 0; i < count; ++i) v[i] += i; + } + + if(Tag::decreasing) reverse(begin(v), end(v)); + } + + return v; + } + + public: + template + std::vector gen_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_numbers(name, count, low, high, tag, loc); + } + + template + std::vector gen_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_numbers(name, count, low, high, tag, loc); + } + + private: + template + T read_number(const std::string& name, T low, T high, Tag tag, source_location loc) { + if(gen) { + auto v = gen_number(name, low, high, tag, loc); + out << std::setprecision(10) << std::fixed << v; + return v; + } + + const auto v = [&] { + if constexpr(std::is_integral::value) + return read_integer(name); + else + return read_float(name); + }(); + + check_number(name, low, high, v, tag, loc); + return v; + } + + // Read a vector of numbers, separated by spaces and ended by a newline. + template + std::vector read_numbers(const std::string& name, int count, T low, T high, Tag tag, + Separator sep, source_location loc) { + if(gen) { + auto v = gen_numbers(name, count, low, high, tag, loc); + + out << std::setprecision(10) << std::fixed; + for(int i = 0; i < count; ++i) { + out << v[i]; + if(i < count - 1) separator(sep); + } + newline(); + + return v; + } + reset(loc); + std::vector v(count); + for(int i = 0; i < count; ++i) { + if constexpr(std::is_integral::value) + v[i] = read_integer(name); + else + v[i] = read_float(name); + check_number(name, low, high, v[i], tag, loc); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + public: + template + long long read_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return read_number(name, low, high, tag, loc); + } + template + std::vector read_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, Separator sep = Space, + source_location loc = source_location::current()) { + return read_numbers(name, count, low, high, tag, sep, loc); + } + + template + long double read_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}, source_location loc = source_location::current()) { + return read_number(name, low, high, tag, loc); + } + template + std::vector read_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, Separator sep = Space, + source_location loc = source_location::current()) { + return read_numbers(name, count, low, high, tag, sep, loc); + } + + // Read a vector of strings, separated by spaces and ended by a newline. + template + std::vector read_strings(const std::string& name, int count, int min, int max, + const std::string_view chars = "", Tag tag = Tag(), + Separator sep = Space, + source_location loc = source_location::current()) { + reset(loc); + if(gen) return gen_strings(name, count, min, max, chars, tag, sep, loc); + assert(!gen); + std::vector v(count); + for(int i = 0; i < count; ++i) { + v[i] = read_string(name, min, max, chars, tag, loc); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + template + std::vector gen_strings(const std::string& name, int count, int min, int max, + const std::string_view chars, Tag /*unused*/, + Separator sep, source_location loc) { + assert(!chars.empty()); + + std::vector v(count); + if constexpr(std::is_same::value) { + for(int i = 0; i < count; ++i) { + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else if constexpr(Tag::unique) { + std::set seen_here; + for(int i = 0; i < count; ++i) { + // Just regenerate strings until success. + std::string s; + do { + s = std::string(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + } while(!seen_here.insert(s).second); + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + assert(false && "Generating increasing/decreasing lists of strings is not " + "supported!"); + } + + newline(); + + return v; + } + + // Check the next character. + bool peek(char c, const std::string& name = "") { + if(gen) { + // TODO + // if(not name.empty() and params.contains(name)) { + // return c == params.at(name).operator()(0, 0, rng); + //} + return Random::bit(rng); + } + if(!ws) in >> std::ws; + if(case_sensitive) return in.peek() == std::char_traits::to_int_type(c); + return tolower(in.peek()) == tolower(std::char_traits::to_int_type(c)); + } + + // Read a string and make sure it equals `expected`. + // Takes by value because it needs to lowercase its arguments. + std::string test_strings(std::vector expected, const std::string& name = "") { + if(gen) { + int index = 0; + // TODO + // if(not name.empty() and params.contains(name)) { + // auto s = params.at(name).operator()(0, 0, rng); + // index = std::find(expected.begin(), expected.end(), s) - expected.begin(); + // assert(0 <= index and index < expected.size()); + //} else { + index = expected.size() == 1 ? 0 : uniform_number(0, expected.size() - 1); + //} + out << expected[index]; + return expected[index]; + } + std::string s = get_string(); + lowercase(s); + + for(std::string e : expected) + if(s == lowercase(e)) return s; + + std::string error; + for(const auto& e : expected) { + if(not error.empty()) error += "|"; + error += e; + } + WA("Expected string \"", error, "\", but found ", s); + } + + // Read a string and make sure it equals `expected`. + std::string test_string(std::string expected, const std::string& name = "") { + return test_strings({std::move(expected)}, name); + } + + // Read an arbitrary string of a given length. + template + std::string read_string(const std::string& name, long long min, long long max, + const std::string_view chars = "", Tag tag = Tag(), + source_location loc = source_location::current()) { + if(gen) { + return gen_string(name, min, max, chars); + } + std::string s = get_string(); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + check_string(name, min, max, s, tag, loc); + return s; + } + + // Read an arbitrary line of a given length. + std::string read_line(const std::string& name, long long min, long long max, + const std::string_view chars = "", + source_location loc = source_location::current()) { + if(gen) { + // TODO: Params for lines. + assert(!chars.empty()); + + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s << '\n'; + return s; + } + + if(ws) { + char next = in.peek(); + if(min > 0 and isspace(next)) + expected("non empty line", next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected("line", "EOF"); + } + std::string s; + if(!getline(in, s)) expected("line", "nothing"); + long long size = s.size(); + if(size < min || size > max) + expected(name + ": line of length between " + std::to_string(min) + " and " + + std::to_string(max), + s); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + log_constraint(name, min, max, size, loc); + return s; + } + + // Return ACCEPTED verdict. + void eof_and_AC() { + eof(); + AC(); + } + + private: + std::function WA_handler = [] {}; + + public: + void set_WA_handler(std::function f) { WA_handler = std::move(f); } + + // Return WA with the given reason. + template + [[noreturn]] void WA(const Ts&... ts) { + static_assert(sizeof...(Ts) > 0); + + WA_handler(); + + auto pos = get_file_pos(); + std::cerr << pos.first << ":" << pos.second << ": "; + + WA_impl(ts...); + } + + // Check that the condition is true. + template + void check(bool b, const Ts&... ts) { + static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message."); + + if(!b) WA(ts...); + } + + // Log some value in a range. + template + void log_constraint(const std::string& name, T low, T high, T v, + source_location loc = source_location::current()) { + // Do not log when line number is unknown/default/unsupported. + if(loc.line() == 0 or constraints_file_path.empty()) return; + + // All integer types get bounds as long long, all floating point types as long_double. + using U = Bounds, long long, long double>>; + + auto [it, inserted] = bounds.emplace(loc, U(name, v, v, low, high)); + assert(std::holds_alternative(it->second)); + auto& done = std::get(it->second); + if(inserted) { + assert(!name.empty() && "Variable names must not be empty."); + assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces."); + } else { + assert(name == done.name && "Variable name must be constant."); + } + if(v < done.min) { + done.min = v; + done.low = low; + } + if(v > done.max) { + done.max = v; + done.high = high; + } + done.has_min |= v == low; + done.has_max |= v == high; + } + + private: + long long read_integer(const std::string& name) { + assert(!gen); + std::string s = get_string("integer"); + if(s.empty()) { + WA(name, ": Want integer, found nothing"); + } + long long v; + auto begin = s.c_str(), end = begin + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, v); + if(ec == std::errc::result_out_of_range){ + WA(name, ": Number " + s + " does not fit in a long long!"); + } else if(ptr != end) { + WA(name, ": Parsing " + s + " as long long failed! Did not process all characters"); + } else if (ec != std::errc{}) { + WA(name, ": Parsing " + s + " as long long failed!"); + } + // Check for leading zero. + if(v == 0) { + if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s); + } + if(v > 0) { + if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + if(v < 0) { + if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s); + if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + return v; + } + + long double read_float(const std::string& name) { + assert(!gen); + std::string s = get_string("long double"); + long double v; + try { + size_t chars_processed; + v = stold(s, &chars_processed); + if(chars_processed != s.size()) + WA(name, ": Parsing ", s, + " as long double failed! Did not process all characters."); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long double!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long double failed!"); + } + return v; + } + + [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") { + assert(!gen && "Expected is not supported for generators."); + if(!s.empty()) + WA("Expected ", exp, ", found ", s); + else + WA(exp); + } + + template + [[noreturn]] void WA_impl(T t) { + std::cerr << t << std::endl; + exit(ret_WA); + } + + std::pair get_file_pos() { + int line = 1, col = 0; + in.clear(); + auto originalPos = in.tellg(); + if(originalPos < 0) return {-1, -1}; + in.seekg(0); + char c; + while((in.tellg() < originalPos) && in.get(c)) { + if(c == '\n') + ++line, col = 0; + else + ++col; + } + return {line, col}; + } + + template + [[noreturn]] void WA_impl(T t, Ts... ts) { + std::cerr << t; + WA_impl(ts...); + } + + std::string get_string(const std::string& wanted = "string") { + assert(!gen && "get_string is not supported for generators."); + if(ws) { + char next = in.peek(); + if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected(wanted, "EOF"); + } + + std::string s; + if(in >> s) { + return s; + } + expected(wanted, "nothing"); + } + + // Return ACCEPTED verdict. + void AC() const { + if(gen) { + // nothing + return; + } + + exit(ret_AC); + } + + void eof() { + if(gen) { + out.flush(); + fclose(stdout); + return; + } + if(in.eof()) return; + // Sometimes EOF hasn't been triggered yet. + if(!ws) in >> std::ws; + char c = in.get(); + if(c == std::char_traits::eof()) return; + std::string got = std::string("\"") + char(c) + '"'; + if(c == '\n') got = "newline"; + expected("EOF", got); + } + + // Convert a string to lowercase is matching is not case sensitive. + std::string& lowercase(std::string& s) const { + if(case_sensitive) return s; + transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; + } + + // Keep track of the min/max value read at every call site. + template + struct Bounds { + Bounds(std::string name_, T min_, T max_, T low_, T high_) + : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT + std::string name; + T min, max; // Smallest / largest value observed + T low, high; // Bounds + bool has_min = false, has_max = false; + }; + + std::map, Bounds>> bounds; + + void write_constraints() { + if(constraints_file_path.empty()) return; + + std::ofstream os(constraints_file_path); + + for(const auto& [location, bound] : bounds) { + os << location_to_string(location) << " "; + std::visit( + [&](const auto& b) { + os << b.name << " " << b.has_min << " " << b.has_max << " " << b.min << " " + << b.max << " " << b.low << " " << b.high << std::endl; + }, + bound); + } + } + + static const int ret_AC = 42, ret_WA = 43; + std::istream& in = std::cin; + std::ostream& out = std::cout; + + public: + const bool ws = true; + const bool case_sensitive = true; + const std::string constraints_file_path; + const bool gen = false; + + std::mt19937_64 rng; + + private: + std::unordered_map params; + + public: + std::string_view get_param(std::string_view name, std::string_view default_) { + auto it = params.find(std::string(name)); + if(it == params.end()) return default_; + return std::get(it->second.generator); + } + + protected: + static std::string get_constraints_file(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == constraints_file_flag) { + if(i + 1 < argc) return argv[i + 1]; + std::cerr << constraints_file_flag << " should be followed by a file path!"; + exit(1); + } + } + return {}; + } +}; + +class Generator : public Validator { + public: + explicit Generator(unsigned int seed) + : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {} +}; + +class InputValidator : public Validator { + public: + // An InputValidator is always both whitespace and case sensitive. + explicit InputValidator(int argc = 0, char** argv = nullptr) + : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv), + get_params(argc, argv)) {} + + private: + static std::optional get_seed(int argc, char** argv) { + for(int i = 1; i < argc - 1; ++i) { + if(argv[i] == generate_flag) { + return std::stol(argv[i + 1]); + } + } + // If no --generate is given, but `generat` is a substring of the binary path, + // use the first argument as seed. + if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) { + return std::stol(argv[1]); + } + return std::nullopt; + } + + static std::unordered_map get_params(int argc, char** argv) { + std::unordered_map params; + for(int i = 1; i < argc - 1; ++i) { + if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue; + if(argv[i] == generate_flag) { + continue; + } + std::string_view name(argv[i] + 1); + std::string_view value(argv[i + 1]); + params.insert({std::string(name), ParamGenerator(value)}); + } + return params; + } +}; + +class OutputValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_, + get_constraints_file(argc, argv)) {} + + private: + static bool is_ws_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == ws_sensitive_flag) return true; + } + return false; + } + + static bool is_case_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == case_sensitive_flag) return true; + } + return false; + } +}; diff --git a/ICPC/nwerc2022_F/data.zip b/ICPC/nwerc2022_F/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..d5994328fc8d14fc4688987a9650a271aa0fbe4c --- /dev/null +++ b/ICPC/nwerc2022_F/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ecf0c3b63e72a3e39274bb80c7b227c503eccad52366caf3dd56a9e414081285 +size 295421524 diff --git a/ICPC/nwerc2022_F/init.yml b/ICPC/nwerc2022_F/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e65235b09d6d0e833bbeaff036dece78bfb707e0 --- /dev/null +++ b/ICPC/nwerc2022_F/init.yml @@ -0,0 +1,665 @@ +archive: data.zip +test_cases: +- in: 001-precision.in + out: 001-precision.ans + points: 1 +- in: 002-precision.in + out: 002-precision.ans + points: 1 +- in: 003-precision.in + out: 003-precision.ans + points: 1 +- in: 004-precision.in + out: 004-precision.ans + points: 1 +- in: 005-gen_jorke1.in + out: 005-gen_jorke1.ans + points: 1 +- in: 006-gen_jorke1.in + out: 006-gen_jorke1.ans + points: 1 +- in: 007-gen_jorke1.in + out: 007-gen_jorke1.ans + points: 1 +- in: 008-gen_jorke1.in + out: 008-gen_jorke1.ans + points: 1 +- in: 009-gen_jorke1.in + out: 009-gen_jorke1.ans + points: 1 +- in: 010-gen_jorke1.in + out: 010-gen_jorke1.ans + points: 1 +- in: 011-gen_jorke2.in + out: 011-gen_jorke2.ans + points: 1 +- in: 012-gen_jorke2.in + out: 012-gen_jorke2.ans + points: 1 +- in: 013-gen_jorke2.in + out: 013-gen_jorke2.ans + points: 1 +- in: 014-gen_jorke2.in + out: 014-gen_jorke2.ans + points: 1 +- in: 015-gen_jorke2.in + out: 015-gen_jorke2.ans + points: 1 +- in: 016-gen_jorke2.in + out: 016-gen_jorke2.ans + points: 1 +- in: 017-side_boxes_hor.in + out: 017-side_boxes_hor.ans + points: 1 +- in: 018-side_boxes_hor.in + out: 018-side_boxes_hor.ans + points: 1 +- in: 019-side_boxes_hor.in + out: 019-side_boxes_hor.ans + points: 1 +- in: 020-side_boxes_hor.in + out: 020-side_boxes_hor.ans + points: 1 +- in: 021-side_boxes_hor.in + out: 021-side_boxes_hor.ans + points: 1 +- in: 022-side_boxes_hor.in + out: 022-side_boxes_hor.ans + points: 1 +- in: 023-side_boxes_ver.in + out: 023-side_boxes_ver.ans + points: 1 +- in: 024-side_boxes_ver.in + out: 024-side_boxes_ver.ans + points: 1 +- in: 025-side_boxes_ver.in + out: 025-side_boxes_ver.ans + points: 1 +- in: 026-side_boxes_ver.in + out: 026-side_boxes_ver.ans + points: 1 +- in: 027-side_boxes_ver.in + out: 027-side_boxes_ver.ans + points: 1 +- in: 028-side_boxes_ver.in + out: 028-side_boxes_ver.ans + points: 1 +- in: 029-worstcase_200000_00.in + out: 029-worstcase_200000_00.ans + points: 1 +- in: 030-worstcase_200000_00.in + out: 030-worstcase_200000_00.ans + points: 1 +- in: 031-worstcase_200000_10.in + out: 031-worstcase_200000_10.ans + points: 1 +- in: 032-worstcase_200000_10.in + out: 032-worstcase_200000_10.ans + points: 1 +- in: 033-worstcase_200000_01.in + out: 033-worstcase_200000_01.ans + points: 1 +- in: 034-worstcase_200000_01.in + out: 034-worstcase_200000_01.ans + points: 1 +- in: 035-worstcase_200000_11.in + out: 035-worstcase_200000_11.ans + points: 1 +- in: 036-worstcase_200000_11.in + out: 036-worstcase_200000_11.ans + points: 1 +- in: 037-doomsday_manual.in + out: 037-doomsday_manual.ans + points: 1 +- in: 038-doomsday_manual.in + out: 038-doomsday_manual.ans + points: 1 +- in: 039-doomsday_manual.in + out: 039-doomsday_manual.ans + points: 1 +- in: 040-doomsday_precision.in + out: 040-doomsday_precision.ans + points: 1 +- in: 041-doomsday_precision.in + out: 041-doomsday_precision.ans + points: 1 +- in: 042-manual.in + out: 042-manual.ans + points: 1 +- in: 043-manual.in + out: 043-manual.ans + points: 1 +- in: 044-manual.in + out: 044-manual.ans + points: 1 +- in: 045-manual.in + out: 045-manual.ans + points: 1 +- in: 046-manual.in + out: 046-manual.ans + points: 1 +- in: 047-manual.in + out: 047-manual.ans + points: 1 +- in: 048-manual.in + out: 048-manual.ans + points: 1 +- in: 049-manual.in + out: 049-manual.ans + points: 1 +- in: 050-manual.in + out: 050-manual.ans + points: 1 +- in: 051-manual.in + out: 051-manual.ans + points: 1 +- in: 052-manual.in + out: 052-manual.ans + points: 1 +- in: 053-manual.in + out: 053-manual.ans + points: 1 +- in: 054-manual.in + out: 054-manual.ans + points: 1 +- in: 055-manual.in + out: 055-manual.ans + points: 1 +- in: 056-manual.in + out: 056-manual.ans + points: 1 +- in: 057-manual.in + out: 057-manual.ans + points: 1 +- in: 058-manual.in + out: 058-manual.ans + points: 1 +- in: 059-manual.in + out: 059-manual.ans + points: 1 +- in: 060-manual.in + out: 060-manual.ans + points: 1 +- in: 061-manual.in + out: 061-manual.ans + points: 1 +- in: 062-manual.in + out: 062-manual.ans + points: 1 +- in: 063-manual.in + out: 063-manual.ans + points: 1 +- in: 064-manual.in + out: 064-manual.ans + points: 1 +- in: 065-minimal-low.in + out: 065-minimal-low.ans + points: 1 +- in: 066-minimal-high.in + out: 066-minimal-high.ans + points: 1 +- in: 067-minimal-low-high.in + out: 067-minimal-low-high.ans + points: 1 +- in: 068-gen1.in + out: 068-gen1.ans + points: 1 +- in: 069-gen1.in + out: 069-gen1.ans + points: 1 +- in: 070-gen1.in + out: 070-gen1.ans + points: 1 +- in: 071-gen1.in + out: 071-gen1.ans + points: 1 +- in: 072-gen2.in + out: 072-gen2.ans + points: 1 +- in: 073-gen2.in + out: 073-gen2.ans + points: 1 +- in: 074-gen2.in + out: 074-gen2.ans + points: 1 +- in: 075-gen2.in + out: 075-gen2.ans + points: 1 +- in: 076-gen3.in + out: 076-gen3.ans + points: 1 +- in: 077-gen4.in + out: 077-gen4.ans + points: 1 +- in: 078-gen5.in + out: 078-gen5.ans + points: 1 +- in: 079-gen6.in + out: 079-gen6.ans + points: 1 +- in: 080-gen6.in + out: 080-gen6.ans + points: 1 +- in: 081-gen7.in + out: 081-gen7.ans + points: 1 +- in: 082-gen7.in + out: 082-gen7.ans + points: 1 +- in: 083-gen7.in + out: 083-gen7.ans + points: 1 +- in: 084-parabola_gen_5.in + out: 084-parabola_gen_5.ans + points: 1 +- in: 085-parabola_gen_20.in + out: 085-parabola_gen_20.ans + points: 1 +- in: 086-parabola_gen_1000.in + out: 086-parabola_gen_1000.ans + points: 1 +- in: 087-parabola_gen_200000.in + out: 087-parabola_gen_200000.ans + points: 1 +- in: 088-parabola_gen_200000.in + out: 088-parabola_gen_200000.ans + points: 1 +- in: 089-parabola_gen_200000.in + out: 089-parabola_gen_200000.ans + points: 1 +- in: 090-parpar_gen_5.in + out: 090-parpar_gen_5.ans + points: 1 +- in: 091-parpar_gen_20.in + out: 091-parpar_gen_20.ans + points: 1 +- in: 092-parpar_gen_1000.in + out: 092-parpar_gen_1000.ans + points: 1 +- in: 093-parpar_gen_5000.in + out: 093-parpar_gen_5000.ans + points: 1 +- in: 094-parpar_gen_10000.in + out: 094-parpar_gen_10000.ans + points: 1 +- in: 095-parpar_gen_200000.in + out: 095-parpar_gen_200000.ans + points: 1 +- in: 096-parpar_gen_200000.in + out: 096-parpar_gen_200000.ans + points: 1 +- in: 097-parpar_gen_200000.in + out: 097-parpar_gen_200000.ans + points: 1 +- in: 098-pardis_5.in + out: 098-pardis_5.ans + points: 1 +- in: 099-pardis_20.in + out: 099-pardis_20.ans + points: 1 +- in: 100-pardis_1000.in + out: 100-pardis_1000.ans + points: 1 +- in: 101-pardis_5000.in + out: 101-pardis_5000.ans + points: 1 +- in: 102-pardis_10000.in + out: 102-pardis_10000.ans + points: 1 +- in: 103-pardis_200000.in + out: 103-pardis_200000.ans + points: 1 +- in: 104-pardis_200000.in + out: 104-pardis_200000.ans + points: 1 +- in: 105-partan_5.in + out: 105-partan_5.ans + points: 1 +- in: 106-partan_20.in + out: 106-partan_20.ans + points: 1 +- in: 107-partan_5000.in + out: 107-partan_5000.ans + points: 1 +- in: 108-partan_10000.in + out: 108-partan_10000.ans + points: 1 +- in: 109-partan_10000.in + out: 109-partan_10000.ans + points: 1 +- in: 110-partan_200000.in + out: 110-partan_200000.ans + points: 1 +- in: 111-partan_200000.in + out: 111-partan_200000.ans + points: 1 +- in: 112-partan_200000.in + out: 112-partan_200000.ans + points: 1 +- in: 113-partan_200000.in + out: 113-partan_200000.ans + points: 1 +- in: 114-worstcase_5_00.in + out: 114-worstcase_5_00.ans + points: 1 +- in: 115-worstcase_20_00.in + out: 115-worstcase_20_00.ans + points: 1 +- in: 116-worstcase_1000_00.in + out: 116-worstcase_1000_00.ans + points: 1 +- in: 117-worstcase_5000_00.in + out: 117-worstcase_5000_00.ans + points: 1 +- in: 118-worstcase_10000_00.in + out: 118-worstcase_10000_00.ans + points: 1 +- in: 119-worstcase_200000_00.in + out: 119-worstcase_200000_00.ans + points: 1 +- in: 120-worstcase_200000_00.in + out: 120-worstcase_200000_00.ans + points: 1 +- in: 121-worstcase_200000_00.in + out: 121-worstcase_200000_00.ans + points: 1 +- in: 122-worstcase_5_10.in + out: 122-worstcase_5_10.ans + points: 1 +- in: 123-worstcase_20_10.in + out: 123-worstcase_20_10.ans + points: 1 +- in: 124-worstcase_1000_10.in + out: 124-worstcase_1000_10.ans + points: 1 +- in: 125-worstcase_5000_10.in + out: 125-worstcase_5000_10.ans + points: 1 +- in: 126-worstcase_10000_10.in + out: 126-worstcase_10000_10.ans + points: 1 +- in: 127-worstcase_200000_10.in + out: 127-worstcase_200000_10.ans + points: 1 +- in: 128-worstcase_200000_10.in + out: 128-worstcase_200000_10.ans + points: 1 +- in: 129-worstcase_200000_10.in + out: 129-worstcase_200000_10.ans + points: 1 +- in: 130-worstcase_200000_10.in + out: 130-worstcase_200000_10.ans + points: 1 +- in: 131-worstcase_200000_10.in + out: 131-worstcase_200000_10.ans + points: 1 +- in: 132-worstcase_200000_10.in + out: 132-worstcase_200000_10.ans + points: 1 +- in: 133-worstcase_20_01.in + out: 133-worstcase_20_01.ans + points: 1 +- in: 134-worstcase_20_11.in + out: 134-worstcase_20_11.ans + points: 1 +- in: 135-box_5_0.in + out: 135-box_5_0.ans + points: 1 +- in: 136-box_7_0.in + out: 136-box_7_0.ans + points: 1 +- in: 137-box_10_0.in + out: 137-box_10_0.ans + points: 1 +- in: 138-box_10_0.in + out: 138-box_10_0.ans + points: 1 +- in: 139-box_7_0.in + out: 139-box_7_0.ans + points: 1 +- in: 140-box_7_0.in + out: 140-box_7_0.ans + points: 1 +- in: 141-box_7_0.in + out: 141-box_7_0.ans + points: 1 +- in: 142-box_5_5.in + out: 142-box_5_5.ans + points: 1 +- in: 143-box_5_5.in + out: 143-box_5_5.ans + points: 1 +- in: 144-box_5_5.in + out: 144-box_5_5.ans + points: 1 +- in: 145-box_5_5.in + out: 145-box_5_5.ans + points: 1 +- in: 146-box_7_5.in + out: 146-box_7_5.ans + points: 1 +- in: 147-box_5_7.in + out: 147-box_5_7.ans + points: 1 +- in: 148-box_7_7.in + out: 148-box_7_7.ans + points: 1 +- in: 149-box_7_7.in + out: 149-box_7_7.ans + points: 1 +- in: 150-box_3_10.in + out: 150-box_3_10.ans + points: 1 +- in: 151-box_3_10.in + out: 151-box_3_10.ans + points: 1 +- in: 152-box_3_10.in + out: 152-box_3_10.ans + points: 1 +- in: 153-prime_line.in + out: 153-prime_line.ans + points: 1 +- in: 154-prime_line.in + out: 154-prime_line.ans + points: 1 +- in: 155-prime_line.in + out: 155-prime_line.ans + points: 1 +- in: 156-manual_break_nils.in + out: 156-manual_break_nils.ans + points: 1 +- in: 157-side_boxes_hor.in + out: 157-side_boxes_hor.ans + points: 1 +- in: 158-side_boxes_hor.in + out: 158-side_boxes_hor.ans + points: 1 +- in: 159-side_boxes_ver.in + out: 159-side_boxes_ver.ans + points: 1 +- in: 160-gen_jorke3.in + out: 160-gen_jorke3.ans + points: 1 +- in: 161-gen_jorke3.in + out: 161-gen_jorke3.ans + points: 1 +- in: 162-gen_jorke3.in + out: 162-gen_jorke3.ans + points: 1 +- in: 163-gen_jorke3.in + out: 163-gen_jorke3.ans + points: 1 +- in: 164-gen_jorke3.in + out: 164-gen_jorke3.ans + points: 1 +- in: 165-gen_jorke3.in + out: 165-gen_jorke3.ans + points: 1 +- in: 166-gen_jorke3.in + out: 166-gen_jorke3.ans + points: 1 +- in: 167-gen_jorke3.in + out: 167-gen_jorke3.ans + points: 1 +- in: 168-gen_jorke3.in + out: 168-gen_jorke3.ans + points: 1 +- in: 169-gen_jorke3.in + out: 169-gen_jorke3.ans + points: 1 +- in: 170-gen_jorke3.in + out: 170-gen_jorke3.ans + points: 1 +- in: 171-gen_jorke3.in + out: 171-gen_jorke3.ans + points: 1 +- in: 172-gen_jorke3.in + out: 172-gen_jorke3.ans + points: 1 +- in: 173-gen_jorke3.in + out: 173-gen_jorke3.ans + points: 1 +- in: 174-gen_jorke3.in + out: 174-gen_jorke3.ans + points: 1 +- in: 175-gen_jorke3.in + out: 175-gen_jorke3.ans + points: 1 +- in: 176-gen_jorke3.in + out: 176-gen_jorke3.ans + points: 1 +- in: 177-gen_jorke3.in + out: 177-gen_jorke3.ans + points: 1 +- in: 178-long_box.in + out: 178-long_box.ans + points: 1 +- in: 179-long_box.in + out: 179-long_box.ans + points: 1 +- in: 180-long_box.in + out: 180-long_box.ans + points: 1 +- in: 181-long_box.in + out: 181-long_box.ans + points: 1 +- in: 182-long_box.in + out: 182-long_box.ans + points: 1 +- in: 183-long_box.in + out: 183-long_box.ans + points: 1 +- in: 184-long_box.in + out: 184-long_box.ans + points: 1 +- in: 185-long_box.in + out: 185-long_box.ans + points: 1 +- in: 186-long_box.in + out: 186-long_box.ans + points: 1 +- in: 187-long_box.in + out: 187-long_box.ans + points: 1 +- in: 188-long_box.in + out: 188-long_box.ans + points: 1 +- in: 189-long_box.in + out: 189-long_box.ans + points: 1 +- in: 190-gen_ragnar_markus.in + out: 190-gen_ragnar_markus.ans + points: 1 +- in: 191-gen_ragnar_markus.in + out: 191-gen_ragnar_markus.ans + points: 1 +- in: 192-gen_ragnar_markus.in + out: 192-gen_ragnar_markus.ans + points: 1 +- in: 193-gen_ragnar_markus.in + out: 193-gen_ragnar_markus.ans + points: 1 +- in: 194-gen_ragnar_markus.in + out: 194-gen_ragnar_markus.ans + points: 1 +- in: 195-gen_ragnar_markus.in + out: 195-gen_ragnar_markus.ans + points: 1 +- in: 196-gen_ragnar_markus.in + out: 196-gen_ragnar_markus.ans + points: 1 +- in: 197-gen_ragnar_markus.in + out: 197-gen_ragnar_markus.ans + points: 1 +- in: 198-gen_ragnar_markus.in + out: 198-gen_ragnar_markus.ans + points: 1 +- in: 199-gen_ragnar_markus.in + out: 199-gen_ragnar_markus.ans + points: 1 +- in: 200-gen_ragnar_markus.in + out: 200-gen_ragnar_markus.ans + points: 1 +- in: 201-gen_ragnar_markus.in + out: 201-gen_ragnar_markus.ans + points: 1 +- in: 202-gen_ragnar_markus.in + out: 202-gen_ragnar_markus.ans + points: 1 +- in: 203-gen_ragnar_markus.in + out: 203-gen_ragnar_markus.ans + points: 1 +- in: 204-gen_ragnar_markus.in + out: 204-gen_ragnar_markus.ans + points: 1 +- in: 205-gen_ragnar_markus.in + out: 205-gen_ragnar_markus.ans + points: 1 +- in: 206-gen_ragnar_markus.in + out: 206-gen_ragnar_markus.ans + points: 1 +- in: 207-gen_ragnar_markus.in + out: 207-gen_ragnar_markus.ans + points: 1 +- in: 208-gen_ragnar_markus.in + out: 208-gen_ragnar_markus.ans + points: 1 +- in: 209-gen_jorke3_fuzzed.in + out: 209-gen_jorke3_fuzzed.ans + points: 1 +- in: 210-gen_jorke3_fuzzed.in + out: 210-gen_jorke3_fuzzed.ans + points: 1 +- in: 211-gen_jorke3_fuzzed.in + out: 211-gen_jorke3_fuzzed.ans + points: 1 +- in: 212-gen_jorke3_fuzzed.in + out: 212-gen_jorke3_fuzzed.ans + points: 1 +- in: 213-gen_jorke3_fuzzed.in + out: 213-gen_jorke3_fuzzed.ans + points: 1 +- in: 214-gen_jorke3_fuzzed.in + out: 214-gen_jorke3_fuzzed.ans + points: 1 +- in: 215-gen_jorke3_fuzzed.in + out: 215-gen_jorke3_fuzzed.ans + points: 1 +- in: 216-gen_jorke3_fuzzed.in + out: 216-gen_jorke3_fuzzed.ans + points: 1 +- in: 217-gen_jorke3_fuzzed.in + out: 217-gen_jorke3_fuzzed.ans + points: 1 +- in: 218-gen8.in + out: 218-gen8.ans + points: 1 +- in: 219-gen8.in + out: 219-gen8.ans + points: 1 +- in: 220-gen8.in + out: 220-gen8.ans + points: 1 +- in: 221-gen8.in + out: 221-gen8.ans + points: 1 diff --git a/ICPC/nwerc2022_G/data.zip b/ICPC/nwerc2022_G/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..2848e41f087c6eefd2298000138bcd01d94fbbde --- /dev/null +++ b/ICPC/nwerc2022_G/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f2f5f0bbf09389c282827ce78c294db9ceaa8b89348714372d3cb13a0610d74 +size 101977 diff --git a/ICPC/nwerc2022_G/init.yml b/ICPC/nwerc2022_G/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f8e67b866efca686edef9cb54ab753bfa42dc178 --- /dev/null +++ b/ICPC/nwerc2022_G/init.yml @@ -0,0 +1,624 @@ +archive: data.zip +interactive: + files: + - output_validators/validate/validate.cpp + - output_validators/validate/validate.h + lang: CPP17 + type: default +test_cases: +- in: 001-period.in + out: 001-period.ans + points: 1 +- in: 002-period.in + out: 002-period.ans + points: 1 +- in: 003-period.in + out: 003-period.ans + points: 1 +- in: 004-period.in + out: 004-period.ans + points: 1 +- in: 005-period.in + out: 005-period.ans + points: 1 +- in: 006-period.in + out: 006-period.ans + points: 1 +- in: 007-period.in + out: 007-period.ans + points: 1 +- in: 008-period.in + out: 008-period.ans + points: 1 +- in: 009-period.in + out: 009-period.ans + points: 1 +- in: 010-period.in + out: 010-period.ans + points: 1 +- in: 011-period.in + out: 011-period.ans + points: 1 +- in: 012-period.in + out: 012-period.ans + points: 1 +- in: 013-debruijn.in + out: 013-debruijn.ans + points: 1 +- in: 014-debruijn.in + out: 014-debruijn.ans + points: 1 +- in: 015-debruijn.in + out: 015-debruijn.ans + points: 1 +- in: 016-debruijn.in + out: 016-debruijn.ans + points: 1 +- in: 017-debruijn.in + out: 017-debruijn.ans + points: 1 +- in: 018-debruijn.in + out: 018-debruijn.ans + points: 1 +- in: 019-debruijn.in + out: 019-debruijn.ans + points: 1 +- in: 020-debruijn.in + out: 020-debruijn.ans + points: 1 +- in: 021-debruijn.in + out: 021-debruijn.ans + points: 1 +- in: 022-debruijn.in + out: 022-debruijn.ans + points: 1 +- in: 023-debruijn.in + out: 023-debruijn.ans + points: 1 +- in: 024-debruijn.in + out: 024-debruijn.ans + points: 1 +- in: 025-constants.in + out: 025-constants.ans + points: 1 +- in: 026-constants.in + out: 026-constants.ans + points: 1 +- in: 027-constants.in + out: 027-constants.ans + points: 1 +- in: 028-constants.in + out: 028-constants.ans + points: 1 +- in: 029-ones.in + out: 029-ones.ans + points: 1 +- in: 030-ones.in + out: 030-ones.ans + points: 1 +- in: 031-ones.in + out: 031-ones.ans + points: 1 +- in: 032-ones.in + out: 032-ones.ans + points: 1 +- in: 033-ones.in + out: 033-ones.ans + points: 1 +- in: 034-ones.in + out: 034-ones.ans + points: 1 +- in: 035-ones.in + out: 035-ones.ans + points: 1 +- in: 036-ones.in + out: 036-ones.ans + points: 1 +- in: 037-ones.in + out: 037-ones.ans + points: 1 +- in: 038-ones.in + out: 038-ones.ans + points: 1 +- in: 039-ones.in + out: 039-ones.ans + points: 1 +- in: 040-ones.in + out: 040-ones.ans + points: 1 +- in: 041-ones.in + out: 041-ones.ans + points: 1 +- in: 042-ones.in + out: 042-ones.ans + points: 1 +- in: 043-ones.in + out: 043-ones.ans + points: 1 +- in: 044-zeroes.in + out: 044-zeroes.ans + points: 1 +- in: 045-zeroes.in + out: 045-zeroes.ans + points: 1 +- in: 046-zeroes.in + out: 046-zeroes.ans + points: 1 +- in: 047-zeroes.in + out: 047-zeroes.ans + points: 1 +- in: 048-zeroes.in + out: 048-zeroes.ans + points: 1 +- in: 049-zeroes.in + out: 049-zeroes.ans + points: 1 +- in: 050-zeroes.in + out: 050-zeroes.ans + points: 1 +- in: 051-zeroes.in + out: 051-zeroes.ans + points: 1 +- in: 052-zeroes.in + out: 052-zeroes.ans + points: 1 +- in: 053-zeroes.in + out: 053-zeroes.ans + points: 1 +- in: 054-zeroes.in + out: 054-zeroes.ans + points: 1 +- in: 055-zeroes.in + out: 055-zeroes.ans + points: 1 +- in: 056-zeroes.in + out: 056-zeroes.ans + points: 1 +- in: 057-zeroes.in + out: 057-zeroes.ans + points: 1 +- in: 058-zeroes.in + out: 058-zeroes.ans + points: 1 +- in: 059-uniform_random.in + out: 059-uniform_random.ans + points: 1 +- in: 060-uniform_random.in + out: 060-uniform_random.ans + points: 1 +- in: 061-uniform_random.in + out: 061-uniform_random.ans + points: 1 +- in: 062-uniform_random.in + out: 062-uniform_random.ans + points: 1 +- in: 063-uniform_random.in + out: 063-uniform_random.ans + points: 1 +- in: 064-uniform_random.in + out: 064-uniform_random.ans + points: 1 +- in: 065-uniform_random.in + out: 065-uniform_random.ans + points: 1 +- in: 066-uniform_random.in + out: 066-uniform_random.ans + points: 1 +- in: 067-uniform_random.in + out: 067-uniform_random.ans + points: 1 +- in: 068-uniform_random.in + out: 068-uniform_random.ans + points: 1 +- in: 069-uniform_random.in + out: 069-uniform_random.ans + points: 1 +- in: 070-uniform_random.in + out: 070-uniform_random.ans + points: 1 +- in: 071-uniform_random.in + out: 071-uniform_random.ans + points: 1 +- in: 072-uniform_random.in + out: 072-uniform_random.ans + points: 1 +- in: 073-uniform_random.in + out: 073-uniform_random.ans + points: 1 +- in: 074-uniform_random.in + out: 074-uniform_random.ans + points: 1 +- in: 075-uniform_random.in + out: 075-uniform_random.ans + points: 1 +- in: 076-uniform_random.in + out: 076-uniform_random.ans + points: 1 +- in: 077-uniform_random.in + out: 077-uniform_random.ans + points: 1 +- in: 078-uniform_random.in + out: 078-uniform_random.ans + points: 1 +- in: 079-uniform_random.in + out: 079-uniform_random.ans + points: 1 +- in: 080-uniform_random.in + out: 080-uniform_random.ans + points: 1 +- in: 081-uniform_random.in + out: 081-uniform_random.ans + points: 1 +- in: 082-uniform_random.in + out: 082-uniform_random.ans + points: 1 +- in: 083-uniform_random.in + out: 083-uniform_random.ans + points: 1 +- in: 084-uniform_random.in + out: 084-uniform_random.ans + points: 1 +- in: 085-uniform_random.in + out: 085-uniform_random.ans + points: 1 +- in: 086-uniform_random.in + out: 086-uniform_random.ans + points: 1 +- in: 087-uniform_random.in + out: 087-uniform_random.ans + points: 1 +- in: 088-biased_one.in + out: 088-biased_one.ans + points: 1 +- in: 089-biased_one.in + out: 089-biased_one.ans + points: 1 +- in: 090-biased_one.in + out: 090-biased_one.ans + points: 1 +- in: 091-biased_one.in + out: 091-biased_one.ans + points: 1 +- in: 092-biased_one.in + out: 092-biased_one.ans + points: 1 +- in: 093-biased_one.in + out: 093-biased_one.ans + points: 1 +- in: 094-biased_one.in + out: 094-biased_one.ans + points: 1 +- in: 095-biased_one.in + out: 095-biased_one.ans + points: 1 +- in: 096-biased_one.in + out: 096-biased_one.ans + points: 1 +- in: 097-biased_one.in + out: 097-biased_one.ans + points: 1 +- in: 098-biased_one.in + out: 098-biased_one.ans + points: 1 +- in: 099-biased_one.in + out: 099-biased_one.ans + points: 1 +- in: 100-biased_one.in + out: 100-biased_one.ans + points: 1 +- in: 101-biased_one.in + out: 101-biased_one.ans + points: 1 +- in: 102-biased_one.in + out: 102-biased_one.ans + points: 1 +- in: 103-biased_one.in + out: 103-biased_one.ans + points: 1 +- in: 104-biased_one.in + out: 104-biased_one.ans + points: 1 +- in: 105-biased_one.in + out: 105-biased_one.ans + points: 1 +- in: 106-biased_one.in + out: 106-biased_one.ans + points: 1 +- in: 107-biased_one.in + out: 107-biased_one.ans + points: 1 +- in: 108-biased_one.in + out: 108-biased_one.ans + points: 1 +- in: 109-biased_one.in + out: 109-biased_one.ans + points: 1 +- in: 110-biased_one.in + out: 110-biased_one.ans + points: 1 +- in: 111-biased_one.in + out: 111-biased_one.ans + points: 1 +- in: 112-biased_one.in + out: 112-biased_one.ans + points: 1 +- in: 113-biased_one.in + out: 113-biased_one.ans + points: 1 +- in: 114-biased_one.in + out: 114-biased_one.ans + points: 1 +- in: 115-biased_one.in + out: 115-biased_one.ans + points: 1 +- in: 116-biased_one.in + out: 116-biased_one.ans + points: 1 +- in: 117-biased_one.in + out: 117-biased_one.ans + points: 1 +- in: 118-biased_one.in + out: 118-biased_one.ans + points: 1 +- in: 119-biased_one.in + out: 119-biased_one.ans + points: 1 +- in: 120-biased_one.in + out: 120-biased_one.ans + points: 1 +- in: 121-biased_one.in + out: 121-biased_one.ans + points: 1 +- in: 122-biased_one.in + out: 122-biased_one.ans + points: 1 +- in: 123-biased_one.in + out: 123-biased_one.ans + points: 1 +- in: 124-biased_one.in + out: 124-biased_one.ans + points: 1 +- in: 125-biased_one.in + out: 125-biased_one.ans + points: 1 +- in: 126-biased_one.in + out: 126-biased_one.ans + points: 1 +- in: 127-biased_one.in + out: 127-biased_one.ans + points: 1 +- in: 128-biased_one.in + out: 128-biased_one.ans + points: 1 +- in: 129-biased_one.in + out: 129-biased_one.ans + points: 1 +- in: 130-biased_one.in + out: 130-biased_one.ans + points: 1 +- in: 131-biased_one.in + out: 131-biased_one.ans + points: 1 +- in: 132-biased_one.in + out: 132-biased_one.ans + points: 1 +- in: 133-biased_one.in + out: 133-biased_one.ans + points: 1 +- in: 134-biased_one.in + out: 134-biased_one.ans + points: 1 +- in: 135-biased_one.in + out: 135-biased_one.ans + points: 1 +- in: 136-biased_one.in + out: 136-biased_one.ans + points: 1 +- in: 137-biased_one.in + out: 137-biased_one.ans + points: 1 +- in: 138-biased_one.in + out: 138-biased_one.ans + points: 1 +- in: 139-biased_one.in + out: 139-biased_one.ans + points: 1 +- in: 140-biased_one.in + out: 140-biased_one.ans + points: 1 +- in: 141-biased_one.in + out: 141-biased_one.ans + points: 1 +- in: 142-biased_one.in + out: 142-biased_one.ans + points: 1 +- in: 143-biased_one.in + out: 143-biased_one.ans + points: 1 +- in: 144-biased_one.in + out: 144-biased_one.ans + points: 1 +- in: 145-biased_one.in + out: 145-biased_one.ans + points: 1 +- in: 146-biased_zero.in + out: 146-biased_zero.ans + points: 1 +- in: 147-biased_zero.in + out: 147-biased_zero.ans + points: 1 +- in: 148-biased_zero.in + out: 148-biased_zero.ans + points: 1 +- in: 149-biased_zero.in + out: 149-biased_zero.ans + points: 1 +- in: 150-biased_zero.in + out: 150-biased_zero.ans + points: 1 +- in: 151-biased_zero.in + out: 151-biased_zero.ans + points: 1 +- in: 152-biased_zero.in + out: 152-biased_zero.ans + points: 1 +- in: 153-biased_zero.in + out: 153-biased_zero.ans + points: 1 +- in: 154-biased_zero.in + out: 154-biased_zero.ans + points: 1 +- in: 155-biased_zero.in + out: 155-biased_zero.ans + points: 1 +- in: 156-biased_zero.in + out: 156-biased_zero.ans + points: 1 +- in: 157-biased_zero.in + out: 157-biased_zero.ans + points: 1 +- in: 158-biased_zero.in + out: 158-biased_zero.ans + points: 1 +- in: 159-biased_zero.in + out: 159-biased_zero.ans + points: 1 +- in: 160-biased_zero.in + out: 160-biased_zero.ans + points: 1 +- in: 161-biased_zero.in + out: 161-biased_zero.ans + points: 1 +- in: 162-biased_zero.in + out: 162-biased_zero.ans + points: 1 +- in: 163-biased_zero.in + out: 163-biased_zero.ans + points: 1 +- in: 164-biased_zero.in + out: 164-biased_zero.ans + points: 1 +- in: 165-biased_zero.in + out: 165-biased_zero.ans + points: 1 +- in: 166-biased_zero.in + out: 166-biased_zero.ans + points: 1 +- in: 167-biased_zero.in + out: 167-biased_zero.ans + points: 1 +- in: 168-biased_zero.in + out: 168-biased_zero.ans + points: 1 +- in: 169-biased_zero.in + out: 169-biased_zero.ans + points: 1 +- in: 170-biased_zero.in + out: 170-biased_zero.ans + points: 1 +- in: 171-biased_zero.in + out: 171-biased_zero.ans + points: 1 +- in: 172-biased_zero.in + out: 172-biased_zero.ans + points: 1 +- in: 173-biased_zero.in + out: 173-biased_zero.ans + points: 1 +- in: 174-biased_zero.in + out: 174-biased_zero.ans + points: 1 +- in: 175-biased_zero.in + out: 175-biased_zero.ans + points: 1 +- in: 176-biased_zero.in + out: 176-biased_zero.ans + points: 1 +- in: 177-biased_zero.in + out: 177-biased_zero.ans + points: 1 +- in: 178-biased_zero.in + out: 178-biased_zero.ans + points: 1 +- in: 179-biased_zero.in + out: 179-biased_zero.ans + points: 1 +- in: 180-biased_zero.in + out: 180-biased_zero.ans + points: 1 +- in: 181-biased_zero.in + out: 181-biased_zero.ans + points: 1 +- in: 182-biased_zero.in + out: 182-biased_zero.ans + points: 1 +- in: 183-biased_zero.in + out: 183-biased_zero.ans + points: 1 +- in: 184-biased_zero.in + out: 184-biased_zero.ans + points: 1 +- in: 185-biased_zero.in + out: 185-biased_zero.ans + points: 1 +- in: 186-biased_zero.in + out: 186-biased_zero.ans + points: 1 +- in: 187-biased_zero.in + out: 187-biased_zero.ans + points: 1 +- in: 188-biased_zero.in + out: 188-biased_zero.ans + points: 1 +- in: 189-biased_zero.in + out: 189-biased_zero.ans + points: 1 +- in: 190-biased_zero.in + out: 190-biased_zero.ans + points: 1 +- in: 191-biased_zero.in + out: 191-biased_zero.ans + points: 1 +- in: 192-biased_zero.in + out: 192-biased_zero.ans + points: 1 +- in: 193-biased_zero.in + out: 193-biased_zero.ans + points: 1 +- in: 194-biased_zero.in + out: 194-biased_zero.ans + points: 1 +- in: 195-biased_zero.in + out: 195-biased_zero.ans + points: 1 +- in: 196-biased_zero.in + out: 196-biased_zero.ans + points: 1 +- in: 197-biased_zero.in + out: 197-biased_zero.ans + points: 1 +- in: 198-biased_zero.in + out: 198-biased_zero.ans + points: 1 +- in: 199-biased_zero.in + out: 199-biased_zero.ans + points: 1 +- in: 200-biased_zero.in + out: 200-biased_zero.ans + points: 1 +- in: 201-biased_zero.in + out: 201-biased_zero.ans + points: 1 +- in: 202-biased_zero.in + out: 202-biased_zero.ans + points: 1 +- in: 203-biased_zero.in + out: 203-biased_zero.ans + points: 1 +- in: 204-biased_zero.in + out: 204-biased_zero.ans + points: 1 +- in: 205-biased_zero.in + out: 205-biased_zero.ans + points: 1 +unbuffered: false diff --git a/ICPC/nwerc2022_G/output_validators/validate/validate.cpp b/ICPC/nwerc2022_G/output_validators/validate/validate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa726753816382cb1fbc984abddba8f41561be07 --- /dev/null +++ b/ICPC/nwerc2022_G/output_validators/validate/validate.cpp @@ -0,0 +1,120 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include +#include +#include + +#include "validate.h" +using namespace std; + +void to_lower(std::string& s) { + for (char& c : s) c |= 0x20; +} + +int main(int argc, char **argv) { + init_io(argc,argv); + + int n; + judge_in >> n; + + int position = 0; + vector state(n); + for (int i = 0; i < n; i++) { + char c; + judge_in >> c; + state[i] = c - '0'; + } + + cout << state[position] << endl; + + int max_queries = 3*n + 500; + int lim_queries = 5*n + 1000; + int queries_used = 0; + while (true) { + string response; + if (!(author_out >> response)) { + wrong_answer("Wrong answer: failed to read response. Queries used: %d\n", queries_used); + } + + if (response == "?") { + queries_used++; + + string query; + if (!(author_out >> query)) { + wrong_answer("Wrong answer: failed to read query. Queries used: %d\n", queries_used); + } + to_lower(query); + + if (query == "left") { + position = (position + n - 1) % n; + } else if (query == "right") { + position = (position + 1) % n; + } else if (query == "flip") { + state[position] = 1 - state[position]; + } else { + wrong_answer("Wrong answer: invalid query type. Queries used: %d\n", queries_used); + } + + cout << state[position] << endl; + } else if (response == "!") { + int guess; + if (!(author_out >> guess)) { + wrong_answer("Wrong answer: failed to read guess. Queries used: %d\n", queries_used); + } + + string junk; + if (author_out >> junk) { + wrong_answer("Wrong answer: trailing output after guess.\n"); + } + + if (guess == n) { + if (queries_used > max_queries) { + wrong_answer("Wrong answer: correct guess, but used too many queries. Queries used: %d (%d too many)\n", queries_used, queries_used-max_queries); + } + break; + } else { + wrong_answer("Wrong answer: incorrect guess %d (ans: %d). Queries used: %d\n", guess, n, queries_used); + } + } else { + wrong_answer("Wrong answer: invalid response type. Queries used: %d\n", queries_used); + } + if (queries_used > lim_queries) { + wrong_answer("Wrong answer: used too many queries. Queries used: %d (%d too many, terminated)\n", queries_used, queries_used-max_queries); + } + } + + string junk; + if (author_out >> junk) { + wrong_answer("Wrong answer: trailing output.\n"); + } + + judge_message("Queries used: %d.\n", queries_used); + + accept(); +} + + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[2], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2022_G/output_validators/validate/validate.h b/ICPC/nwerc2022_G/output_validators/validate/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..9e451541645b53135db0d7a24a1ca2abeb779a7a --- /dev/null +++ b/ICPC/nwerc2022_G/output_validators/validate/validate.h @@ -0,0 +1,154 @@ +/* Utility functions for writing output validators for the Kattis + * problem format. + * + * The primary functions and variables available are the following. + * In many cases, the only functions needed are "init_io", + * "wrong_answer", and "accept". + * + * - init_io(argc, argv): + * initialization + * + * - judge_in, judge_ans, author_out: + * std::istream objects for judge input file, judge answer + * file, and submission output file. + * + * - accept(): + * exit and give Accepted! + * + * - accept_with_score(double score): + * exit with Accepted and give a score (for scoring problems) + * + * - judge_message(std::string msg, ...): + * printf-style function for emitting a judge message (a + * message that gets displayed to a privileged user with access + * to secret data etc). + * + * - wrong_answer(std::string msg, ...): + * printf-style function for exitting and giving Wrong Answer, + * and emitting a judge message (which would typically explain + * the cause of the Wrong Answer) + * + * - judge_error(std::string msg, ...): + * printf-style function for exitting and giving Judge Error, + * and emitting a judge message (which would typically explain + * the cause of the Judge Error) + * + * - author_message(std::string msg, ...): + * printf-style function for emitting an author message (a + * message that gets displayed to the author of the + * submission). (Use with caution, and be careful not to let + * it leak information!) + * + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +typedef void (*feedback_function)(const std::string &, ...); + +const int EXITCODE_AC = 42; +const int EXITCODE_WA = 43; +const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt"; +const std::string FILENAME_JUDGE_MESSAGE = "null"; +const std::string FILENAME_JUDGE_ERROR = "judgeerror.txt"; +const std::string FILENAME_SCORE = "score.txt"; + +#define USAGE "%s: judge_in judge_ans feedback_dir < author_out\n" + +std::ifstream judge_in, judge_ans; +std::istream author_out(std::cin.rdbuf()); + +char *feedbackdir = NULL; + +void vreport_feedback(const std::string &category, + const std::string &msg, + va_list pvar) { + std::ostringstream fname; + if (feedbackdir) + fname << feedbackdir << '/'; + fname << category; + FILE *f = fopen(fname.str().c_str(), "a"); + assert(f); + vfprintf(f, msg.c_str(), pvar); + fclose(f); +} + +void report_feedback(const std::string &category, const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(category, msg, pvar); +} + +void author_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_AUTHOR_MESSAGE, msg, pvar); +} + +void judge_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); +} + +void wrong_answer(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); + exit(EXITCODE_WA); +} + +void judge_error(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_ERROR, msg, pvar); + assert(0); +} + +void accept() { + exit(EXITCODE_AC); +} + +void accept_with_score(double scorevalue) { + report_feedback(FILENAME_SCORE, "%.9le", scorevalue); + exit(EXITCODE_AC); +} + + +bool is_directory(const char *path) { +if(std::string(path) == std::string("/dev")) return 1; + struct stat entry; + return stat(path, &entry) == 0 && S_ISDIR(entry.st_mode); +} + +void init_io(int argc, char **argv) { + if(argc < 4) { + fprintf(stderr, USAGE, argv[0]); + judge_error("Usage: %s judgein judgeans feedbackdir [opts] < userout", argv[0]); + } + + // Set up feedbackdir first, as that allows us to produce feedback + // files for errors in the other parameters. + if (!is_directory(argv[3])) { + judge_error("%s: %s is not a directory\n", argv[0], argv[3]); + } + feedbackdir = argv[3]; + + judge_in.open(argv[1], std::ios_base::in); + if (judge_in.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[1]); + } + + judge_ans.open(argv[2], std::ios_base::in); + if (judge_ans.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[2]); + } + + author_out.rdbuf(std::cin.rdbuf()); +} \ No newline at end of file diff --git a/ICPC/nwerc2022_H/data.zip b/ICPC/nwerc2022_H/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..5b85d8a58dcc10b7d127b47bf2d0131ceff7f754 --- /dev/null +++ b/ICPC/nwerc2022_H/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67e095af096b197afd21937619a0a8bff678c8b5c9bf747d261b0de61c8d6229 +size 32405712 diff --git a/ICPC/nwerc2022_H/init.yml b/ICPC/nwerc2022_H/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..729cb3cedec91052ad46c28d336a425c1784a64c --- /dev/null +++ b/ICPC/nwerc2022_H/init.yml @@ -0,0 +1,251 @@ +archive: data.zip +test_cases: +- in: 01-path-tree.in + out: 01-path-tree.ans + points: 1 +- in: 02-path-tree.in + out: 02-path-tree.ans + points: 1 +- in: 03-path-tree.in + out: 03-path-tree.ans + points: 1 +- in: 04-complete.in + out: 04-complete.ans + points: 1 +- in: 05-complete.in + out: 05-complete.ans + points: 1 +- in: 06-fibonacci_path_on_leaf.in + out: 06-fibonacci_path_on_leaf.ans + points: 1 +- in: 07-fibonacci_path_on_leaf.in + out: 07-fibonacci_path_on_leaf.ans + points: 1 +- in: 08-fibonacci_random.in + out: 08-fibonacci_random.ans + points: 1 +- in: 09-fibonacci_random.in + out: 09-fibonacci_random.ans + points: 1 +- in: 10-copath.in + out: 10-copath.ans + points: 1 +- in: 11-copath.in + out: 11-copath.ans + points: 1 +- in: 12-copath.in + out: 12-copath.ans + points: 1 +- in: 13-binary.in + out: 13-binary.ans + points: 1 +- in: 14-binary.in + out: 14-binary.ans + points: 1 +- in: 15-random2.in + out: 15-random2.ans + points: 1 +- in: 16-random2.in + out: 16-random2.ans + points: 1 +- in: 17-random2.in + out: 17-random2.ans + points: 1 +- in: 18-random2.in + out: 18-random2.ans + points: 1 +- in: 19-random2.in + out: 19-random2.ans + points: 1 +- in: 20-fibonacci_path_on_leaf.in + out: 20-fibonacci_path_on_leaf.ans + points: 1 +- in: 21-fibonacci_path_on_leaf.in + out: 21-fibonacci_path_on_leaf.ans + points: 1 +- in: 22-fibonacci_path_on_leaf.in + out: 22-fibonacci_path_on_leaf.ans + points: 1 +- in: 23-fibonacci_path_on_leaf.in + out: 23-fibonacci_path_on_leaf.ans + points: 1 +- in: 24-fibonacci_path_on_leaf.in + out: 24-fibonacci_path_on_leaf.ans + points: 1 +- in: 25-fibonacci_path_on_leaf.in + out: 25-fibonacci_path_on_leaf.ans + points: 1 +- in: 26-fibonacci_path_on_leaf.in + out: 26-fibonacci_path_on_leaf.ans + points: 1 +- in: 27-fibonacci_path_on_leaf.in + out: 27-fibonacci_path_on_leaf.ans + points: 1 +- in: 28-fibonacci_path_on_leaf.in + out: 28-fibonacci_path_on_leaf.ans + points: 1 +- in: 29-fibonacci_path_on_leaf.in + out: 29-fibonacci_path_on_leaf.ans + points: 1 +- in: 30-fibonacci_path_on_leaf.in + out: 30-fibonacci_path_on_leaf.ans + points: 1 +- in: 31-fibonacci_path_on_leaf.in + out: 31-fibonacci_path_on_leaf.ans + points: 1 +- in: 32-fibonacci_random.in + out: 32-fibonacci_random.ans + points: 1 +- in: 33-fibonacci_random.in + out: 33-fibonacci_random.ans + points: 1 +- in: 34-fibonacci_random.in + out: 34-fibonacci_random.ans + points: 1 +- in: 35-fibonacci_random.in + out: 35-fibonacci_random.ans + points: 1 +- in: 36-fibonacci_random.in + out: 36-fibonacci_random.ans + points: 1 +- in: 37-fibonacci_random.in + out: 37-fibonacci_random.ans + points: 1 +- in: 38-fibonacci_random.in + out: 38-fibonacci_random.ans + points: 1 +- in: 39-fibonacci_random.in + out: 39-fibonacci_random.ans + points: 1 +- in: 40-fibonacci_random.in + out: 40-fibonacci_random.ans + points: 1 +- in: 41-fibonacci_random.in + out: 41-fibonacci_random.ans + points: 1 +- in: 42-fibonacci_random.in + out: 42-fibonacci_random.ans + points: 1 +- in: 43-fibonacci.in + out: 43-fibonacci.ans + points: 1 +- in: 44-path.in + out: 44-path.ans + points: 1 +- in: 45-path.in + out: 45-path.ans + points: 1 +- in: 46-copath-small.in + out: 46-copath-small.ans + points: 1 +- in: 47-copath-small.in + out: 47-copath-small.ans + points: 1 +- in: 48-random.in + out: 48-random.ans + points: 1 +- in: 49-random.in + out: 49-random.ans + points: 1 +- in: 50-random.in + out: 50-random.ans + points: 1 +- in: 51-random.in + out: 51-random.ans + points: 1 +- in: 52-random.in + out: 52-random.ans + points: 1 +- in: 53-random.in + out: 53-random.ans + points: 1 +- in: 54-random.in + out: 54-random.ans + points: 1 +- in: 55-random.in + out: 55-random.ans + points: 1 +- in: 56-random.in + out: 56-random.ans + points: 1 +- in: 57-random.in + out: 57-random.ans + points: 1 +- in: 58-random.in + out: 58-random.ans + points: 1 +- in: 59-random.in + out: 59-random.ans + points: 1 +- in: 60-random.in + out: 60-random.ans + points: 1 +- in: 61-random.in + out: 61-random.ans + points: 1 +- in: 62-random.in + out: 62-random.ans + points: 1 +- in: 63-random.in + out: 63-random.ans + points: 1 +- in: 64-random.in + out: 64-random.ans + points: 1 +- in: 65-random.in + out: 65-random.ans + points: 1 +- in: 66-random.in + out: 66-random.ans + points: 1 +- in: 67-random.in + out: 67-random.ans + points: 1 +- in: 68-random.in + out: 68-random.ans + points: 1 +- in: 69-random2-small.in + out: 69-random2-small.ans + points: 1 +- in: 70-random2-small.in + out: 70-random2-small.ans + points: 1 +- in: 71-random2-small.in + out: 71-random2-small.ans + points: 1 +- in: 72-random2-small.in + out: 72-random2-small.ans + points: 1 +- in: 73-random2-small.in + out: 73-random2-small.ans + points: 1 +- in: 74-random2-small.in + out: 74-random2-small.ans + points: 1 +- in: 75-random2-small.in + out: 75-random2-small.ans + points: 1 +- in: 76-random2-small.in + out: 76-random2-small.ans + points: 1 +- in: 77-binary.in + out: 77-binary.ans + points: 1 +- in: 78-binary.in + out: 78-binary.ans + points: 1 +- in: 79-binary.in + out: 79-binary.ans + points: 1 +- in: 80-binary.in + out: 80-binary.ans + points: 1 +- in: 81-binary.in + out: 81-binary.ans + points: 1 +- in: 82-binary.in + out: 82-binary.ans + points: 1 +- in: 83-binary.in + out: 83-binary.ans + points: 1 diff --git a/ICPC/nwerc2022_I/data.zip b/ICPC/nwerc2022_I/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..5d8c625d6b0a28ec6e04567e1af4bdf98616a7c7 --- /dev/null +++ b/ICPC/nwerc2022_I/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72281fe73c0859d81835dd0bdc762a728a8b3dcf6197dd1ae3f461d2304eef18 +size 5549755 diff --git a/ICPC/nwerc2022_I/init.yml b/ICPC/nwerc2022_I/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6b97383da338c2bc4336f7056f0d563337956ff5 --- /dev/null +++ b/ICPC/nwerc2022_I/init.yml @@ -0,0 +1,223 @@ +archive: data.zip +checker: + args: + files: + - output_validators/output_validator/output_validator.cpp + - output_validators/output_validator/validation.h + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 01-length-one-num.in + out: 01-length-one-num.ans + points: 1 +- in: 02-length-one-fizz.in + out: 02-length-one-fizz.ans + points: 1 +- in: 03-length-one-buzz.in + out: 03-length-one-buzz.ans + points: 1 +- in: 04-length-one-fizzbuzz.in + out: 04-length-one-fizzbuzz.ans + points: 1 +- in: 05-random-small.in + out: 05-random-small.ans + points: 1 +- in: 06-random-small.in + out: 06-random-small.ans + points: 1 +- in: 07-random-small.in + out: 07-random-small.ans + points: 1 +- in: 08-random-small.in + out: 08-random-small.ans + points: 1 +- in: 09-random-small.in + out: 09-random-small.ans + points: 1 +- in: 10-random-small.in + out: 10-random-small.ans + points: 1 +- in: 11-random-small.in + out: 11-random-small.ans + points: 1 +- in: 12-random-small.in + out: 12-random-small.ans + points: 1 +- in: 13-random-small.in + out: 13-random-small.ans + points: 1 +- in: 14-random-small.in + out: 14-random-small.ans + points: 1 +- in: 15-random-small.in + out: 15-random-small.ans + points: 1 +- in: 16-random-small.in + out: 16-random-small.ans + points: 1 +- in: 17-random-small.in + out: 17-random-small.ans + points: 1 +- in: 18-random-small.in + out: 18-random-small.ans + points: 1 +- in: 19-random-small.in + out: 19-random-small.ans + points: 1 +- in: 20-random-small.in + out: 20-random-small.ans + points: 1 +- in: 21-random-small.in + out: 21-random-small.ans + points: 1 +- in: 22-random-small.in + out: 22-random-small.ans + points: 1 +- in: 23-random-small.in + out: 23-random-small.ans + points: 1 +- in: 24-random-small.in + out: 24-random-small.ans + points: 1 +- in: 25-random-small-fuzz.in + out: 25-random-small-fuzz.ans + points: 1 +- in: 26-random-small-fuzz.in + out: 26-random-small-fuzz.ans + points: 1 +- in: 27-random-max.in + out: 27-random-max.ans + points: 1 +- in: 28-random-max.in + out: 28-random-max.ans + points: 1 +- in: 29-random-max.in + out: 29-random-max.ans + points: 1 +- in: 30-random-max.in + out: 30-random-max.ans + points: 1 +- in: 31-random-max.in + out: 31-random-max.ans + points: 1 +- in: 32-random.in + out: 32-random.ans + points: 1 +- in: 33-random.in + out: 33-random.ans + points: 1 +- in: 34-random.in + out: 34-random.ans + points: 1 +- in: 35-random.in + out: 35-random.ans + points: 1 +- in: 36-random.in + out: 36-random.ans + points: 1 +- in: 37-random.in + out: 37-random.ans + points: 1 +- in: 38-random.in + out: 38-random.ans + points: 1 +- in: 39-random.in + out: 39-random.ans + points: 1 +- in: 40-random.in + out: 40-random.ans + points: 1 +- in: 41-random.in + out: 41-random.ans + points: 1 +- in: 42-just-max.in + out: 42-just-max.ans + points: 1 +- in: 43-max-no-fizz-no-buzz.in + out: 43-max-no-fizz-no-buzz.ans + points: 1 +- in: 44-one-fizzbuzz.in + out: 44-one-fizzbuzz.ans + points: 1 +- in: 45-two-fizzbuzz.in + out: 45-two-fizzbuzz.ans + points: 1 +- in: 46-many-fizzbuzz.in + out: 46-many-fizzbuzz.ans + points: 1 +- in: 47-no-fizz-no-buzz.in + out: 47-no-fizz-no-buzz.ans + points: 1 +- in: 48-no-fizz-one-buzz.in + out: 48-no-fizz-one-buzz.ans + points: 1 +- in: 49-no-fizz-two-buzz.in + out: 49-no-fizz-two-buzz.ans + points: 1 +- in: 50-no-fizz-many-buzz.in + out: 50-no-fizz-many-buzz.ans + points: 1 +- in: 51-no-fizz-all-buzz.in + out: 51-no-fizz-all-buzz.ans + points: 1 +- in: 52-one-fizz-no-buzz.in + out: 52-one-fizz-no-buzz.ans + points: 1 +- in: 53-one-fizz-one-buzz.in + out: 53-one-fizz-one-buzz.ans + points: 1 +- in: 54-one-fizz-two-buzz.in + out: 54-one-fizz-two-buzz.ans + points: 1 +- in: 55-one-fizz-many-buzz.in + out: 55-one-fizz-many-buzz.ans + points: 1 +- in: 56-one-fizz-all-buzz.in + out: 56-one-fizz-all-buzz.ans + points: 1 +- in: 57-two-fizz-no-buzz.in + out: 57-two-fizz-no-buzz.ans + points: 1 +- in: 58-two-fizz-one-buzz.in + out: 58-two-fizz-one-buzz.ans + points: 1 +- in: 59-two-fizz-two-buzz.in + out: 59-two-fizz-two-buzz.ans + points: 1 +- in: 60-two-fizz-many-buzz.in + out: 60-two-fizz-many-buzz.ans + points: 1 +- in: 61-two-fizz-all-buzz.in + out: 61-two-fizz-all-buzz.ans + points: 1 +- in: 62-many-fizz-no-buzz.in + out: 62-many-fizz-no-buzz.ans + points: 1 +- in: 63-many-fizz-one-buzz.in + out: 63-many-fizz-one-buzz.ans + points: 1 +- in: 64-many-fizz-two-buzz.in + out: 64-many-fizz-two-buzz.ans + points: 1 +- in: 65-many-fizz-many-buzz.in + out: 65-many-fizz-many-buzz.ans + points: 1 +- in: 66-many-fizz-all-buzz.in + out: 66-many-fizz-all-buzz.ans + points: 1 +- in: 67-all-fizz-no-buzz.in + out: 67-all-fizz-no-buzz.ans + points: 1 +- in: 68-all-fizz-one-buzz.in + out: 68-all-fizz-one-buzz.ans + points: 1 +- in: 69-all-fizz-two-buzz.in + out: 69-all-fizz-two-buzz.ans + points: 1 +- in: 70-all-fizz-many-buzz.in + out: 70-all-fizz-many-buzz.ans + points: 1 +- in: 71-all-fizz-all-buzz.in + out: 71-all-fizz-all-buzz.ans + points: 1 diff --git a/ICPC/nwerc2022_I/output_validators/output_validator/output_validator.cpp b/ICPC/nwerc2022_I/output_validators/output_validator/output_validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3422c4d89e79710fc092bd388e31e097adaf6cf2 --- /dev/null +++ b/ICPC/nwerc2022_I/output_validators/output_validator/output_validator.cpp @@ -0,0 +1,54 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validation.h" + +int main(int argc, char **argv) { + std::ifstream in(argv[1]); + OutputValidator v(argc, argv); + + int c, d; + in >> c >> d; + + std::vector items(d-c+1); + for (auto &s: items) in >> s; + + int a = v.read_integer("a", 1, 1'000'000); + v.space(); + int b = v.read_integer("b", 1, 1'000'000); + v.newline(); + + for (int i = c; i <= d; i++) { + std::string str; + if (i%a == 0) str += "Fizz"; + if (i%b == 0) str += "Buzz"; + if (str.empty()) str += std::to_string(i); + + v.check(str == items[i-c], "Mismatch at position ", i, ": expected ", items[i-c], ", got ", str); + } +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2022_I/output_validators/output_validator/validation.h b/ICPC/nwerc2022_I/output_validators/output_validator/validation.h new file mode 100644 index 0000000000000000000000000000000000000000..a12961a6605a90b83e02bec0c8f9c0e72626ebb2 --- /dev/null +++ b/ICPC/nwerc2022_I/output_validators/output_validator/validation.h @@ -0,0 +1,1520 @@ +#pragma once +// A header library to safely parse team input. +// It does not support floating points or big integers. +// Author: Ragnar Groot Koerkamp + +// The easiest way to use this is to symlink it from a validator directory, +// so that it will be picked up when creating a contest zip. + +// The default checking behaviour is lenient for both white space and case. +// When validating .in and .ans files, the case_sensitive and +// space_change_sensitive flags should be passed. When validating team output, +// the flags in problem.yaml should be used. + +// Compile with -Duse_source_location to enable +// std::experimental::source_location. This is needed for constraints checking. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef use_source_location +#include +constexpr bool has_source_location = true; +using std::experimental::source_location; +namespace std { +bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +} // namespace std +namespace std::experimental::fundamentals_v2 { +bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +} // namespace std::experimental::fundamentals_v2 +#else +constexpr bool has_source_location = false; +struct source_location { + static source_location current() { return {}; } + [[nodiscard]] int line() const { return 0; } // NOLINT + [[nodiscard]] std::string file_name() const { return ""; } // NOLINT +}; +inline bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +#endif + +inline std::string location_to_string(source_location loc) { + return std::string(loc.file_name()) + ":" + std::to_string(loc.line()); +} + +const std::string_view case_sensitive_flag = "case_sensitive"; +const std::string_view ws_sensitive_flag = "space_change_sensitive"; +const std::string_view constraints_file_flag = "--constraints_file"; +const std::string_view generate_flag = "--generate"; +const std::string_view generate_binary_substring = "generat"; + +inline struct ArbitraryTag { + static constexpr bool unique = false; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Arbitrary; +inline struct UniqueTag : ArbitraryTag { + static constexpr bool unique = true; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Unique; +inline struct IncreasingTag : ArbitraryTag { static constexpr bool increasing = true; } Increasing; +inline struct DecreasingTag : ArbitraryTag { static constexpr bool decreasing = true; } Decreasing; +inline struct StrictlyIncreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool increasing = true; +} StrictlyIncreasing; +inline struct StrictlyDecreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool decreasing = true; +} StrictlyDecreasing; + +template +struct Merge : T... { + static constexpr bool unique = (T::unique || ...); + static constexpr bool strict = (T::strict || ...); + static constexpr bool increasing = (T::increasing || ...); + static constexpr bool decreasing = (T::decreasing || ...); +}; + +template and std::is_base_of_v, int> = 0> +auto operator|(T1 /*unused*/, T2 /*unused*/) { + return Merge(); +} + +enum Separator { Space, Newline }; + +// this contains some specific code which emulates c++20 features +namespace cpp20 { + +constexpr int countl_zero(unsigned long long x) { + int res = 64; + for(int i = 32; i > 0; i >>= 1) { + if((x >> i) > 0) { + res -= i; + x >>= i; + } + } + if(x > 0) res--; + return res; +} + +int popcount(unsigned long long x) { + return static_cast(std::bitset<64>(x).count()); +} + +constexpr long double PI = 3.141592653589793238462643383279502884l; + +} // namespace cpp20 + +namespace Random { + +constexpr unsigned int default_seed = 3141592653; // some digits of PI + +unsigned long long bits64(std::mt19937_64& rng) { + static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull); + static_assert(std::mt19937_64::min() == 0ull); + return rng(); +} + +// generates a uniform real in [0, 1) +long double real64(std::mt19937_64& rng) { + // a long double can represent more than 2^64 values in the range [0, 1)... + // another problem is that real64() < 1.0/3.0 is technically biased. + long double res = bits64(rng) / 0x1.0p64l; + res += bits64(rng) / 0x1.0p128l; + assert(res < 1.0l); + return res; +} + +bool bit(std::mt19937_64& rng) { + return cpp20::popcount(bits64(rng)) & 1; +} + +} // namespace Random + +template +constexpr bool is_number_v = std::is_same_v or std::is_same_v; + +namespace Generators { + +template +struct ConstGenerator { + static_assert(is_number_v or std::is_same_v or std::is_same_v); + static constexpr std::string_view name = "const"; + using Args = std::tuple; + + const T const_; + + explicit ConstGenerator(T val) : const_(std::move(val)) {} + + // For char and string, the constant store has a different type than the min and max length + // passed in. + template + T operator()(U low, U high, std::mt19937_64& rng) const { + return std::clamp(const_, low, high); + } +}; + +struct MinGenerator { + static constexpr std::string_view name = "min"; + using Args = std::tuple<>; + + explicit MinGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return low; + } +}; + +struct MaxGenerator { + static constexpr std::string_view name = "max"; + using Args = std::tuple<>; + + explicit MaxGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return high; + } +}; + +struct UniformGenerator { + static constexpr std::string_view name = "uniform"; + using Args = std::tuple<>; + + explicit UniformGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + if(low == high) return low; + + if constexpr(std::is_same_v) { + assert(low < high); + // Since C++20 we can assume Two's Complement but any sane system used it before anyway. + // Rejection sampling is not as fast as possible but definitely unbiased. + auto ul = static_cast(low); + auto uh = static_cast(high); + int shifts = cpp20::countl_zero(uh - ul); + unsigned long long res; + do { + res = Random::bits64(rng) >> shifts; + } while(res > uh - ul); + return static_cast(res + ul); + } else { + assert(low < high); + return low + Random::real64(rng) * (high - low); + } + } +}; + +template +struct RangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "range"; + using Args = std::tuple; + + const T low_, high_; + + explicit RangeGenerator(T low, T high) : low_(low), high_(high) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng); + } +}; + +template +struct StepRangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "steprange"; + using Args = std::tuple; + + const T low_, high_, step_; + + explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + // round up low to the first multiple of step_. + T start; + if(low <= low_) { + start = low_; + } else { + // first multiple of low_+k*step_ >= low + start = low_ + (long long)((low - low_) / step_) * step_; + if(start < low) start += step_; + assert(low <= start && start < low + step_); + } + long long maxsteps = (std::min(high, high_) - start) / step_; + long long steps = UniformGenerator()(0ll, maxsteps, rng); + return start + steps * step_; + } +}; + +struct NormalDistributionGenerator { + static constexpr std::string_view name = "normal"; + using T = long double; + using Args = std::tuple; + + const T mean_, stddev_; + + explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) { + assert(stddev_ >= 0); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + T u1 = Random::real64(rng); + T u2 = Random::real64(rng); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + } + return v; + } +}; + +struct ExponentialDistributionGenerator { + static constexpr std::string_view name = "exponential"; + using T = long double; + using Args = std::tuple; + + T lambda_; + + explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + v = low - std::log(Random::real64(rng)) / lambda_; + if(v < high) return v; + } + } +}; + +struct GeometricDistributionGenerator { + static constexpr std::string_view name = "geometric"; + using T = long long; + using Args = std::tuple; + + double p_; + + explicit GeometricDistributionGenerator(double p) : p_(p) { + assert(p_ > 0); + assert(p_ < 1); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + T v; + while(true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric + // distribution[...]" + v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_)); + if(v <= high) return v; + } + } +}; + +struct BinomialDistributionGenerator { + static constexpr std::string_view name = "binomial"; + using T = long long; + using Args = std::tuple; + + long long n_; + double p_; + + explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) { + assert(p_ >= 0); + assert(p_ <= 1); + std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!" + << std::endl; + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + // this will be slow for large n + // (a faster implementation requires efficient poisson sampling) + while(true) { + T v = 0; + for(long long i = 0; i < n_; i++) { + v += Random::real64(rng) < p_ ? 1 : 0; + } + if(v >= low && v <= high) return v; + } + } +}; + +template +struct ChoiceGenerator { + using GeneratorType = std::conditional_t< + std::is_same_v, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, GeometricDistributionGenerator, + BinomialDistributionGenerator>, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, NormalDistributionGenerator, + ExponentialDistributionGenerator>>; + + std::vector> generators_; + double total_weight_; + + template + struct Pack {}; + + template + static A parse_number(std::string_view s) { + static_assert(is_number_v); + if constexpr(std::is_same_v) + return stoll(std::string(s)); + else + return stold(std::string(s)); + } + + template + static A parse_argument(std::string_view& s) { + auto end = s.find_first_of(",)"); + assert(end != std::string_view::npos); + auto v = parse_number(s.substr(0, end)); + s.remove_prefix(end); + // Pop the trailing , or ) + s.remove_prefix(1); + return v; + } + + template + static std::tuple parse_arguments(std::string_view& s, + Pack> /*unused*/) { + std::tuple args{parse_argument(s)...}; + return args; + } + + // Try parsing one generator type from the start of s. + template + static void parse_generator(std::string_view& s, std::optional& out) { + if(out) return; + if(s.substr(0, G::name.size()) != G::name) return; + + // Drop the name. + s.remove_prefix(G::name.size()); + if constexpr(std::tuple_size_v == 0) { + out.emplace(std::in_place_type_t{}); + return; + } + + // Drop the ( + assert(not s.empty() and s.front() == '('); + s.remove_prefix(1); + + auto args = parse_arguments(s, Pack{}); + // Construct the resulting generator in-place in the variant.. + std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t{}, _args...); }, + args); + } + + template + static std::optional parse_generators(std::string_view& s, + Pack> /*unused*/) { + std::optional out; + (parse_generator(s, out), ...); + return out; + } + + explicit ChoiceGenerator(std::string_view s) : total_weight_(0) { + // PARSE + while(not s.empty()) { + auto generator = parse_generators(s, Pack{}); + if(!generator) { + // Check for range syntax: + auto comma = s.find_first_of(",:"); + if(comma == std::string::npos) comma = s.size(); + auto dots = s.find(".."); + if(dots != std::string_view::npos and dots < comma) { + auto start = s.substr(0, dots); + auto end = s.substr(dots + 2, comma - dots - 2); + + generator.emplace(std::in_place_type_t>{}, + parse_number(start), parse_number(end)); + s.remove_prefix(comma); + } + + // Fall back to constant. + if(!generator) { + generator.emplace(std::in_place_type_t>{}, + parse_number(s.substr(0, comma))); + s.remove_prefix(comma); + } + } + + // Parse weight if given. + double weight = 1; + if(not s.empty() and s.front() == ':') { + s.remove_prefix(1); + auto comma = s.find(','); + if(comma == std::string_view::npos) comma = s.size(); + weight = parse_number(s.substr(0, comma)); + s.remove_prefix(comma); + } + + // should now be at , or end + assert(s.empty() or s.front() == ','); + if(not s.empty()) s.remove_prefix(1); + generators_.emplace_back(std::move(*generator), weight); + total_weight_ += weight; + } + } + + T operator()(T low, T high, std::mt19937_64& rng) const { + Generators::UniformGenerator uniform; + double x = uniform.operator()(0, total_weight_, rng); + for(size_t i = 0; i < generators_.size(); ++i) { + x -= generators_[i].second; + if(x <= 0) + return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first); + } + assert(false); + } +}; + +struct ParamGenerator { + std::variant, ChoiceGenerator> + generator; + explicit ParamGenerator(std::string_view s) : generator(s) {} + + template + T operator()(T low, T high, std::mt19937_64& rng) { + static_assert(is_number_v); + if(std::holds_alternative(generator)) { + generator = ChoiceGenerator(std::get(generator)); + } + return std::get>(generator)(low, high, rng); + } +}; + +} // namespace Generators + +using Generators::ParamGenerator; + +namespace Random { +template +void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) { + Generators::UniformGenerator uniform; + long long n = last - first; + for(long long i = n - 1; i > 0; i--) { + std::swap(first[i], first[uniform(0ll, i, rng)]); + } +} + +template +void shuffle(std::pair& in, std::mt19937_64& rng) { + if(bit(rng)) std::swap(in.first, in.second); +} + +template +auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) { + assert(first != last); + Generators::UniformGenerator uniform; + long long n = last - first; + return first[uniform(0ll, n - 1, rng)]; +} + +template +const T& select(const std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +template +T& select(std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +} // namespace Random + +class Validator { + protected: + Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "", + std::optional seed = std::nullopt, + std::unordered_map params_ = {}) + : in(in_), ws(ws_), case_sensitive(case_), + constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()), + rng(seed.value_or(Random::default_seed)), params(std::move(params_)) { + + std::ios_base::sync_with_stdio(false); + in.tie(nullptr); + + if(gen) return; + if(ws) + in >> std::noskipws; + else + in >> std::skipws; + + if(!constraints_file_path.empty()) { + assert(has_source_location); // NOLINT + } + } + + public: + // No copying, no moving. + Validator(const Validator&) = delete; + Validator(Validator&&) = delete; + void operator=(const Validator&) = delete; + void operator=(Validator&&) = delete; + + // At the end of the scope, check whether the EOF has been reached. + // If so, return AC. Otherwise, return WA. + ~Validator() { + eof(); + write_constraints(); + AC(); + } + + void space() { + if(gen) { + out << ' '; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected space, found EOF."); + if(c != ' ') + expected("space", std::string("\"") + + ((c == '\n' or c == '\r') ? std::string("newline") + : std::string(1, c)) + + "\""); + } + } + + void newline() { + if(gen) { + out << '\n'; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected newline, found EOF."); + if(c != '\n') { + if(c == '\r') + expected("newline", "DOS line ending (\\r)"); + else + expected("newline", std::string("\"") + c + "\""); + } + } + } + + private: + void separator(Separator s) { + switch(s) { + case Separator::Space: space(); break; + case Separator::Newline: newline(); break; + } + } + + template + auto& seen() { + static std::map> seen; + return seen; + } + template + auto& last_seen() { + static std::map last_seen; + return last_seen; + } + template + auto& integers_seen() { + static std::map, std::vector, bool>> + integers_seen; + return integers_seen; + } + template + void reset(source_location loc) { + seen().erase(loc); + last_seen().erase(loc); + integers_seen().erase(loc); + } + + template + void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/, + source_location loc) { + static_assert(is_number_v); + if(v < low or v > high) { + std::string type_name; + if constexpr(std::is_integral_v) { + type_name = "integer"; + } + if constexpr(std::is_floating_point_v) { + type_name = "float"; + } + expected(name + ": " + type_name + " between " + std::to_string(low) + " and " + + std::to_string(high), + std::to_string(v)); + } + log_constraint(name, low, high, v, loc); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[loc].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else { + auto [it, inserted] = last_seen().emplace(loc, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + template + void check_string(const std::string& name, int low, int high, const std::string& v, + Tag /*unused*/, source_location loc) { + using T = std::string; + if((int) v.size() < low or (int) v.size() > high) { + expected(name + ": " + "string with" + " length between " + std::to_string(low) + + " and " + std::to_string(high), + v); + } + log_constraint(name, low, high, static_cast(v.size()), loc); + if constexpr(Tag::unique) { + // static map> seen; + auto [it, inserted] = seen()[loc].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else if(Tag::increasing or Tag::decreasing) { + // static map last_seen; + auto [it, inserted] = last_seen().emplace(loc, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + // Generate a random integer in [low, high] or float in [low, high). + template + T uniform_number(T low, T high) { + assert(low <= high); + Generators::UniformGenerator uniform; + if constexpr(std::is_integral::value) + return uniform.operator()(low, high, rng); + else + return uniform.operator()(low, high, rng); + } + + template + T gen_number(const std::string& name, T low, T high, Tag /*unused*/, source_location loc) { + static_assert(is_number_v); + T v; + + if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + if constexpr(std::is_integral::value) { + auto& [seen_here, remaining_here, use_remaining] = integers_seen()[loc]; + + if(use_remaining) { + check(!remaining_here.empty(), name, ": no unique values left"); + v = remaining_here.back(); + remaining_here.pop_back(); + } else { + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + + struct CountIterator { + T v; + T& operator*() { return v; } + T& operator++() { return ++v; } + T operator++(int) { return v++; } + bool operator!=(CountIterator r) { return v != r.v; } + }; + + if(seen_here.size() > (high - low) / 2) { + use_remaining = true; + set_difference(CountIterator{low}, CountIterator{high + 1}, + seen_here.begin(), seen_here.end(), + std::back_inserter(remaining_here)); + } + } + } else { + // For floats, just regenerate numbers until success. + auto& seen_here = seen()[loc]; + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + } + + } else { + assert(not Tag::increasing && "Generating increasing sequences is not yet supported!"); + assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!"); + assert((std::is_same::value) && + "Only Unique and Arbitrary are supported!"); + + if(params.find(name) != params.end()) { + v = params.at(name).operator()(low, high, rng); + // This will be checked during input validation of the generated case. + // assert(low <= v and v <= high); + } else { + v = uniform_number(low, high); + } + } + + return v; + } + + std::string gen_string(const std::string& name, long long low, long long high, + std::string_view chars) { + assert(!chars.empty()); + + int len; + if(params.find(name + ".length") != params.end()) + len = params.at(name + ".length").operator()(low, high, rng); + else + len = uniform_number(low, high); + std::string s(len, ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s; + return s; + } + + public: + template + long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_number(name, low, high, tag, loc); + } + + template + long double gen_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}, source_location loc = source_location::current()) { + return gen_number(name, low, high, tag, loc); + } + + private: + template + std::vector gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/, + source_location loc) { + static_assert(is_number_v); + std::vector v; + v.reserve(count); + if constexpr(std::is_same_v) { + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + } else if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + std::set seen_here; + if constexpr(std::is_integral_v) { + if(2 * count < high - low) { + for(int i = 0; i < count; ++i) { + // If density < 1/2: retry. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } else { + // If density >= 1/2, crop a random permutation. + v.resize(high - low + 1); + iota(begin(v), end(v), low); + Random::shuffle(begin(v), end(v), rng); + v.resize(count); + } + } else { + for(int i = 0; i < count; ++i) { + // For floats, just regenerate numbers until success. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + constexpr bool integral_strict = Tag::strict and std::is_integral::value; + if(integral_strict) { + assert(params.find(name) == params.end() && + "Parameters are not supported for strict integer values."); + high = high - count + 1; + } + + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + + sort(begin(v), end(v)); + + if(integral_strict) { + for(int i = 0; i < count; ++i) v[i] += i; + } + + if(Tag::decreasing) reverse(begin(v), end(v)); + } + + return v; + } + + public: + template + std::vector gen_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_numbers(name, count, low, high, tag, loc); + } + + template + std::vector gen_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_numbers(name, count, low, high, tag, loc); + } + + private: + template + T read_number(const std::string& name, T low, T high, Tag tag, source_location loc) { + if(gen) { + auto v = gen_number(name, low, high, tag, loc); + out << std::setprecision(10) << std::fixed << v; + return v; + } + + const auto v = [&] { + if constexpr(std::is_integral::value) + return read_integer(name); + else + return read_float(name); + }(); + + check_number(name, low, high, v, tag, loc); + return v; + } + + // Read a vector of numbers, separated by spaces and ended by a newline. + template + std::vector read_numbers(const std::string& name, int count, T low, T high, Tag tag, + Separator sep, source_location loc) { + if(gen) { + auto v = gen_numbers(name, count, low, high, tag, loc); + + out << std::setprecision(10) << std::fixed; + for(int i = 0; i < count; ++i) { + out << v[i]; + if(i < count - 1) separator(sep); + } + newline(); + + return v; + } + reset(loc); + std::vector v(count); + for(int i = 0; i < count; ++i) { + if constexpr(std::is_integral::value) + v[i] = read_integer(name); + else + v[i] = read_float(name); + check_number(name, low, high, v[i], tag, loc); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + public: + template + long long read_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return read_number(name, low, high, tag, loc); + } + template + std::vector read_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, Separator sep = Space, + source_location loc = source_location::current()) { + return read_numbers(name, count, low, high, tag, sep, loc); + } + + template + long double read_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}, source_location loc = source_location::current()) { + return read_number(name, low, high, tag, loc); + } + template + std::vector read_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, Separator sep = Space, + source_location loc = source_location::current()) { + return read_numbers(name, count, low, high, tag, sep, loc); + } + + // Read a vector of strings, separated by spaces and ended by a newline. + template + std::vector read_strings(const std::string& name, int count, int min, int max, + const std::string_view chars = "", Tag tag = Tag(), + Separator sep = Space, + source_location loc = source_location::current()) { + reset(loc); + if(gen) return gen_strings(name, count, min, max, chars, tag, sep, loc); + assert(!gen); + std::vector v(count); + for(int i = 0; i < count; ++i) { + v[i] = read_string(name, min, max, chars, tag, loc); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + template + std::vector gen_strings(const std::string& name, int count, int min, int max, + const std::string_view chars, Tag /*unused*/, + Separator sep, source_location loc) { + assert(!chars.empty()); + + std::vector v(count); + if constexpr(std::is_same::value) { + for(int i = 0; i < count; ++i) { + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else if constexpr(Tag::unique) { + std::set seen_here; + for(int i = 0; i < count; ++i) { + // Just regenerate strings until success. + std::string s; + do { + s = std::string(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + } while(!seen_here.insert(s).second); + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + assert(false && "Generating increasing/decreasing lists of strings is not " + "supported!"); + } + + newline(); + + return v; + } + + // Check the next character. + bool peek(char c, const std::string& name = "") { + if(gen) { + // TODO + // if(not name.empty() and params.contains(name)) { + // return c == params.at(name).operator()(0, 0, rng); + //} + return Random::bit(rng); + } + if(!ws) in >> std::ws; + if(case_sensitive) return in.peek() == std::char_traits::to_int_type(c); + return tolower(in.peek()) == tolower(std::char_traits::to_int_type(c)); + } + + // Read a string and make sure it equals `expected`. + // Takes by value because it needs to lowercase its arguments. + std::string test_strings(std::vector expected, const std::string& name = "") { + if(gen) { + int index = 0; + // TODO + // if(not name.empty() and params.contains(name)) { + // auto s = params.at(name).operator()(0, 0, rng); + // index = std::find(expected.begin(), expected.end(), s) - expected.begin(); + // assert(0 <= index and index < expected.size()); + //} else { + index = expected.size() == 1 ? 0 : uniform_number(0, expected.size() - 1); + //} + out << expected[index]; + return expected[index]; + } + std::string s = get_string(); + lowercase(s); + + for(std::string e : expected) + if(s == lowercase(e)) return s; + + std::string error; + for(const auto& e : expected) { + if(not error.empty()) error += "|"; + error += e; + } + WA("Expected string \"", error, "\", but found ", s); + } + + // Read a string and make sure it equals `expected`. + std::string test_string(std::string expected, const std::string& name = "") { + return test_strings({std::move(expected)}, name); + } + + // Read an arbitrary string of a given length. + template + std::string read_string(const std::string& name, long long min, long long max, + const std::string_view chars = "", Tag tag = Tag(), + source_location loc = source_location::current()) { + if(gen) { + return gen_string(name, min, max, chars); + } + std::string s = get_string(); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + check_string(name, min, max, s, tag, loc); + return s; + } + + // Read an arbitrary line of a given length. + std::string read_line(const std::string& name, long long min, long long max, + const std::string_view chars = "", + source_location loc = source_location::current()) { + if(gen) { + // TODO: Params for lines. + assert(!chars.empty()); + + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s << '\n'; + return s; + } + + if(ws) { + char next = in.peek(); + if(min > 0 and isspace(next)) + expected("non empty line", next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected("line", "EOF"); + } + std::string s; + if(!getline(in, s)) expected("line", "nothing"); + long long size = s.size(); + if(size < min || size > max) + expected(name + ": line of length between " + std::to_string(min) + " and " + + std::to_string(max), + s); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + log_constraint(name, min, max, size, loc); + return s; + } + + // Return ACCEPTED verdict. + void eof_and_AC() { + eof(); + AC(); + } + + private: + std::function WA_handler = [] {}; + + public: + void set_WA_handler(std::function f) { WA_handler = std::move(f); } + + // Return WA with the given reason. + template + [[noreturn]] void WA(const Ts&... ts) { + static_assert(sizeof...(Ts) > 0); + + WA_handler(); + + auto pos = get_file_pos(); + std::cerr << pos.first << ":" << pos.second << ": "; + + WA_impl(ts...); + } + + // Check that the condition is true. + template + void check(bool b, const Ts&... ts) { + static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message."); + + if(!b) WA(ts...); + } + + // Log some value in a range. + template + void log_constraint(const std::string& name, T low, T high, T v, + source_location loc = source_location::current()) { + // Do not log when line number is unknown/default/unsupported. + if(loc.line() == 0 or constraints_file_path.empty()) return; + + // All integer types get bounds as long long, all floating point types as long_double. + using U = Bounds, long long, long double>>; + + auto [it, inserted] = bounds.emplace(loc, U(name, v, v, low, high)); + assert(std::holds_alternative(it->second)); + auto& done = std::get(it->second); + if(inserted) { + assert(!name.empty() && "Variable names must not be empty."); + assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces."); + } else { + assert(name == done.name && "Variable name must be constant."); + } + if(v < done.min) { + done.min = v; + done.low = low; + } + if(v > done.max) { + done.max = v; + done.high = high; + } + done.has_min |= v == low; + done.has_max |= v == high; + } + + private: + long long read_integer(const std::string& name) { + assert(!gen); + std::string s = get_string("integer"); + if(s.empty()) { + WA(name, ": Want integer, found nothing"); + } + long long v; + auto begin = s.c_str(), end = begin + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, v); + if(ec == std::errc::result_out_of_range){ + WA(name, ": Number " + s + " does not fit in a long long!"); + } else if(ptr != end) { + WA(name, ": Parsing " + s + " as long long failed! Did not process all characters"); + } else if (ec != std::errc{}) { + WA(name, ": Parsing " + s + " as long long failed!"); + } + // Check for leading zero. + if(v == 0) { + if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s); + } + if(v > 0) { + if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + if(v < 0) { + if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s); + if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + return v; + } + + long double read_float(const std::string& name) { + assert(!gen); + std::string s = get_string("long double"); + long double v; + try { + size_t chars_processed; + v = stold(s, &chars_processed); + if(chars_processed != s.size()) + WA(name, ": Parsing ", s, + " as long double failed! Did not process all characters."); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long double!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long double failed!"); + } + return v; + } + + [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") { + assert(!gen && "Expected is not supported for generators."); + if(!s.empty()) + WA("Expected ", exp, ", found ", s); + else + WA(exp); + } + + template + [[noreturn]] void WA_impl(T t) { + std::cerr << t << std::endl; + exit(ret_WA); + } + + std::pair get_file_pos() { + int line = 1, col = 0; + in.clear(); + auto originalPos = in.tellg(); + if(originalPos < 0) return {-1, -1}; + in.seekg(0); + char c; + while((in.tellg() < originalPos) && in.get(c)) { + if(c == '\n') + ++line, col = 0; + else + ++col; + } + return {line, col}; + } + + template + [[noreturn]] void WA_impl(T t, Ts... ts) { + std::cerr << t; + WA_impl(ts...); + } + + std::string get_string(const std::string& wanted = "string") { + assert(!gen && "get_string is not supported for generators."); + if(ws) { + char next = in.peek(); + if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected(wanted, "EOF"); + } + + std::string s; + if(in >> s) { + return s; + } + expected(wanted, "nothing"); + } + + // Return ACCEPTED verdict. + void AC() const { + if(gen) { + // nothing + return; + } + + exit(ret_AC); + } + + void eof() { + if(gen) { + out.flush(); + fclose(stdout); + return; + } + if(in.eof()) return; + // Sometimes EOF hasn't been triggered yet. + if(!ws) in >> std::ws; + char c = in.get(); + if(c == std::char_traits::eof()) return; + std::string got = std::string("\"") + char(c) + '"'; + if(c == '\n') got = "newline"; + expected("EOF", got); + } + + // Convert a string to lowercase is matching is not case sensitive. + std::string& lowercase(std::string& s) const { + if(case_sensitive) return s; + transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; + } + + // Keep track of the min/max value read at every call site. + template + struct Bounds { + Bounds(std::string name_, T min_, T max_, T low_, T high_) + : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT + std::string name; + T min, max; // Smallest / largest value observed + T low, high; // Bounds + bool has_min = false, has_max = false; + }; + + std::map, Bounds>> bounds; + + void write_constraints() { + if(constraints_file_path.empty()) return; + + std::ofstream os(constraints_file_path); + + for(const auto& [location, bound] : bounds) { + os << location_to_string(location) << " "; + std::visit( + [&](const auto& b) { + os << b.name << " " << b.has_min << " " << b.has_max << " " << b.min << " " + << b.max << " " << b.low << " " << b.high << std::endl; + }, + bound); + } + } + + static const int ret_AC = 42, ret_WA = 43; + std::istream& in = std::cin; + std::ostream& out = std::cout; + + public: + const bool ws = true; + const bool case_sensitive = true; + const std::string constraints_file_path; + const bool gen = false; + + std::mt19937_64 rng; + + private: + std::unordered_map params; + + public: + std::string_view get_param(std::string_view name, std::string_view default_) { + auto it = params.find(std::string(name)); + if(it == params.end()) return default_; + return std::get(it->second.generator); + } + + protected: + static std::string get_constraints_file(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == constraints_file_flag) { + if(i + 1 < argc) return argv[i + 1]; + std::cerr << constraints_file_flag << " should be followed by a file path!"; + exit(1); + } + } + return {}; + } +}; + +class Generator : public Validator { + public: + explicit Generator(unsigned int seed) + : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {} +}; + +class InputValidator : public Validator { + public: + // An InputValidator is always both whitespace and case sensitive. + explicit InputValidator(int argc = 0, char** argv = nullptr) + : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv), + get_params(argc, argv)) {} + + private: + static std::optional get_seed(int argc, char** argv) { + for(int i = 1; i < argc - 1; ++i) { + if(argv[i] == generate_flag) { + return std::stol(argv[i + 1]); + } + } + // If no --generate is given, but `generat` is a substring of the binary path, + // use the first argument as seed. + if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) { + return std::stol(argv[1]); + } + return std::nullopt; + } + + static std::unordered_map get_params(int argc, char** argv) { + std::unordered_map params; + for(int i = 1; i < argc - 1; ++i) { + if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue; + if(argv[i] == generate_flag) { + continue; + } + std::string_view name(argv[i] + 1); + std::string_view value(argv[i + 1]); + params.insert({std::string(name), ParamGenerator(value)}); + } + return params; + } +}; + +class OutputValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_, + get_constraints_file(argc, argv)) {} + + private: + static bool is_ws_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == ws_sensitive_flag) return true; + } + return false; + } + + static bool is_case_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == case_sensitive_flag) return true; + } + return false; + } +}; diff --git a/ICPC/nwerc2022_J/data.zip b/ICPC/nwerc2022_J/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..e5b6280ee7af4bdbc7c179b3bc56deefb338d140 --- /dev/null +++ b/ICPC/nwerc2022_J/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e980aaccf3b6013c6279a2daa2da2569b5deecf8006b706234b2af05ccb1401 +size 77274230 diff --git a/ICPC/nwerc2022_J/init.yml b/ICPC/nwerc2022_J/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5c9ebaf686b66d615e52d889014319c8588230cf --- /dev/null +++ b/ICPC/nwerc2022_J/init.yml @@ -0,0 +1,377 @@ +archive: data.zip +test_cases: +- in: 001-tower_overlapping.in + out: 001-tower_overlapping.ans + points: 1 +- in: 002-tower_overlapping.in + out: 002-tower_overlapping.ans + points: 1 +- in: 003-tower_overlapping.in + out: 003-tower_overlapping.ans + points: 1 +- in: 004-tower_overlapping.in + out: 004-tower_overlapping.ans + points: 1 +- in: 005-tower_overlapping.in + out: 005-tower_overlapping.ans + points: 1 +- in: 006-manual.in + out: 006-manual.ans + points: 1 +- in: 007-manual.in + out: 007-manual.ans + points: 1 +- in: 008-manual.in + out: 008-manual.ans + points: 1 +- in: 009-manual.in + out: 009-manual.ans + points: 1 +- in: 010-manual.in + out: 010-manual.ans + points: 1 +- in: 011-fuzz-small.in + out: 011-fuzz-small.ans + points: 1 +- in: 012-fuzz-small.in + out: 012-fuzz-small.ans + points: 1 +- in: 013-fuzz-small.in + out: 013-fuzz-small.ans + points: 1 +- in: 014-fuzz-small.in + out: 014-fuzz-small.ans + points: 1 +- in: 015-fuzz.in + out: 015-fuzz.ans + points: 1 +- in: 016-fuzz.in + out: 016-fuzz.ans + points: 1 +- in: 017-fuzz.in + out: 017-fuzz.ans + points: 1 +- in: 018-fuzz.in + out: 018-fuzz.ans + points: 1 +- in: 019-fuzz.in + out: 019-fuzz.ans + points: 1 +- in: 020-fuzz.in + out: 020-fuzz.ans + points: 1 +- in: 021-fuzz.in + out: 021-fuzz.ans + points: 1 +- in: 022-max-left.in + out: 022-max-left.ans + points: 1 +- in: 023-max-right.in + out: 023-max-right.ans + points: 1 +- in: 024-max-left-shufle.in + out: 024-max-left-shufle.ans + points: 1 +- in: 025-bipartite.in + out: 025-bipartite.ans + points: 1 +- in: 026-bipartite.in + out: 026-bipartite.ans + points: 1 +- in: 027-bipartite.in + out: 027-bipartite.ans + points: 1 +- in: 028-bipartite.in + out: 028-bipartite.ans + points: 1 +- in: 029-bipartite.in + out: 029-bipartite.ans + points: 1 +- in: 030-tower.in + out: 030-tower.ans + points: 1 +- in: 031-random.in + out: 031-random.ans + points: 1 +- in: 032-random.in + out: 032-random.ans + points: 1 +- in: 033-random.in + out: 033-random.ans + points: 1 +- in: 034-random.in + out: 034-random.ans + points: 1 +- in: 035-random-few-ends.in + out: 035-random-few-ends.ans + points: 1 +- in: 036-random-few-ends.in + out: 036-random-few-ends.ans + points: 1 +- in: 037-random-few-ends.in + out: 037-random-few-ends.ans + points: 1 +- in: 038-random-few-ends.in + out: 038-random-few-ends.ans + points: 1 +- in: 039-random-many-ends.in + out: 039-random-many-ends.ans + points: 1 +- in: 040-random-many-ends.in + out: 040-random-many-ends.ans + points: 1 +- in: 041-random-many-ends.in + out: 041-random-many-ends.ans + points: 1 +- in: 042-random-many-ends.in + out: 042-random-many-ends.ans + points: 1 +- in: 043-random-many-ends.in + out: 043-random-many-ends.ans + points: 1 +- in: 044-random-many-ends.in + out: 044-random-many-ends.ans + points: 1 +- in: 045-random-small.in + out: 045-random-small.ans + points: 1 +- in: 046-random-small.in + out: 046-random-small.ans + points: 1 +- in: 047-random-small.in + out: 047-random-small.ans + points: 1 +- in: 048-random-small.in + out: 048-random-small.ans + points: 1 +- in: 049-small.in + out: 049-small.ans + points: 1 +- in: 050-small.in + out: 050-small.ans + points: 1 +- in: 051-small.in + out: 051-small.ans + points: 1 +- in: 052-small.in + out: 052-small.ans + points: 1 +- in: 053-small.in + out: 053-small.ans + points: 1 +- in: 054-tower.in + out: 054-tower.ans + points: 1 +- in: 055-tower.in + out: 055-tower.ans + points: 1 +- in: 056-overlapping.in + out: 056-overlapping.ans + points: 1 +- in: 057-overlapping.in + out: 057-overlapping.ans + points: 1 +- in: 058-complete.in + out: 058-complete.ans + points: 1 +- in: 059-complete.in + out: 059-complete.ans + points: 1 +- in: 060-complete.in + out: 060-complete.ans + points: 1 +- in: 061-complete.in + out: 061-complete.ans + points: 1 +- in: 062-complete.in + out: 062-complete.ans + points: 1 +- in: 063-dense.in + out: 063-dense.ans + points: 1 +- in: 064-dense.in + out: 064-dense.ans + points: 1 +- in: 065-dense.in + out: 065-dense.ans + points: 1 +- in: 066-dense.in + out: 066-dense.ans + points: 1 +- in: 067-dense.in + out: 067-dense.ans + points: 1 +- in: 068-dense.in + out: 068-dense.ans + points: 1 +- in: 069-dense.in + out: 069-dense.ans + points: 1 +- in: 070-dense.in + out: 070-dense.ans + points: 1 +- in: 071-dense.in + out: 071-dense.ans + points: 1 +- in: 072-dense-maxn.in + out: 072-dense-maxn.ans + points: 1 +- in: 073-dense-maxn.in + out: 073-dense-maxn.ans + points: 1 +- in: 074-dense-maxn.in + out: 074-dense-maxn.ans + points: 1 +- in: 075-dense-maxn.in + out: 075-dense-maxn.ans + points: 1 +- in: 076-dense-maxn.in + out: 076-dense-maxn.ans + points: 1 +- in: 077-dense-maxn.in + out: 077-dense-maxn.ans + points: 1 +- in: 078-dense-maxn.in + out: 078-dense-maxn.ans + points: 1 +- in: 079-dense-maxn.in + out: 079-dense-maxn.ans + points: 1 +- in: 080-dense-maxn.in + out: 080-dense-maxn.ans + points: 1 +- in: 081-dense-maxn.in + out: 081-dense-maxn.ans + points: 1 +- in: 082-tree.in + out: 082-tree.ans + points: 1 +- in: 083-tree.in + out: 083-tree.ans + points: 1 +- in: 084-tree.in + out: 084-tree.ans + points: 1 +- in: 085-tree.in + out: 085-tree.ans + points: 1 +- in: 086-tree.in + out: 086-tree.ans + points: 1 +- in: 087-tree.in + out: 087-tree.ans + points: 1 +- in: 088-tree-binary.in + out: 088-tree-binary.ans + points: 1 +- in: 089-tree-binary.in + out: 089-tree-binary.ans + points: 1 +- in: 090-tree-binary.in + out: 090-tree-binary.ans + points: 1 +- in: 091-tree-binary.in + out: 091-tree-binary.ans + points: 1 +- in: 092-tree-binary.in + out: 092-tree-binary.ans + points: 1 +- in: 093-tree-binary.in + out: 093-tree-binary.ans + points: 1 +- in: 094-tree-binary.in + out: 094-tree-binary.ans + points: 1 +- in: 095-tree-binary-deep.in + out: 095-tree-binary-deep.ans + points: 1 +- in: 096-tree-binary-deep.in + out: 096-tree-binary-deep.ans + points: 1 +- in: 097-tree-binary-deep.in + out: 097-tree-binary-deep.ans + points: 1 +- in: 098-tree-binary-deep.in + out: 098-tree-binary-deep.ans + points: 1 +- in: 099-tree-binary-deep.in + out: 099-tree-binary-deep.ans + points: 1 +- in: 100-tree-binary-deep.in + out: 100-tree-binary-deep.ans + points: 1 +- in: 101-tree-random.in + out: 101-tree-random.ans + points: 1 +- in: 102-tree-random.in + out: 102-tree-random.ans + points: 1 +- in: 103-tree-random.in + out: 103-tree-random.ans + points: 1 +- in: 104-tree-random.in + out: 104-tree-random.ans + points: 1 +- in: 105-tree-random.in + out: 105-tree-random.ans + points: 1 +- in: 106-tree-random.in + out: 106-tree-random.ans + points: 1 +- in: 107-tree-large.in + out: 107-tree-large.ans + points: 1 +- in: 108-tree-large.in + out: 108-tree-large.ans + points: 1 +- in: 109-tree-large.in + out: 109-tree-large.ans + points: 1 +- in: 110-tree-pathy.in + out: 110-tree-pathy.ans + points: 1 +- in: 111-tree-pathy.in + out: 111-tree-pathy.ans + points: 1 +- in: 112-tree-pathy.in + out: 112-tree-pathy.ans + points: 1 +- in: 113-tree-pathy.in + out: 113-tree-pathy.ans + points: 1 +- in: 114-tree-pathy.in + out: 114-tree-pathy.ans + points: 1 +- in: 115-tree-pathy.in + out: 115-tree-pathy.ans + points: 1 +- in: 116-tree-pathy.in + out: 116-tree-pathy.ans + points: 1 +- in: 117-tree-pathy-deep.in + out: 117-tree-pathy-deep.ans + points: 1 +- in: 118-tree-pathy-deep.in + out: 118-tree-pathy-deep.ans + points: 1 +- in: 119-tree-pathy-deep.in + out: 119-tree-pathy-deep.ans + points: 1 +- in: 120-tree-pathy-deep.in + out: 120-tree-pathy-deep.ans + points: 1 +- in: 121-tree-pathy-deep.in + out: 121-tree-pathy-deep.ans + points: 1 +- in: 122-tree-pathy-deep.in + out: 122-tree-pathy-deep.ans + points: 1 +- in: 123-tree-pathy-deep.in + out: 123-tree-pathy-deep.ans + points: 1 +- in: 124-tree-pathy-deep.in + out: 124-tree-pathy-deep.ans + points: 1 +- in: 125-tree-pathy-deep.in + out: 125-tree-pathy-deep.ans + points: 1 diff --git a/ICPC/nwerc2022_K/data.zip b/ICPC/nwerc2022_K/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..b2139dacae0678314e2fb4f519980770b787a772 --- /dev/null +++ b/ICPC/nwerc2022_K/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:598d142a779315a78464d1ea3b333ae881c6f035fa8b7ae0169df2ca7e46e22d +size 19948886 diff --git a/ICPC/nwerc2022_K/init.yml b/ICPC/nwerc2022_K/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b71027e36592dd1420b26cb497351ed88b975fe5 --- /dev/null +++ b/ICPC/nwerc2022_K/init.yml @@ -0,0 +1,491 @@ +archive: data.zip +test_cases: +- in: 001-2multiedges_selfloops.in + out: 001-2multiedges_selfloops.ans + points: 1 +- in: 002-2multiedges.in + out: 002-2multiedges.ans + points: 1 +- in: 003-2selfloops_degree3.in + out: 003-2selfloops_degree3.ans + points: 1 +- in: 004-3selfloops_degree3.in + out: 004-3selfloops_degree3.ans + points: 1 +- in: 005-cycle_and_edge.in + out: 005-cycle_and_edge.ans + points: 1 +- in: 006-cycle_and_selfloop.in + out: 006-cycle_and_selfloop.ans + points: 1 +- in: 007-cycle_and_vertex.in + out: 007-cycle_and_vertex.ans + points: 1 +- in: 008-multiedge_on_cycle.in + out: 008-multiedge_on_cycle.ans + points: 1 +- in: 009-selfloop_edge_cycle.in + out: 009-selfloop_edge_cycle.ans + points: 1 +- in: 010-selfloops_on_cycle.in + out: 010-selfloops_on_cycle.ans + points: 1 +- in: 011-two_cycles.in + out: 011-two_cycles.ans + points: 1 +- in: 012-two_paths.in + out: 012-two_paths.ans + points: 1 +- in: 013-matching.in + out: 013-matching.ans + points: 1 +- in: 014-random.in + out: 014-random.ans + points: 1 +- in: 015-random.in + out: 015-random.ans + points: 1 +- in: 016-random.in + out: 016-random.ans + points: 1 +- in: 017-random.in + out: 017-random.ans + points: 1 +- in: 018-random.in + out: 018-random.ans + points: 1 +- in: 019-random.in + out: 019-random.ans + points: 1 +- in: 020-random.in + out: 020-random.ans + points: 1 +- in: 021-random.in + out: 021-random.ans + points: 1 +- in: 022-random.in + out: 022-random.ans + points: 1 +- in: 023-random.in + out: 023-random.ans + points: 1 +- in: 024-random-possible.in + out: 024-random-possible.ans + points: 1 +- in: 025-random-possible.in + out: 025-random-possible.ans + points: 1 +- in: 026-random-possible.in + out: 026-random-possible.ans + points: 1 +- in: 027-random-possible.in + out: 027-random-possible.ans + points: 1 +- in: 028-random-possible.in + out: 028-random-possible.ans + points: 1 +- in: 029-random-possible.in + out: 029-random-possible.ans + points: 1 +- in: 030-random-possible.in + out: 030-random-possible.ans + points: 1 +- in: 031-random-possible.in + out: 031-random-possible.ans + points: 1 +- in: 032-random-possible.in + out: 032-random-possible.ans + points: 1 +- in: 033-random-possible.in + out: 033-random-possible.ans + points: 1 +- in: 034-long-cycle.in + out: 034-long-cycle.ans + points: 1 +- in: 035-two-long-cycles.in + out: 035-two-long-cycles.ans + points: 1 +- in: 036-long-chain.in + out: 036-long-chain.ans + points: 1 +- in: 037-two-long-chains.in + out: 037-two-long-chains.ans + points: 1 +- in: 038-long-cycle-and-chain.in + out: 038-long-cycle-and-chain.ans + points: 1 +- in: 039-long-cycle-and-two-chains.in + out: 039-long-cycle-and-two-chains.ans + points: 1 +- in: 040-long-cycle-and-edge.in + out: 040-long-cycle-and-edge.ans + points: 1 +- in: 041-long-chain-and-edge.in + out: 041-long-chain-and-edge.ans + points: 1 +- in: 042-long-cycle-decorated.in + out: 042-long-cycle-decorated.ans + points: 1 +- in: 043-two-long-cycles-decorated.in + out: 043-two-long-cycles-decorated.ans + points: 1 +- in: 044-long-chain-decorated.in + out: 044-long-chain-decorated.ans + points: 1 +- in: 045-two-long-chains-decorated.in + out: 045-two-long-chains-decorated.ans + points: 1 +- in: 046-long-cycle-and-node.in + out: 046-long-cycle-and-node.ans + points: 1 +- in: 047-long-cycle-and-selfloop.in + out: 047-long-cycle-and-selfloop.ans + points: 1 +- in: 048-many-2-chains.in + out: 048-many-2-chains.ans + points: 1 +- in: 049-many-selfloops.in + out: 049-many-selfloops.ans + points: 1 +- in: 050-many-5-chains.in + out: 050-many-5-chains.ans + points: 1 +- in: 051-long-cycle-and-clique.in + out: 051-long-cycle-and-clique.ans + points: 1 +- in: 052-two-long-cycles-and-clique.in + out: 052-two-long-cycles-and-clique.ans + points: 1 +- in: 053-long-chain-and-clique.in + out: 053-long-chain-and-clique.ans + points: 1 +- in: 054-two-long-chains-and-clique.in + out: 054-two-long-chains-and-clique.ans + points: 1 +- in: 055-many-2-chains-and-clique.in + out: 055-many-2-chains-and-clique.ans + points: 1 +- in: 056-many-selfloops-and-clique.in + out: 056-many-selfloops-and-clique.ans + points: 1 +- in: 057-many-5-chains-and-clique.in + out: 057-many-5-chains-and-clique.ans + points: 1 +- in: 058-large-clique.in + out: 058-large-clique.ans + points: 1 +- in: 059-large-clique.in + out: 059-large-clique.ans + points: 1 +- in: 060-large-clique-decorated.in + out: 060-large-clique-decorated.ans + points: 1 +- in: 061-large-clique-decorated.in + out: 061-large-clique-decorated.ans + points: 1 +- in: 062-peter.in + out: 062-peter.ans + points: 1 +- in: 063-peter.in + out: 063-peter.ans + points: 1 +- in: 064-random-mutated.in + out: 064-random-mutated.ans + points: 1 +- in: 065-random-mutated.in + out: 065-random-mutated.ans + points: 1 +- in: 066-random-mutated.in + out: 066-random-mutated.ans + points: 1 +- in: 067-random-mutated.in + out: 067-random-mutated.ans + points: 1 +- in: 068-random-mutated.in + out: 068-random-mutated.ans + points: 1 +- in: 069-random-mutated.in + out: 069-random-mutated.ans + points: 1 +- in: 070-random-mutated.in + out: 070-random-mutated.ans + points: 1 +- in: 071-random-mutated.in + out: 071-random-mutated.ans + points: 1 +- in: 072-random-mutated.in + out: 072-random-mutated.ans + points: 1 +- in: 073-random-mutated.in + out: 073-random-mutated.ans + points: 1 +- in: 074-random-mutated.in + out: 074-random-mutated.ans + points: 1 +- in: 075-random-mutated.in + out: 075-random-mutated.ans + points: 1 +- in: 076-random-mutated.in + out: 076-random-mutated.ans + points: 1 +- in: 077-random-mutated.in + out: 077-random-mutated.ans + points: 1 +- in: 078-random-mutated.in + out: 078-random-mutated.ans + points: 1 +- in: 079-random-mutated.in + out: 079-random-mutated.ans + points: 1 +- in: 080-random-mutated.in + out: 080-random-mutated.ans + points: 1 +- in: 081-random-mutated.in + out: 081-random-mutated.ans + points: 1 +- in: 082-random-mutated.in + out: 082-random-mutated.ans + points: 1 +- in: 083-random-mutated.in + out: 083-random-mutated.ans + points: 1 +- in: 084-random-mutated.in + out: 084-random-mutated.ans + points: 1 +- in: 085-random-mutated.in + out: 085-random-mutated.ans + points: 1 +- in: 086-random-mutated.in + out: 086-random-mutated.ans + points: 1 +- in: 087-random-mutated.in + out: 087-random-mutated.ans + points: 1 +- in: 088-random-mutated.in + out: 088-random-mutated.ans + points: 1 +- in: 089-random-mutated.in + out: 089-random-mutated.ans + points: 1 +- in: 090-random-mutated.in + out: 090-random-mutated.ans + points: 1 +- in: 091-random-mutated.in + out: 091-random-mutated.ans + points: 1 +- in: 092-random-mutated.in + out: 092-random-mutated.ans + points: 1 +- in: 093-random-mutated.in + out: 093-random-mutated.ans + points: 1 +- in: 094-random-mutated.in + out: 094-random-mutated.ans + points: 1 +- in: 095-random-mutated.in + out: 095-random-mutated.ans + points: 1 +- in: 096-random-mutated.in + out: 096-random-mutated.ans + points: 1 +- in: 097-random-mutated.in + out: 097-random-mutated.ans + points: 1 +- in: 098-random-mutated.in + out: 098-random-mutated.ans + points: 1 +- in: 099-random-mutated.in + out: 099-random-mutated.ans + points: 1 +- in: 100-random-mutated.in + out: 100-random-mutated.ans + points: 1 +- in: 101-random-mutated.in + out: 101-random-mutated.ans + points: 1 +- in: 102-random-mutated.in + out: 102-random-mutated.ans + points: 1 +- in: 103-random-mutated.in + out: 103-random-mutated.ans + points: 1 +- in: 104-random-mutated.in + out: 104-random-mutated.ans + points: 1 +- in: 105-random-mutated.in + out: 105-random-mutated.ans + points: 1 +- in: 106-random-mutated.in + out: 106-random-mutated.ans + points: 1 +- in: 107-random-mutated.in + out: 107-random-mutated.ans + points: 1 +- in: 108-random-mutated.in + out: 108-random-mutated.ans + points: 1 +- in: 109-random-mutated.in + out: 109-random-mutated.ans + points: 1 +- in: 110-random-mutated.in + out: 110-random-mutated.ans + points: 1 +- in: 111-random-mutated.in + out: 111-random-mutated.ans + points: 1 +- in: 112-random-mutated.in + out: 112-random-mutated.ans + points: 1 +- in: 113-random-mutated.in + out: 113-random-mutated.ans + points: 1 +- in: 114-random-mutated.in + out: 114-random-mutated.ans + points: 1 +- in: 115-random-mutated.in + out: 115-random-mutated.ans + points: 1 +- in: 116-random-mutated.in + out: 116-random-mutated.ans + points: 1 +- in: 117-random-mutated.in + out: 117-random-mutated.ans + points: 1 +- in: 118-random-mutated.in + out: 118-random-mutated.ans + points: 1 +- in: 119-random-mutated.in + out: 119-random-mutated.ans + points: 1 +- in: 120-random-mutated.in + out: 120-random-mutated.ans + points: 1 +- in: 121-random-mutated.in + out: 121-random-mutated.ans + points: 1 +- in: 122-random-mutated.in + out: 122-random-mutated.ans + points: 1 +- in: 123-random-mutated.in + out: 123-random-mutated.ans + points: 1 +- in: 124-random-mutated.in + out: 124-random-mutated.ans + points: 1 +- in: 125-random-mutated.in + out: 125-random-mutated.ans + points: 1 +- in: 126-random-mutated.in + out: 126-random-mutated.ans + points: 1 +- in: 127-random-mutated.in + out: 127-random-mutated.ans + points: 1 +- in: 128-random-mutated.in + out: 128-random-mutated.ans + points: 1 +- in: 129-random-mutated.in + out: 129-random-mutated.ans + points: 1 +- in: 130-random-mutated.in + out: 130-random-mutated.ans + points: 1 +- in: 131-random-mutated.in + out: 131-random-mutated.ans + points: 1 +- in: 132-random-mutated.in + out: 132-random-mutated.ans + points: 1 +- in: 133-random-mutated.in + out: 133-random-mutated.ans + points: 1 +- in: 134-random-mutated.in + out: 134-random-mutated.ans + points: 1 +- in: 135-random-mutated.in + out: 135-random-mutated.ans + points: 1 +- in: 136-random-mutated.in + out: 136-random-mutated.ans + points: 1 +- in: 137-random-mutated.in + out: 137-random-mutated.ans + points: 1 +- in: 138-random-mutated.in + out: 138-random-mutated.ans + points: 1 +- in: 139-random-mutated.in + out: 139-random-mutated.ans + points: 1 +- in: 140-random-mutated.in + out: 140-random-mutated.ans + points: 1 +- in: 141-random-mutated.in + out: 141-random-mutated.ans + points: 1 +- in: 142-random-mutated.in + out: 142-random-mutated.ans + points: 1 +- in: 143-random-mutated.in + out: 143-random-mutated.ans + points: 1 +- in: 144-random-mutated.in + out: 144-random-mutated.ans + points: 1 +- in: 145-random-mutated.in + out: 145-random-mutated.ans + points: 1 +- in: 146-random-mutated.in + out: 146-random-mutated.ans + points: 1 +- in: 147-random-mutated.in + out: 147-random-mutated.ans + points: 1 +- in: 148-random-mutated.in + out: 148-random-mutated.ans + points: 1 +- in: 149-random-mutated.in + out: 149-random-mutated.ans + points: 1 +- in: 150-random-mutated.in + out: 150-random-mutated.ans + points: 1 +- in: 151-random-mutated.in + out: 151-random-mutated.ans + points: 1 +- in: 152-random-mutated.in + out: 152-random-mutated.ans + points: 1 +- in: 153-random-mutated.in + out: 153-random-mutated.ans + points: 1 +- in: 154-random-mutated.in + out: 154-random-mutated.ans + points: 1 +- in: 155-random-mutated.in + out: 155-random-mutated.ans + points: 1 +- in: 156-random-mutated.in + out: 156-random-mutated.ans + points: 1 +- in: 157-random-mutated.in + out: 157-random-mutated.ans + points: 1 +- in: 158-random-mutated.in + out: 158-random-mutated.ans + points: 1 +- in: 159-random-mutated.in + out: 159-random-mutated.ans + points: 1 +- in: 160-random-mutated.in + out: 160-random-mutated.ans + points: 1 +- in: 161-random-mutated.in + out: 161-random-mutated.ans + points: 1 +- in: 162-random-mutated.in + out: 162-random-mutated.ans + points: 1 +- in: 163-random-mutated.in + out: 163-random-mutated.ans + points: 1 diff --git a/ICPC/nwerc2022_L/data.zip b/ICPC/nwerc2022_L/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..373874dac46413989fe4b8c0d3b453f62add33cf --- /dev/null +++ b/ICPC/nwerc2022_L/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99155e33e1631315454d4789cc8de5c8534227e940264de6ce0dbbcfef1fa4e4 +size 1388307 diff --git a/ICPC/nwerc2022_L/init.yml b/ICPC/nwerc2022_L/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..85c60975b87e18c57dd3acaf09f931abf87a6aa7 --- /dev/null +++ b/ICPC/nwerc2022_L/init.yml @@ -0,0 +1,496 @@ +archive: data.zip +checker: + args: + files: + - output_validators/validate/output-validator.cc + - output_validators/validate/validation.h + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 001-anti-two-step.in + out: 001-anti-two-step.ans + points: 1 +- in: 002-anti-two-step.in + out: 002-anti-two-step.ans + points: 1 +- in: 003-anti-two-step.in + out: 003-anti-two-step.ans + points: 1 +- in: 004-anti-two-step.in + out: 004-anti-two-step.ans + points: 1 +- in: 005-slack.in + out: 005-slack.ans + points: 1 +- in: 006-slack.in + out: 006-slack.ans + points: 1 +- in: 007-slack.in + out: 007-slack.ans + points: 1 +- in: 008-multi-triangle.in + out: 008-multi-triangle.ans + points: 1 +- in: 009-multi-triangle.in + out: 009-multi-triangle.ans + points: 1 +- in: 010-multi-triangle.in + out: 010-multi-triangle.ans + points: 1 +- in: 011-spanning-tree.in + out: 011-spanning-tree.ans + points: 1 +- in: 012-spanning-tree.in + out: 012-spanning-tree.ans + points: 1 +- in: 013-spanning-tree.in + out: 013-spanning-tree.ans + points: 1 +- in: 014-random.in + out: 014-random.ans + points: 1 +- in: 015-random.in + out: 015-random.ans + points: 1 +- in: 016-random.in + out: 016-random.ans + points: 1 +- in: 017-random.in + out: 017-random.ans + points: 1 +- in: 018-random.in + out: 018-random.ans + points: 1 +- in: 019-random.in + out: 019-random.ans + points: 1 +- in: 020-random.in + out: 020-random.ans + points: 1 +- in: 021-random.in + out: 021-random.ans + points: 1 +- in: 022-random.in + out: 022-random.ans + points: 1 +- in: 023-random.in + out: 023-random.ans + points: 1 +- in: 024-random.in + out: 024-random.ans + points: 1 +- in: 025-random.in + out: 025-random.ans + points: 1 +- in: 026-random.in + out: 026-random.ans + points: 1 +- in: 027-random.in + out: 027-random.ans + points: 1 +- in: 028-random.in + out: 028-random.ans + points: 1 +- in: 029-random.in + out: 029-random.ans + points: 1 +- in: 030-random-no-green.in + out: 030-random-no-green.ans + points: 1 +- in: 031-random-no-green.in + out: 031-random-no-green.ans + points: 1 +- in: 032-random-no-green.in + out: 032-random-no-green.ans + points: 1 +- in: 033-random-no-green.in + out: 033-random-no-green.ans + points: 1 +- in: 034-random-no-green.in + out: 034-random-no-green.ans + points: 1 +- in: 035-random-no-green.in + out: 035-random-no-green.ans + points: 1 +- in: 036-random-no-green.in + out: 036-random-no-green.ans + points: 1 +- in: 037-random-no-green.in + out: 037-random-no-green.ans + points: 1 +- in: 038-random-no-green.in + out: 038-random-no-green.ans + points: 1 +- in: 039-random-no-green.in + out: 039-random-no-green.ans + points: 1 +- in: 040-random-no-green.in + out: 040-random-no-green.ans + points: 1 +- in: 041-random-no-green.in + out: 041-random-no-green.ans + points: 1 +- in: 042-random-no-green.in + out: 042-random-no-green.ans + points: 1 +- in: 043-random-no-green.in + out: 043-random-no-green.ans + points: 1 +- in: 044-separate-greens.in + out: 044-separate-greens.ans + points: 1 +- in: 045-all-black.in + out: 045-all-black.ans + points: 1 +- in: 046-all-black.in + out: 046-all-black.ans + points: 1 +- in: 047-all-black.in + out: 047-all-black.ans + points: 1 +- in: 048-all-black.in + out: 048-all-black.ans + points: 1 +- in: 049-all-black.in + out: 049-all-black.ans + points: 1 +- in: 050-all-black.in + out: 050-all-black.ans + points: 1 +- in: 051-manual.in + out: 051-manual.ans + points: 1 +- in: 052-manual.in + out: 052-manual.ans + points: 1 +- in: 053-manual.in + out: 053-manual.ans + points: 1 +- in: 054-manual.in + out: 054-manual.ans + points: 1 +- in: 055-manual.in + out: 055-manual.ans + points: 1 +- in: 056-manual.in + out: 056-manual.ans + points: 1 +- in: 057-english.in + out: 057-english.ans + points: 1 +- in: 058-english.in + out: 058-english.ans + points: 1 +- in: 059-all-yellow.in + out: 059-all-yellow.ans + points: 1 +- in: 060-all-yellow.in + out: 060-all-yellow.ans + points: 1 +- in: 061-all-yellow.in + out: 061-all-yellow.ans + points: 1 +- in: 062-all-yellow.in + out: 062-all-yellow.ans + points: 1 +- in: 063-all-yellow.in + out: 063-all-yellow.ans + points: 1 +- in: 064-all-yellow.in + out: 064-all-yellow.ans + points: 1 +- in: 065-all-yellow.in + out: 065-all-yellow.ans + points: 1 +- in: 066-all-yellow.in + out: 066-all-yellow.ans + points: 1 +- in: 067-all-yellow.in + out: 067-all-yellow.ans + points: 1 +- in: 068-all-yellow.in + out: 068-all-yellow.ans + points: 1 +- in: 069-all-yellow.in + out: 069-all-yellow.ans + points: 1 +- in: 070-all-yellow.in + out: 070-all-yellow.ans + points: 1 +- in: 071-all-yellow.in + out: 071-all-yellow.ans + points: 1 +- in: 072-all-yellow.in + out: 072-all-yellow.ans + points: 1 +- in: 073-all-yellow.in + out: 073-all-yellow.ans + points: 1 +- in: 074-black-and-green.in + out: 074-black-and-green.ans + points: 1 +- in: 075-black-and-green.in + out: 075-black-and-green.ans + points: 1 +- in: 076-black-and-green.in + out: 076-black-and-green.ans + points: 1 +- in: 077-black-and-green.in + out: 077-black-and-green.ans + points: 1 +- in: 078-black-and-green.in + out: 078-black-and-green.ans + points: 1 +- in: 079-black-and-green.in + out: 079-black-and-green.ans + points: 1 +- in: 080-black-and-green.in + out: 080-black-and-green.ans + points: 1 +- in: 081-black-and-green.in + out: 081-black-and-green.ans + points: 1 +- in: 082-black-and-green.in + out: 082-black-and-green.ans + points: 1 +- in: 083-black-and-green.in + out: 083-black-and-green.ans + points: 1 +- in: 084-rotate.in + out: 084-rotate.ans + points: 1 +- in: 085-split.in + out: 085-split.ans + points: 1 +- in: 086-split.in + out: 086-split.ans + points: 1 +- in: 087-split.in + out: 087-split.ans + points: 1 +- in: 088-incremental.in + out: 088-incremental.ans + points: 1 +- in: 089-incremental.in + out: 089-incremental.ans + points: 1 +- in: 090-incremental.in + out: 090-incremental.ans + points: 1 +- in: 091-incremental.in + out: 091-incremental.ans + points: 1 +- in: 092-incremental.in + out: 092-incremental.ans + points: 1 +- in: 093-incremental.in + out: 093-incremental.ans + points: 1 +- in: 094-incremental.in + out: 094-incremental.ans + points: 1 +- in: 095-fuzz.in + out: 095-fuzz.ans + points: 1 +- in: 096-slack.in + out: 096-slack.ans + points: 1 +- in: 097-slack.in + out: 097-slack.ans + points: 1 +- in: 098-slack.in + out: 098-slack.ans + points: 1 +- in: 099-slack.in + out: 099-slack.ans + points: 1 +- in: 100-triangle.in + out: 100-triangle.ans + points: 1 +- in: 101-fuzz.in + out: 101-fuzz.ans + points: 1 +- in: 102-fuzz.in + out: 102-fuzz.ans + points: 1 +- in: 103-fuzz.in + out: 103-fuzz.ans + points: 1 +- in: 104-fuzz.in + out: 104-fuzz.ans + points: 1 +- in: 105-fuzz.in + out: 105-fuzz.ans + points: 1 +- in: 106-fuzz.in + out: 106-fuzz.ans + points: 1 +- in: 107-fuzz.in + out: 107-fuzz.ans + points: 1 +- in: 108-fuzz.in + out: 108-fuzz.ans + points: 1 +- in: 109-fuzz.in + out: 109-fuzz.ans + points: 1 +- in: 110-fuzz.in + out: 110-fuzz.ans + points: 1 +- in: 111-fuzz.in + out: 111-fuzz.ans + points: 1 +- in: 112-fuzz.in + out: 112-fuzz.ans + points: 1 +- in: 113-fuzz.in + out: 113-fuzz.ans + points: 1 +- in: 114-fuzz.in + out: 114-fuzz.ans + points: 1 +- in: 115-fuzz.in + out: 115-fuzz.ans + points: 1 +- in: 116-fuzz.in + out: 116-fuzz.ans + points: 1 +- in: 117-fuzz.in + out: 117-fuzz.ans + points: 1 +- in: 118-fuzz.in + out: 118-fuzz.ans + points: 1 +- in: 119-fuzz.in + out: 119-fuzz.ans + points: 1 +- in: 120-fuzz.in + out: 120-fuzz.ans + points: 1 +- in: 121-fuzz.in + out: 121-fuzz.ans + points: 1 +- in: 122-fuzz.in + out: 122-fuzz.ans + points: 1 +- in: 123-fuzz.in + out: 123-fuzz.ans + points: 1 +- in: 124-fuzz.in + out: 124-fuzz.ans + points: 1 +- in: 125-fuzz.in + out: 125-fuzz.ans + points: 1 +- in: 126-fuzz.in + out: 126-fuzz.ans + points: 1 +- in: 127-fuzz.in + out: 127-fuzz.ans + points: 1 +- in: 128-fuzz.in + out: 128-fuzz.ans + points: 1 +- in: 129-fuzz.in + out: 129-fuzz.ans + points: 1 +- in: 130-fuzz.in + out: 130-fuzz.ans + points: 1 +- in: 131-fuzz.in + out: 131-fuzz.ans + points: 1 +- in: 132-fuzz.in + out: 132-fuzz.ans + points: 1 +- in: 133-fuzz.in + out: 133-fuzz.ans + points: 1 +- in: 134-fuzz.in + out: 134-fuzz.ans + points: 1 +- in: 135-fuzz.in + out: 135-fuzz.ans + points: 1 +- in: 136-fuzz.in + out: 136-fuzz.ans + points: 1 +- in: 137-fuzz.in + out: 137-fuzz.ans + points: 1 +- in: 138-fuzz.in + out: 138-fuzz.ans + points: 1 +- in: 139-fuzz.in + out: 139-fuzz.ans + points: 1 +- in: 140-fuzz.in + out: 140-fuzz.ans + points: 1 +- in: 141-fuzz.in + out: 141-fuzz.ans + points: 1 +- in: 142-fuzz.in + out: 142-fuzz.ans + points: 1 +- in: 143-fuzz.in + out: 143-fuzz.ans + points: 1 +- in: 144-fuzz.in + out: 144-fuzz.ans + points: 1 +- in: 145-fuzz.in + out: 145-fuzz.ans + points: 1 +- in: 146-fuzz.in + out: 146-fuzz.ans + points: 1 +- in: 147-fuzz.in + out: 147-fuzz.ans + points: 1 +- in: 148-fuzz.in + out: 148-fuzz.ans + points: 1 +- in: 149-fuzz.in + out: 149-fuzz.ans + points: 1 +- in: 150-fuzz.in + out: 150-fuzz.ans + points: 1 +- in: 151-fuzz.in + out: 151-fuzz.ans + points: 1 +- in: 152-fuzz.in + out: 152-fuzz.ans + points: 1 +- in: 153-fuzz.in + out: 153-fuzz.ans + points: 1 +- in: 154-fuzz.in + out: 154-fuzz.ans + points: 1 +- in: 155-fuzz.in + out: 155-fuzz.ans + points: 1 +- in: 156-fuzz.in + out: 156-fuzz.ans + points: 1 +- in: 157-fuzz.in + out: 157-fuzz.ans + points: 1 +- in: 158-anti-two-step.in + out: 158-anti-two-step.ans + points: 1 +- in: 159-anti-two-step.in + out: 159-anti-two-step.ans + points: 1 +- in: 160-anti-two-step.in + out: 160-anti-two-step.ans + points: 1 +- in: 161-anti-two-step.in + out: 161-anti-two-step.ans + points: 1 +- in: 162-anti-two-step.in + out: 162-anti-two-step.ans + points: 1 diff --git a/ICPC/nwerc2022_L/output_validators/validate/output-validator.cc b/ICPC/nwerc2022_L/output_validators/validate/output-validator.cc new file mode 100644 index 0000000000000000000000000000000000000000..7f3428595ed280832a9791257ab86d4d9512268f --- /dev/null +++ b/ICPC/nwerc2022_L/output_validators/validate/output-validator.cc @@ -0,0 +1,86 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include +#include +#include "validation.h" + +std::string wordle_query(std::string query, std::string answer) { + int n = std::size(query); + std::string res(n, 'B'); + + std::array count = {}; + for (char c: answer) count[c-'a']++; + + // place green tiles + for (int i = 0; i < n; i++) { + if (query[i] == answer[i]) { + res[i] = 'G'; + count[query[i]-'a']--; + } + } + + // place yellow tiles + for (int i = 0; i < n; i++) { + if (res[i] != 'G' && count[query[i]-'a'] > 0) { + count[query[i]-'a']--; + res[i] = 'Y'; + } + } + + return res; +} + +int main(int argc, char **argv) { + std::ifstream in(argv[1]); + OutputValidator v(argc, argv); + + int m, n; + in >> m >> n; + + std::vector words(m-1), colors(m-1); + for (int i = 0; i < m-1; i++) { + in >> words[i] >> colors[i]; + } + + std::string all_letters = std::string(26, 'a') + std::string(26, 'A'); + for (int i = 0; i < 26; i++) { + all_letters[i] += i; + all_letters[26+i] += i; + } + + // TODO: extend validation.h with case insensitivity? + std::string answer = v.read_string("word", n, n, all_letters); + for (char& c : answer) c |= 0x20; + v.newline(); + + for (int i = 0; i < m-1; i++) { + v.check(wordle_query(words[i], answer) == colors[i], + "Wrong answer: does not fit word ", i); + } +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2022_L/output_validators/validate/validation.h b/ICPC/nwerc2022_L/output_validators/validate/validation.h new file mode 100644 index 0000000000000000000000000000000000000000..a12961a6605a90b83e02bec0c8f9c0e72626ebb2 --- /dev/null +++ b/ICPC/nwerc2022_L/output_validators/validate/validation.h @@ -0,0 +1,1520 @@ +#pragma once +// A header library to safely parse team input. +// It does not support floating points or big integers. +// Author: Ragnar Groot Koerkamp + +// The easiest way to use this is to symlink it from a validator directory, +// so that it will be picked up when creating a contest zip. + +// The default checking behaviour is lenient for both white space and case. +// When validating .in and .ans files, the case_sensitive and +// space_change_sensitive flags should be passed. When validating team output, +// the flags in problem.yaml should be used. + +// Compile with -Duse_source_location to enable +// std::experimental::source_location. This is needed for constraints checking. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef use_source_location +#include +constexpr bool has_source_location = true; +using std::experimental::source_location; +namespace std { +bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +} // namespace std +namespace std::experimental::fundamentals_v2 { +bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +} // namespace std::experimental::fundamentals_v2 +#else +constexpr bool has_source_location = false; +struct source_location { + static source_location current() { return {}; } + [[nodiscard]] int line() const { return 0; } // NOLINT + [[nodiscard]] std::string file_name() const { return ""; } // NOLINT +}; +inline bool operator<(const source_location& l, const source_location& r) { + return l.line() < r.line(); +} +#endif + +inline std::string location_to_string(source_location loc) { + return std::string(loc.file_name()) + ":" + std::to_string(loc.line()); +} + +const std::string_view case_sensitive_flag = "case_sensitive"; +const std::string_view ws_sensitive_flag = "space_change_sensitive"; +const std::string_view constraints_file_flag = "--constraints_file"; +const std::string_view generate_flag = "--generate"; +const std::string_view generate_binary_substring = "generat"; + +inline struct ArbitraryTag { + static constexpr bool unique = false; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Arbitrary; +inline struct UniqueTag : ArbitraryTag { + static constexpr bool unique = true; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Unique; +inline struct IncreasingTag : ArbitraryTag { static constexpr bool increasing = true; } Increasing; +inline struct DecreasingTag : ArbitraryTag { static constexpr bool decreasing = true; } Decreasing; +inline struct StrictlyIncreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool increasing = true; +} StrictlyIncreasing; +inline struct StrictlyDecreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool decreasing = true; +} StrictlyDecreasing; + +template +struct Merge : T... { + static constexpr bool unique = (T::unique || ...); + static constexpr bool strict = (T::strict || ...); + static constexpr bool increasing = (T::increasing || ...); + static constexpr bool decreasing = (T::decreasing || ...); +}; + +template and std::is_base_of_v, int> = 0> +auto operator|(T1 /*unused*/, T2 /*unused*/) { + return Merge(); +} + +enum Separator { Space, Newline }; + +// this contains some specific code which emulates c++20 features +namespace cpp20 { + +constexpr int countl_zero(unsigned long long x) { + int res = 64; + for(int i = 32; i > 0; i >>= 1) { + if((x >> i) > 0) { + res -= i; + x >>= i; + } + } + if(x > 0) res--; + return res; +} + +int popcount(unsigned long long x) { + return static_cast(std::bitset<64>(x).count()); +} + +constexpr long double PI = 3.141592653589793238462643383279502884l; + +} // namespace cpp20 + +namespace Random { + +constexpr unsigned int default_seed = 3141592653; // some digits of PI + +unsigned long long bits64(std::mt19937_64& rng) { + static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull); + static_assert(std::mt19937_64::min() == 0ull); + return rng(); +} + +// generates a uniform real in [0, 1) +long double real64(std::mt19937_64& rng) { + // a long double can represent more than 2^64 values in the range [0, 1)... + // another problem is that real64() < 1.0/3.0 is technically biased. + long double res = bits64(rng) / 0x1.0p64l; + res += bits64(rng) / 0x1.0p128l; + assert(res < 1.0l); + return res; +} + +bool bit(std::mt19937_64& rng) { + return cpp20::popcount(bits64(rng)) & 1; +} + +} // namespace Random + +template +constexpr bool is_number_v = std::is_same_v or std::is_same_v; + +namespace Generators { + +template +struct ConstGenerator { + static_assert(is_number_v or std::is_same_v or std::is_same_v); + static constexpr std::string_view name = "const"; + using Args = std::tuple; + + const T const_; + + explicit ConstGenerator(T val) : const_(std::move(val)) {} + + // For char and string, the constant store has a different type than the min and max length + // passed in. + template + T operator()(U low, U high, std::mt19937_64& rng) const { + return std::clamp(const_, low, high); + } +}; + +struct MinGenerator { + static constexpr std::string_view name = "min"; + using Args = std::tuple<>; + + explicit MinGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return low; + } +}; + +struct MaxGenerator { + static constexpr std::string_view name = "max"; + using Args = std::tuple<>; + + explicit MaxGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return high; + } +}; + +struct UniformGenerator { + static constexpr std::string_view name = "uniform"; + using Args = std::tuple<>; + + explicit UniformGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + if(low == high) return low; + + if constexpr(std::is_same_v) { + assert(low < high); + // Since C++20 we can assume Two's Complement but any sane system used it before anyway. + // Rejection sampling is not as fast as possible but definitely unbiased. + auto ul = static_cast(low); + auto uh = static_cast(high); + int shifts = cpp20::countl_zero(uh - ul); + unsigned long long res; + do { + res = Random::bits64(rng) >> shifts; + } while(res > uh - ul); + return static_cast(res + ul); + } else { + assert(low < high); + return low + Random::real64(rng) * (high - low); + } + } +}; + +template +struct RangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "range"; + using Args = std::tuple; + + const T low_, high_; + + explicit RangeGenerator(T low, T high) : low_(low), high_(high) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng); + } +}; + +template +struct StepRangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "steprange"; + using Args = std::tuple; + + const T low_, high_, step_; + + explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + // round up low to the first multiple of step_. + T start; + if(low <= low_) { + start = low_; + } else { + // first multiple of low_+k*step_ >= low + start = low_ + (long long)((low - low_) / step_) * step_; + if(start < low) start += step_; + assert(low <= start && start < low + step_); + } + long long maxsteps = (std::min(high, high_) - start) / step_; + long long steps = UniformGenerator()(0ll, maxsteps, rng); + return start + steps * step_; + } +}; + +struct NormalDistributionGenerator { + static constexpr std::string_view name = "normal"; + using T = long double; + using Args = std::tuple; + + const T mean_, stddev_; + + explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) { + assert(stddev_ >= 0); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + T u1 = Random::real64(rng); + T u2 = Random::real64(rng); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + } + return v; + } +}; + +struct ExponentialDistributionGenerator { + static constexpr std::string_view name = "exponential"; + using T = long double; + using Args = std::tuple; + + T lambda_; + + explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + v = low - std::log(Random::real64(rng)) / lambda_; + if(v < high) return v; + } + } +}; + +struct GeometricDistributionGenerator { + static constexpr std::string_view name = "geometric"; + using T = long long; + using Args = std::tuple; + + double p_; + + explicit GeometricDistributionGenerator(double p) : p_(p) { + assert(p_ > 0); + assert(p_ < 1); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + T v; + while(true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric + // distribution[...]" + v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_)); + if(v <= high) return v; + } + } +}; + +struct BinomialDistributionGenerator { + static constexpr std::string_view name = "binomial"; + using T = long long; + using Args = std::tuple; + + long long n_; + double p_; + + explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) { + assert(p_ >= 0); + assert(p_ <= 1); + std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!" + << std::endl; + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + // this will be slow for large n + // (a faster implementation requires efficient poisson sampling) + while(true) { + T v = 0; + for(long long i = 0; i < n_; i++) { + v += Random::real64(rng) < p_ ? 1 : 0; + } + if(v >= low && v <= high) return v; + } + } +}; + +template +struct ChoiceGenerator { + using GeneratorType = std::conditional_t< + std::is_same_v, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, GeometricDistributionGenerator, + BinomialDistributionGenerator>, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, NormalDistributionGenerator, + ExponentialDistributionGenerator>>; + + std::vector> generators_; + double total_weight_; + + template + struct Pack {}; + + template + static A parse_number(std::string_view s) { + static_assert(is_number_v); + if constexpr(std::is_same_v) + return stoll(std::string(s)); + else + return stold(std::string(s)); + } + + template + static A parse_argument(std::string_view& s) { + auto end = s.find_first_of(",)"); + assert(end != std::string_view::npos); + auto v = parse_number(s.substr(0, end)); + s.remove_prefix(end); + // Pop the trailing , or ) + s.remove_prefix(1); + return v; + } + + template + static std::tuple parse_arguments(std::string_view& s, + Pack> /*unused*/) { + std::tuple args{parse_argument(s)...}; + return args; + } + + // Try parsing one generator type from the start of s. + template + static void parse_generator(std::string_view& s, std::optional& out) { + if(out) return; + if(s.substr(0, G::name.size()) != G::name) return; + + // Drop the name. + s.remove_prefix(G::name.size()); + if constexpr(std::tuple_size_v == 0) { + out.emplace(std::in_place_type_t{}); + return; + } + + // Drop the ( + assert(not s.empty() and s.front() == '('); + s.remove_prefix(1); + + auto args = parse_arguments(s, Pack{}); + // Construct the resulting generator in-place in the variant.. + std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t{}, _args...); }, + args); + } + + template + static std::optional parse_generators(std::string_view& s, + Pack> /*unused*/) { + std::optional out; + (parse_generator(s, out), ...); + return out; + } + + explicit ChoiceGenerator(std::string_view s) : total_weight_(0) { + // PARSE + while(not s.empty()) { + auto generator = parse_generators(s, Pack{}); + if(!generator) { + // Check for range syntax: + auto comma = s.find_first_of(",:"); + if(comma == std::string::npos) comma = s.size(); + auto dots = s.find(".."); + if(dots != std::string_view::npos and dots < comma) { + auto start = s.substr(0, dots); + auto end = s.substr(dots + 2, comma - dots - 2); + + generator.emplace(std::in_place_type_t>{}, + parse_number(start), parse_number(end)); + s.remove_prefix(comma); + } + + // Fall back to constant. + if(!generator) { + generator.emplace(std::in_place_type_t>{}, + parse_number(s.substr(0, comma))); + s.remove_prefix(comma); + } + } + + // Parse weight if given. + double weight = 1; + if(not s.empty() and s.front() == ':') { + s.remove_prefix(1); + auto comma = s.find(','); + if(comma == std::string_view::npos) comma = s.size(); + weight = parse_number(s.substr(0, comma)); + s.remove_prefix(comma); + } + + // should now be at , or end + assert(s.empty() or s.front() == ','); + if(not s.empty()) s.remove_prefix(1); + generators_.emplace_back(std::move(*generator), weight); + total_weight_ += weight; + } + } + + T operator()(T low, T high, std::mt19937_64& rng) const { + Generators::UniformGenerator uniform; + double x = uniform.operator()(0, total_weight_, rng); + for(size_t i = 0; i < generators_.size(); ++i) { + x -= generators_[i].second; + if(x <= 0) + return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first); + } + assert(false); + } +}; + +struct ParamGenerator { + std::variant, ChoiceGenerator> + generator; + explicit ParamGenerator(std::string_view s) : generator(s) {} + + template + T operator()(T low, T high, std::mt19937_64& rng) { + static_assert(is_number_v); + if(std::holds_alternative(generator)) { + generator = ChoiceGenerator(std::get(generator)); + } + return std::get>(generator)(low, high, rng); + } +}; + +} // namespace Generators + +using Generators::ParamGenerator; + +namespace Random { +template +void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) { + Generators::UniformGenerator uniform; + long long n = last - first; + for(long long i = n - 1; i > 0; i--) { + std::swap(first[i], first[uniform(0ll, i, rng)]); + } +} + +template +void shuffle(std::pair& in, std::mt19937_64& rng) { + if(bit(rng)) std::swap(in.first, in.second); +} + +template +auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) { + assert(first != last); + Generators::UniformGenerator uniform; + long long n = last - first; + return first[uniform(0ll, n - 1, rng)]; +} + +template +const T& select(const std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +template +T& select(std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +} // namespace Random + +class Validator { + protected: + Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "", + std::optional seed = std::nullopt, + std::unordered_map params_ = {}) + : in(in_), ws(ws_), case_sensitive(case_), + constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()), + rng(seed.value_or(Random::default_seed)), params(std::move(params_)) { + + std::ios_base::sync_with_stdio(false); + in.tie(nullptr); + + if(gen) return; + if(ws) + in >> std::noskipws; + else + in >> std::skipws; + + if(!constraints_file_path.empty()) { + assert(has_source_location); // NOLINT + } + } + + public: + // No copying, no moving. + Validator(const Validator&) = delete; + Validator(Validator&&) = delete; + void operator=(const Validator&) = delete; + void operator=(Validator&&) = delete; + + // At the end of the scope, check whether the EOF has been reached. + // If so, return AC. Otherwise, return WA. + ~Validator() { + eof(); + write_constraints(); + AC(); + } + + void space() { + if(gen) { + out << ' '; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected space, found EOF."); + if(c != ' ') + expected("space", std::string("\"") + + ((c == '\n' or c == '\r') ? std::string("newline") + : std::string(1, c)) + + "\""); + } + } + + void newline() { + if(gen) { + out << '\n'; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected newline, found EOF."); + if(c != '\n') { + if(c == '\r') + expected("newline", "DOS line ending (\\r)"); + else + expected("newline", std::string("\"") + c + "\""); + } + } + } + + private: + void separator(Separator s) { + switch(s) { + case Separator::Space: space(); break; + case Separator::Newline: newline(); break; + } + } + + template + auto& seen() { + static std::map> seen; + return seen; + } + template + auto& last_seen() { + static std::map last_seen; + return last_seen; + } + template + auto& integers_seen() { + static std::map, std::vector, bool>> + integers_seen; + return integers_seen; + } + template + void reset(source_location loc) { + seen().erase(loc); + last_seen().erase(loc); + integers_seen().erase(loc); + } + + template + void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/, + source_location loc) { + static_assert(is_number_v); + if(v < low or v > high) { + std::string type_name; + if constexpr(std::is_integral_v) { + type_name = "integer"; + } + if constexpr(std::is_floating_point_v) { + type_name = "float"; + } + expected(name + ": " + type_name + " between " + std::to_string(low) + " and " + + std::to_string(high), + std::to_string(v)); + } + log_constraint(name, low, high, v, loc); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[loc].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else { + auto [it, inserted] = last_seen().emplace(loc, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + template + void check_string(const std::string& name, int low, int high, const std::string& v, + Tag /*unused*/, source_location loc) { + using T = std::string; + if((int) v.size() < low or (int) v.size() > high) { + expected(name + ": " + "string with" + " length between " + std::to_string(low) + + " and " + std::to_string(high), + v); + } + log_constraint(name, low, high, static_cast(v.size()), loc); + if constexpr(Tag::unique) { + // static map> seen; + auto [it, inserted] = seen()[loc].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else if(Tag::increasing or Tag::decreasing) { + // static map last_seen; + auto [it, inserted] = last_seen().emplace(loc, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + // Generate a random integer in [low, high] or float in [low, high). + template + T uniform_number(T low, T high) { + assert(low <= high); + Generators::UniformGenerator uniform; + if constexpr(std::is_integral::value) + return uniform.operator()(low, high, rng); + else + return uniform.operator()(low, high, rng); + } + + template + T gen_number(const std::string& name, T low, T high, Tag /*unused*/, source_location loc) { + static_assert(is_number_v); + T v; + + if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + if constexpr(std::is_integral::value) { + auto& [seen_here, remaining_here, use_remaining] = integers_seen()[loc]; + + if(use_remaining) { + check(!remaining_here.empty(), name, ": no unique values left"); + v = remaining_here.back(); + remaining_here.pop_back(); + } else { + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + + struct CountIterator { + T v; + T& operator*() { return v; } + T& operator++() { return ++v; } + T operator++(int) { return v++; } + bool operator!=(CountIterator r) { return v != r.v; } + }; + + if(seen_here.size() > (high - low) / 2) { + use_remaining = true; + set_difference(CountIterator{low}, CountIterator{high + 1}, + seen_here.begin(), seen_here.end(), + std::back_inserter(remaining_here)); + } + } + } else { + // For floats, just regenerate numbers until success. + auto& seen_here = seen()[loc]; + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + } + + } else { + assert(not Tag::increasing && "Generating increasing sequences is not yet supported!"); + assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!"); + assert((std::is_same::value) && + "Only Unique and Arbitrary are supported!"); + + if(params.find(name) != params.end()) { + v = params.at(name).operator()(low, high, rng); + // This will be checked during input validation of the generated case. + // assert(low <= v and v <= high); + } else { + v = uniform_number(low, high); + } + } + + return v; + } + + std::string gen_string(const std::string& name, long long low, long long high, + std::string_view chars) { + assert(!chars.empty()); + + int len; + if(params.find(name + ".length") != params.end()) + len = params.at(name + ".length").operator()(low, high, rng); + else + len = uniform_number(low, high); + std::string s(len, ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s; + return s; + } + + public: + template + long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_number(name, low, high, tag, loc); + } + + template + long double gen_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}, source_location loc = source_location::current()) { + return gen_number(name, low, high, tag, loc); + } + + private: + template + std::vector gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/, + source_location loc) { + static_assert(is_number_v); + std::vector v; + v.reserve(count); + if constexpr(std::is_same_v) { + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + } else if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + std::set seen_here; + if constexpr(std::is_integral_v) { + if(2 * count < high - low) { + for(int i = 0; i < count; ++i) { + // If density < 1/2: retry. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } else { + // If density >= 1/2, crop a random permutation. + v.resize(high - low + 1); + iota(begin(v), end(v), low); + Random::shuffle(begin(v), end(v), rng); + v.resize(count); + } + } else { + for(int i = 0; i < count; ++i) { + // For floats, just regenerate numbers until success. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + constexpr bool integral_strict = Tag::strict and std::is_integral::value; + if(integral_strict) { + assert(params.find(name) == params.end() && + "Parameters are not supported for strict integer values."); + high = high - count + 1; + } + + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + + sort(begin(v), end(v)); + + if(integral_strict) { + for(int i = 0; i < count; ++i) v[i] += i; + } + + if(Tag::decreasing) reverse(begin(v), end(v)); + } + + return v; + } + + public: + template + std::vector gen_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_numbers(name, count, low, high, tag, loc); + } + + template + std::vector gen_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return gen_numbers(name, count, low, high, tag, loc); + } + + private: + template + T read_number(const std::string& name, T low, T high, Tag tag, source_location loc) { + if(gen) { + auto v = gen_number(name, low, high, tag, loc); + out << std::setprecision(10) << std::fixed << v; + return v; + } + + const auto v = [&] { + if constexpr(std::is_integral::value) + return read_integer(name); + else + return read_float(name); + }(); + + check_number(name, low, high, v, tag, loc); + return v; + } + + // Read a vector of numbers, separated by spaces and ended by a newline. + template + std::vector read_numbers(const std::string& name, int count, T low, T high, Tag tag, + Separator sep, source_location loc) { + if(gen) { + auto v = gen_numbers(name, count, low, high, tag, loc); + + out << std::setprecision(10) << std::fixed; + for(int i = 0; i < count; ++i) { + out << v[i]; + if(i < count - 1) separator(sep); + } + newline(); + + return v; + } + reset(loc); + std::vector v(count); + for(int i = 0; i < count; ++i) { + if constexpr(std::is_integral::value) + v[i] = read_integer(name); + else + v[i] = read_float(name); + check_number(name, low, high, v[i], tag, loc); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + public: + template + long long read_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}, + source_location loc = source_location::current()) { + return read_number(name, low, high, tag, loc); + } + template + std::vector read_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, Separator sep = Space, + source_location loc = source_location::current()) { + return read_numbers(name, count, low, high, tag, sep, loc); + } + + template + long double read_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}, source_location loc = source_location::current()) { + return read_number(name, low, high, tag, loc); + } + template + std::vector read_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, Separator sep = Space, + source_location loc = source_location::current()) { + return read_numbers(name, count, low, high, tag, sep, loc); + } + + // Read a vector of strings, separated by spaces and ended by a newline. + template + std::vector read_strings(const std::string& name, int count, int min, int max, + const std::string_view chars = "", Tag tag = Tag(), + Separator sep = Space, + source_location loc = source_location::current()) { + reset(loc); + if(gen) return gen_strings(name, count, min, max, chars, tag, sep, loc); + assert(!gen); + std::vector v(count); + for(int i = 0; i < count; ++i) { + v[i] = read_string(name, min, max, chars, tag, loc); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + template + std::vector gen_strings(const std::string& name, int count, int min, int max, + const std::string_view chars, Tag /*unused*/, + Separator sep, source_location loc) { + assert(!chars.empty()); + + std::vector v(count); + if constexpr(std::is_same::value) { + for(int i = 0; i < count; ++i) { + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else if constexpr(Tag::unique) { + std::set seen_here; + for(int i = 0; i < count; ++i) { + // Just regenerate strings until success. + std::string s; + do { + s = std::string(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + } while(!seen_here.insert(s).second); + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + assert(false && "Generating increasing/decreasing lists of strings is not " + "supported!"); + } + + newline(); + + return v; + } + + // Check the next character. + bool peek(char c, const std::string& name = "") { + if(gen) { + // TODO + // if(not name.empty() and params.contains(name)) { + // return c == params.at(name).operator()(0, 0, rng); + //} + return Random::bit(rng); + } + if(!ws) in >> std::ws; + if(case_sensitive) return in.peek() == std::char_traits::to_int_type(c); + return tolower(in.peek()) == tolower(std::char_traits::to_int_type(c)); + } + + // Read a string and make sure it equals `expected`. + // Takes by value because it needs to lowercase its arguments. + std::string test_strings(std::vector expected, const std::string& name = "") { + if(gen) { + int index = 0; + // TODO + // if(not name.empty() and params.contains(name)) { + // auto s = params.at(name).operator()(0, 0, rng); + // index = std::find(expected.begin(), expected.end(), s) - expected.begin(); + // assert(0 <= index and index < expected.size()); + //} else { + index = expected.size() == 1 ? 0 : uniform_number(0, expected.size() - 1); + //} + out << expected[index]; + return expected[index]; + } + std::string s = get_string(); + lowercase(s); + + for(std::string e : expected) + if(s == lowercase(e)) return s; + + std::string error; + for(const auto& e : expected) { + if(not error.empty()) error += "|"; + error += e; + } + WA("Expected string \"", error, "\", but found ", s); + } + + // Read a string and make sure it equals `expected`. + std::string test_string(std::string expected, const std::string& name = "") { + return test_strings({std::move(expected)}, name); + } + + // Read an arbitrary string of a given length. + template + std::string read_string(const std::string& name, long long min, long long max, + const std::string_view chars = "", Tag tag = Tag(), + source_location loc = source_location::current()) { + if(gen) { + return gen_string(name, min, max, chars); + } + std::string s = get_string(); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + check_string(name, min, max, s, tag, loc); + return s; + } + + // Read an arbitrary line of a given length. + std::string read_line(const std::string& name, long long min, long long max, + const std::string_view chars = "", + source_location loc = source_location::current()) { + if(gen) { + // TODO: Params for lines. + assert(!chars.empty()); + + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s << '\n'; + return s; + } + + if(ws) { + char next = in.peek(); + if(min > 0 and isspace(next)) + expected("non empty line", next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected("line", "EOF"); + } + std::string s; + if(!getline(in, s)) expected("line", "nothing"); + long long size = s.size(); + if(size < min || size > max) + expected(name + ": line of length between " + std::to_string(min) + " and " + + std::to_string(max), + s); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + log_constraint(name, min, max, size, loc); + return s; + } + + // Return ACCEPTED verdict. + void eof_and_AC() { + eof(); + AC(); + } + + private: + std::function WA_handler = [] {}; + + public: + void set_WA_handler(std::function f) { WA_handler = std::move(f); } + + // Return WA with the given reason. + template + [[noreturn]] void WA(const Ts&... ts) { + static_assert(sizeof...(Ts) > 0); + + WA_handler(); + + auto pos = get_file_pos(); + std::cerr << pos.first << ":" << pos.second << ": "; + + WA_impl(ts...); + } + + // Check that the condition is true. + template + void check(bool b, const Ts&... ts) { + static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message."); + + if(!b) WA(ts...); + } + + // Log some value in a range. + template + void log_constraint(const std::string& name, T low, T high, T v, + source_location loc = source_location::current()) { + // Do not log when line number is unknown/default/unsupported. + if(loc.line() == 0 or constraints_file_path.empty()) return; + + // All integer types get bounds as long long, all floating point types as long_double. + using U = Bounds, long long, long double>>; + + auto [it, inserted] = bounds.emplace(loc, U(name, v, v, low, high)); + assert(std::holds_alternative(it->second)); + auto& done = std::get(it->second); + if(inserted) { + assert(!name.empty() && "Variable names must not be empty."); + assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces."); + } else { + assert(name == done.name && "Variable name must be constant."); + } + if(v < done.min) { + done.min = v; + done.low = low; + } + if(v > done.max) { + done.max = v; + done.high = high; + } + done.has_min |= v == low; + done.has_max |= v == high; + } + + private: + long long read_integer(const std::string& name) { + assert(!gen); + std::string s = get_string("integer"); + if(s.empty()) { + WA(name, ": Want integer, found nothing"); + } + long long v; + auto begin = s.c_str(), end = begin + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, v); + if(ec == std::errc::result_out_of_range){ + WA(name, ": Number " + s + " does not fit in a long long!"); + } else if(ptr != end) { + WA(name, ": Parsing " + s + " as long long failed! Did not process all characters"); + } else if (ec != std::errc{}) { + WA(name, ": Parsing " + s + " as long long failed!"); + } + // Check for leading zero. + if(v == 0) { + if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s); + } + if(v > 0) { + if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + if(v < 0) { + if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s); + if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + return v; + } + + long double read_float(const std::string& name) { + assert(!gen); + std::string s = get_string("long double"); + long double v; + try { + size_t chars_processed; + v = stold(s, &chars_processed); + if(chars_processed != s.size()) + WA(name, ": Parsing ", s, + " as long double failed! Did not process all characters."); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long double!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long double failed!"); + } + return v; + } + + [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") { + assert(!gen && "Expected is not supported for generators."); + if(!s.empty()) + WA("Expected ", exp, ", found ", s); + else + WA(exp); + } + + template + [[noreturn]] void WA_impl(T t) { + std::cerr << t << std::endl; + exit(ret_WA); + } + + std::pair get_file_pos() { + int line = 1, col = 0; + in.clear(); + auto originalPos = in.tellg(); + if(originalPos < 0) return {-1, -1}; + in.seekg(0); + char c; + while((in.tellg() < originalPos) && in.get(c)) { + if(c == '\n') + ++line, col = 0; + else + ++col; + } + return {line, col}; + } + + template + [[noreturn]] void WA_impl(T t, Ts... ts) { + std::cerr << t; + WA_impl(ts...); + } + + std::string get_string(const std::string& wanted = "string") { + assert(!gen && "get_string is not supported for generators."); + if(ws) { + char next = in.peek(); + if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected(wanted, "EOF"); + } + + std::string s; + if(in >> s) { + return s; + } + expected(wanted, "nothing"); + } + + // Return ACCEPTED verdict. + void AC() const { + if(gen) { + // nothing + return; + } + + exit(ret_AC); + } + + void eof() { + if(gen) { + out.flush(); + fclose(stdout); + return; + } + if(in.eof()) return; + // Sometimes EOF hasn't been triggered yet. + if(!ws) in >> std::ws; + char c = in.get(); + if(c == std::char_traits::eof()) return; + std::string got = std::string("\"") + char(c) + '"'; + if(c == '\n') got = "newline"; + expected("EOF", got); + } + + // Convert a string to lowercase is matching is not case sensitive. + std::string& lowercase(std::string& s) const { + if(case_sensitive) return s; + transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; + } + + // Keep track of the min/max value read at every call site. + template + struct Bounds { + Bounds(std::string name_, T min_, T max_, T low_, T high_) + : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT + std::string name; + T min, max; // Smallest / largest value observed + T low, high; // Bounds + bool has_min = false, has_max = false; + }; + + std::map, Bounds>> bounds; + + void write_constraints() { + if(constraints_file_path.empty()) return; + + std::ofstream os(constraints_file_path); + + for(const auto& [location, bound] : bounds) { + os << location_to_string(location) << " "; + std::visit( + [&](const auto& b) { + os << b.name << " " << b.has_min << " " << b.has_max << " " << b.min << " " + << b.max << " " << b.low << " " << b.high << std::endl; + }, + bound); + } + } + + static const int ret_AC = 42, ret_WA = 43; + std::istream& in = std::cin; + std::ostream& out = std::cout; + + public: + const bool ws = true; + const bool case_sensitive = true; + const std::string constraints_file_path; + const bool gen = false; + + std::mt19937_64 rng; + + private: + std::unordered_map params; + + public: + std::string_view get_param(std::string_view name, std::string_view default_) { + auto it = params.find(std::string(name)); + if(it == params.end()) return default_; + return std::get(it->second.generator); + } + + protected: + static std::string get_constraints_file(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == constraints_file_flag) { + if(i + 1 < argc) return argv[i + 1]; + std::cerr << constraints_file_flag << " should be followed by a file path!"; + exit(1); + } + } + return {}; + } +}; + +class Generator : public Validator { + public: + explicit Generator(unsigned int seed) + : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {} +}; + +class InputValidator : public Validator { + public: + // An InputValidator is always both whitespace and case sensitive. + explicit InputValidator(int argc = 0, char** argv = nullptr) + : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv), + get_params(argc, argv)) {} + + private: + static std::optional get_seed(int argc, char** argv) { + for(int i = 1; i < argc - 1; ++i) { + if(argv[i] == generate_flag) { + return std::stol(argv[i + 1]); + } + } + // If no --generate is given, but `generat` is a substring of the binary path, + // use the first argument as seed. + if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) { + return std::stol(argv[1]); + } + return std::nullopt; + } + + static std::unordered_map get_params(int argc, char** argv) { + std::unordered_map params; + for(int i = 1; i < argc - 1; ++i) { + if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue; + if(argv[i] == generate_flag) { + continue; + } + std::string_view name(argv[i] + 1); + std::string_view value(argv[i + 1]); + params.insert({std::string(name), ParamGenerator(value)}); + } + return params; + } +}; + +class OutputValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_, + get_constraints_file(argc, argv)) {} + + private: + static bool is_ws_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == ws_sensitive_flag) return true; + } + return false; + } + + static bool is_case_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == case_sensitive_flag) return true; + } + return false; + } +}; diff --git a/ICPC/nwerc2023_A/data.zip b/ICPC/nwerc2023_A/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..b6038d85968d76d809c696af0c9f17fb9f6d58db --- /dev/null +++ b/ICPC/nwerc2023_A/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb24aeac8306c68202fc2dde976466ba81c12dfeb111cd2df644468ba06ce0c3 +size 26893358 diff --git a/ICPC/nwerc2023_A/init.yml b/ICPC/nwerc2023_A/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..43960bcba1497b578afa39977689724557189576 --- /dev/null +++ b/ICPC/nwerc2023_A/init.yml @@ -0,0 +1,350 @@ +archive: data.zip +test_cases: +- in: 001-one_plug.in + out: 001-one_plug.ans + points: 1 +- in: 002-one_socket.in + out: 002-one_socket.ans + points: 1 +- in: 003-much_free.in + out: 003-much_free.ans + points: 1 +- in: 004-much_free.in + out: 004-much_free.ans + points: 1 +- in: 005-two_max_length.in + out: 005-two_max_length.ans + points: 1 +- in: 006-greedy_edge_case_small.in + out: 006-greedy_edge_case_small.ans + points: 1 +- in: 007-greedy_edge_case_small.in + out: 007-greedy_edge_case_small.ans + points: 1 +- in: 008-tight-pack.in + out: 008-tight-pack.ans + points: 1 +- in: 009-many_gaps.in + out: 009-many_gaps.ans + points: 1 +- in: 010-greedy_edge_case.in + out: 010-greedy_edge_case.ans + points: 1 +- in: 011-greedy_edge_case.in + out: 011-greedy_edge_case.ans + points: 1 +- in: 012-almost_max_constraints.in + out: 012-almost_max_constraints.ans + points: 1 +- in: 013-almost_max_constraints.in + out: 013-almost_max_constraints.ans + points: 1 +- in: 014-random.in + out: 014-random.ans + points: 1 +- in: 015-random.in + out: 015-random.ans + points: 1 +- in: 016-random.in + out: 016-random.ans + points: 1 +- in: 017-random.in + out: 017-random.ans + points: 1 +- in: 018-random.in + out: 018-random.ans + points: 1 +- in: 019-random.in + out: 019-random.ans + points: 1 +- in: 020-random.in + out: 020-random.ans + points: 1 +- in: 021-random.in + out: 021-random.ans + points: 1 +- in: 022-max_constraints.in + out: 022-max_constraints.ans + points: 1 +- in: 023-almost_max_constraints.in + out: 023-almost_max_constraints.ans + points: 1 +- in: 024-almost_max_constraints.in + out: 024-almost_max_constraints.ans + points: 1 +- in: 025-almost_max_constraints.in + out: 025-almost_max_constraints.ans + points: 1 +- in: 026-greedy_edge_case.in + out: 026-greedy_edge_case.ans + points: 1 +- in: 027-greedy_edge_case.in + out: 027-greedy_edge_case.ans + points: 1 +- in: 028-greedy_edge_case.in + out: 028-greedy_edge_case.ans + points: 1 +- in: 029-greedy_edge_case_small.in + out: 029-greedy_edge_case_small.ans + points: 1 +- in: 030-greedy_edge_case_small.in + out: 030-greedy_edge_case_small.ans + points: 1 +- in: 031-greedy_edge_case_small.in + out: 031-greedy_edge_case_small.ans + points: 1 +- in: 032-greedy_edge_case_small.in + out: 032-greedy_edge_case_small.ans + points: 1 +- in: 033-greedy_edge_case_small.in + out: 033-greedy_edge_case_small.ans + points: 1 +- in: 034-three_type_case.in + out: 034-three_type_case.ans + points: 1 +- in: 035-three_type_case.in + out: 035-three_type_case.ans + points: 1 +- in: 036-three_type_case.in + out: 036-three_type_case.ans + points: 1 +- in: 037-three_type_case.in + out: 037-three_type_case.ans + points: 1 +- in: 038-three_type_case.in + out: 038-three_type_case.ans + points: 1 +- in: 039-two_type_case.in + out: 039-two_type_case.ans + points: 1 +- in: 040-two_type_case.in + out: 040-two_type_case.ans + points: 1 +- in: 041-two_type_case.in + out: 041-two_type_case.ans + points: 1 +- in: 042-two_type_case.in + out: 042-two_type_case.ans + points: 1 +- in: 043-two_type_case.in + out: 043-two_type_case.ans + points: 1 +- in: 044-some_large_plugs.in + out: 044-some_large_plugs.ans + points: 1 +- in: 045-some_large_plugs.in + out: 045-some_large_plugs.ans + points: 1 +- in: 046-some_large_plugs.in + out: 046-some_large_plugs.ans + points: 1 +- in: 047-some_large_plugs.in + out: 047-some_large_plugs.ans + points: 1 +- in: 048-some_large_plugs.in + out: 048-some_large_plugs.ans + points: 1 +- in: 049-some_large_plugs.in + out: 049-some_large_plugs.ans + points: 1 +- in: 050-some_large_plugs.in + out: 050-some_large_plugs.ans + points: 1 +- in: 051-some_large_plugs.in + out: 051-some_large_plugs.ans + points: 1 +- in: 052-some_large_plugs.in + out: 052-some_large_plugs.ans + points: 1 +- in: 053-some_large_plugs.in + out: 053-some_large_plugs.ans + points: 1 +- in: 054-some_large_plugs.in + out: 054-some_large_plugs.ans + points: 1 +- in: 055-some_large_plugs.in + out: 055-some_large_plugs.ans + points: 1 +- in: 056-some_large_plugs.in + out: 056-some_large_plugs.ans + points: 1 +- in: 057-some_modulo_class.in + out: 057-some_modulo_class.ans + points: 1 +- in: 058-some_modulo_class.in + out: 058-some_modulo_class.ans + points: 1 +- in: 059-some_modulo_class.in + out: 059-some_modulo_class.ans + points: 1 +- in: 060-some_modulo_class.in + out: 060-some_modulo_class.ans + points: 1 +- in: 061-some_modulo_class.in + out: 061-some_modulo_class.ans + points: 1 +- in: 062-some_modulo_class.in + out: 062-some_modulo_class.ans + points: 1 +- in: 063-some_modulo_class.in + out: 063-some_modulo_class.ans + points: 1 +- in: 064-some_modulo_class.in + out: 064-some_modulo_class.ans + points: 1 +- in: 065-some_modulo_class.in + out: 065-some_modulo_class.ans + points: 1 +- in: 066-some_modulo_class.in + out: 066-some_modulo_class.ans + points: 1 +- in: 067-some_modulo_class.in + out: 067-some_modulo_class.ans + points: 1 +- in: 068-some_modulo_class.in + out: 068-some_modulo_class.ans + points: 1 +- in: 069-some_modulo_class.in + out: 069-some_modulo_class.ans + points: 1 +- in: 070-some_modulo_class.in + out: 070-some_modulo_class.ans + points: 1 +- in: 071-some_modulo_class.in + out: 071-some_modulo_class.ans + points: 1 +- in: 072-some_modulo_class.in + out: 072-some_modulo_class.ans + points: 1 +- in: 073-some_modulo_class.in + out: 073-some_modulo_class.ans + points: 1 +- in: 074-some_modulo_class.in + out: 074-some_modulo_class.ans + points: 1 +- in: 075-some_modulo_class.in + out: 075-some_modulo_class.ans + points: 1 +- in: 076-some_modulo_class.in + out: 076-some_modulo_class.ans + points: 1 +- in: 077-some_modulo_class.in + out: 077-some_modulo_class.ans + points: 1 +- in: 078-some_modulo_class.in + out: 078-some_modulo_class.ans + points: 1 +- in: 079-some_modulo_class.in + out: 079-some_modulo_class.ans + points: 1 +- in: 080-some_modulo_class.in + out: 080-some_modulo_class.ans + points: 1 +- in: 081-some_modulo_class.in + out: 081-some_modulo_class.ans + points: 1 +- in: 082-some_modulo_class.in + out: 082-some_modulo_class.ans + points: 1 +- in: 083-some_modulo_class.in + out: 083-some_modulo_class.ans + points: 1 +- in: 084-some_modulo_class.in + out: 084-some_modulo_class.ans + points: 1 +- in: 085-some_modulo_class.in + out: 085-some_modulo_class.ans + points: 1 +- in: 086-some_modulo_class.in + out: 086-some_modulo_class.ans + points: 1 +- in: 087-some_modulo_class.in + out: 087-some_modulo_class.ans + points: 1 +- in: 088-some_modulo_class.in + out: 088-some_modulo_class.ans + points: 1 +- in: 089-some_modulo_class.in + out: 089-some_modulo_class.ans + points: 1 +- in: 090-some_modulo_class.in + out: 090-some_modulo_class.ans + points: 1 +- in: 091-some_modulo_class.in + out: 091-some_modulo_class.ans + points: 1 +- in: 092-some_modulo_class.in + out: 092-some_modulo_class.ans + points: 1 +- in: 093-some_modulo_class.in + out: 093-some_modulo_class.ans + points: 1 +- in: 094-some_modulo_class.in + out: 094-some_modulo_class.ans + points: 1 +- in: 095-some_modulo_class.in + out: 095-some_modulo_class.ans + points: 1 +- in: 096-some_modulo_class.in + out: 096-some_modulo_class.ans + points: 1 +- in: 097-some_modulo_class.in + out: 097-some_modulo_class.ans + points: 1 +- in: 098-some_modulo_class.in + out: 098-some_modulo_class.ans + points: 1 +- in: 099-some_modulo_class.in + out: 099-some_modulo_class.ans + points: 1 +- in: 100-some_modulo_class.in + out: 100-some_modulo_class.ans + points: 1 +- in: 101-some_modulo_class.in + out: 101-some_modulo_class.ans + points: 1 +- in: 102-some_modulo_class.in + out: 102-some_modulo_class.ans + points: 1 +- in: 103-some_modulo_class.in + out: 103-some_modulo_class.ans + points: 1 +- in: 104-some_modulo_class.in + out: 104-some_modulo_class.ans + points: 1 +- in: 105-some_modulo_class.in + out: 105-some_modulo_class.ans + points: 1 +- in: 106-some_modulo_class.in + out: 106-some_modulo_class.ans + points: 1 +- in: 107-some_modulo_class.in + out: 107-some_modulo_class.ans + points: 1 +- in: 108-some_modulo_class.in + out: 108-some_modulo_class.ans + points: 1 +- in: 109-some_modulo_class.in + out: 109-some_modulo_class.ans + points: 1 +- in: 110-some_modulo_class.in + out: 110-some_modulo_class.ans + points: 1 +- in: 111-some_modulo_class.in + out: 111-some_modulo_class.ans + points: 1 +- in: 112-some_modulo_class.in + out: 112-some_modulo_class.ans + points: 1 +- in: 113-some_modulo_class.in + out: 113-some_modulo_class.ans + points: 1 +- in: 114-some_modulo_class.in + out: 114-some_modulo_class.ans + points: 1 +- in: 115-some_modulo_class.in + out: 115-some_modulo_class.ans + points: 1 +- in: 116-some_modulo_class.in + out: 116-some_modulo_class.ans + points: 1 diff --git a/ICPC/nwerc2023_B/data.zip b/ICPC/nwerc2023_B/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..f1ce48c29f8fed249993603cceb18d0945849780 --- /dev/null +++ b/ICPC/nwerc2023_B/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec6dceb011ea9328d261a0dfbff0d804afec39333cb02894d8054f26e978da0d +size 22766975 diff --git a/ICPC/nwerc2023_B/init.yml b/ICPC/nwerc2023_B/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac4eecad1e83dac45baad1e405214654db817ce2 --- /dev/null +++ b/ICPC/nwerc2023_B/init.yml @@ -0,0 +1,406 @@ +archive: data.zip +checker: + args: + files: + - output_validators/output_validator/validate.h + - output_validators/output_validator/outputValidator.cpp + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 001-earlyBreak.in + out: 001-earlyBreak.ans + points: 1 +- in: 002-manual_impossible.in + out: 002-manual_impossible.ans + points: 1 +- in: 003-manual_impossible.in + out: 003-manual_impossible.ans + points: 1 +- in: 004-ones_twos.in + out: 004-ones_twos.ans + points: 1 +- in: 005-ones_twos.in + out: 005-ones_twos.ans + points: 1 +- in: 006-ones_twos.in + out: 006-ones_twos.ans + points: 1 +- in: 007-residue.in + out: 007-residue.ans + points: 1 +- in: 008-residue.in + out: 008-residue.ans + points: 1 +- in: 009-residue.in + out: 009-residue.ans + points: 1 +- in: 010-residue.in + out: 010-residue.ans + points: 1 +- in: 011-residue.in + out: 011-residue.ans + points: 1 +- in: 012-residue.in + out: 012-residue.ans + points: 1 +- in: 013-residue.in + out: 013-residue.ans + points: 1 +- in: 014-residue.in + out: 014-residue.ans + points: 1 +- in: 015-residue.in + out: 015-residue.ans + points: 1 +- in: 016-residue.in + out: 016-residue.ans + points: 1 +- in: 017-residue.in + out: 017-residue.ans + points: 1 +- in: 018-residue.in + out: 018-residue.ans + points: 1 +- in: 019-residue.in + out: 019-residue.ans + points: 1 +- in: 020-random.in + out: 020-random.ans + points: 1 +- in: 021-random.in + out: 021-random.ans + points: 1 +- in: 022-random.in + out: 022-random.ans + points: 1 +- in: 023-random.in + out: 023-random.ans + points: 1 +- in: 024-random.in + out: 024-random.ans + points: 1 +- in: 025-useAll.in + out: 025-useAll.ans + points: 1 +- in: 026-useAll.in + out: 026-useAll.ans + points: 1 +- in: 027-useAll.in + out: 027-useAll.ans + points: 1 +- in: 028-unique.in + out: 028-unique.ans + points: 1 +- in: 029-unique.in + out: 029-unique.ans + points: 1 +- in: 030-unique.in + out: 030-unique.ans + points: 1 +- in: 031-unique.in + out: 031-unique.ans + points: 1 +- in: 032-unique.in + out: 032-unique.ans + points: 1 +- in: 033-unique.in + out: 033-unique.ans + points: 1 +- in: 034-many.in + out: 034-many.ans + points: 1 +- in: 035-residue.in + out: 035-residue.ans + points: 1 +- in: 036-residue.in + out: 036-residue.ans + points: 1 +- in: 037-residue.in + out: 037-residue.ans + points: 1 +- in: 038-residue.in + out: 038-residue.ans + points: 1 +- in: 039-residue.in + out: 039-residue.ans + points: 1 +- in: 040-residue.in + out: 040-residue.ans + points: 1 +- in: 041-residue.in + out: 041-residue.ans + points: 1 +- in: 042-residue.in + out: 042-residue.ans + points: 1 +- in: 043-residue.in + out: 043-residue.ans + points: 1 +- in: 044-residue.in + out: 044-residue.ans + points: 1 +- in: 045-residue.in + out: 045-residue.ans + points: 1 +- in: 046-residue.in + out: 046-residue.ans + points: 1 +- in: 047-residue.in + out: 047-residue.ans + points: 1 +- in: 048-manual_possible.in + out: 048-manual_possible.ans + points: 1 +- in: 049-manual_possible.in + out: 049-manual_possible.ans + points: 1 +- in: 050-manual_possible.in + out: 050-manual_possible.ans + points: 1 +- in: 051-manual_possible.in + out: 051-manual_possible.ans + points: 1 +- in: 052-manual_possible.in + out: 052-manual_possible.ans + points: 1 +- in: 053-manual_possible.in + out: 053-manual_possible.ans + points: 1 +- in: 054-manual_possible.in + out: 054-manual_possible.ans + points: 1 +- in: 055-manual_possible.in + out: 055-manual_possible.ans + points: 1 +- in: 056-manual_possible.in + out: 056-manual_possible.ans + points: 1 +- in: 057-manual_possible.in + out: 057-manual_possible.ans + points: 1 +- in: 058-manual_possible.in + out: 058-manual_possible.ans + points: 1 +- in: 059-manual_impossible.in + out: 059-manual_impossible.ans + points: 1 +- in: 060-manual_impossible.in + out: 060-manual_impossible.ans + points: 1 +- in: 061-manual_impossible.in + out: 061-manual_impossible.ans + points: 1 +- in: 062-random.in + out: 062-random.ans + points: 1 +- in: 063-random.in + out: 063-random.ans + points: 1 +- in: 064-random.in + out: 064-random.ans + points: 1 +- in: 065-random.in + out: 065-random.ans + points: 1 +- in: 066-random.in + out: 066-random.ans + points: 1 +- in: 067-random.in + out: 067-random.ans + points: 1 +- in: 068-random.in + out: 068-random.ans + points: 1 +- in: 069-random.in + out: 069-random.ans + points: 1 +- in: 070-random.in + out: 070-random.ans + points: 1 +- in: 071-random.in + out: 071-random.ans + points: 1 +- in: 072-range.in + out: 072-range.ans + points: 1 +- in: 073-range.in + out: 073-range.ans + points: 1 +- in: 074-range.in + out: 074-range.ans + points: 1 +- in: 075-range.in + out: 075-range.ans + points: 1 +- in: 076-range.in + out: 076-range.ans + points: 1 +- in: 077-range.in + out: 077-range.ans + points: 1 +- in: 078-range.in + out: 078-range.ans + points: 1 +- in: 079-range.in + out: 079-range.ans + points: 1 +- in: 080-range.in + out: 080-range.ans + points: 1 +- in: 081-range.in + out: 081-range.ans + points: 1 +- in: 082-range.in + out: 082-range.ans + points: 1 +- in: 083-range.in + out: 083-range.ans + points: 1 +- in: 084-many_same.in + out: 084-many_same.ans + points: 1 +- in: 085-many_same.in + out: 085-many_same.ans + points: 1 +- in: 086-many_same.in + out: 086-many_same.ans + points: 1 +- in: 087-many_same.in + out: 087-many_same.ans + points: 1 +- in: 088-many_same.in + out: 088-many_same.ans + points: 1 +- in: 089-many_same.in + out: 089-many_same.ans + points: 1 +- in: 090-many_same.in + out: 090-many_same.ans + points: 1 +- in: 091-many_same.in + out: 091-many_same.ans + points: 1 +- in: 092-many_same.in + out: 092-many_same.ans + points: 1 +- in: 093-many_same.in + out: 093-many_same.ans + points: 1 +- in: 094-many_same.in + out: 094-many_same.ans + points: 1 +- in: 095-many_same.in + out: 095-many_same.ans + points: 1 +- in: 096-many_same.in + out: 096-many_same.ans + points: 1 +- in: 097-powers_of_two.in + out: 097-powers_of_two.ans + points: 1 +- in: 098-powers_of_two.in + out: 098-powers_of_two.ans + points: 1 +- in: 099-powers_of_two.in + out: 099-powers_of_two.ans + points: 1 +- in: 100-powers_of_two.in + out: 100-powers_of_two.ans + points: 1 +- in: 101-powers_of_three.in + out: 101-powers_of_three.ans + points: 1 +- in: 102-powers_of_three.in + out: 102-powers_of_three.ans + points: 1 +- in: 103-diviors.in + out: 103-diviors.ans + points: 1 +- in: 104-max.in + out: 104-max.ans + points: 1 +- in: 105-max.in + out: 105-max.ans + points: 1 +- in: 106-max.in + out: 106-max.ans + points: 1 +- in: 107-max.in + out: 107-max.ans + points: 1 +- in: 108-min.in + out: 108-min.ans + points: 1 +- in: 109-min.in + out: 109-min.ans + points: 1 +- in: 110-min.in + out: 110-min.ans + points: 1 +- in: 111-min.in + out: 111-min.ans + points: 1 +- in: 112-min.in + out: 112-min.ans + points: 1 +- in: 113-min.in + out: 113-min.ans + points: 1 +- in: 114-small.in + out: 114-small.ans + points: 1 +- in: 115-small.in + out: 115-small.ans + points: 1 +- in: 116-small.in + out: 116-small.ans + points: 1 +- in: 117-small.in + out: 117-small.ans + points: 1 +- in: 118-small.in + out: 118-small.ans + points: 1 +- in: 119-small.in + out: 119-small.ans + points: 1 +- in: 120-small.in + out: 120-small.ans + points: 1 +- in: 121-small.in + out: 121-small.ans + points: 1 +- in: 122-small.in + out: 122-small.ans + points: 1 +- in: 123-small.in + out: 123-small.ans + points: 1 +- in: 124-small.in + out: 124-small.ans + points: 1 +- in: 125-small.in + out: 125-small.ans + points: 1 +- in: 126-small.in + out: 126-small.ans + points: 1 +- in: 127-small.in + out: 127-small.ans + points: 1 +- in: 128-small.in + out: 128-small.ans + points: 1 +- in: 129-small.in + out: 129-small.ans + points: 1 +- in: 130-small.in + out: 130-small.ans + points: 1 +- in: 131-small.in + out: 131-small.ans + points: 1 +- in: 132-small.in + out: 132-small.ans + points: 1 diff --git a/ICPC/nwerc2023_B/output_validators/output_validator/outputValidator.cpp b/ICPC/nwerc2023_B/output_validators/output_validator/outputValidator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6def88c8ffecffebd7ffae1430357e1aca74841d --- /dev/null +++ b/ICPC/nwerc2023_B/output_validators/output_validator/outputValidator.cpp @@ -0,0 +1,104 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validate.h" + +int main(int argc, char **argv) { + OutputValidator::init(argc, argv); // initialize streams, rng and parse arguments + using namespace OutputValidator; + + Integer n = testIn.integer(); + Integer w = testIn.integer(); + auto ws = testIn.integers(n); + std::sort(ws.begin(), ws.end()); + ws.push_back(LARGE); + + auto check = [&](std::vector> wall, std::string_view sol, Verdict v){ + for (auto& row : wall) { + Integer sum = 0; + for (Integer& brick : row) { + if (*std::lower_bound(ws.begin(), ws.end(), brick) != brick) { + juryOut << sol << " solution contains invalid brick: " << brick << v; + } + brick += sum; + sum = brick; + } + if (sum != w) { + juryOut << sol << " solution has invalid row length: " << sum << v; + } + row.pop_back(); + } + Integer a = 0; + Integer b = 0; + while(a < wall[0].size() && b < wall[1].size()) { + if(wall[0][a] < wall[1][b]) + a++; + else if(wall[0][a] > wall[1][b]) + b++; + else + juryOut << sol << " solution is unstable at x=" << wall[0][a] << v; + } + }; + + auto jury = juryAns.string(std::regex("(impossible|possible)", std::regex::icase)); + auto team = teamAns.string(std::regex("(impossible|possible)", std::regex::icase)); + if (caseSensitive) { + if(jury != "possible" && jury != "impossible") juryOut << "wrong case" << FAIL; + if(team != "possible" && team != "impossible") juryOut << "wrong case" << WA; + } + toLower(jury); + toLower(team); + teamAns.newline(); + + if(jury == "possible") { + Integer rows = 2; //juryAns.integer(1, 11); + std::vector> wall(rows); + for (auto& row : wall) { + Integer k = juryAns.integer(1, w+1); + row = juryAns.integers(1, w+1, k); + } + check(wall, "jury", FAIL); + } + if(team == "possible") { + Integer rows = 2; //teamAns.integer(1, 11); + std::vector> wall(rows); + for (auto& row : wall) { + Integer k = teamAns.integer(1, w+1); + teamAns.newline(); + row = teamAns.integers(1, w+1, k); + teamAns.newline(); + } + check(wall, "team", WA); + } + + if(jury == "possible" && team == "impossible") juryOut << "team found no solution but jury did" << WA; + if(team == "possible" && jury == "impossible") juryOut << "jury found no solution but team did" << FAIL; + + teamAns.eof(); + return AC; +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2023_B/output_validators/output_validator/validate.h b/ICPC/nwerc2023_B/output_validators/output_validator/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..73a2289afda07cd2370d02439fb91fea2ee1743b --- /dev/null +++ b/ICPC/nwerc2023_B/output_validators/output_validator/validate.h @@ -0,0 +1,2662 @@ +//============================================================================// +// validate.h // +//============================================================================// +// This header can be used to safely parse team output tokenwise. We support: // +// - string tokens (get converted to lowercase) // +// - integer tokens in [-2^63, 2^63) // +// - float tokens (relative and absolute error of 10^6 is allowed by default) // +// Tokens need to be separated by whitespace (any amount). The following // +// command line flags allow stricter checking: // +// - caseSensitive: string tokens don't get converted to lowercase // +// - space_change_sensitive: tokens need to be separated by the corect // +// amount of whitespaces // +// - FLOAT_{RELATIVE|ABSOLUTE}_TOLERANCE: allowed relative/absolute error // +// // +// This header can also be used to safely verify input files. In this case // +// tokens are case sensitive and all whitespaces have to be checked. Also // +// whitespaces are not interchangeable. // +// // +// This header can be used to generate random numbers in a deterministic and // +// reproducable fashion. (The randomness is consistent across compilers and // +// machines) // +//============================================================================// +// version 2.3.2 // +// https://github.com/mzuenni/icpc-header // +//============================================================================// + +#ifndef VALIDATE_H +#define VALIDATE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//============================================================================// +// Basic definitions and constants // +//============================================================================// +// default types +using Integer = std::int64_t; +using Real = long double; + +// derived types +using UInteger = std::make_unsigned::type; +constexpr Integer operator ""_int(unsigned long long int value) {return static_cast(value);} +constexpr UInteger operator ""_uint(unsigned long long int value) {return static_cast(value);} +constexpr Real operator ""_real(unsigned long long int value) {return static_cast(value);} +constexpr Real operator ""_real(long double value) {return static_cast(value);} + +// settings which can be overwritten before the include! +//#define DOUBLE_FALLBACK +namespace Settings { + namespace details { + using RandomEngine = std::mt19937_64; + constexpr Integer LARGE = 0x3FFF'FFFF'FFFF'FFFF; + constexpr bool DEFAULT_CASE_LOWER = true; + constexpr int DEFAULT_PRECISION = 6; + constexpr Real DEFAULT_EPS = 1e-6_real; + + [[noreturn]] void exitVerdict(int exitCode) { + //throw exitCode; + //quick_exit(exitCode); + std::exit(exitCode); + } + } + using namespace details; +} +// make settings publically available +using Settings::RandomEngine; +using Settings::LARGE; +using Settings::DEFAULT_CASE_LOWER; +using Settings::DEFAULT_PRECISION; +using Settings::DEFAULT_EPS; +using Settings::exitVerdict; + +// useful constants +constexpr std::string_view LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view UPPER = LETTER.substr(0, 26); +constexpr std::string_view LOWER = LETTER.substr(26); +constexpr std::string_view VOWEL = "AEIOUaeiou"; +constexpr std::string_view UPPER_VOWELS = VOWEL.substr(0, 5); +constexpr std::string_view LOWER_VOWELS = VOWEL.substr(5); +constexpr std::string_view CONSONANT = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"; +constexpr std::string_view UPPER_CONSONANT = CONSONANT.substr(0, 26 - 5); +constexpr std::string_view LOWER_CONSONANT = CONSONANT.substr(26 - 5); +constexpr std::string_view ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view UPPER_ALPHA_NUMERIC = ALPHA_NUMERIC.substr(0, 10 + 26); +constexpr std::string_view LOWER_ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view DIGITS = ALPHA_NUMERIC.substr(0, 10); +constexpr std::string_view BRACKETS = "()[]{}<>"; +constexpr char NEWLINE = '\n'; +constexpr char SPACE = ' '; +constexpr char NOSEP = '\0'; +constexpr Real PI = 3.1415926535897932384626433832795028_real; + + +//============================================================================// +// internal definitions and constants // +//============================================================================// +constexpr UInteger DEFAULT_SEED = 3141592653589793238_uint; +constexpr std::string_view CASE_SENSITIVE = "case_sensitive"; +constexpr std::string_view SPACE_SENSITIVE = "space_change_sensitive"; +constexpr std::string_view FLOAT_ABSOLUTE_TOLERANCE = "float_absolute_tolerance"; +constexpr std::string_view FLOAT_RELATIVE_TOLERANCE = "float_relative_tolerance"; +constexpr std::string_view FLOAT_TOLERANCE = "float_tolerance"; +constexpr std::string_view JUDGE_MESSAGE = "null"; +constexpr char DEFAULT_SEPARATOR = SPACE; +constexpr std::string_view EMPTY_COMMAND = ""; +constexpr std::string_view COMMAND_PREFIX = "--"; +constexpr std::string_view CONSTRAINT_COMMAND = "--constraints_file"; +constexpr std::string_view SEED_COMMAND = "--seed"; +constexpr auto REGEX_OPTIONS = std::regex::nosubs | std::regex::optimize; +inline const std::regex INTEGER_REGEX("0|-?[1-9][0-9]*", REGEX_OPTIONS); +inline const std::regex REAL_REGEX("-?(0|([1-9][0-9]*))(\\.[0-9]*)?([eE][+-]?(0|([1-9][0-9]*)))?", REGEX_OPTIONS); +inline const std::regex STRICT_REAL_REGEX("-?(0|([1-9][0-9]*))\\.?[0-9]*", REGEX_OPTIONS); + +static_assert(2'000'000'000'000'000'000_int < LARGE / 2, "LARGE too small"); +static_assert(LARGE <= std::numeric_limits::max() / 2, "LARGE too big"); + +static_assert(-1 == 0xFFFF'FFFF'FFFF'FFFF_int, "Two's complement for signed numbers is required" ); +static_assert(std::is_convertible_v, "Incompatible Integer and UInteger types?!"); +static_assert(std::is_convertible_v, "Incompatible Integer and UInteger types?!"); +static_assert(sizeof(Integer) == sizeof(UInteger), "Incompatible Integer and UInteger types?!"); + +template +constexpr void judgeAssert(bool asserted, std::string_view message) { + if (!asserted) throw T(message.data()); +} + + +//============================================================================// +// SFINAE // +//============================================================================// +namespace details { + template + struct IsContainer : std::false_type {}; + + template + struct IsContainer>()))>> : std::true_type { + using iterator_type = decltype(std::begin(std::declval>())); + using value_type = std::remove_reference_t>()))>; + }; + + template + struct IsStdArray : std::false_type {}; + + template + struct IsStdArray> : std::true_type {}; + + template + struct IsTupleLike : std::false_type {}; + + template + struct IsTupleLike))>> : std::true_type {}; + + template + struct HasOstreamOperator : std::false_type {}; + + template + struct HasOstreamOperator() << std::declval())>> : std::true_type {}; +} + + +//============================================================================// +// Verdicts // +//============================================================================// +struct Verdict final { + int exitCode; + + constexpr explicit Verdict(int exitCode_ = 1) : exitCode(exitCode_) {} + + constexpr operator int() const { + return exitCode; + } + + [[noreturn]] void exit() const { + exitVerdict(exitCode); + } + + friend void operator<<(std::ostream& os, const Verdict& v) { + os << std::endl; + v.exit(); + } +}; + +// default verdicts (we do not support scoring) +constexpr Verdict AC(42); +constexpr Verdict WA(43); +constexpr Verdict PE = WA; +constexpr Verdict FAIL(1); + + +//============================================================================// +// Output streams // +//============================================================================// +class NullStream final : public std::ostream { + class NullBuffer final : public std::streambuf { + protected: + std::streamsize xsputn(const char* /**/, std::streamsize n) override { + return n; + } + int overflow(int c = std::char_traits::eof()) override { + return std::char_traits::not_eof(c); + } + } nullBuffer; +public: + NullStream() : std::ostream(&nullBuffer) {} +}; + +namespace details { + NullStream nullStream; +} + +class OutputStream final { + std::unique_ptr managed; + std::ostream* os; + + void init() { + *os << std::boolalpha; + *os << std::fixed; + *os << std::setprecision(DEFAULT_PRECISION); + } + +public: + OutputStream() : os(&details::nullStream) {} + OutputStream(std::ostream& os_) : os(&os_) {init();} + explicit OutputStream(const std::filesystem::path& path) : managed(std::make_unique(path)), os(managed.get()) { + judgeAssert(managed->good(), "OutputStream: Could not open File: " + path.string()); + init(); + } + + OutputStream(OutputStream&& other) = default; + OutputStream& operator=(OutputStream&& other) = default; + + OutputStream(const OutputStream&) = delete; + OutputStream& operator=(const OutputStream&) = delete; + + + template + OutputStream& operator<<(const std::pair& t) { + return *this << t.first << DEFAULT_SEPARATOR << t.second; + } + + template + OutputStream& operator<<(const std::tuple& t) { + return join(t, std::index_sequence_for(), DEFAULT_SEPARATOR); + } + + template + OutputStream& operator<<(const T& x) { + if constexpr ((std::is_array_v and !std::is_same_v, char*>) or + (details::IsContainer{} and !details::HasOstreamOperator{})) { + return join(std::begin(x), std::end(x), DEFAULT_SEPARATOR); + } else { + *os << x; + return *this; + } + } + + OutputStream& operator<<(std::ostream& (*manip)(std::ostream&)) { + *os << manip; + return *this; + } + + template + OutputStream& join(const Tuple& t, std::index_sequence /**/, char separator) { + static_assert(std::tuple_size_v == sizeof...(Is)); + if (separator != NOSEP) ((*os << (Is == 0 ? std::string_view() : std::string_view(&separator, 1)), *this << std::get(t)), ...); + else ((*this << std::get(t)), ...); + return *this; + } + + template + OutputStream& join(T first, T last, char separator) { + for (auto it = first; it != last; it++) { + if (it != first and separator != NOSEP) *os << separator; + *this << *it; + } + return *this; + } +}; + +namespace ValidateBase { + // define this early so everyone can use it! + OutputStream juryErr(std::cerr); + OutputStream juryOut(std::cout); +} + +// allow printing colletions as: +// join(begin(), end(), [sep]) +namespace details { + template + class TempWriter final { + C callable; + public: + constexpr explicit TempWriter(const C& callable_) : callable(callable_) {} + + TempWriter(const TempWriter&) = delete; + TempWriter(TempWriter&&) = delete; + TempWriter& operator=(const TempWriter&) = delete; + TempWriter& operator=(TempWriter&&) = delete; + + std::string asString() const { + std::ostringstream os; + OutputStream tmp(os); + tmp << *this; + return os.str(); + } + + explicit operator std::string() const { + return asString(); + } + + friend OutputStream& operator<<(OutputStream& os, const TempWriter& writer) { + writer.callable(os); + return os; + } + + friend OutputStream& operator<<(std::ostream& os, const TempWriter& writer) = delete; //news OutputStream + }; + + struct JoinListCapture { + std::function callable; + + template + JoinListCapture(Args&&... args) + : callable([t = std::forward_as_tuple(args...)](OutputStream& os, char separator) { + os.join(t, std::index_sequence_for(), separator); + }) {} + }; +} + +template +constexpr auto join(T first, T last, char separator = DEFAULT_SEPARATOR) { + return details::TempWriter([=](OutputStream& os) { + os.join(first, last, separator); + }); +} + +template{}>, + typename = std::enable_if_t>>{}>> +constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) { + if constexpr(std::is_rvalue_reference_v) { + if constexpr (std::is_array_v) { + return details::TempWriter([c, separator](OutputStream& os) { + os.join(std::begin(c), std::end(c), separator); + }); + } else { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + os.join(std::begin(c), std::end(c), separator); + }); + } + } else { + return join(std::begin(c), std::end(c), separator); + } +} + +template>::value> +constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) { + if constexpr(std::is_rvalue_reference_v) { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + os.join(c, std::make_index_sequence{}, separator); + }); + } else { + return details::TempWriter([&c, separator](OutputStream& os) { + os.join(c, std::make_index_sequence{}, separator); + }); + } +} + +template, char>>> +constexpr auto join(T (&c)[N], char separator = DEFAULT_SEPARATOR) { + static_assert(N > 0, "c-strings should be null terminated!"); + return join(std::begin(c), std::prev(std::end(c)), separator); +} + +template, char>>> +constexpr auto join(T (&&c)[N], char separator = DEFAULT_SEPARATOR) { + static_assert(N > 0, "c-strings should be null terminated!"); + return details::TempWriter([c, separator](OutputStream& os) { + os.join(std::begin(c), std::prev(std::end(c)), separator); + }); +} + +template{}>, + typename = std::enable_if_t{}>, + typename = std::enable_if_t{}>> +constexpr auto join(const T& t, char separator = DEFAULT_SEPARATOR) = delete; + +auto join(details::JoinListCapture c, char separator = DEFAULT_SEPARATOR) { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + c.callable(os, separator); + }); +} + + +//============================================================================// +// Basic datastructures // +//============================================================================// +// make usage of std::priority_queue easier... +namespace details { + template> + struct invertCompare { + constexpr bool operator()(const T &lhs, const T &rhs) const { + return Compare{}(rhs, lhs); + } + }; +} +template> +using MinPQ = std::priority_queue, details::invertCompare>; +template> +using MaxPQ = std::priority_queue, Compare>; + +template +bool contains(const C& container, const K& key) { + return container.find(key) != container.end(); +} + +template +void append(C1& c1, const C2& c2) { + static_assert(std::is_same_v::value_type, + typename details::IsContainer::value_type>, "cannot append container of different value type!"); + if (static_cast(&c1) != static_cast(&c2)) { + for (auto&& e : c2) c1.emplace(c1.end(), e); + } else { + C2 tmp = c2; + for (auto&& e : tmp) c1.emplace(c1.end(), e); + } +} + +template +void append(C1& c1, const typename C1::value_type(&c2)[N]) { + for (auto&& e : c2) c1.emplace(c1.end(), e); +} + +struct shorter { + template + bool operator()(const U& a, const V& b) const { + return std::size(a) < std::size(b); + } +}; + +struct longer { + template + bool operator()(const U& a, const V& b) const { + return std::size(b) < std::size(a); + } +}; + +namespace details { + template + struct Flatten {using value_type = T;}; + + template + struct Flatten{}>> : Flatten::value_type> {}; + + template + void flatAppend(CR&& c, std::vector& res) { + using C = std::remove_reference_t; + if constexpr(std::is_same_v) { + res.emplace_back(std::forward(c)); + } else if constexpr (!IsContainer{}) { + static_assert(IsContainer{}, "invalid base type for flatten()!"); + } else { + if constexpr (std::is_rvalue_reference_v) { + for (auto&& v : c) flatAppend(std::move(v), res); + } else { + for (auto&& v : c) flatAppend(v, res); + } + } + } +} + +template +auto flatten(CR&& c) { + std::vector res; + details::flatAppend(std::forward(c), res); + return res; +} + +template +auto flatten(CR&& c) { + using C = std::remove_reference_t; + return flatten::value_type, CR>(std::forward(c)); +} + +template +struct boolean { + bool value; + std::optional reason; + + constexpr boolean(bool value_) : value(value_) {} + constexpr boolean(bool value_, const T& reason_) : value(value_), reason(reason_) {} + + constexpr operator bool() const { + return value; + } + + constexpr bool hasReason() const { + return reason.has_value(); + } +}; + + +//============================================================================// +// Utility // +//============================================================================// +// for sequences +template::value_type>>> +auto isPerm(RandomIt first, RandomIt last, typename std::iterator_traits::value_type offset = 0) { + using T = typename std::iterator_traits::value_type; + auto count = std::distance(first, last); + std::vector seen(count, false); + for (; first != last; first++) { + const T& x = *first; + if (x < offset or x - offset >= count or seen[x - offset]) { + return boolean(false, x); + } + seen[x - offset] = true; + } + return boolean(true); +} +template::value_type>, bool> = true> +auto isPerm(const C& c, typename details::IsContainer::value_type offset = 0) { + return isPerm(std::begin(c), std::end(c), offset); +} + +template +auto isPerm(itA firstA, itA lastA, itB firstB, itB lastB) { + using T = typename std::iterator_traits::value_type; + std::vector::value_type> a(firstA, lastA); + std::vector::value_type> b(firstB, lastB); + if (a.size() != b.size()) return boolean(false); + std::sort(a.begin(), a.end()); + std::sort(b.begin(), b.end()); + for (std::size_t i = 0; i < a.size(); i++) { + if (a[i] != b[i]) return boolean(false, a[i]); + } + return boolean(true); +} +template{}>, + typename = std::enable_if_t{}>> +auto isPerm(const C1& c1, const C2& c2) { + return isPerm(std::begin(c1), std::end(c1), std::begin(c2), std::end(c2)); +} + +template +constexpr boolean anyAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + if (first != last) { + for (Integer i = 1; std::next(first) != last; first++, i++) { + if (p(*first, *std::next(first))) { + return boolean(true, i); + } + } + } + return boolean(false); +} +template +constexpr boolean anyAdjacent(const C& c, BinaryPredicate p) { + return anyAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean noneAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + auto res = anyAdjacent(first, last, p); + res.value = !res.value; + return res; +} +template +constexpr boolean noneAdjacent(const C& c, BinaryPredicate p) { + return noneAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean allAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + return noneAdjacent(first, last, std::not_fn(p)); +} +template +constexpr boolean allAdjacent(const C& c, BinaryPredicate p) { + return noneAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean areIncreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::less()); +} +template +constexpr boolean areIncreasing(const C& c) { + return areIncreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areNonDecreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::less_equal()); +} +template +constexpr boolean areNonDecreasing(const C& c) { + return areNonDecreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areDecreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::greater()); +} +template +constexpr boolean areDecreasing(const C& c) { + return areDecreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areNonIncreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::greater_equal()); +} +template +constexpr boolean areNonIncreasing(const C& c) { + return areNonIncreasing(std::begin(c), std::end(c)); +} + +template +constexpr auto areDistinct(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + std::vector tmp(first, last); + std::sort(tmp.begin(), tmp.end()); + auto [b, v] = anyAdjacent(tmp, std::equal_to()); + if (v) return boolean(!b, tmp[*v]); + return boolean(!b); +} +template +constexpr auto areDistinct(const C& c) { + return areDistinct(std::begin(c), std::end(c)); +} + + +// for strings (cctype functions are not safe to use with char...) +constexpr bool isLower(char c) { + return c >= 'a' and c <= 'z'; +} + +constexpr bool isUpper(char c) { + return c >= 'A' and c <= 'Z'; +} + +constexpr bool isLetter(char c) { + return isLower(c) or isUpper(c); +} + +constexpr bool isDigit(char c) { + return c >= '0' and c <= '9'; +} + +constexpr char toLower(char c) { + if (isUpper(c)) c += 'a' - 'A'; + return c; +} + +constexpr bool isVowel(char c) { + c = toLower(c); + for (char x : LOWER_VOWELS) { + if (c == x) return true; + } + return false; +} + +constexpr bool isConsonant(char c) { + return isLetter(c) and !isVowel(c); +} + +constexpr char toUpper(char c) { + if (isLower(c)) c -= 'a' - 'A'; + return c; +} + +constexpr char toDefaultCase(char c) { + if constexpr (DEFAULT_CASE_LOWER) return toLower(c); + return toUpper(c); +} + +void toLower(std::string& s) { + for (char& c : s) c = toLower(c); +} + +void toUpper(std::string& s) { + for (char& c : s) c = toUpper(c); +} + +void toDefaultCase(std::string& s) { + if constexpr (DEFAULT_CASE_LOWER) return toLower(s); + return toUpper(s); +} + +constexpr bool isLower(std::string_view s) { + for (char c : s) if (!isLower(c)) return false; + return true; +} + +constexpr boolean isUpper(std::string_view s) { + for (char c : s) if (!isUpper(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isLetter(std::string_view s) { + for (char c : s) if (!isLetter(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isDigit(std::string_view s) { + for (char c : s) if (!isDigit(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isVowel(std::string_view s) { + for (char c : s) if (!isVowel(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isConsonant(std::string_view s) { + for (char c : s) if (!isConsonant(c)) return boolean(false, c); + return boolean(true); +} + +std::vector thueMorse(Integer lower, Integer upper) { + judgeAssert(lower < upper, "thueMorse(): Lower must be less than upper!"); + std::vector res(upper - lower); + for (Integer i = lower; i < upper; i++) { + res[i] = std::bitset<64>(i).count() % 2; + } + return res; +} + +std::vector thueMorse(Integer upper) { + return thueMorse(0, upper); +} + +// allow using std::pair and std::complex similiar +// (may be useful for geometric problem) +template +constexpr auto& getX(T& point) { + return std::get<0>(point); +} +template +constexpr auto& getY(T& point) { + return std::get<1>(point); +} +template +constexpr auto& getZ(T& point) { + return std::get<2>(point); +} +template +constexpr auto getX(const T& point) { + return std::get<0>(point); +} +template +constexpr auto getY(const T& point) { + return std::get<1>(point); +} +template +constexpr auto getZ(const T& point) { + return std::get<2>(point); +} + +template +constexpr auto& getX(std::complex& point) { + return reinterpret_cast(point)[0]; +} +template +constexpr auto& getY(std::complex& point) { + return reinterpret_cast(point)[1]; +} +template +constexpr auto getX(const std::complex& point) { + return reinterpret_cast(point)[0]; +} +template +constexpr auto getY(const std::complex& point) { + return reinterpret_cast(point)[1]; +} + +template +constexpr std::pair convert(const std::complex& t) { + return {getX(t), getY(t)}; +} + +template +constexpr std::complex::type> +convert(const std::pair& t) { + return {getX(t), getY(t)}; +} + + +namespace details { + // Test two numbers for equality, accounting for +/-INF, NaN and precision. + // Real expected is considered the reference value for relative error. + bool floatEqual(Real given, Real expected, Real floatAbsTol, Real floatRelTol) { + judgeAssert(floatAbsTol >= 0.0_real, "floatEqual(): floatAbsTol must be positive!"); + judgeAssert(floatRelTol >= 0.0_real, "floatEqual(): floatRelTol must be positive!"); + // Finite values are compared with some tolerance + if (std::isfinite(given) and std::isfinite(expected)) { + Real absDiff = std::abs(given-expected); + Real relDiff = std::abs((given-expected)/expected); + return absDiff <= floatAbsTol or relDiff <= floatRelTol; + } + // NaN is equal to NaN (-NaN is also equal NaN) + if (std::isnan(given) and std::isnan(expected)) { + return true; + } + // Infinite values are equal if their sign matches + if (std::isinf(given) and std::isinf(expected)) { + return std::signbit(given) == std::signbit(expected); + } + // Values in different classes are always different. + return false; + } + + constexpr boolean stringEqual(std::string_view a, std::string_view b, bool caseSensitive) { + std::size_t i = 0; + for (; i < a.size() and i < b.size(); i++) { + char aa = a[i]; + char bb = b[i]; + if (!caseSensitive) { + aa = toDefaultCase(aa); + bb = toDefaultCase(bb); + } + if (aa != bb) { + return boolean(false, i); + } + } + if (a.size() != b.size()) { + return boolean(false, i); + } else { + return boolean(true); + } + } + + constexpr bool isToken(std::string_view a) { + for (char c : a) { + if (c == ' ') return false; + if (c == '\n') return false; + if (c == '\r') return false; + if (c == '\t') return false; + if (c == '\f') return false; + if (c == '\v') return false; + } + return true; + } + + template + bool parse(std::string_view s, T& res) { + const char* begin = s.data(); + const char* end = s.data() + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, res); + return ptr == end and ec == std::errc(); + } + #ifdef DOUBLE_FALLBACK + template<> + bool parse(std::string_view s, Real& res) { + try { + std::size_t pos = 0; + res = std::stold(std::string(s), &pos); + return pos == s.size(); + } catch(...) { + return false; + } + } + #endif + +} + + +//============================================================================// +// Math // +//============================================================================// +namespace details { + constexpr std::array TRIAL_PRIMES = { + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, + }; + constexpr std::array MILLER_RABIN_WITNESS = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; + + // these operations are safe as long as the value would fit in Integer + constexpr UInteger mulMod(UInteger lhs, UInteger rhs, UInteger mod) { + UInteger res = 0; + while (rhs > 0) { + if (rhs & 1) res = (lhs + res) % mod; + lhs = (lhs + lhs) % mod; + rhs /= 2; + } + return res; + } + + constexpr UInteger powMod(UInteger base, UInteger exp, UInteger mod) { + UInteger res = 1; + if (mod <= 0x1'0000'0000) { + while (exp > 0) { + if (exp & 1) res = (base * res) % mod; + base = (base * base) % mod; + exp /= 2; + } + } else { + while (exp > 0) { + if (exp & 1) res = mulMod(base, res, mod); + base = mulMod(base, base, mod); + exp /= 2; + } + } + return res; + } + + constexpr Integer extendedEuclid(Integer a, Integer b, Integer& x, Integer& y) { + if (a == 0) { + x = 0; + y = 1; + return b; + } else { + Integer x1 = 0; + Integer y1 = 0; + Integer d = extendedEuclid(b % a, a, x1, y1); + x = y1 - (b / a) * x1; + y = x1; + return d; + } + } +} + +constexpr Integer applyMod(Integer x, Integer mod) { + x %= mod; + if (x < 0) x += mod; + return x; +} + +constexpr Integer mulMod(Integer lhs, Integer rhs, Integer mod) { + judgeAssert(mod > 0, "mulMod(): mod must be positive!"); + UInteger ul = static_cast(applyMod(lhs, mod)); + UInteger ur = static_cast(applyMod(rhs, mod)); + UInteger um = static_cast(mod); + return static_cast(details::mulMod(ul, ur, um)); +} + +constexpr Integer powMod(Integer base, Integer exp, Integer mod) { + judgeAssert(mod > 0, "powMod(): mod must be positive!"); + judgeAssert(exp >= 0, "powMod(): exp must be non negative!"); + UInteger ub = static_cast(applyMod(base, mod)); + UInteger ue = static_cast(exp); + UInteger um = static_cast(mod); + return static_cast(details::powMod(ub, ue, um)); +} + +constexpr Integer multInv(Integer n, Integer mod) { + judgeAssert(mod > 0, "multInv(): mod must be positive!"); + Integer x = 0; + Integer y = 0; + Integer g = details::extendedEuclid(n, mod, x, y); + if (g != 1) return -1; + else return applyMod(x, mod); +} + +constexpr bool isPrime(Integer n) { + for (Integer p : details::TRIAL_PRIMES) { + if (n <= p or n % p == 0) { + return n == p; + } + } + if (details::powMod(details::TRIAL_PRIMES.back() + 1, n - 1, n) != 1) { + return false; + } + UInteger un = static_cast(n); + UInteger d = un - 1; + UInteger j = 0; + while (d % 2 == 0) { + d /= 2; + j++; + } + for (UInteger a : details::MILLER_RABIN_WITNESS) { + if (a % un == 0) continue; + UInteger v = details::powMod(a, d, un); + if (v == 1 or v == un - 1) continue; + for (UInteger i = 1; i < j; i++) { + v = details::mulMod(v, v, un); + if (v == un - 1 or v <= 1) break; + } + if (v != un - 1) return false; + } + return true; +} + +std::vector primes(Integer lower, Integer upper) { + judgeAssert(lower < upper, "primes(): Lower must be less than upper!"); + lower = std::max(2, lower); + upper = std::max(2, upper); + Integer count = upper - lower; + Integer cache = (count + 1) / 2; + + std::vector notPrime(cache), notPrimeSegment(cache); + for (Integer i = 3; i < count; i += 2) { + if (!notPrime[i / 2]) { + for (Integer j = i * i; j < count; j += 2 * i) { + notPrime[j / 2] = true; + } + Integer lowest = lower - (lower % (2*i)) + i; + if (lowest < lower) lowest += 2*i; + for (Integer j = std::max(i * i, lowest); j < upper; j += 2 * i) { + notPrimeSegment[(j - lower) / 2] = true; + } + } + } + std::vector res; + if (lower <= 2 and 2 < upper) res.emplace_back(2); + for (Integer i = lower | 1; i < upper; i += 2) { + if (!notPrimeSegment[(i - lower) / 2] and (i < count*count or isPrime(i))) { + res.emplace_back(i); + } + } + return res; +} + +std::vector primes(Integer upper) { + return primes(0, upper); +} + +template +constexpr Integer sign(T x) { + return (T(0) < x) - (x < T(0)); +} + + +//============================================================================// +// Geometry (this is just for utility stuff...) // +//============================================================================// +namespace details { + template + constexpr Integer cross(Point a, Point b) { + return getX(a) * getY(b) - getY(a) * getX(b); + } + template + constexpr Integer cross(Point p, Point a, Point b) { + getX(a) -= getX(p); + getY(a) -= getY(p); + getX(b) -= getX(p); + getY(b) -= getY(p); + return cross(a, b); + } + + template + constexpr bool left(Point p) { + return getX(p) == 0 ? getY(p) < 0 : getX(p) < 0; + } + + template + void cyclicSort(std::vector& in) { + std::sort(in.begin(), in.end(), [](const Point& a, const Point& b){ + return left(a) != left(b) ? left(a) > left(b) : cross(a, b) > 0; + }); + } +} + + +template +constexpr bool areConvex(RandomIt first, RandomIt last) { + std::size_t n = 0; + for (auto it = first; it != last; it++) { + n++; + judgeAssert(std::abs(getX(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!"); + judgeAssert(std::abs(getY(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!"); + } + if (n < 3) return false; + bool hasArea = false; + for (std::size_t i = 0; i < n; i++) { + if (first[i] == first[(i+1) % n]) return false; + if (details::cross(first[0], first[i], first[(i+1) % n]) < 0) return false; + if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) < 0) return false; + hasArea |= details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) != 0; + } + return hasArea; +} +template +constexpr bool areConvex(const C& c) { + return areConvex(std::begin(c), std::end(c)); +} + +template +constexpr bool areStrictlyConvex(RandomIt first, RandomIt last) { + if (!areConvex(first, last)) return false; + std::size_t n = std::distance(first, last); + for (std::size_t i = 0; i < n; i++) { + if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) == 0) return false; + } + return true; +} +template +constexpr bool areStrictlyConvex(const C& c) { + return areStrictlyConvex(std::begin(c), std::end(c)); +} + +//============================================================================// +// Random // +//============================================================================// +namespace Random { + // You should not rely on the implementation in details! + // Especially you should never use randomNumberGenerator on your own. There is no function in + // c++ which uses a random engine and is not implementation defined. + namespace details { + constexpr Real PI = 3.141592653589793238462643383279502884_real; + constexpr Integer PRIME_TRIALS = 4*1600; + + RandomEngine randomNumberGenerator(DEFAULT_SEED); + static_assert(RandomEngine::max() == 0xFFFF'FFFF'FFFF'FFFF_uint, "Random Engine should produce 64bit of randomness"); + static_assert(RandomEngine::min() == 0_uint, "Random Engine should produce 64bit of randomness"); + + constexpr UInteger bitMask(UInteger x) { + static_assert(sizeof(UInteger) == 8, "bitMask requires 8byte UInteger!"); + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + x |= x >> 32; + return x; + } + } + + void seed(UInteger seed) { + details::randomNumberGenerator.seed(seed); + } + + //========================================================================// + // Distributions and generators // + //========================================================================// + bool bit() {// in {0, 1} + return std::bitset<64>(details::randomNumberGenerator()).count() & 1; + } + + Integer integer() {// in [-2^63, 2^63) + return static_cast(details::randomNumberGenerator()); + } + Integer integer(Integer lower, Integer upper) {// in [lower, upper) + judgeAssert(lower < upper, "Random::integer(): Lower must be less than upper!"); + UInteger ul = static_cast(lower); + UInteger uu = static_cast(upper); + UInteger mask = details::bitMask(uu - ul - 1_uint); + UInteger res; + do { + res = details::randomNumberGenerator() & mask; + } while (res >= uu - ul); + return static_cast(res + ul); + } + Integer integer(Integer upper) {// in [0, upper) + return integer(0, upper); + } + + Real real() {// in [0, 1) + while (true) { + Real res = details::randomNumberGenerator() / 0x1.0p64_real; + res += details::randomNumberGenerator() / 0x1.0p128_real; + if (0.0_real <= res and res < 1.0_real) return res; + } + } + Real real(Real upper) {// in [0, upper) + judgeAssert(std::isfinite(upper), "Random::real(): Upper must be finite!"); + judgeAssert(upper > 0.0_real, "Random::real(): Upper must be greater than zero!"); + while (true) { + Real res = real() * upper; + if (0.0_real <= res and res < upper) return res; + } + } + Real real(Real lower, Real upper) {// in [lower, upper) + judgeAssert(std::isfinite(lower), "Random::real(): Lower must be finite!"); + judgeAssert(std::isfinite(upper), "Random::real(): Upper must be finite!"); + judgeAssert(lower < upper, "Random::real(): Lower must be less than upper!"); + while (true) { + Real x = real(); + Real res = lower * (1.0_real - x) + upper * x; + if (lower <= res and res < upper) return res; + } + } + + Real normal(Real mean, Real stddev) {// theoretically in (-inf, inf) + judgeAssert(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!"); + Real u1 = real(); + Real u2 = real(); + Real res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2); + return std::sqrt(stddev) * res + mean; + } + Real normal(Real lower, Real upper, Real mean, Real stddev) {// in [lower, upper) + judgeAssert(!std::isnan(lower), "Random::normal(): Lower must not be NaN!"); + judgeAssert(!std::isnan(upper), "Random::normal(): Upper must not be NaN!"); + judgeAssert(lower < upper, "Random::normal(): Lower must be less than upper!"); + judgeAssert(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!"); + Real res; + while (true) { + Real u1 = real(); + Real u2 = real(); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2); + res = std::sqrt(stddev) * res + mean; + if (lower <= res and res < upper) return res; + res = std::sqrt(-2.0_real * std::log(u1)) * std::sin(2.0_real * details::PI * u2); + res = std::sqrt(stddev) * res + mean; + if (lower <= res and res < upper) return res; + } + } + + Real exponential(Real lambda) {// theoretically in [0, inf) + judgeAssert(lambda > 0.0_real, "Random::lambda(): lambda must be positive!"); + return -std::log(real()) / lambda; + } + Real exponential(Real lower, Real upper, Real lambda) {// in [lower, upper) + judgeAssert(std::isfinite(lower), "Random::exponential(): Lower must be finite!"); + judgeAssert(!std::isnan(upper), "Random::exponential(): Upper must not be NaN!"); + judgeAssert(lower < upper, "Random::exponential(): Lower must be less than upper!"); + judgeAssert(lambda > 0.0_real, "Random::exponential(): Lambda must be positive!"); + while (true) { + Real res = lower - std::log(real()) / lambda; + if (res < upper) return res; + } + } + + Integer geometric(Real p) {// theoretically in [0, inf) + judgeAssert(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!"); + return std::llround(std::floor(std::log(real()) / std::log1p(-p))); + } + Integer geometric(Integer lower, Integer upper, Real p) {// in [lower, upper) + judgeAssert(lower < upper, "Random::geometric(): Lower must be less than upper!"); + judgeAssert(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!"); + while (true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric distribution[...]" + Integer res = lower + std::llround(std::floor(std::log(real()) / std::log1p(-p))); + if (res < upper) return res; + } + } + + Integer binomial(Integer n, Real p) {// in [0, n] + judgeAssert(n >= 0, "Random::binomial(): n must be non negative!"); + judgeAssert(0.0_real <= p and p <= 1.0_real, "Random::binomial(): p must be in [0,1)!"); + bool swap = p > 0.5_real; + p = std::min(p, 1.0_real - p); + if (p*n < 10.0_real) { + // BG: Geometric method + // https://dl.acm.org/doi/pdf/10.1145/42372.42381 + Integer res = 0; + Integer y = 0; + Real lg = std::log1p(-p); + if (lg >= 0) return swap ? n : 0; + do { + y += std::llround(std::floor(std::log(real()) / lg)) + 1; + if (y > n) return swap ? n - res : res; + res++; + } while (true); + } else { + // BTRS algorithm + // https://epub.wu.ac.at/1242/1/document.pdf + // note that the original paper has an error + // the break condition at the end has to be log(v) < h[...] + Real q = 1.0_real - p; + Real spq = std::sqrt(n * p * q); + Real b = 1.15_real + 2.53_real * spq; + Real a = -0.0873_real + 0.0248_real * b + 0.01_real * p; + Real c = n * p + 0.5_real; + Real vr = 0.92_real - 4.2_real / b; + + bool initialized = false; + Real alpha, lpq, m, h; + do { + Real u = real() - 0.5_real; + Real us = 0.5_real - std::abs(u); + Integer res = std::llround(std::floor((2.0_real * a / us + b) * u + c)); + if (res < 0 or res > n) continue; + + Real v = real(); + if (us >= 0.07_real and v <= vr) { + return swap ? n - res : res; + } + + if (!initialized) { + alpha = (2.83_real + 5.1_real / b) * spq; + lpq = std::log(p / q); + m = std::llround(std::floor((n + 1) * p)); + h = std::lgamma(m + 1) + std::lgamma(n - m + 1); + initialized = true; + } + v *= alpha / (a / (us * us) + b); + if (std::log(v) <= h - std::lgamma(res + 1) - std::lgamma(n - res + 1) + (res - m) * lpq) { + return swap ? n - res : res; + } + } while (true); + } + } + Integer binomial(Integer lower, Integer upper, Integer n, Real p) {// in [lower, upper) + judgeAssert(lower < upper, "Random::binomial(): n Lower must be less than upper!"); + while (true) { + Integer res = binomial(n, p); + if (lower <= res and res < upper) return res; + } + } + + Integer maximum(Integer lower, Integer upper, Integer n) {// in [lower, upper) + judgeAssert(n > 0, "Random::maximum(): n musst be positive!"); + judgeAssert(lower < upper, "Random::maximum(): Lower must be less than upper!"); + if (n < 5) { + Integer res = lower; + for (Integer i = 0; i < n; i++) res = std::max(res, integer(lower, upper)); + return res; + } else {// such large n seem unlikely + UInteger ul = static_cast(lower); + UInteger uu = static_cast(upper); + UInteger res = (uu - ul) * std::exp2(std::log2(real()) / n); + return std::min(upper - 1, static_cast(res + ul)); + } + } + Integer maximum(Integer upper, Integer n) { + return maximum(0, upper, n); + } + + Integer minimum(Integer lower, Integer upper, Integer n) {// in [lower, upper) + return upper - 1 - maximum(0, upper - lower, n); + } + Integer minimum(Integer upper, Integer n) { + return minimum(0, upper, n); + } + + Integer prime(Integer lower, Integer upper) {// in [lower, upper) + judgeAssert(lower < upper, "Random::prime(): Lower must be less than upper!"); + Integer sampleL = lower <= 2 ? 0 : (lower / 2); + Integer sampleU = upper / 2; + if (sampleL < sampleU) { + for (Integer i = 0; i < details::PRIME_TRIALS and i < 4 * (upper - lower); i++) { + Integer res = std::max(2, 2*integer(sampleL, sampleU) | 1); + if (isPrime(res)) return res; + } + } + judgeAssert(false, "Random::prime(): range contains no primes?"); + return -1; + } + Integer prime(Integer upper) {// in [0, upper) + return prime(0, upper); + } + + + //========================================================================// + // utility // + //========================================================================// + template + typename std::iterator_traits::reference + select(RandomIt first, RandomIt last) { + judgeAssert(first < last, "Random::select(): Lower must be less than upper!"); + return first[integer(0, last - first)]; + } + + template + typename ::details::IsContainer::value_type select(const C& c) { + return select(std::begin(c), std::end(c)); + } + + template + typename C::reference select(C& c) { + return select(std::begin(c), std::end(c)); + } + + template + T select(const T(&c)[N]) { + return select(std::begin(c), std::end(c)); + } + + template + T& select(T(&c)[N]) { + return select(std::begin(c), std::end(c)); + } + + template + T select(const std::pair& t) { + return bit() ? getX(t) : getY(t); + } + + template + T select(const std::complex& t) { + return bit() ? getX(t) : getY(t); + } + + template + void shuffle(RandomIt first, RandomIt last) { + using std::swap; + auto n = last - first; + for (auto i = n-1; i > 0; i--) { + swap(first[i], first[integer(0, i+1)]); + } + } + + template + void shuffle(C& c) { + return shuffle(std::begin(c), std::end(c)); + } + + template + void shuffle(std::pair& t) { + using std::swap; + if (bit()) swap(getX(t), getY(t)); + } + + template + void shuffle(std::complex& t) { + using std::swap; + if (bit()) swap(getX(t), getY(t)); + } + + template + Integer rotate(RandomIt first, RandomIt last) { + Integer rotation = integer(0, last - first); + std::rotate(first, first + rotation, last); + return rotation; + } + + template + Integer rotate(C& c) { + return rotate(std::begin(c), std::end(c)); + } + + //========================================================================// + // sequences // + //========================================================================// + std::vector distinct(Integer count, Integer lower, Integer upper) { + judgeAssert(count >= 0, "Random::distinct(): Count must be non negative!"); + judgeAssert(lower + count <= upper, "Random::distinct(): Lower must be less than upper + count!"); + std::map used; + std::vector res; + for (Integer i = 0; i < count; i++) { + Integer x = integer(lower, upper - i); + auto it = used.find(x); + if (it != used.end()) res.emplace_back(it->second); + else res.emplace_back(x); + it = used.find(upper - i - 1); + if (it != used.end()) used[x] = it->second; + else used[x] = upper - i - 1; + } + return res; + } + std::vector distinct(Integer count, Integer upper) { + return distinct(count, 0, upper); + } + + std::vector perm(Integer count, Integer offset = 0) { + return distinct(count, offset, offset+count); + } + + std::vector perm(const std::vector& cycles, Integer offset = 0) { + auto p = perm(std::accumulate(cycles.begin(), cycles.end(), 0_int)); + std::vector res(p.size()); + Integer tmp = 0; + for (std::size_t i = 0; i < cycles.size(); tmp += cycles[i], i++) { + judgeAssert(cycles[i] > 0, "Random::perm(): Cycle lengths must be positive!"); + for (Integer j = tmp; j + 1 < tmp + cycles[i]; j++) { + res[p[j]] = p[j + 1] + offset; + } + res[p[tmp + cycles[i] - 1]] = p[tmp] + offset; + } + return res; + } + + std::vector perm(std::initializer_list cycles, Integer offset = 0) { + return perm(std::vector(cycles), offset); + } + + std::vector multiple(Integer count, Integer lower, Integer upper) { + std::vector res(count); + for (Integer& x : res) x = integer(lower, upper); + return res; + } + std::vector multiple(Integer count, Integer upper) { + return multiple(count, 0, upper); + } + + std::vector increasing(Integer count, Integer lower, Integer upper) { + std::vector res = distinct(count, lower, upper); + std::sort(res.begin(), res.end(), std::less()); + return res; + } + std::vector increasing(Integer count, Integer upper) { + return increasing(count, 0, upper); + } + + std::vector decreasing(Integer count, Integer lower, Integer upper) { + std::vector res = distinct(count, lower, upper); + std::sort(res.begin(), res.end(), std::greater()); + return res; + } + std::vector decreasing(Integer count, Integer upper) { + return decreasing(count, 0, upper); + } + + std::vector nonDecreasing(Integer count, Integer lower, Integer upper) { + std::vector res = multiple(count, lower, upper); + std::sort(res.begin(), res.end(), std::less()); + return res; + } + std::vector nonDecreasing(Integer count, Integer upper) { + return nonDecreasing(count, 0, upper); + } + + std::vector nonIncreasing(Integer count, Integer lower, Integer upper) { + std::vector res = multiple(count, lower, upper); + std::sort(res.begin(), res.end(), std::greater()); + return res; + } + std::vector nonIncreasing(Integer count, Integer upper) { + return nonIncreasing(count, 0, upper); + } + + std::vector partition(Integer n, Integer k, Integer min = 1) { + judgeAssert(n > 0, "Random::partition(): n must be positive!"); + judgeAssert(k > 0, "Random::partition(): k must be positive!"); + judgeAssert(min <= 0 or k <= n / min, "Random::partition(): k too large!"); + n -= (min - 1) * k; + std::vector res = increasing(k-1, 1, n); + res.emplace_back(n); + for (Integer i = 0, last = 0; i < k; i++) { + res[i] -= last; + last += res[i]; + res[i] += min - 1; + } + return res; + } + + std::string bracketSequence(Integer n, char open = '(', char close = ')') {//proper bracket sequence of length 2*n + judgeAssert(0 <= n and n <= 0x7FFF'FFFF, "Random::bracketSequence(): n out of range!"); + std::string res(2 * n, open); + for (Integer i = 0, diff = 0; i < 2 * n; i++) { + Integer opened = (i + diff) / 2; + if (integer((2 * n - i) * (diff + 1)) < (n - opened) * (diff + 2)) { + diff++; + } else { + res[i] = close; + diff--; + } + } + return res; + } + + //========================================================================// + // geometry // + //========================================================================// + template> + std::vector convex(Integer n, Integer dim) { + judgeAssert(dim <= 0x3FFF'FFFF, "Random::convex(): dim too large!"); + judgeAssert(dim > 0, "Random::convex(): dim must be positive!"); + judgeAssert(n <= 8*dim - 8, "Random::convex(): dim too small!"); + judgeAssert(n >= 3, "Random::convex(): n too small!"); + + while (true) { + Integer left = 1 + binomial(n - 2, 0.5); + Integer down = 1 + binomial(n - 2, 0.5); + auto x = partition(2 * dim - 2, left, 0); + auto y = partition(2 * dim - 2, down, 0); + for (auto& z : x) z = -z; + for (auto& z : y) z = -z; + append(x, partition(2 * dim - 2, n - left, 0)); + append(y, partition(2 * dim - 2, n - down, 0)); + auto itX = std::partition(x.begin(), x.end(), [](Integer z){return z == 0;}); + auto itY = std::partition(y.begin(), y.end(), [](Integer z){return z != 0;}); + if (std::distance(x.begin(), itX) + std::distance(itY, y.end()) > n) continue; + shuffle(itX, x.end()); + if (itX != x.begin()) shuffle(y.begin(), itY); + + std::vector dirs(n); + for (Integer i = 0; i < n; i++) { + dirs[i] = {x[i], y[i]}; + } + ::details::cyclicSort(dirs); + + std::vector res = {{0, 0}}; + Integer maxX = 0; + Integer maxY = 0; + for (auto dir : dirs) { + Point tmp = res.back(); + getX(tmp) += getX(dir); + getY(tmp) += getY(dir); + maxX = std::max(maxX, getX(tmp)); + maxY = std::max(maxY, getY(tmp)); + res.emplace_back(tmp); + } + res.pop_back(); + for (auto& point : res) { + getX(point) += dim - 1 - maxX; + getY(point) += dim - 1 - maxY; + } + return res; + } + } + + template> + std::vector nonCollinearPoints(Integer n, Integer dim) { + judgeAssert(dim <= 0x1FFF'FFFF, "Random::nonCollinearPoints(): dim too large!"); + judgeAssert(n >= 0, "Random::nonCollinearPoints(): dim must be non negative!"); + judgeAssert(dim > n, "Random::nonCollinearPoints(): dim too small!"); + Integer p = prime(dim - 1, 2*dim + 2); + Integer rotA = 0; + Integer rotB = 0; + while (rotA == 0 && rotB == 0) { + rotA = integer(0, p); + rotB = integer(0, p); + } + std::array abc = { + integer(1, p), + integer(0, p), + integer(0, p), + }; + Integer dx = integer(-dim + 1, dim - p); + Integer dy = integer(-dim + 1, dim - p); + + auto xs = distinct(n, p); + std::vector res; + for (auto tmpX : xs) { + Integer tmpY = 0; + for (Integer add : abc[0]) { + tmpY *= tmpX; + tmpY += add; + tmpY %= p; + } + + Integer x = applyMod(tmpX * rotA - tmpY * rotB, p); + Integer y = applyMod(tmpX * rotB + tmpY * rotA, p); + + res.emplace_back(x + dx, y + dy); + } + return res; + } + +} // namespace Random + + +//============================================================================// +// args parser // +//============================================================================// +class ParamaterBase { + friend class Command; + friend struct Paramater; + + std::optional token; + + template + T parse(std::string_view s) const { + T res = {}; + judgeAssert(details::parse(s, res), "Command: Could not parse args"); + return res; + } + + ParamaterBase() = default; + explicit ParamaterBase(std::string_view token_) : token(token_) {} + +public: + std::string asString() const { + return std::string(token.value()); + } + + std::string asString(std::string_view defaultValue) const { + return std::string(token.value_or(defaultValue)); + } + + Integer asInteger() const { + return parse(token.value()); + } + + Integer asInteger(Integer defaultValue) const { + return token ? asInteger() : defaultValue; + } + + Real asReal() const { + return parse(token.value()); + } + + Real asReal(Real defaultValue) const { + return token ? asReal() : defaultValue; + } +}; + +struct Paramater final : private ParamaterBase { + using ParamaterBase::ParamaterBase; + using ParamaterBase::asString; + using ParamaterBase::asInteger; + using ParamaterBase::asReal; + + bool exists() const { + return token.has_value(); + } + + explicit operator bool() const { + return exists(); + } +}; + +class Command final : private ParamaterBase { + const std::vector& raw; + const Integer first, count; + const bool found; +public: + explicit Command(const std::vector& raw_) : raw(raw_), first(0), count(0), found(false) {} + explicit Command(const std::vector& raw_, Integer first_, Integer count_) + : ParamaterBase(count_ == 0 ? ParamaterBase() : ParamaterBase(raw_[first_])), + raw(raw_), first(first_), count(count_), found(true) { + judgeAssert(count >= 0, "Command: Invalid command in args!"); + } + + bool exists() const { + return found; + } + + explicit operator bool() const { + return exists(); + } + + Integer parameterCount() const { + return count; + } + + Paramater operator[](Integer i) const { + if (i >= 0 and i < count) return Paramater(raw[first + i]); + return Paramater(); + } + + using ParamaterBase::asString; + using ParamaterBase::asInteger; + using ParamaterBase::asReal; + + std::vector asStrings() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [](const std::string& value) { + return std::string(value); + }); + return res; + } + + std::vector asIntegers() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [this](const std::string& value) { + return parse(value); + }); + return res; + } + + std::vector asReals() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [this](const std::string& value) { + return parse(value); + }); + return res; + } + +}; + +class CommandParser final { + std::vector raw; + std::map> commands; + std::map tokens; + + static bool isCommand(std::string_view s) { + return s.size() > 2 and s.substr(0, 2) == COMMAND_PREFIX; + } + void addCommand(std::string_view command, Integer first, Integer count = 0) { + judgeAssert(commands.count(command) == 0, "Command: Duplcated command in args!"); + commands.emplace(command, std::pair{first, count}); + } + +public: + CommandParser() = default; + explicit CommandParser(int argc, char** argv) { + raw.assign(argc, {}); + std::string_view command = EMPTY_COMMAND; + Integer first = 0; + Integer count = 0; + for (int i = 0; i < argc; i++) { + raw[i] = std::string(argv[i]); + tokens.emplace(raw[i], i+1); + if (isCommand(raw[i])) { + addCommand(command, first, count); + command = raw[i]; + first = i+1; + count = 0; + } else { + count++; + } + } + addCommand(command, first, count); + } + CommandParser(CommandParser&&) = default; + CommandParser& operator=(CommandParser&&) = default; + + CommandParser(const CommandParser&) = delete; + CommandParser& operator=(const CommandParser&) = delete; + + std::string_view operator[](Integer t) const { + judgeAssert(t >= 0 and t < static_cast(raw.size()), "Command: Index out of args!"); + return raw[t]; + } + Command operator[](std::string_view command) const & { + judgeAssert(details::isToken(command), "Command: must not contain a space!"); + auto it = commands.find(command); + if (it == commands.end()) return Command(raw); + return Command(raw, it->second.first, it->second.second); + } + Command getRaw(std::string_view command) const & { + judgeAssert(details::isToken(command), "Command: must not contain a space!"); + auto it = tokens.find(command); + if (it == tokens.end()) return Command(raw); + return Command(raw, it->second, raw.size() - it->second); + } + Command getRaw() const & { + return Command(raw, 0, raw.size()); + } +}; + + +//============================================================================// +// Constraints // +//============================================================================// +template +class Bounds final { + bool hadMin, hadMax; // was value==lower/upper at some point + T min, max; // range of seen values + T lower, upper; // bounds for value +public: + constexpr explicit Bounds(T lower_, T upper_, T value_) : + hadMin(false), hadMax(false), + min(value_), max(value_), + lower(lower_), upper(upper_) { + update(lower_, upper_, value_); + } + + void update(T lower_, T upper_, T value_) { + if constexpr (std::is_same_v) { + hadMin |= details::floatEqual(value_, lower_, DEFAULT_EPS, DEFAULT_EPS); + hadMax |= details::floatEqual(value_, upper_, DEFAULT_EPS, DEFAULT_EPS); + } else { + hadMin |= value_ == lower_; + hadMax |= value_ == upper_; + } + min = std::min(min, value_); + max = std::max(max, value_); + lower = std::min(lower, lower_); + upper = std::max(upper, upper_); + } + + friend std::ostream& operator<<(std::ostream& os, const Bounds& bounds) { + os << bounds.hadMin << " " << bounds.hadMax << " "; + os << bounds.min << " " << bounds.max << " "; + return os << bounds.lower << " " << bounds.upper; + } + +}; + +namespace details { + //using typeIndex = std::type_index; + using typeIndex = void*; + + template + typeIndex getTypeIndex() { + //return std::type_index(type id(T)); + static T* uniqueTypeIndex = nullptr; + return &uniqueTypeIndex; + } +} + +class Constraint final { + friend class ConstraintsLogger; + std::variant< + std::monostate, // uninitialized + Bounds, // Integer or container bound + Bounds // Real bound + > bound; + std::optional type; + + template + void update(T lower, T upper, T value) { + if constexpr(std::is_integral_v) { + upper--; // for BAPCtools the range is closed but we use half open ranges! + } + if (!type) { + type = details::getTypeIndex(); + bound = Bounds(lower, upper, value); + } + judgeAssert(type == details::getTypeIndex(), "Constraint: type must not change!"); + std::get>(bound).update(lower, upper, value); + } +public: + Constraint() = default; + Constraint(Constraint&&) = default; + Constraint& operator=(Constraint&&) = default; + + Constraint(const Constraint&) = delete; + Constraint& operator=(const Constraint&) = delete; + + template, bool> = true> + void log(Integer lower, Integer upper, V value) { + update(lower, upper, value); + } + + template, bool> = true> + void log(Real lower, Real upper, V value) { + update(lower, upper, value); + } + + template, bool> = true> + void log(Integer lower, Integer upper, const C& container) { + update(lower, upper, static_cast(std::size(container))); + } +}; + +class ConstraintsLogger final { + std::optional fileName; + std::map byName; + std::vector> constraints; +public: + ConstraintsLogger() = default; + explicit ConstraintsLogger(std::string_view fileName_) : fileName(fileName_) {} + + ConstraintsLogger(ConstraintsLogger&&) = default; + ConstraintsLogger& operator=(ConstraintsLogger&&) = default; + + ConstraintsLogger(const ConstraintsLogger&) = delete; + ConstraintsLogger& operator=(const ConstraintsLogger&) = delete; + + Constraint& operator[](const std::string& name) & { + judgeAssert(details::isToken(name), "Constraint: name must not contain a space!"); + auto res = byName.try_emplace(name, constraints.size()); + if (res.second) constraints.emplace_back(std::make_unique()); + return *(constraints[res.first->second]); + } + + void write() const { + if (!fileName) return; + std::ofstream os(*fileName); + os << std::noboolalpha; + os << std::fixed; + os << std::setprecision(DEFAULT_PRECISION); + for (const auto& [name, id] : byName) { + const Constraint& c = *(constraints[id]); + if (c.type) { + os << "LocationNotSupported:" << name << " " << name << " "; + if (c.bound.index() == 1) os << std::get<1>(c.bound); + if (c.bound.index() == 2) os << std::get<2>(c.bound); + os << std::endl; + } + } + } + + ~ConstraintsLogger() noexcept { + write(); + } +}; + +//============================================================================// +// custom input stream // +//============================================================================// +class InputStream final { + std::unique_ptr managed; + std::istream* in; + bool spaceSensitive, caseSensitive; + Verdict onFail; + Real floatAbsTol; + Real floatRelTol; + + void init() { + if (spaceSensitive) *in >> std::noskipws; + else *in >> std::skipws; + } + + void checkIn() { + judgeAssert(in != nullptr, "InputStream: not initialized!"); + } + +public: + InputStream() = default; + explicit InputStream(const std::filesystem::path& path, + bool spaceSensitive_, + bool caseSensitive_, + Verdict onFail_, + Real floatAbsTol_ = DEFAULT_EPS, + Real floatRelTol_ = DEFAULT_EPS) : + managed(std::make_unique(path)), + in(managed.get()), + spaceSensitive(spaceSensitive_), + caseSensitive(caseSensitive_), + onFail(onFail_), + floatAbsTol(floatAbsTol_), + floatRelTol(floatRelTol_) { + judgeAssert(managed->good(), "InputStream: Could not open File: " + path.string()); + init(); + } + explicit InputStream(std::istream& in_, + bool spaceSensitive_, + bool caseSensitive_, + Verdict onFail_, + Real floatAbsTol_ = DEFAULT_EPS, + Real floatRelTol_ = DEFAULT_EPS) : + managed(), + in(&in_), + spaceSensitive(spaceSensitive_), + caseSensitive(caseSensitive_), + onFail(onFail_), + floatAbsTol(floatAbsTol_), + floatRelTol(floatRelTol_) { + init(); + } + + InputStream(InputStream&& other) = default; + InputStream& operator=(InputStream&& other) = default; + + InputStream(const InputStream&) = delete; + InputStream& operator=(const InputStream&) = delete; + + void eof() { + checkIn(); + if (!spaceSensitive) *in >> std::ws; + if (in->peek() != std::char_traits::eof()) { + in->get(); + ValidateBase::juryOut << "Missing EOF!"; + fail(); + } + } + + void noteof() { + checkIn(); + if (!spaceSensitive) *in >> std::ws; + if (in->peek() == std::char_traits::eof()) { + ValidateBase::juryOut << "Unexpected EOF!" << onFail; + } + } + + void space() { + if (spaceSensitive) { + noteof(); + if (in->get() != std::char_traits::to_int_type(SPACE)) { + ValidateBase::juryOut << "Missing space!"; + fail(); + } + } + } + + void newline() { + if (spaceSensitive) { + noteof(); + if (in->get() != std::char_traits::to_int_type(NEWLINE)) { + ValidateBase::juryOut << "Missing newline!"; + fail(); + } + } + } + +private: + void check(const std::string& token, const std::regex& pattern) { + if (!std::regex_match(token, pattern)) { + ValidateBase::juryOut << "Token \"" << token << "\" does not match pattern!"; + fail(); + } + } + + std::function checkSeparator(char separator) { + if (separator == SPACE) return [this](){space();}; + if (separator == NEWLINE) return [this](){newline();}; + judgeAssert(false, "InputStream: Separator must be ' ' or '\\n'!"); + return {}; + } + + template + T parse(const std::string& s) { + T res = {}; + if (!details::parse(s, res)) { + ValidateBase::juryOut << "Could not parse token \"" << s << "\"!"; + fail(); + } + return res; + } + +public: + std::string string() { + noteof(); + if (spaceSensitive and !std::isgraph(in->peek())) { + in->get(); + ValidateBase::juryOut << "Invalid whitespace!"; + fail(); + } + std::string res; + *in >> res; + if (res.empty()) { + ValidateBase::juryOut << "Unexpected EOF!" << onFail; + } + if (!caseSensitive) toDefaultCase(res); + return res; + } + + std::string string(Integer lower, Integer upper) { + std::string t = string(); + Integer length = static_cast(t.size()); + if (length < lower or length >= upper) { + ValidateBase::juryOut << "String length " << length << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return t; + } + + std::string string(Integer lower, Integer upper, Constraint& constraint) { + std::string res = string(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + std::string string(const std::regex& pattern) { + std::string t = string(); + check(t, pattern); + return t; + } + + std::string string(const std::regex& pattern, Integer lower, Integer upper) { + std::string t = string(lower, upper); + check(t, pattern); + return t; + } + + std::string string(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint) { + std::string res = string(pattern, lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector strings(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = string(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector strings(Integer count, char separator = DEFAULT_SEPARATOR) { + return strings<>(count, separator); + } + + std::vector strings(Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(lower, upper, count, separator); + } + + std::vector strings(Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(lower, upper, constraint, count, separator); + } + + std::vector strings(const std::regex& pattern, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, count, separator); + } + + std::vector strings(const std::regex& pattern, Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, lower, upper, count, separator); + } + + std::vector strings(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, lower, upper, constraint, count, separator); + } + + Integer integer() { + return parse(string(INTEGER_REGEX)); + } + + Integer integer(Integer lower, Integer upper) { + Integer res = integer(); + if (res < lower or res >= upper) { + ValidateBase::juryOut << "Integer " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } + + Integer integer(Integer lower, Integer upper, Constraint& constraint) { + Integer res = integer(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector integers(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = integer(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector integers(Integer count, char separator = DEFAULT_SEPARATOR) { + return integers<>(count, separator); + } + + std::vector integers(Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return integers(lower, upper, count, separator); + } + + std::vector integers(Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return integers(lower, upper, constraint, count, separator); + } + + // this does not allow NaN or Inf! + // However, those should never be desired. + Real real() { + return parse(string(REAL_REGEX)); + } + + Real real(Real lower, Real upper) {// uses eps + Real res = real(); + if (details::floatEqual(res, lower, floatAbsTol, floatRelTol)) return res; + if (details::floatEqual(res, upper, floatAbsTol, floatRelTol)) return res; + if (std::isnan(res) or !(res >= lower) or !(res < upper)) { + ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } + + Real real(Real lower, Real upper, Constraint& constraint) { + Real res = real(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector reals(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = real(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector reals(Integer count, char separator = DEFAULT_SEPARATOR) { + return reals<>(count, separator); + } + + std::vector reals(Real lower, Real upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return reals(lower, upper, count, separator); + } + + std::vector reals(Real lower, Real upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return reals(lower, upper, constraint, count, separator); + } + + Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals) {// does not use eps + std::string t = string(STRICT_REAL_REGEX); + auto dot = t.find('.'); + Integer decimals = dot == std::string::npos ? 0 : t.size() - dot - 1; + if (decimals < minDecimals or decimals >= maxDecimals) { + ValidateBase::juryOut << "Real " << t << " has wrong amount of decimals!"; + fail(); + return 0; + } + try { + Real res = parse(t); + if (std::isnan(res) or !(res >= lower) or !(res < upper)) { + ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } catch(...) { + ValidateBase::juryOut << "Could not parse token \"" << t << "\" as real!"; + fail(); + return 0; + } + } + + Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint) { + Real res = realStrict(lower, upper, minDecimals, maxDecimals); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector realsStrict(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = realStrict(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, + Integer count, char separator = DEFAULT_SEPARATOR) { + return realsStrict(lower, upper, minDecimals, maxDecimals, count, separator); + } + + std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return realsStrict(lower, upper, minDecimals, maxDecimals, constraint, count, separator); + } + + void expectString(std::string_view expected) { + judgeAssert(details::isToken(expected), "InputStream: expected must not contain a space!"); + std::string seen = string(); + auto [eq, pos] = details::stringEqual(seen, expected, caseSensitive); + if (!eq) { + if (seen.size() > 80) { + seen = seen.substr(0, 75) + "[...]"; + } + ValidateBase::juryOut << "Expected \"" << expected << "\" but got \"" << seen << "\"!"; + if (pos and *pos > 5) { + ValidateBase::juryOut << " (different at position: " << *pos+1 << ")"; + } + fail(); + } + } + + void expectInt(Integer expected) { + Integer seen = integer(); + if (seen != expected) { + ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!"; + fail(); + } + } + + void expectReal(Real expected) { + Real seen = real(); + if (details::floatEqual(seen, expected, floatAbsTol, floatRelTol)) { + ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!"; + if (std::isfinite(seen) and std::isfinite(expected)) { + Real absDiff = std::abs(seen-expected); + Real relDiff = std::abs((seen-expected)/expected); + ValidateBase::juryOut << " (abs: " << absDiff << ", rel: " << relDiff << ")"; + } + fail(); + } + } +private: + void fail() { + //try to find input position... + in->clear(); + auto originalPos = in->tellg(); + in->seekg(0); + if (originalPos != std::streamoff(-1) and *in) { + Integer line = 1; + std::size_t l = 0, r = 0; + std::string buffer; + bool extend = true; + while (*in and in->tellg() < originalPos) { + l = r = buffer.size(); + if (std::isgraph(in->peek())) { + std::string tmp; + *in >> tmp; + buffer += tmp; + } else if (in->peek() == std::char_traits::to_int_type(NEWLINE)) { + line++; + in->get(); + if (in->tellg() < originalPos) { + buffer.clear(); + } else { + buffer += ' '; + extend = false; + } + } else { + buffer += std::char_traits::to_char_type(in->get()); + } + if (*in and in->tellg() >= originalPos) { + r = buffer.size(); + } + } + if (l != r) { + ValidateBase::juryOut << " Line: " << line << ", Char: " << l << '\n'; + if (extend) { + char tmp; + while ((buffer.size() < 80 or buffer.size() < r + 80) and in->get(tmp) and tmp != NEWLINE) { + buffer += tmp; + } + } + if (r > 60 and l > 20) { + Integer offset = std::min(l - 20, r - 60); + l -= offset; + r -= offset; + buffer = "[...]" + buffer.substr(offset + 5); + } + if (buffer.size() > 80) { + buffer = buffer.substr(0, 75); + buffer += "[...]"; + r = std::min(r, buffer.size()); + } + ValidateBase::juryOut << buffer << '\n'; + ValidateBase::juryOut << std::string(l, ' ') << '^' << std::string(r - l - 1, '~'); + } + } + ValidateBase::juryOut << onFail; + } +}; + + +//============================================================================// +// state guard // +//============================================================================// +namespace details { + bool initialized(bool set = false) { + static bool value = false; + return std::exchange(value, value |= set); + } + + struct InitGuard final { + ~InitGuard() { + if (std::uncaught_exceptions() == 0) { + judgeAssert(initialized(), "validate.h: init(argc, argv) was never called!"); + } + } + } initGuard; +} + + +//============================================================================// +// Settings // +//============================================================================// +template +class SettingBase { + template + friend class Setting; + friend class SettingCaseSensitive; + + T value; + + SettingBase(T value_) : value(value_) {} + +public: + SettingBase(SettingBase&& other) = delete; + SettingBase(const SettingBase&) = delete; + SettingBase& operator=(SettingBase&& other) = delete; + SettingBase& operator=(const SettingBase&) = delete; + + operator T() const { + return value; + } + + SettingBase& operator=(T value_) { + judgeAssert(!details::initialized(), "validate.h: Cannot change setting after init(argc, argv) was called!"); + value = value_; + return *this; + } +}; + +template +class Setting final : public SettingBase { +public: + Setting(T value) : SettingBase(value) {} + using SettingBase::operator T; + using SettingBase::operator=; +}; + +class SettingCaseSensitive final : public SettingBase { +public: + SettingCaseSensitive(bool value) : SettingBase(value) {} + using SettingBase::operator bool; + using SettingBase::operator=; + + std::regex regex(std::string_view s, std::regex_constants::syntax_option_type f = std::regex_constants::ECMAScript) const { + if (!value) f |= std::regex_constants::icase; + return std::regex(s.data(), s.size(), f); + } +}; + + +//============================================================================// +// Validators and stuff // +//============================================================================// +namespace ValidateBase { + //OutputStream juryOut(std::cout); //already defined earlier + //OutputStream juryErr(std::cerr); + CommandParser arguments; + //you may change these values before calling::init() but not afterwards! + Setting floatAbsTol(DEFAULT_EPS); + Setting floatRelTol(DEFAULT_EPS); + Setting spaceSensitive(false); + SettingCaseSensitive caseSensitive(false); + + // Real r2 is considered the reference value for relative error. + bool floatEqual(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return details::floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + bool floatLess(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return given <= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + bool floatGreater(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return given >= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + constexpr boolean stringEqual(std::string_view a, std::string_view b, bool caseSensitive_ = caseSensitive) { + return details::stringEqual(a, b, caseSensitive_); + } + + namespace details { + void init(int argc, char** argv) { + judgeAssert(!::details::initialized(), "validate.h: init(argc, argv) was called twice!"); + + //std::ios_base::sync_with_stdio(false); + //cin.tie(nullptr); + + arguments = CommandParser(argc, argv); + if (auto seed = arguments[SEED_COMMAND]) Random::seed(seed.asInteger()); + // parse default flags manually, since they dont use '--' prefix + auto eps = arguments.getRaw(FLOAT_TOLERANCE); + floatAbsTol = eps.asReal(floatAbsTol); + floatRelTol = eps.asReal(floatRelTol); + floatAbsTol = arguments.getRaw(FLOAT_ABSOLUTE_TOLERANCE).asReal(floatAbsTol); + floatRelTol = arguments.getRaw(FLOAT_RELATIVE_TOLERANCE).asReal(floatRelTol); + + if (arguments.getRaw(SPACE_SENSITIVE)) spaceSensitive = true; + if (arguments.getRaw(CASE_SENSITIVE)) caseSensitive = true; + + ::details::initialized(true); + } + } + +} // namespace ValidateBase + +namespace ConstraintsBase { + ConstraintsLogger constraint; + + void initConstraints() { + if (auto file = ValidateBase::arguments[CONSTRAINT_COMMAND]) { + constraint = ConstraintsLogger(file.asString()); + } + } + +} // namespace ConstraintsBase + +//called as ./validator [arguments] < inputfile +namespace InputValidator { + using namespace ValidateBase; + using namespace ConstraintsBase; + + InputStream testIn; + + void init(int argc, char** argv) { + spaceSensitive = true; + caseSensitive = true; + + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::cout); + + testIn = InputStream(std::cin, spaceSensitive, caseSensitive, WA, floatAbsTol, floatRelTol); + initConstraints(); + } + +} // namespace InputValidator + +//called as ./validator input judgeanswer feedbackdir < teamoutput +namespace OutputValidator { + using namespace ValidateBase; + using namespace ConstraintsBase; + + InputStream testIn; + InputStream juryAns; + InputStream teamAns; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE); + + testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL); + juryAns = InputStream(std::filesystem::path(arguments[2]), false, caseSensitive, FAIL); + teamAns = InputStream(std::cin, spaceSensitive, caseSensitive, WA); + initConstraints(); + } + +} // namespace OutputValidator + +//called as ./interactor input judgeanswer feedbackdir <> teamoutput +namespace Interactor { + using namespace ValidateBase; + + OutputStream toTeam; + InputStream testIn; + InputStream fromTeam; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE); + toTeam = OutputStream(std::cout); + + testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL); + fromTeam = InputStream(std::cin, spaceSensitive, caseSensitive, WA); + } + +} // namespace Interactor + +//called as ./generator [arguments] +namespace Generator { + using namespace ValidateBase; + + OutputStream testOut; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::cerr); + testOut = OutputStream(std::cout); + } + +} // namespace Generator + +#endif diff --git a/ICPC/nwerc2023_C/data.zip b/ICPC/nwerc2023_C/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..1120efaa641e345751218e9e3025b6200aa648bb --- /dev/null +++ b/ICPC/nwerc2023_C/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:649797f71211929574b32c8992a4bad824163cfa41c8f121fe22b710fff88829 +size 48190763 diff --git a/ICPC/nwerc2023_C/init.yml b/ICPC/nwerc2023_C/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..188964f572d794999e750af61a85e5ee9afb4c66 --- /dev/null +++ b/ICPC/nwerc2023_C/init.yml @@ -0,0 +1,137 @@ +archive: data.zip +test_cases: +- in: 01-query-biggest.in + out: 01-query-biggest.ans + points: 1 +- in: 02-random.in + out: 02-random.ans + points: 1 +- in: 03-random_even.in + out: 03-random_even.ans + points: 1 +- in: 04-random_occupied.in + out: 04-random_occupied.ans + points: 1 +- in: 05-distinct_primes.in + out: 05-distinct_primes.ans + points: 1 +- in: 06-big_prime.in + out: 06-big_prime.ans + points: 1 +- in: 07-small_prime.in + out: 07-small_prime.ans + points: 1 +- in: 08-semiprime.in + out: 08-semiprime.ans + points: 1 +- in: 09-composite.in + out: 09-composite.ans + points: 1 +- in: 10-random.in + out: 10-random.ans + points: 1 +- in: 11-random.in + out: 11-random.ans + points: 1 +- in: 12-random.in + out: 12-random.ans + points: 1 +- in: 13-random.in + out: 13-random.ans + points: 1 +- in: 14-random.in + out: 14-random.ans + points: 1 +- in: 15-random_even.in + out: 15-random_even.ans + points: 1 +- in: 16-random_even.in + out: 16-random_even.ans + points: 1 +- in: 17-random_even.in + out: 17-random_even.ans + points: 1 +- in: 18-random_even.in + out: 18-random_even.ans + points: 1 +- in: 19-random_even.in + out: 19-random_even.ans + points: 1 +- in: 20-random_occupied.in + out: 20-random_occupied.ans + points: 1 +- in: 21-random_occupied.in + out: 21-random_occupied.ans + points: 1 +- in: 22-distinct_primes.in + out: 22-distinct_primes.ans + points: 1 +- in: 23-distinct_primes.in + out: 23-distinct_primes.ans + points: 1 +- in: 24-power_of_two.in + out: 24-power_of_two.ans + points: 1 +- in: 25-follow.in + out: 25-follow.ans + points: 1 +- in: 26-follow.in + out: 26-follow.ans + points: 1 +- in: 27-random.in + out: 27-random.ans + points: 1 +- in: 28-random.in + out: 28-random.ans + points: 1 +- in: 29-big_prime.in + out: 29-big_prime.ans + points: 1 +- in: 30-big_prime.in + out: 30-big_prime.ans + points: 1 +- in: 31-small_prime.in + out: 31-small_prime.ans + points: 1 +- in: 32-semiprime.in + out: 32-semiprime.ans + points: 1 +- in: 33-semiprime.in + out: 33-semiprime.ans + points: 1 +- in: 34-composite.in + out: 34-composite.ans + points: 1 +- in: 35-query_all.in + out: 35-query_all.ans + points: 1 +- in: 36-query_all.in + out: 36-query_all.ans + points: 1 +- in: 37-query_all.in + out: 37-query_all.ans + points: 1 +- in: 38-query_all.in + out: 38-query_all.ans + points: 1 +- in: 39-query_all.in + out: 39-query_all.ans + points: 1 +- in: 40-query_all.in + out: 40-query_all.ans + points: 1 +- in: 41-manual.in + out: 41-manual.ans + points: 1 +- in: 42-manual.in + out: 42-manual.ans + points: 1 +- in: 43-manual.in + out: 43-manual.ans + points: 1 +- in: 44-manual.in + out: 44-manual.ans + points: 1 +- in: 45-manual.in + out: 45-manual.ans + points: 1 diff --git a/ICPC/nwerc2023_D/data.zip b/ICPC/nwerc2023_D/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..a8651cfc5a03b9b856b45fb153bd1f288fc36ae3 --- /dev/null +++ b/ICPC/nwerc2023_D/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aab1e5aeb5b1c01da996d45dca2f863a670ae6b3937726d223786ed3d892f8f7 +size 21922 diff --git a/ICPC/nwerc2023_D/init.yml b/ICPC/nwerc2023_D/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ddf034e6944be490dbbb90ac1969e88b5de089fe --- /dev/null +++ b/ICPC/nwerc2023_D/init.yml @@ -0,0 +1,255 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 01-rand_min.in + out: 01-rand_min.ans + points: 1 +- in: 02-rand_almost_max.in + out: 02-rand_almost_max.ans + points: 1 +- in: 03-rand_almost_max.in + out: 03-rand_almost_max.ans + points: 1 +- in: 04-rand_almost_max.in + out: 04-rand_almost_max.ans + points: 1 +- in: 05-rand_max.in + out: 05-rand_max.ans + points: 1 +- in: 06-rand_worst.in + out: 06-rand_worst.ans + points: 1 +- in: 07-rand_worst.in + out: 07-rand_worst.ans + points: 1 +- in: 08-rand_worst_rows.in + out: 08-rand_worst_rows.ans + points: 1 +- in: 09-rand_worst_rows.in + out: 09-rand_worst_rows.ans + points: 1 +- in: 10-rand_worst_cols.in + out: 10-rand_worst_cols.ans + points: 1 +- in: 11-rand_worst_cols.in + out: 11-rand_worst_cols.ans + points: 1 +- in: 12-all_empty.in + out: 12-all_empty.ans + points: 1 +- in: 13-all_empty.in + out: 13-all_empty.ans + points: 1 +- in: 14-all_empty.in + out: 14-all_empty.ans + points: 1 +- in: 15-all_empty.in + out: 15-all_empty.ans + points: 1 +- in: 16-all_empty.in + out: 16-all_empty.ans + points: 1 +- in: 17-all_empty.in + out: 17-all_empty.ans + points: 1 +- in: 18-all_empty.in + out: 18-all_empty.ans + points: 1 +- in: 19-all_empty.in + out: 19-all_empty.ans + points: 1 +- in: 20-all_empty.in + out: 20-all_empty.ans + points: 1 +- in: 21-all_empty.in + out: 21-all_empty.ans + points: 1 +- in: 22-all_empty.in + out: 22-all_empty.ans + points: 1 +- in: 23-all_empty.in + out: 23-all_empty.ans + points: 1 +- in: 24-all_full.in + out: 24-all_full.ans + points: 1 +- in: 25-all_full.in + out: 25-all_full.ans + points: 1 +- in: 26-all_full.in + out: 26-all_full.ans + points: 1 +- in: 27-all_full.in + out: 27-all_full.ans + points: 1 +- in: 28-all_full.in + out: 28-all_full.ans + points: 1 +- in: 29-all_full.in + out: 29-all_full.ans + points: 1 +- in: 30-all_full.in + out: 30-all_full.ans + points: 1 +- in: 31-all_full.in + out: 31-all_full.ans + points: 1 +- in: 32-all_full.in + out: 32-all_full.ans + points: 1 +- in: 33-all_full.in + out: 33-all_full.ans + points: 1 +- in: 34-all_full.in + out: 34-all_full.ans + points: 1 +- in: 35-all_full.in + out: 35-all_full.ans + points: 1 +- in: 36-exact_fit.in + out: 36-exact_fit.ans + points: 1 +- in: 37-exact_fit.in + out: 37-exact_fit.ans + points: 1 +- in: 38-exact_fit.in + out: 38-exact_fit.ans + points: 1 +- in: 39-exact_fit.in + out: 39-exact_fit.ans + points: 1 +- in: 40-exact_fit.in + out: 40-exact_fit.ans + points: 1 +- in: 41-exact_fit.in + out: 41-exact_fit.ans + points: 1 +- in: 42-exact_fit.in + out: 42-exact_fit.ans + points: 1 +- in: 43-exact_fit.in + out: 43-exact_fit.ans + points: 1 +- in: 44-exact_fit.in + out: 44-exact_fit.ans + points: 1 +- in: 45-exact_fit.in + out: 45-exact_fit.ans + points: 1 +- in: 46-exact_fit.in + out: 46-exact_fit.ans + points: 1 +- in: 47-exact_fit_shuffled.in + out: 47-exact_fit_shuffled.ans + points: 1 +- in: 48-exact_fit_shuffled.in + out: 48-exact_fit_shuffled.ans + points: 1 +- in: 49-exact_fit_shuffled.in + out: 49-exact_fit_shuffled.ans + points: 1 +- in: 50-exact_fit_shuffled.in + out: 50-exact_fit_shuffled.ans + points: 1 +- in: 51-exact_fit_shuffled.in + out: 51-exact_fit_shuffled.ans + points: 1 +- in: 52-exact_fit_shuffled.in + out: 52-exact_fit_shuffled.ans + points: 1 +- in: 53-exact_fit_shuffled.in + out: 53-exact_fit_shuffled.ans + points: 1 +- in: 54-exact_fit_shuffled.in + out: 54-exact_fit_shuffled.ans + points: 1 +- in: 55-exact_fit_shuffled.in + out: 55-exact_fit_shuffled.ans + points: 1 +- in: 56-exact_fit_shuffled.in + out: 56-exact_fit_shuffled.ans + points: 1 +- in: 57-exact_fit_shuffled.in + out: 57-exact_fit_shuffled.ans + points: 1 +- in: 58-corners.in + out: 58-corners.ans + points: 1 +- in: 59-corners.in + out: 59-corners.ans + points: 1 +- in: 60-corners.in + out: 60-corners.ans + points: 1 +- in: 61-corners.in + out: 61-corners.ans + points: 1 +- in: 62-corners.in + out: 62-corners.ans + points: 1 +- in: 63-4corners.in + out: 63-4corners.ans + points: 1 +- in: 64-4corners.in + out: 64-4corners.ans + points: 1 +- in: 65-4corners.in + out: 65-4corners.ans + points: 1 +- in: 66-4corners.in + out: 66-4corners.ans + points: 1 +- in: 67-4corners.in + out: 67-4corners.ans + points: 1 +- in: 68-4corners.in + out: 68-4corners.ans + points: 1 +- in: 69-4corners.in + out: 69-4corners.ans + points: 1 +- in: 70-4corners.in + out: 70-4corners.ans + points: 1 +- in: 71-4corners.in + out: 71-4corners.ans + points: 1 +- in: 72-corner.in + out: 72-corner.ans + points: 1 +- in: 73-corner.in + out: 73-corner.ans + points: 1 +- in: 74-corner.in + out: 74-corner.ans + points: 1 +- in: 75-corner.in + out: 75-corner.ans + points: 1 +- in: 76-corner.in + out: 76-corner.ans + points: 1 +- in: 77-corner.in + out: 77-corner.ans + points: 1 +- in: 78-corner.in + out: 78-corner.ans + points: 1 +- in: 79-corner.in + out: 79-corner.ans + points: 1 +- in: 80-corner.in + out: 80-corner.ans + points: 1 +- in: 81-corner.in + out: 81-corner.ans + points: 1 +- in: 82-corner.in + out: 82-corner.ans + points: 1 +- in: 83-corner.in + out: 83-corner.ans + points: 1 diff --git a/ICPC/nwerc2023_E/data.zip b/ICPC/nwerc2023_E/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..f06ed70a397634d070b956b5a0fd896a4cb29da0 --- /dev/null +++ b/ICPC/nwerc2023_E/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d2d6977cbb540127a2425e6d396e1aa9dcea3c85eb53900366b6d8f16d04079 +size 242919 diff --git a/ICPC/nwerc2023_E/init.yml b/ICPC/nwerc2023_E/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b617f971a768f7af357fba9d1e57ce51d623b27f --- /dev/null +++ b/ICPC/nwerc2023_E/init.yml @@ -0,0 +1,404 @@ +archive: data.zip +test_cases: +- in: 001-twos.in + out: 001-twos.ans + points: 1 +- in: 002-rivals.in + out: 002-rivals.ans + points: 1 +- in: 003-tree2.in + out: 003-tree2.ans + points: 1 +- in: 004-tiny.in + out: 004-tiny.ans + points: 1 +- in: 005-tiny.in + out: 005-tiny.ans + points: 1 +- in: 006-tiny.in + out: 006-tiny.ans + points: 1 +- in: 007-tiny.in + out: 007-tiny.ans + points: 1 +- in: 008-tiny.in + out: 008-tiny.ans + points: 1 +- in: 009-tiny.in + out: 009-tiny.ans + points: 1 +- in: 010-tiny.in + out: 010-tiny.ans + points: 1 +- in: 011-tiny.in + out: 011-tiny.ans + points: 1 +- in: 012-tiny.in + out: 012-tiny.ans + points: 1 +- in: 013-wrong_base.in + out: 013-wrong_base.ans + points: 1 +- in: 014-wrong_base.in + out: 014-wrong_base.ans + points: 1 +- in: 015-random.in + out: 015-random.ans + points: 1 +- in: 016-random.in + out: 016-random.ans + points: 1 +- in: 017-random.in + out: 017-random.ans + points: 1 +- in: 018-random.in + out: 018-random.ans + points: 1 +- in: 019-random.in + out: 019-random.ans + points: 1 +- in: 020-random.in + out: 020-random.ans + points: 1 +- in: 021-random.in + out: 021-random.ans + points: 1 +- in: 022-random.in + out: 022-random.ans + points: 1 +- in: 023-chain.in + out: 023-chain.ans + points: 1 +- in: 024-chain.in + out: 024-chain.ans + points: 1 +- in: 025-chain.in + out: 025-chain.ans + points: 1 +- in: 026-chain.in + out: 026-chain.ans + points: 1 +- in: 027-chain.in + out: 027-chain.ans + points: 1 +- in: 028-max_output.in + out: 028-max_output.ans + points: 1 +- in: 029-rivals.in + out: 029-rivals.ans + points: 1 +- in: 030-rivals.in + out: 030-rivals.ans + points: 1 +- in: 031-rivals.in + out: 031-rivals.ans + points: 1 +- in: 032-rivals.in + out: 032-rivals.ans + points: 1 +- in: 033-rivals.in + out: 033-rivals.ans + points: 1 +- in: 034-rivals.in + out: 034-rivals.ans + points: 1 +- in: 035-rivals.in + out: 035-rivals.ans + points: 1 +- in: 036-rivals.in + out: 036-rivals.ans + points: 1 +- in: 037-long_lists.in + out: 037-long_lists.ans + points: 1 +- in: 038-long_lists.in + out: 038-long_lists.ans + points: 1 +- in: 039-long_lists.in + out: 039-long_lists.ans + points: 1 +- in: 040-long_lists.in + out: 040-long_lists.ans + points: 1 +- in: 041-long_lists.in + out: 041-long_lists.ans + points: 1 +- in: 042-one_long_list.in + out: 042-one_long_list.ans + points: 1 +- in: 043-tree.in + out: 043-tree.ans + points: 1 +- in: 044-tree.in + out: 044-tree.ans + points: 1 +- in: 045-tree.in + out: 045-tree.ans + points: 1 +- in: 046-tree.in + out: 046-tree.ans + points: 1 +- in: 047-tree.in + out: 047-tree.ans + points: 1 +- in: 048-tree.in + out: 048-tree.ans + points: 1 +- in: 049-tree.in + out: 049-tree.ans + points: 1 +- in: 050-almost_isomorphic.in + out: 050-almost_isomorphic.ans + points: 1 +- in: 051-almost_isomorphic.in + out: 051-almost_isomorphic.ans + points: 1 +- in: 052-almost_isomorphic.in + out: 052-almost_isomorphic.ans + points: 1 +- in: 053-almost_isomorphic.in + out: 053-almost_isomorphic.ans + points: 1 +- in: 054-almost_isomorphic.in + out: 054-almost_isomorphic.ans + points: 1 +- in: 055-almost_isomorphic.in + out: 055-almost_isomorphic.ans + points: 1 +- in: 056-almost_isomorphic.in + out: 056-almost_isomorphic.ans + points: 1 +- in: 057-triangles.in + out: 057-triangles.ans + points: 1 +- in: 058-triangles.in + out: 058-triangles.ans + points: 1 +- in: 059-triangles.in + out: 059-triangles.ans + points: 1 +- in: 060-triangles.in + out: 060-triangles.ans + points: 1 +- in: 061-triangles.in + out: 061-triangles.ans + points: 1 +- in: 062-triangles.in + out: 062-triangles.ans + points: 1 +- in: 063-triangles.in + out: 063-triangles.ans + points: 1 +- in: 064-triangles.in + out: 064-triangles.ans + points: 1 +- in: 065-triangles.in + out: 065-triangles.ans + points: 1 +- in: 066-triangles.in + out: 066-triangles.ans + points: 1 +- in: 067-tree2.in + out: 067-tree2.ans + points: 1 +- in: 068-tree2.in + out: 068-tree2.ans + points: 1 +- in: 069-tree2.in + out: 069-tree2.ans + points: 1 +- in: 070-tree2.in + out: 070-tree2.ans + points: 1 +- in: 071-tree2.in + out: 071-tree2.ans + points: 1 +- in: 072-tree2.in + out: 072-tree2.ans + points: 1 +- in: 073-tree2.in + out: 073-tree2.ans + points: 1 +- in: 074-tree2.in + out: 074-tree2.ans + points: 1 +- in: 075-one_query.in + out: 075-one_query.ans + points: 1 +- in: 076-anti_ragnar.in + out: 076-anti_ragnar.ans + points: 1 +- in: 077-fibonacci.in + out: 077-fibonacci.ans + points: 1 +- in: 078-flipflop-1s.in + out: 078-flipflop-1s.ans + points: 1 +- in: 079-flipflop-1s.in + out: 079-flipflop-1s.ans + points: 1 +- in: 080-flipflop-1s.in + out: 080-flipflop-1s.ans + points: 1 +- in: 081-flipflop-2s.in + out: 081-flipflop-2s.ans + points: 1 +- in: 082-flipflop-2s.in + out: 082-flipflop-2s.ans + points: 1 +- in: 083-flipflop-2s.in + out: 083-flipflop-2s.ans + points: 1 +- in: 084-flipflop-2s.in + out: 084-flipflop-2s.ans + points: 1 +- in: 085-flipflop-2s.in + out: 085-flipflop-2s.ans + points: 1 +- in: 086-flipflop-2s.in + out: 086-flipflop-2s.ans + points: 1 +- in: 087-flipflop-3s.in + out: 087-flipflop-3s.ans + points: 1 +- in: 088-flipflop-3s.in + out: 088-flipflop-3s.ans + points: 1 +- in: 089-flipflop-3s.in + out: 089-flipflop-3s.ans + points: 1 +- in: 090-flipflop-3s.in + out: 090-flipflop-3s.ans + points: 1 +- in: 091-flipflop-3s.in + out: 091-flipflop-3s.ans + points: 1 +- in: 092-flipflop-3s.in + out: 092-flipflop-3s.ans + points: 1 +- in: 093-flipflop-4s.in + out: 093-flipflop-4s.ans + points: 1 +- in: 094-flipflop-4s.in + out: 094-flipflop-4s.ans + points: 1 +- in: 095-flipflop-4s.in + out: 095-flipflop-4s.ans + points: 1 +- in: 096-flipflop-4s.in + out: 096-flipflop-4s.ans + points: 1 +- in: 097-flipflop-4s.in + out: 097-flipflop-4s.ans + points: 1 +- in: 098-flipflop-4s.in + out: 098-flipflop-4s.ans + points: 1 +- in: 099-flipflop-9s.in + out: 099-flipflop-9s.ans + points: 1 +- in: 100-flipflop-9s.in + out: 100-flipflop-9s.ans + points: 1 +- in: 101-flipflop-9s.in + out: 101-flipflop-9s.ans + points: 1 +- in: 102-flipflop-9s.in + out: 102-flipflop-9s.ans + points: 1 +- in: 103-flipflop-9s.in + out: 103-flipflop-9s.ans + points: 1 +- in: 104-flipflop-9s.in + out: 104-flipflop-9s.ans + points: 1 +- in: 105-flipflop-id-1s.in + out: 105-flipflop-id-1s.ans + points: 1 +- in: 106-flipflop-id-1s.in + out: 106-flipflop-id-1s.ans + points: 1 +- in: 107-flipflop-id-1s.in + out: 107-flipflop-id-1s.ans + points: 1 +- in: 108-flipflop-id-2s.in + out: 108-flipflop-id-2s.ans + points: 1 +- in: 109-flipflop-id-2s.in + out: 109-flipflop-id-2s.ans + points: 1 +- in: 110-flipflop-id-2s.in + out: 110-flipflop-id-2s.ans + points: 1 +- in: 111-flipflop-id-3s.in + out: 111-flipflop-id-3s.ans + points: 1 +- in: 112-flipflop-id-3s.in + out: 112-flipflop-id-3s.ans + points: 1 +- in: 113-flipflop-id-3s.in + out: 113-flipflop-id-3s.ans + points: 1 +- in: 114-flipflop-id-4s.in + out: 114-flipflop-id-4s.ans + points: 1 +- in: 115-flipflop-id-4s.in + out: 115-flipflop-id-4s.ans + points: 1 +- in: 116-flipflop-id-4s.in + out: 116-flipflop-id-4s.ans + points: 1 +- in: 117-flipflop-id-9s.in + out: 117-flipflop-id-9s.ans + points: 1 +- in: 118-flipflop-id-9s.in + out: 118-flipflop-id-9s.ans + points: 1 +- in: 119-flipflop-id-9s.in + out: 119-flipflop-id-9s.ans + points: 1 +- in: 120-flipflop-id-1s-p.in + out: 120-flipflop-id-1s-p.ans + points: 1 +- in: 121-flipflop-id-1s-p.in + out: 121-flipflop-id-1s-p.ans + points: 1 +- in: 122-flipflop-id-1s-p.in + out: 122-flipflop-id-1s-p.ans + points: 1 +- in: 123-flipflop-id-2s-p.in + out: 123-flipflop-id-2s-p.ans + points: 1 +- in: 124-flipflop-id-2s-p.in + out: 124-flipflop-id-2s-p.ans + points: 1 +- in: 125-flipflop-id-2s-p.in + out: 125-flipflop-id-2s-p.ans + points: 1 +- in: 126-flipflop-id-3s-p.in + out: 126-flipflop-id-3s-p.ans + points: 1 +- in: 127-flipflop-id-3s-p.in + out: 127-flipflop-id-3s-p.ans + points: 1 +- in: 128-flipflop-id-3s-p.in + out: 128-flipflop-id-3s-p.ans + points: 1 +- in: 129-flipflop-id-4s-p.in + out: 129-flipflop-id-4s-p.ans + points: 1 +- in: 130-flipflop-id-4s-p.in + out: 130-flipflop-id-4s-p.ans + points: 1 +- in: 131-flipflop-id-4s-p.in + out: 131-flipflop-id-4s-p.ans + points: 1 +- in: 132-flipflop-id-9s-p.in + out: 132-flipflop-id-9s-p.ans + points: 1 +- in: 133-flipflop-id-9s-p.in + out: 133-flipflop-id-9s-p.ans + points: 1 +- in: 134-flipflop-id-9s-p.in + out: 134-flipflop-id-9s-p.ans + points: 1 diff --git a/ICPC/nwerc2023_F/data.zip b/ICPC/nwerc2023_F/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..5531ef27ccfe0c46a442b5cb311dbb9eb3459340 --- /dev/null +++ b/ICPC/nwerc2023_F/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:578c303741e521844c78cdfa125ff3dd0e48444b3f99282cddd941cfc59844ad +size 19220 diff --git a/ICPC/nwerc2023_F/init.yml b/ICPC/nwerc2023_F/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..0b26bb5eb4478f1451d31ad9bed2f2dc65a7d0d1 --- /dev/null +++ b/ICPC/nwerc2023_F/init.yml @@ -0,0 +1,223 @@ +archive: data.zip +checker: + args: + files: + - output_validators/output_validator/validate.h + - output_validators/output_validator/outputValidator.cpp + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 01-manual-many-subsets.in + out: 01-manual-many-subsets.ans + points: 1 +- in: 02-possible.in + out: 02-possible.ans + points: 1 +- in: 03-impossible.in + out: 03-impossible.ans + points: 1 +- in: 04-manual.in + out: 04-manual.ans + points: 1 +- in: 05-manual.in + out: 05-manual.ans + points: 1 +- in: 06-manual.in + out: 06-manual.ans + points: 1 +- in: 07-manual.in + out: 07-manual.ans + points: 1 +- in: 08-manual.in + out: 08-manual.ans + points: 1 +- in: 09-manual.in + out: 09-manual.ans + points: 1 +- in: 10-manual.in + out: 10-manual.ans + points: 1 +- in: 11-manual.in + out: 11-manual.ans + points: 1 +- in: 12-manual.in + out: 12-manual.ans + points: 1 +- in: 13-manual.in + out: 13-manual.ans + points: 1 +- in: 14-manual.in + out: 14-manual.ans + points: 1 +- in: 15-manual.in + out: 15-manual.ans + points: 1 +- in: 16-manual.in + out: 16-manual.ans + points: 1 +- in: 17-overflow.in + out: 17-overflow.ans + points: 1 +- in: 18-overflow.in + out: 18-overflow.ans + points: 1 +- in: 19-manual.in + out: 19-manual.ans + points: 1 +- in: 20-manual.in + out: 20-manual.ans + points: 1 +- in: 21-manual.in + out: 21-manual.ans + points: 1 +- in: 22-manual.in + out: 22-manual.ans + points: 1 +- in: 23-manual.in + out: 23-manual.ans + points: 1 +- in: 24-manual.in + out: 24-manual.ans + points: 1 +- in: 25-manual.in + out: 25-manual.ans + points: 1 +- in: 26-manual.in + out: 26-manual.ans + points: 1 +- in: 27-manual.in + out: 27-manual.ans + points: 1 +- in: 28-manual.in + out: 28-manual.ans + points: 1 +- in: 29-manual.in + out: 29-manual.ans + points: 1 +- in: 30-manual.in + out: 30-manual.ans + points: 1 +- in: 31-manual.in + out: 31-manual.ans + points: 1 +- in: 32-manual.in + out: 32-manual.ans + points: 1 +- in: 33-need_gcd.in + out: 33-need_gcd.ans + points: 1 +- in: 34-need_gcd.in + out: 34-need_gcd.ans + points: 1 +- in: 35-possible.in + out: 35-possible.ans + points: 1 +- in: 36-possible.in + out: 36-possible.ans + points: 1 +- in: 37-possible.in + out: 37-possible.ans + points: 1 +- in: 38-possible.in + out: 38-possible.ans + points: 1 +- in: 39-possible.in + out: 39-possible.ans + points: 1 +- in: 40-possible.in + out: 40-possible.ans + points: 1 +- in: 41-possible.in + out: 41-possible.ans + points: 1 +- in: 42-possible.in + out: 42-possible.ans + points: 1 +- in: 43-possible.in + out: 43-possible.ans + points: 1 +- in: 44-possible.in + out: 44-possible.ans + points: 1 +- in: 45-possible.in + out: 45-possible.ans + points: 1 +- in: 46-possible.in + out: 46-possible.ans + points: 1 +- in: 47-impossible.in + out: 47-impossible.ans + points: 1 +- in: 48-impossible.in + out: 48-impossible.ans + points: 1 +- in: 49-impossible.in + out: 49-impossible.ans + points: 1 +- in: 50-impossible.in + out: 50-impossible.ans + points: 1 +- in: 51-impossible.in + out: 51-impossible.ans + points: 1 +- in: 52-impossible.in + out: 52-impossible.ans + points: 1 +- in: 53-impossible.in + out: 53-impossible.ans + points: 1 +- in: 54-impossible.in + out: 54-impossible.ans + points: 1 +- in: 55-impossible.in + out: 55-impossible.ans + points: 1 +- in: 56-impossible.in + out: 56-impossible.ans + points: 1 +- in: 57-impossible.in + out: 57-impossible.ans + points: 1 +- in: 58-impossible.in + out: 58-impossible.ans + points: 1 +- in: 59-manual-many-subsets.in + out: 59-manual-many-subsets.ans + points: 1 +- in: 60-manual-many-subsets.in + out: 60-manual-many-subsets.ans + points: 1 +- in: 61-manual-many-subsets.in + out: 61-manual-many-subsets.ans + points: 1 +- in: 62-manual-many-subsets.in + out: 62-manual-many-subsets.ans + points: 1 +- in: 63-manual-many-subsets.in + out: 63-manual-many-subsets.ans + points: 1 +- in: 64-manual-many-subsets.in + out: 64-manual-many-subsets.ans + points: 1 +- in: 65-manual-many-subsets.in + out: 65-manual-many-subsets.ans + points: 1 +- in: 66-manual-many-subsets.in + out: 66-manual-many-subsets.ans + points: 1 +- in: 67-manual-many-subsets.in + out: 67-manual-many-subsets.ans + points: 1 +- in: 68-manual-many-subsets.in + out: 68-manual-many-subsets.ans + points: 1 +- in: 69-manual-many-subsets.in + out: 69-manual-many-subsets.ans + points: 1 +- in: 70-manual-many-subsets.in + out: 70-manual-many-subsets.ans + points: 1 +- in: 71-manual-many-subsets.in + out: 71-manual-many-subsets.ans + points: 1 diff --git a/ICPC/nwerc2023_F/output_validators/output_validator/outputValidator.cpp b/ICPC/nwerc2023_F/output_validators/output_validator/outputValidator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..504680424165bb5608521e94d5c80bc557544fc0 --- /dev/null +++ b/ICPC/nwerc2023_F/output_validators/output_validator/outputValidator.cpp @@ -0,0 +1,84 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validate.h" + +std::pair isSubsequence(std::string_view x, std::string_view of) { + std::size_t i = 0; + std::string remain; + for (std::size_t j = 0; j < of.size(); j++) { + if (i < x.size() && x[i] == of[j]) i++; + else remain.push_back(of[j]); + } + std::sort(remain.begin(), remain.end()); + return {i == x.size(), remain}; +} + +int main(int argc, char **argv) { + OutputValidator::init(argc, argv); + using namespace OutputValidator; + + if (stringEqual(juryAns.string(), "impossible")) { + teamAns.expectString("impossible"); + teamAns.newline(); + teamAns.eof(); + juryOut << "OK impossible" << AC; + } else { + teamAns.expectString("possible"); + teamAns.newline(); + std::string a = testIn.string(); + std::string b = testIn.string(); + Integer c = testIn.integer(); + Integer d = testIn.integer(); + + std::string a2 = teamAns.string(INTEGER_REGEX); + teamAns.space(); + std::string b2 = teamAns.string(INTEGER_REGEX); + teamAns.newline(); + + auto [ba, ra] = isSubsequence(a2, a); + auto [bb, rb] = isSubsequence(b2, b); + + if (!ba) juryOut << "a' not generated by cancelling digits!" << WA; + if (!bb) juryOut << "b' not generated by cancelling digits!" << WA; + if (ra != rb) juryOut << ra << " != " << rb << ": cancelled digits are not the same" << WA; + + Integer a3 = std::stoll(a2); + Integer b3 = std::stoll(b2); + if (a3 == 0 || b3 == 0 || + mulMod(c, b3, 1'000'000'007) != mulMod(a3, d, 1'000'000'007) || //product of mods is larger than 10^18*10^18 + mulMod(c, b3, 1'000'000'009) != mulMod(a3, d, 1'000'000'009) || + mulMod(c, b3, 1'000'000'021) != mulMod(a3, d, 1'000'000'021) || + mulMod(c, b3, 1'000'000'033) != mulMod(a3, d, 1'000'000'033)) { + juryOut << a << "/" << b << " != " << c << "/" << d << WA; + } + + teamAns.eof(); + juryOut << "OK possible" << AC; + } +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2023_F/output_validators/output_validator/validate.h b/ICPC/nwerc2023_F/output_validators/output_validator/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..73a2289afda07cd2370d02439fb91fea2ee1743b --- /dev/null +++ b/ICPC/nwerc2023_F/output_validators/output_validator/validate.h @@ -0,0 +1,2662 @@ +//============================================================================// +// validate.h // +//============================================================================// +// This header can be used to safely parse team output tokenwise. We support: // +// - string tokens (get converted to lowercase) // +// - integer tokens in [-2^63, 2^63) // +// - float tokens (relative and absolute error of 10^6 is allowed by default) // +// Tokens need to be separated by whitespace (any amount). The following // +// command line flags allow stricter checking: // +// - caseSensitive: string tokens don't get converted to lowercase // +// - space_change_sensitive: tokens need to be separated by the corect // +// amount of whitespaces // +// - FLOAT_{RELATIVE|ABSOLUTE}_TOLERANCE: allowed relative/absolute error // +// // +// This header can also be used to safely verify input files. In this case // +// tokens are case sensitive and all whitespaces have to be checked. Also // +// whitespaces are not interchangeable. // +// // +// This header can be used to generate random numbers in a deterministic and // +// reproducable fashion. (The randomness is consistent across compilers and // +// machines) // +//============================================================================// +// version 2.3.2 // +// https://github.com/mzuenni/icpc-header // +//============================================================================// + +#ifndef VALIDATE_H +#define VALIDATE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//============================================================================// +// Basic definitions and constants // +//============================================================================// +// default types +using Integer = std::int64_t; +using Real = long double; + +// derived types +using UInteger = std::make_unsigned::type; +constexpr Integer operator ""_int(unsigned long long int value) {return static_cast(value);} +constexpr UInteger operator ""_uint(unsigned long long int value) {return static_cast(value);} +constexpr Real operator ""_real(unsigned long long int value) {return static_cast(value);} +constexpr Real operator ""_real(long double value) {return static_cast(value);} + +// settings which can be overwritten before the include! +//#define DOUBLE_FALLBACK +namespace Settings { + namespace details { + using RandomEngine = std::mt19937_64; + constexpr Integer LARGE = 0x3FFF'FFFF'FFFF'FFFF; + constexpr bool DEFAULT_CASE_LOWER = true; + constexpr int DEFAULT_PRECISION = 6; + constexpr Real DEFAULT_EPS = 1e-6_real; + + [[noreturn]] void exitVerdict(int exitCode) { + //throw exitCode; + //quick_exit(exitCode); + std::exit(exitCode); + } + } + using namespace details; +} +// make settings publically available +using Settings::RandomEngine; +using Settings::LARGE; +using Settings::DEFAULT_CASE_LOWER; +using Settings::DEFAULT_PRECISION; +using Settings::DEFAULT_EPS; +using Settings::exitVerdict; + +// useful constants +constexpr std::string_view LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view UPPER = LETTER.substr(0, 26); +constexpr std::string_view LOWER = LETTER.substr(26); +constexpr std::string_view VOWEL = "AEIOUaeiou"; +constexpr std::string_view UPPER_VOWELS = VOWEL.substr(0, 5); +constexpr std::string_view LOWER_VOWELS = VOWEL.substr(5); +constexpr std::string_view CONSONANT = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"; +constexpr std::string_view UPPER_CONSONANT = CONSONANT.substr(0, 26 - 5); +constexpr std::string_view LOWER_CONSONANT = CONSONANT.substr(26 - 5); +constexpr std::string_view ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view UPPER_ALPHA_NUMERIC = ALPHA_NUMERIC.substr(0, 10 + 26); +constexpr std::string_view LOWER_ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view DIGITS = ALPHA_NUMERIC.substr(0, 10); +constexpr std::string_view BRACKETS = "()[]{}<>"; +constexpr char NEWLINE = '\n'; +constexpr char SPACE = ' '; +constexpr char NOSEP = '\0'; +constexpr Real PI = 3.1415926535897932384626433832795028_real; + + +//============================================================================// +// internal definitions and constants // +//============================================================================// +constexpr UInteger DEFAULT_SEED = 3141592653589793238_uint; +constexpr std::string_view CASE_SENSITIVE = "case_sensitive"; +constexpr std::string_view SPACE_SENSITIVE = "space_change_sensitive"; +constexpr std::string_view FLOAT_ABSOLUTE_TOLERANCE = "float_absolute_tolerance"; +constexpr std::string_view FLOAT_RELATIVE_TOLERANCE = "float_relative_tolerance"; +constexpr std::string_view FLOAT_TOLERANCE = "float_tolerance"; +constexpr std::string_view JUDGE_MESSAGE = "null"; +constexpr char DEFAULT_SEPARATOR = SPACE; +constexpr std::string_view EMPTY_COMMAND = ""; +constexpr std::string_view COMMAND_PREFIX = "--"; +constexpr std::string_view CONSTRAINT_COMMAND = "--constraints_file"; +constexpr std::string_view SEED_COMMAND = "--seed"; +constexpr auto REGEX_OPTIONS = std::regex::nosubs | std::regex::optimize; +inline const std::regex INTEGER_REGEX("0|-?[1-9][0-9]*", REGEX_OPTIONS); +inline const std::regex REAL_REGEX("-?(0|([1-9][0-9]*))(\\.[0-9]*)?([eE][+-]?(0|([1-9][0-9]*)))?", REGEX_OPTIONS); +inline const std::regex STRICT_REAL_REGEX("-?(0|([1-9][0-9]*))\\.?[0-9]*", REGEX_OPTIONS); + +static_assert(2'000'000'000'000'000'000_int < LARGE / 2, "LARGE too small"); +static_assert(LARGE <= std::numeric_limits::max() / 2, "LARGE too big"); + +static_assert(-1 == 0xFFFF'FFFF'FFFF'FFFF_int, "Two's complement for signed numbers is required" ); +static_assert(std::is_convertible_v, "Incompatible Integer and UInteger types?!"); +static_assert(std::is_convertible_v, "Incompatible Integer and UInteger types?!"); +static_assert(sizeof(Integer) == sizeof(UInteger), "Incompatible Integer and UInteger types?!"); + +template +constexpr void judgeAssert(bool asserted, std::string_view message) { + if (!asserted) throw T(message.data()); +} + + +//============================================================================// +// SFINAE // +//============================================================================// +namespace details { + template + struct IsContainer : std::false_type {}; + + template + struct IsContainer>()))>> : std::true_type { + using iterator_type = decltype(std::begin(std::declval>())); + using value_type = std::remove_reference_t>()))>; + }; + + template + struct IsStdArray : std::false_type {}; + + template + struct IsStdArray> : std::true_type {}; + + template + struct IsTupleLike : std::false_type {}; + + template + struct IsTupleLike))>> : std::true_type {}; + + template + struct HasOstreamOperator : std::false_type {}; + + template + struct HasOstreamOperator() << std::declval())>> : std::true_type {}; +} + + +//============================================================================// +// Verdicts // +//============================================================================// +struct Verdict final { + int exitCode; + + constexpr explicit Verdict(int exitCode_ = 1) : exitCode(exitCode_) {} + + constexpr operator int() const { + return exitCode; + } + + [[noreturn]] void exit() const { + exitVerdict(exitCode); + } + + friend void operator<<(std::ostream& os, const Verdict& v) { + os << std::endl; + v.exit(); + } +}; + +// default verdicts (we do not support scoring) +constexpr Verdict AC(42); +constexpr Verdict WA(43); +constexpr Verdict PE = WA; +constexpr Verdict FAIL(1); + + +//============================================================================// +// Output streams // +//============================================================================// +class NullStream final : public std::ostream { + class NullBuffer final : public std::streambuf { + protected: + std::streamsize xsputn(const char* /**/, std::streamsize n) override { + return n; + } + int overflow(int c = std::char_traits::eof()) override { + return std::char_traits::not_eof(c); + } + } nullBuffer; +public: + NullStream() : std::ostream(&nullBuffer) {} +}; + +namespace details { + NullStream nullStream; +} + +class OutputStream final { + std::unique_ptr managed; + std::ostream* os; + + void init() { + *os << std::boolalpha; + *os << std::fixed; + *os << std::setprecision(DEFAULT_PRECISION); + } + +public: + OutputStream() : os(&details::nullStream) {} + OutputStream(std::ostream& os_) : os(&os_) {init();} + explicit OutputStream(const std::filesystem::path& path) : managed(std::make_unique(path)), os(managed.get()) { + judgeAssert(managed->good(), "OutputStream: Could not open File: " + path.string()); + init(); + } + + OutputStream(OutputStream&& other) = default; + OutputStream& operator=(OutputStream&& other) = default; + + OutputStream(const OutputStream&) = delete; + OutputStream& operator=(const OutputStream&) = delete; + + + template + OutputStream& operator<<(const std::pair& t) { + return *this << t.first << DEFAULT_SEPARATOR << t.second; + } + + template + OutputStream& operator<<(const std::tuple& t) { + return join(t, std::index_sequence_for(), DEFAULT_SEPARATOR); + } + + template + OutputStream& operator<<(const T& x) { + if constexpr ((std::is_array_v and !std::is_same_v, char*>) or + (details::IsContainer{} and !details::HasOstreamOperator{})) { + return join(std::begin(x), std::end(x), DEFAULT_SEPARATOR); + } else { + *os << x; + return *this; + } + } + + OutputStream& operator<<(std::ostream& (*manip)(std::ostream&)) { + *os << manip; + return *this; + } + + template + OutputStream& join(const Tuple& t, std::index_sequence /**/, char separator) { + static_assert(std::tuple_size_v == sizeof...(Is)); + if (separator != NOSEP) ((*os << (Is == 0 ? std::string_view() : std::string_view(&separator, 1)), *this << std::get(t)), ...); + else ((*this << std::get(t)), ...); + return *this; + } + + template + OutputStream& join(T first, T last, char separator) { + for (auto it = first; it != last; it++) { + if (it != first and separator != NOSEP) *os << separator; + *this << *it; + } + return *this; + } +}; + +namespace ValidateBase { + // define this early so everyone can use it! + OutputStream juryErr(std::cerr); + OutputStream juryOut(std::cout); +} + +// allow printing colletions as: +// join(begin(), end(), [sep]) +namespace details { + template + class TempWriter final { + C callable; + public: + constexpr explicit TempWriter(const C& callable_) : callable(callable_) {} + + TempWriter(const TempWriter&) = delete; + TempWriter(TempWriter&&) = delete; + TempWriter& operator=(const TempWriter&) = delete; + TempWriter& operator=(TempWriter&&) = delete; + + std::string asString() const { + std::ostringstream os; + OutputStream tmp(os); + tmp << *this; + return os.str(); + } + + explicit operator std::string() const { + return asString(); + } + + friend OutputStream& operator<<(OutputStream& os, const TempWriter& writer) { + writer.callable(os); + return os; + } + + friend OutputStream& operator<<(std::ostream& os, const TempWriter& writer) = delete; //news OutputStream + }; + + struct JoinListCapture { + std::function callable; + + template + JoinListCapture(Args&&... args) + : callable([t = std::forward_as_tuple(args...)](OutputStream& os, char separator) { + os.join(t, std::index_sequence_for(), separator); + }) {} + }; +} + +template +constexpr auto join(T first, T last, char separator = DEFAULT_SEPARATOR) { + return details::TempWriter([=](OutputStream& os) { + os.join(first, last, separator); + }); +} + +template{}>, + typename = std::enable_if_t>>{}>> +constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) { + if constexpr(std::is_rvalue_reference_v) { + if constexpr (std::is_array_v) { + return details::TempWriter([c, separator](OutputStream& os) { + os.join(std::begin(c), std::end(c), separator); + }); + } else { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + os.join(std::begin(c), std::end(c), separator); + }); + } + } else { + return join(std::begin(c), std::end(c), separator); + } +} + +template>::value> +constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) { + if constexpr(std::is_rvalue_reference_v) { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + os.join(c, std::make_index_sequence{}, separator); + }); + } else { + return details::TempWriter([&c, separator](OutputStream& os) { + os.join(c, std::make_index_sequence{}, separator); + }); + } +} + +template, char>>> +constexpr auto join(T (&c)[N], char separator = DEFAULT_SEPARATOR) { + static_assert(N > 0, "c-strings should be null terminated!"); + return join(std::begin(c), std::prev(std::end(c)), separator); +} + +template, char>>> +constexpr auto join(T (&&c)[N], char separator = DEFAULT_SEPARATOR) { + static_assert(N > 0, "c-strings should be null terminated!"); + return details::TempWriter([c, separator](OutputStream& os) { + os.join(std::begin(c), std::prev(std::end(c)), separator); + }); +} + +template{}>, + typename = std::enable_if_t{}>, + typename = std::enable_if_t{}>> +constexpr auto join(const T& t, char separator = DEFAULT_SEPARATOR) = delete; + +auto join(details::JoinListCapture c, char separator = DEFAULT_SEPARATOR) { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + c.callable(os, separator); + }); +} + + +//============================================================================// +// Basic datastructures // +//============================================================================// +// make usage of std::priority_queue easier... +namespace details { + template> + struct invertCompare { + constexpr bool operator()(const T &lhs, const T &rhs) const { + return Compare{}(rhs, lhs); + } + }; +} +template> +using MinPQ = std::priority_queue, details::invertCompare>; +template> +using MaxPQ = std::priority_queue, Compare>; + +template +bool contains(const C& container, const K& key) { + return container.find(key) != container.end(); +} + +template +void append(C1& c1, const C2& c2) { + static_assert(std::is_same_v::value_type, + typename details::IsContainer::value_type>, "cannot append container of different value type!"); + if (static_cast(&c1) != static_cast(&c2)) { + for (auto&& e : c2) c1.emplace(c1.end(), e); + } else { + C2 tmp = c2; + for (auto&& e : tmp) c1.emplace(c1.end(), e); + } +} + +template +void append(C1& c1, const typename C1::value_type(&c2)[N]) { + for (auto&& e : c2) c1.emplace(c1.end(), e); +} + +struct shorter { + template + bool operator()(const U& a, const V& b) const { + return std::size(a) < std::size(b); + } +}; + +struct longer { + template + bool operator()(const U& a, const V& b) const { + return std::size(b) < std::size(a); + } +}; + +namespace details { + template + struct Flatten {using value_type = T;}; + + template + struct Flatten{}>> : Flatten::value_type> {}; + + template + void flatAppend(CR&& c, std::vector& res) { + using C = std::remove_reference_t; + if constexpr(std::is_same_v) { + res.emplace_back(std::forward(c)); + } else if constexpr (!IsContainer{}) { + static_assert(IsContainer{}, "invalid base type for flatten()!"); + } else { + if constexpr (std::is_rvalue_reference_v) { + for (auto&& v : c) flatAppend(std::move(v), res); + } else { + for (auto&& v : c) flatAppend(v, res); + } + } + } +} + +template +auto flatten(CR&& c) { + std::vector res; + details::flatAppend(std::forward(c), res); + return res; +} + +template +auto flatten(CR&& c) { + using C = std::remove_reference_t; + return flatten::value_type, CR>(std::forward(c)); +} + +template +struct boolean { + bool value; + std::optional reason; + + constexpr boolean(bool value_) : value(value_) {} + constexpr boolean(bool value_, const T& reason_) : value(value_), reason(reason_) {} + + constexpr operator bool() const { + return value; + } + + constexpr bool hasReason() const { + return reason.has_value(); + } +}; + + +//============================================================================// +// Utility // +//============================================================================// +// for sequences +template::value_type>>> +auto isPerm(RandomIt first, RandomIt last, typename std::iterator_traits::value_type offset = 0) { + using T = typename std::iterator_traits::value_type; + auto count = std::distance(first, last); + std::vector seen(count, false); + for (; first != last; first++) { + const T& x = *first; + if (x < offset or x - offset >= count or seen[x - offset]) { + return boolean(false, x); + } + seen[x - offset] = true; + } + return boolean(true); +} +template::value_type>, bool> = true> +auto isPerm(const C& c, typename details::IsContainer::value_type offset = 0) { + return isPerm(std::begin(c), std::end(c), offset); +} + +template +auto isPerm(itA firstA, itA lastA, itB firstB, itB lastB) { + using T = typename std::iterator_traits::value_type; + std::vector::value_type> a(firstA, lastA); + std::vector::value_type> b(firstB, lastB); + if (a.size() != b.size()) return boolean(false); + std::sort(a.begin(), a.end()); + std::sort(b.begin(), b.end()); + for (std::size_t i = 0; i < a.size(); i++) { + if (a[i] != b[i]) return boolean(false, a[i]); + } + return boolean(true); +} +template{}>, + typename = std::enable_if_t{}>> +auto isPerm(const C1& c1, const C2& c2) { + return isPerm(std::begin(c1), std::end(c1), std::begin(c2), std::end(c2)); +} + +template +constexpr boolean anyAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + if (first != last) { + for (Integer i = 1; std::next(first) != last; first++, i++) { + if (p(*first, *std::next(first))) { + return boolean(true, i); + } + } + } + return boolean(false); +} +template +constexpr boolean anyAdjacent(const C& c, BinaryPredicate p) { + return anyAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean noneAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + auto res = anyAdjacent(first, last, p); + res.value = !res.value; + return res; +} +template +constexpr boolean noneAdjacent(const C& c, BinaryPredicate p) { + return noneAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean allAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + return noneAdjacent(first, last, std::not_fn(p)); +} +template +constexpr boolean allAdjacent(const C& c, BinaryPredicate p) { + return noneAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean areIncreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::less()); +} +template +constexpr boolean areIncreasing(const C& c) { + return areIncreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areNonDecreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::less_equal()); +} +template +constexpr boolean areNonDecreasing(const C& c) { + return areNonDecreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areDecreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::greater()); +} +template +constexpr boolean areDecreasing(const C& c) { + return areDecreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areNonIncreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::greater_equal()); +} +template +constexpr boolean areNonIncreasing(const C& c) { + return areNonIncreasing(std::begin(c), std::end(c)); +} + +template +constexpr auto areDistinct(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + std::vector tmp(first, last); + std::sort(tmp.begin(), tmp.end()); + auto [b, v] = anyAdjacent(tmp, std::equal_to()); + if (v) return boolean(!b, tmp[*v]); + return boolean(!b); +} +template +constexpr auto areDistinct(const C& c) { + return areDistinct(std::begin(c), std::end(c)); +} + + +// for strings (cctype functions are not safe to use with char...) +constexpr bool isLower(char c) { + return c >= 'a' and c <= 'z'; +} + +constexpr bool isUpper(char c) { + return c >= 'A' and c <= 'Z'; +} + +constexpr bool isLetter(char c) { + return isLower(c) or isUpper(c); +} + +constexpr bool isDigit(char c) { + return c >= '0' and c <= '9'; +} + +constexpr char toLower(char c) { + if (isUpper(c)) c += 'a' - 'A'; + return c; +} + +constexpr bool isVowel(char c) { + c = toLower(c); + for (char x : LOWER_VOWELS) { + if (c == x) return true; + } + return false; +} + +constexpr bool isConsonant(char c) { + return isLetter(c) and !isVowel(c); +} + +constexpr char toUpper(char c) { + if (isLower(c)) c -= 'a' - 'A'; + return c; +} + +constexpr char toDefaultCase(char c) { + if constexpr (DEFAULT_CASE_LOWER) return toLower(c); + return toUpper(c); +} + +void toLower(std::string& s) { + for (char& c : s) c = toLower(c); +} + +void toUpper(std::string& s) { + for (char& c : s) c = toUpper(c); +} + +void toDefaultCase(std::string& s) { + if constexpr (DEFAULT_CASE_LOWER) return toLower(s); + return toUpper(s); +} + +constexpr bool isLower(std::string_view s) { + for (char c : s) if (!isLower(c)) return false; + return true; +} + +constexpr boolean isUpper(std::string_view s) { + for (char c : s) if (!isUpper(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isLetter(std::string_view s) { + for (char c : s) if (!isLetter(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isDigit(std::string_view s) { + for (char c : s) if (!isDigit(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isVowel(std::string_view s) { + for (char c : s) if (!isVowel(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isConsonant(std::string_view s) { + for (char c : s) if (!isConsonant(c)) return boolean(false, c); + return boolean(true); +} + +std::vector thueMorse(Integer lower, Integer upper) { + judgeAssert(lower < upper, "thueMorse(): Lower must be less than upper!"); + std::vector res(upper - lower); + for (Integer i = lower; i < upper; i++) { + res[i] = std::bitset<64>(i).count() % 2; + } + return res; +} + +std::vector thueMorse(Integer upper) { + return thueMorse(0, upper); +} + +// allow using std::pair and std::complex similiar +// (may be useful for geometric problem) +template +constexpr auto& getX(T& point) { + return std::get<0>(point); +} +template +constexpr auto& getY(T& point) { + return std::get<1>(point); +} +template +constexpr auto& getZ(T& point) { + return std::get<2>(point); +} +template +constexpr auto getX(const T& point) { + return std::get<0>(point); +} +template +constexpr auto getY(const T& point) { + return std::get<1>(point); +} +template +constexpr auto getZ(const T& point) { + return std::get<2>(point); +} + +template +constexpr auto& getX(std::complex& point) { + return reinterpret_cast(point)[0]; +} +template +constexpr auto& getY(std::complex& point) { + return reinterpret_cast(point)[1]; +} +template +constexpr auto getX(const std::complex& point) { + return reinterpret_cast(point)[0]; +} +template +constexpr auto getY(const std::complex& point) { + return reinterpret_cast(point)[1]; +} + +template +constexpr std::pair convert(const std::complex& t) { + return {getX(t), getY(t)}; +} + +template +constexpr std::complex::type> +convert(const std::pair& t) { + return {getX(t), getY(t)}; +} + + +namespace details { + // Test two numbers for equality, accounting for +/-INF, NaN and precision. + // Real expected is considered the reference value for relative error. + bool floatEqual(Real given, Real expected, Real floatAbsTol, Real floatRelTol) { + judgeAssert(floatAbsTol >= 0.0_real, "floatEqual(): floatAbsTol must be positive!"); + judgeAssert(floatRelTol >= 0.0_real, "floatEqual(): floatRelTol must be positive!"); + // Finite values are compared with some tolerance + if (std::isfinite(given) and std::isfinite(expected)) { + Real absDiff = std::abs(given-expected); + Real relDiff = std::abs((given-expected)/expected); + return absDiff <= floatAbsTol or relDiff <= floatRelTol; + } + // NaN is equal to NaN (-NaN is also equal NaN) + if (std::isnan(given) and std::isnan(expected)) { + return true; + } + // Infinite values are equal if their sign matches + if (std::isinf(given) and std::isinf(expected)) { + return std::signbit(given) == std::signbit(expected); + } + // Values in different classes are always different. + return false; + } + + constexpr boolean stringEqual(std::string_view a, std::string_view b, bool caseSensitive) { + std::size_t i = 0; + for (; i < a.size() and i < b.size(); i++) { + char aa = a[i]; + char bb = b[i]; + if (!caseSensitive) { + aa = toDefaultCase(aa); + bb = toDefaultCase(bb); + } + if (aa != bb) { + return boolean(false, i); + } + } + if (a.size() != b.size()) { + return boolean(false, i); + } else { + return boolean(true); + } + } + + constexpr bool isToken(std::string_view a) { + for (char c : a) { + if (c == ' ') return false; + if (c == '\n') return false; + if (c == '\r') return false; + if (c == '\t') return false; + if (c == '\f') return false; + if (c == '\v') return false; + } + return true; + } + + template + bool parse(std::string_view s, T& res) { + const char* begin = s.data(); + const char* end = s.data() + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, res); + return ptr == end and ec == std::errc(); + } + #ifdef DOUBLE_FALLBACK + template<> + bool parse(std::string_view s, Real& res) { + try { + std::size_t pos = 0; + res = std::stold(std::string(s), &pos); + return pos == s.size(); + } catch(...) { + return false; + } + } + #endif + +} + + +//============================================================================// +// Math // +//============================================================================// +namespace details { + constexpr std::array TRIAL_PRIMES = { + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, + }; + constexpr std::array MILLER_RABIN_WITNESS = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; + + // these operations are safe as long as the value would fit in Integer + constexpr UInteger mulMod(UInteger lhs, UInteger rhs, UInteger mod) { + UInteger res = 0; + while (rhs > 0) { + if (rhs & 1) res = (lhs + res) % mod; + lhs = (lhs + lhs) % mod; + rhs /= 2; + } + return res; + } + + constexpr UInteger powMod(UInteger base, UInteger exp, UInteger mod) { + UInteger res = 1; + if (mod <= 0x1'0000'0000) { + while (exp > 0) { + if (exp & 1) res = (base * res) % mod; + base = (base * base) % mod; + exp /= 2; + } + } else { + while (exp > 0) { + if (exp & 1) res = mulMod(base, res, mod); + base = mulMod(base, base, mod); + exp /= 2; + } + } + return res; + } + + constexpr Integer extendedEuclid(Integer a, Integer b, Integer& x, Integer& y) { + if (a == 0) { + x = 0; + y = 1; + return b; + } else { + Integer x1 = 0; + Integer y1 = 0; + Integer d = extendedEuclid(b % a, a, x1, y1); + x = y1 - (b / a) * x1; + y = x1; + return d; + } + } +} + +constexpr Integer applyMod(Integer x, Integer mod) { + x %= mod; + if (x < 0) x += mod; + return x; +} + +constexpr Integer mulMod(Integer lhs, Integer rhs, Integer mod) { + judgeAssert(mod > 0, "mulMod(): mod must be positive!"); + UInteger ul = static_cast(applyMod(lhs, mod)); + UInteger ur = static_cast(applyMod(rhs, mod)); + UInteger um = static_cast(mod); + return static_cast(details::mulMod(ul, ur, um)); +} + +constexpr Integer powMod(Integer base, Integer exp, Integer mod) { + judgeAssert(mod > 0, "powMod(): mod must be positive!"); + judgeAssert(exp >= 0, "powMod(): exp must be non negative!"); + UInteger ub = static_cast(applyMod(base, mod)); + UInteger ue = static_cast(exp); + UInteger um = static_cast(mod); + return static_cast(details::powMod(ub, ue, um)); +} + +constexpr Integer multInv(Integer n, Integer mod) { + judgeAssert(mod > 0, "multInv(): mod must be positive!"); + Integer x = 0; + Integer y = 0; + Integer g = details::extendedEuclid(n, mod, x, y); + if (g != 1) return -1; + else return applyMod(x, mod); +} + +constexpr bool isPrime(Integer n) { + for (Integer p : details::TRIAL_PRIMES) { + if (n <= p or n % p == 0) { + return n == p; + } + } + if (details::powMod(details::TRIAL_PRIMES.back() + 1, n - 1, n) != 1) { + return false; + } + UInteger un = static_cast(n); + UInteger d = un - 1; + UInteger j = 0; + while (d % 2 == 0) { + d /= 2; + j++; + } + for (UInteger a : details::MILLER_RABIN_WITNESS) { + if (a % un == 0) continue; + UInteger v = details::powMod(a, d, un); + if (v == 1 or v == un - 1) continue; + for (UInteger i = 1; i < j; i++) { + v = details::mulMod(v, v, un); + if (v == un - 1 or v <= 1) break; + } + if (v != un - 1) return false; + } + return true; +} + +std::vector primes(Integer lower, Integer upper) { + judgeAssert(lower < upper, "primes(): Lower must be less than upper!"); + lower = std::max(2, lower); + upper = std::max(2, upper); + Integer count = upper - lower; + Integer cache = (count + 1) / 2; + + std::vector notPrime(cache), notPrimeSegment(cache); + for (Integer i = 3; i < count; i += 2) { + if (!notPrime[i / 2]) { + for (Integer j = i * i; j < count; j += 2 * i) { + notPrime[j / 2] = true; + } + Integer lowest = lower - (lower % (2*i)) + i; + if (lowest < lower) lowest += 2*i; + for (Integer j = std::max(i * i, lowest); j < upper; j += 2 * i) { + notPrimeSegment[(j - lower) / 2] = true; + } + } + } + std::vector res; + if (lower <= 2 and 2 < upper) res.emplace_back(2); + for (Integer i = lower | 1; i < upper; i += 2) { + if (!notPrimeSegment[(i - lower) / 2] and (i < count*count or isPrime(i))) { + res.emplace_back(i); + } + } + return res; +} + +std::vector primes(Integer upper) { + return primes(0, upper); +} + +template +constexpr Integer sign(T x) { + return (T(0) < x) - (x < T(0)); +} + + +//============================================================================// +// Geometry (this is just for utility stuff...) // +//============================================================================// +namespace details { + template + constexpr Integer cross(Point a, Point b) { + return getX(a) * getY(b) - getY(a) * getX(b); + } + template + constexpr Integer cross(Point p, Point a, Point b) { + getX(a) -= getX(p); + getY(a) -= getY(p); + getX(b) -= getX(p); + getY(b) -= getY(p); + return cross(a, b); + } + + template + constexpr bool left(Point p) { + return getX(p) == 0 ? getY(p) < 0 : getX(p) < 0; + } + + template + void cyclicSort(std::vector& in) { + std::sort(in.begin(), in.end(), [](const Point& a, const Point& b){ + return left(a) != left(b) ? left(a) > left(b) : cross(a, b) > 0; + }); + } +} + + +template +constexpr bool areConvex(RandomIt first, RandomIt last) { + std::size_t n = 0; + for (auto it = first; it != last; it++) { + n++; + judgeAssert(std::abs(getX(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!"); + judgeAssert(std::abs(getY(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!"); + } + if (n < 3) return false; + bool hasArea = false; + for (std::size_t i = 0; i < n; i++) { + if (first[i] == first[(i+1) % n]) return false; + if (details::cross(first[0], first[i], first[(i+1) % n]) < 0) return false; + if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) < 0) return false; + hasArea |= details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) != 0; + } + return hasArea; +} +template +constexpr bool areConvex(const C& c) { + return areConvex(std::begin(c), std::end(c)); +} + +template +constexpr bool areStrictlyConvex(RandomIt first, RandomIt last) { + if (!areConvex(first, last)) return false; + std::size_t n = std::distance(first, last); + for (std::size_t i = 0; i < n; i++) { + if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) == 0) return false; + } + return true; +} +template +constexpr bool areStrictlyConvex(const C& c) { + return areStrictlyConvex(std::begin(c), std::end(c)); +} + +//============================================================================// +// Random // +//============================================================================// +namespace Random { + // You should not rely on the implementation in details! + // Especially you should never use randomNumberGenerator on your own. There is no function in + // c++ which uses a random engine and is not implementation defined. + namespace details { + constexpr Real PI = 3.141592653589793238462643383279502884_real; + constexpr Integer PRIME_TRIALS = 4*1600; + + RandomEngine randomNumberGenerator(DEFAULT_SEED); + static_assert(RandomEngine::max() == 0xFFFF'FFFF'FFFF'FFFF_uint, "Random Engine should produce 64bit of randomness"); + static_assert(RandomEngine::min() == 0_uint, "Random Engine should produce 64bit of randomness"); + + constexpr UInteger bitMask(UInteger x) { + static_assert(sizeof(UInteger) == 8, "bitMask requires 8byte UInteger!"); + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + x |= x >> 32; + return x; + } + } + + void seed(UInteger seed) { + details::randomNumberGenerator.seed(seed); + } + + //========================================================================// + // Distributions and generators // + //========================================================================// + bool bit() {// in {0, 1} + return std::bitset<64>(details::randomNumberGenerator()).count() & 1; + } + + Integer integer() {// in [-2^63, 2^63) + return static_cast(details::randomNumberGenerator()); + } + Integer integer(Integer lower, Integer upper) {// in [lower, upper) + judgeAssert(lower < upper, "Random::integer(): Lower must be less than upper!"); + UInteger ul = static_cast(lower); + UInteger uu = static_cast(upper); + UInteger mask = details::bitMask(uu - ul - 1_uint); + UInteger res; + do { + res = details::randomNumberGenerator() & mask; + } while (res >= uu - ul); + return static_cast(res + ul); + } + Integer integer(Integer upper) {// in [0, upper) + return integer(0, upper); + } + + Real real() {// in [0, 1) + while (true) { + Real res = details::randomNumberGenerator() / 0x1.0p64_real; + res += details::randomNumberGenerator() / 0x1.0p128_real; + if (0.0_real <= res and res < 1.0_real) return res; + } + } + Real real(Real upper) {// in [0, upper) + judgeAssert(std::isfinite(upper), "Random::real(): Upper must be finite!"); + judgeAssert(upper > 0.0_real, "Random::real(): Upper must be greater than zero!"); + while (true) { + Real res = real() * upper; + if (0.0_real <= res and res < upper) return res; + } + } + Real real(Real lower, Real upper) {// in [lower, upper) + judgeAssert(std::isfinite(lower), "Random::real(): Lower must be finite!"); + judgeAssert(std::isfinite(upper), "Random::real(): Upper must be finite!"); + judgeAssert(lower < upper, "Random::real(): Lower must be less than upper!"); + while (true) { + Real x = real(); + Real res = lower * (1.0_real - x) + upper * x; + if (lower <= res and res < upper) return res; + } + } + + Real normal(Real mean, Real stddev) {// theoretically in (-inf, inf) + judgeAssert(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!"); + Real u1 = real(); + Real u2 = real(); + Real res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2); + return std::sqrt(stddev) * res + mean; + } + Real normal(Real lower, Real upper, Real mean, Real stddev) {// in [lower, upper) + judgeAssert(!std::isnan(lower), "Random::normal(): Lower must not be NaN!"); + judgeAssert(!std::isnan(upper), "Random::normal(): Upper must not be NaN!"); + judgeAssert(lower < upper, "Random::normal(): Lower must be less than upper!"); + judgeAssert(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!"); + Real res; + while (true) { + Real u1 = real(); + Real u2 = real(); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2); + res = std::sqrt(stddev) * res + mean; + if (lower <= res and res < upper) return res; + res = std::sqrt(-2.0_real * std::log(u1)) * std::sin(2.0_real * details::PI * u2); + res = std::sqrt(stddev) * res + mean; + if (lower <= res and res < upper) return res; + } + } + + Real exponential(Real lambda) {// theoretically in [0, inf) + judgeAssert(lambda > 0.0_real, "Random::lambda(): lambda must be positive!"); + return -std::log(real()) / lambda; + } + Real exponential(Real lower, Real upper, Real lambda) {// in [lower, upper) + judgeAssert(std::isfinite(lower), "Random::exponential(): Lower must be finite!"); + judgeAssert(!std::isnan(upper), "Random::exponential(): Upper must not be NaN!"); + judgeAssert(lower < upper, "Random::exponential(): Lower must be less than upper!"); + judgeAssert(lambda > 0.0_real, "Random::exponential(): Lambda must be positive!"); + while (true) { + Real res = lower - std::log(real()) / lambda; + if (res < upper) return res; + } + } + + Integer geometric(Real p) {// theoretically in [0, inf) + judgeAssert(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!"); + return std::llround(std::floor(std::log(real()) / std::log1p(-p))); + } + Integer geometric(Integer lower, Integer upper, Real p) {// in [lower, upper) + judgeAssert(lower < upper, "Random::geometric(): Lower must be less than upper!"); + judgeAssert(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!"); + while (true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric distribution[...]" + Integer res = lower + std::llround(std::floor(std::log(real()) / std::log1p(-p))); + if (res < upper) return res; + } + } + + Integer binomial(Integer n, Real p) {// in [0, n] + judgeAssert(n >= 0, "Random::binomial(): n must be non negative!"); + judgeAssert(0.0_real <= p and p <= 1.0_real, "Random::binomial(): p must be in [0,1)!"); + bool swap = p > 0.5_real; + p = std::min(p, 1.0_real - p); + if (p*n < 10.0_real) { + // BG: Geometric method + // https://dl.acm.org/doi/pdf/10.1145/42372.42381 + Integer res = 0; + Integer y = 0; + Real lg = std::log1p(-p); + if (lg >= 0) return swap ? n : 0; + do { + y += std::llround(std::floor(std::log(real()) / lg)) + 1; + if (y > n) return swap ? n - res : res; + res++; + } while (true); + } else { + // BTRS algorithm + // https://epub.wu.ac.at/1242/1/document.pdf + // note that the original paper has an error + // the break condition at the end has to be log(v) < h[...] + Real q = 1.0_real - p; + Real spq = std::sqrt(n * p * q); + Real b = 1.15_real + 2.53_real * spq; + Real a = -0.0873_real + 0.0248_real * b + 0.01_real * p; + Real c = n * p + 0.5_real; + Real vr = 0.92_real - 4.2_real / b; + + bool initialized = false; + Real alpha, lpq, m, h; + do { + Real u = real() - 0.5_real; + Real us = 0.5_real - std::abs(u); + Integer res = std::llround(std::floor((2.0_real * a / us + b) * u + c)); + if (res < 0 or res > n) continue; + + Real v = real(); + if (us >= 0.07_real and v <= vr) { + return swap ? n - res : res; + } + + if (!initialized) { + alpha = (2.83_real + 5.1_real / b) * spq; + lpq = std::log(p / q); + m = std::llround(std::floor((n + 1) * p)); + h = std::lgamma(m + 1) + std::lgamma(n - m + 1); + initialized = true; + } + v *= alpha / (a / (us * us) + b); + if (std::log(v) <= h - std::lgamma(res + 1) - std::lgamma(n - res + 1) + (res - m) * lpq) { + return swap ? n - res : res; + } + } while (true); + } + } + Integer binomial(Integer lower, Integer upper, Integer n, Real p) {// in [lower, upper) + judgeAssert(lower < upper, "Random::binomial(): n Lower must be less than upper!"); + while (true) { + Integer res = binomial(n, p); + if (lower <= res and res < upper) return res; + } + } + + Integer maximum(Integer lower, Integer upper, Integer n) {// in [lower, upper) + judgeAssert(n > 0, "Random::maximum(): n musst be positive!"); + judgeAssert(lower < upper, "Random::maximum(): Lower must be less than upper!"); + if (n < 5) { + Integer res = lower; + for (Integer i = 0; i < n; i++) res = std::max(res, integer(lower, upper)); + return res; + } else {// such large n seem unlikely + UInteger ul = static_cast(lower); + UInteger uu = static_cast(upper); + UInteger res = (uu - ul) * std::exp2(std::log2(real()) / n); + return std::min(upper - 1, static_cast(res + ul)); + } + } + Integer maximum(Integer upper, Integer n) { + return maximum(0, upper, n); + } + + Integer minimum(Integer lower, Integer upper, Integer n) {// in [lower, upper) + return upper - 1 - maximum(0, upper - lower, n); + } + Integer minimum(Integer upper, Integer n) { + return minimum(0, upper, n); + } + + Integer prime(Integer lower, Integer upper) {// in [lower, upper) + judgeAssert(lower < upper, "Random::prime(): Lower must be less than upper!"); + Integer sampleL = lower <= 2 ? 0 : (lower / 2); + Integer sampleU = upper / 2; + if (sampleL < sampleU) { + for (Integer i = 0; i < details::PRIME_TRIALS and i < 4 * (upper - lower); i++) { + Integer res = std::max(2, 2*integer(sampleL, sampleU) | 1); + if (isPrime(res)) return res; + } + } + judgeAssert(false, "Random::prime(): range contains no primes?"); + return -1; + } + Integer prime(Integer upper) {// in [0, upper) + return prime(0, upper); + } + + + //========================================================================// + // utility // + //========================================================================// + template + typename std::iterator_traits::reference + select(RandomIt first, RandomIt last) { + judgeAssert(first < last, "Random::select(): Lower must be less than upper!"); + return first[integer(0, last - first)]; + } + + template + typename ::details::IsContainer::value_type select(const C& c) { + return select(std::begin(c), std::end(c)); + } + + template + typename C::reference select(C& c) { + return select(std::begin(c), std::end(c)); + } + + template + T select(const T(&c)[N]) { + return select(std::begin(c), std::end(c)); + } + + template + T& select(T(&c)[N]) { + return select(std::begin(c), std::end(c)); + } + + template + T select(const std::pair& t) { + return bit() ? getX(t) : getY(t); + } + + template + T select(const std::complex& t) { + return bit() ? getX(t) : getY(t); + } + + template + void shuffle(RandomIt first, RandomIt last) { + using std::swap; + auto n = last - first; + for (auto i = n-1; i > 0; i--) { + swap(first[i], first[integer(0, i+1)]); + } + } + + template + void shuffle(C& c) { + return shuffle(std::begin(c), std::end(c)); + } + + template + void shuffle(std::pair& t) { + using std::swap; + if (bit()) swap(getX(t), getY(t)); + } + + template + void shuffle(std::complex& t) { + using std::swap; + if (bit()) swap(getX(t), getY(t)); + } + + template + Integer rotate(RandomIt first, RandomIt last) { + Integer rotation = integer(0, last - first); + std::rotate(first, first + rotation, last); + return rotation; + } + + template + Integer rotate(C& c) { + return rotate(std::begin(c), std::end(c)); + } + + //========================================================================// + // sequences // + //========================================================================// + std::vector distinct(Integer count, Integer lower, Integer upper) { + judgeAssert(count >= 0, "Random::distinct(): Count must be non negative!"); + judgeAssert(lower + count <= upper, "Random::distinct(): Lower must be less than upper + count!"); + std::map used; + std::vector res; + for (Integer i = 0; i < count; i++) { + Integer x = integer(lower, upper - i); + auto it = used.find(x); + if (it != used.end()) res.emplace_back(it->second); + else res.emplace_back(x); + it = used.find(upper - i - 1); + if (it != used.end()) used[x] = it->second; + else used[x] = upper - i - 1; + } + return res; + } + std::vector distinct(Integer count, Integer upper) { + return distinct(count, 0, upper); + } + + std::vector perm(Integer count, Integer offset = 0) { + return distinct(count, offset, offset+count); + } + + std::vector perm(const std::vector& cycles, Integer offset = 0) { + auto p = perm(std::accumulate(cycles.begin(), cycles.end(), 0_int)); + std::vector res(p.size()); + Integer tmp = 0; + for (std::size_t i = 0; i < cycles.size(); tmp += cycles[i], i++) { + judgeAssert(cycles[i] > 0, "Random::perm(): Cycle lengths must be positive!"); + for (Integer j = tmp; j + 1 < tmp + cycles[i]; j++) { + res[p[j]] = p[j + 1] + offset; + } + res[p[tmp + cycles[i] - 1]] = p[tmp] + offset; + } + return res; + } + + std::vector perm(std::initializer_list cycles, Integer offset = 0) { + return perm(std::vector(cycles), offset); + } + + std::vector multiple(Integer count, Integer lower, Integer upper) { + std::vector res(count); + for (Integer& x : res) x = integer(lower, upper); + return res; + } + std::vector multiple(Integer count, Integer upper) { + return multiple(count, 0, upper); + } + + std::vector increasing(Integer count, Integer lower, Integer upper) { + std::vector res = distinct(count, lower, upper); + std::sort(res.begin(), res.end(), std::less()); + return res; + } + std::vector increasing(Integer count, Integer upper) { + return increasing(count, 0, upper); + } + + std::vector decreasing(Integer count, Integer lower, Integer upper) { + std::vector res = distinct(count, lower, upper); + std::sort(res.begin(), res.end(), std::greater()); + return res; + } + std::vector decreasing(Integer count, Integer upper) { + return decreasing(count, 0, upper); + } + + std::vector nonDecreasing(Integer count, Integer lower, Integer upper) { + std::vector res = multiple(count, lower, upper); + std::sort(res.begin(), res.end(), std::less()); + return res; + } + std::vector nonDecreasing(Integer count, Integer upper) { + return nonDecreasing(count, 0, upper); + } + + std::vector nonIncreasing(Integer count, Integer lower, Integer upper) { + std::vector res = multiple(count, lower, upper); + std::sort(res.begin(), res.end(), std::greater()); + return res; + } + std::vector nonIncreasing(Integer count, Integer upper) { + return nonIncreasing(count, 0, upper); + } + + std::vector partition(Integer n, Integer k, Integer min = 1) { + judgeAssert(n > 0, "Random::partition(): n must be positive!"); + judgeAssert(k > 0, "Random::partition(): k must be positive!"); + judgeAssert(min <= 0 or k <= n / min, "Random::partition(): k too large!"); + n -= (min - 1) * k; + std::vector res = increasing(k-1, 1, n); + res.emplace_back(n); + for (Integer i = 0, last = 0; i < k; i++) { + res[i] -= last; + last += res[i]; + res[i] += min - 1; + } + return res; + } + + std::string bracketSequence(Integer n, char open = '(', char close = ')') {//proper bracket sequence of length 2*n + judgeAssert(0 <= n and n <= 0x7FFF'FFFF, "Random::bracketSequence(): n out of range!"); + std::string res(2 * n, open); + for (Integer i = 0, diff = 0; i < 2 * n; i++) { + Integer opened = (i + diff) / 2; + if (integer((2 * n - i) * (diff + 1)) < (n - opened) * (diff + 2)) { + diff++; + } else { + res[i] = close; + diff--; + } + } + return res; + } + + //========================================================================// + // geometry // + //========================================================================// + template> + std::vector convex(Integer n, Integer dim) { + judgeAssert(dim <= 0x3FFF'FFFF, "Random::convex(): dim too large!"); + judgeAssert(dim > 0, "Random::convex(): dim must be positive!"); + judgeAssert(n <= 8*dim - 8, "Random::convex(): dim too small!"); + judgeAssert(n >= 3, "Random::convex(): n too small!"); + + while (true) { + Integer left = 1 + binomial(n - 2, 0.5); + Integer down = 1 + binomial(n - 2, 0.5); + auto x = partition(2 * dim - 2, left, 0); + auto y = partition(2 * dim - 2, down, 0); + for (auto& z : x) z = -z; + for (auto& z : y) z = -z; + append(x, partition(2 * dim - 2, n - left, 0)); + append(y, partition(2 * dim - 2, n - down, 0)); + auto itX = std::partition(x.begin(), x.end(), [](Integer z){return z == 0;}); + auto itY = std::partition(y.begin(), y.end(), [](Integer z){return z != 0;}); + if (std::distance(x.begin(), itX) + std::distance(itY, y.end()) > n) continue; + shuffle(itX, x.end()); + if (itX != x.begin()) shuffle(y.begin(), itY); + + std::vector dirs(n); + for (Integer i = 0; i < n; i++) { + dirs[i] = {x[i], y[i]}; + } + ::details::cyclicSort(dirs); + + std::vector res = {{0, 0}}; + Integer maxX = 0; + Integer maxY = 0; + for (auto dir : dirs) { + Point tmp = res.back(); + getX(tmp) += getX(dir); + getY(tmp) += getY(dir); + maxX = std::max(maxX, getX(tmp)); + maxY = std::max(maxY, getY(tmp)); + res.emplace_back(tmp); + } + res.pop_back(); + for (auto& point : res) { + getX(point) += dim - 1 - maxX; + getY(point) += dim - 1 - maxY; + } + return res; + } + } + + template> + std::vector nonCollinearPoints(Integer n, Integer dim) { + judgeAssert(dim <= 0x1FFF'FFFF, "Random::nonCollinearPoints(): dim too large!"); + judgeAssert(n >= 0, "Random::nonCollinearPoints(): dim must be non negative!"); + judgeAssert(dim > n, "Random::nonCollinearPoints(): dim too small!"); + Integer p = prime(dim - 1, 2*dim + 2); + Integer rotA = 0; + Integer rotB = 0; + while (rotA == 0 && rotB == 0) { + rotA = integer(0, p); + rotB = integer(0, p); + } + std::array abc = { + integer(1, p), + integer(0, p), + integer(0, p), + }; + Integer dx = integer(-dim + 1, dim - p); + Integer dy = integer(-dim + 1, dim - p); + + auto xs = distinct(n, p); + std::vector res; + for (auto tmpX : xs) { + Integer tmpY = 0; + for (Integer add : abc[0]) { + tmpY *= tmpX; + tmpY += add; + tmpY %= p; + } + + Integer x = applyMod(tmpX * rotA - tmpY * rotB, p); + Integer y = applyMod(tmpX * rotB + tmpY * rotA, p); + + res.emplace_back(x + dx, y + dy); + } + return res; + } + +} // namespace Random + + +//============================================================================// +// args parser // +//============================================================================// +class ParamaterBase { + friend class Command; + friend struct Paramater; + + std::optional token; + + template + T parse(std::string_view s) const { + T res = {}; + judgeAssert(details::parse(s, res), "Command: Could not parse args"); + return res; + } + + ParamaterBase() = default; + explicit ParamaterBase(std::string_view token_) : token(token_) {} + +public: + std::string asString() const { + return std::string(token.value()); + } + + std::string asString(std::string_view defaultValue) const { + return std::string(token.value_or(defaultValue)); + } + + Integer asInteger() const { + return parse(token.value()); + } + + Integer asInteger(Integer defaultValue) const { + return token ? asInteger() : defaultValue; + } + + Real asReal() const { + return parse(token.value()); + } + + Real asReal(Real defaultValue) const { + return token ? asReal() : defaultValue; + } +}; + +struct Paramater final : private ParamaterBase { + using ParamaterBase::ParamaterBase; + using ParamaterBase::asString; + using ParamaterBase::asInteger; + using ParamaterBase::asReal; + + bool exists() const { + return token.has_value(); + } + + explicit operator bool() const { + return exists(); + } +}; + +class Command final : private ParamaterBase { + const std::vector& raw; + const Integer first, count; + const bool found; +public: + explicit Command(const std::vector& raw_) : raw(raw_), first(0), count(0), found(false) {} + explicit Command(const std::vector& raw_, Integer first_, Integer count_) + : ParamaterBase(count_ == 0 ? ParamaterBase() : ParamaterBase(raw_[first_])), + raw(raw_), first(first_), count(count_), found(true) { + judgeAssert(count >= 0, "Command: Invalid command in args!"); + } + + bool exists() const { + return found; + } + + explicit operator bool() const { + return exists(); + } + + Integer parameterCount() const { + return count; + } + + Paramater operator[](Integer i) const { + if (i >= 0 and i < count) return Paramater(raw[first + i]); + return Paramater(); + } + + using ParamaterBase::asString; + using ParamaterBase::asInteger; + using ParamaterBase::asReal; + + std::vector asStrings() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [](const std::string& value) { + return std::string(value); + }); + return res; + } + + std::vector asIntegers() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [this](const std::string& value) { + return parse(value); + }); + return res; + } + + std::vector asReals() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [this](const std::string& value) { + return parse(value); + }); + return res; + } + +}; + +class CommandParser final { + std::vector raw; + std::map> commands; + std::map tokens; + + static bool isCommand(std::string_view s) { + return s.size() > 2 and s.substr(0, 2) == COMMAND_PREFIX; + } + void addCommand(std::string_view command, Integer first, Integer count = 0) { + judgeAssert(commands.count(command) == 0, "Command: Duplcated command in args!"); + commands.emplace(command, std::pair{first, count}); + } + +public: + CommandParser() = default; + explicit CommandParser(int argc, char** argv) { + raw.assign(argc, {}); + std::string_view command = EMPTY_COMMAND; + Integer first = 0; + Integer count = 0; + for (int i = 0; i < argc; i++) { + raw[i] = std::string(argv[i]); + tokens.emplace(raw[i], i+1); + if (isCommand(raw[i])) { + addCommand(command, first, count); + command = raw[i]; + first = i+1; + count = 0; + } else { + count++; + } + } + addCommand(command, first, count); + } + CommandParser(CommandParser&&) = default; + CommandParser& operator=(CommandParser&&) = default; + + CommandParser(const CommandParser&) = delete; + CommandParser& operator=(const CommandParser&) = delete; + + std::string_view operator[](Integer t) const { + judgeAssert(t >= 0 and t < static_cast(raw.size()), "Command: Index out of args!"); + return raw[t]; + } + Command operator[](std::string_view command) const & { + judgeAssert(details::isToken(command), "Command: must not contain a space!"); + auto it = commands.find(command); + if (it == commands.end()) return Command(raw); + return Command(raw, it->second.first, it->second.second); + } + Command getRaw(std::string_view command) const & { + judgeAssert(details::isToken(command), "Command: must not contain a space!"); + auto it = tokens.find(command); + if (it == tokens.end()) return Command(raw); + return Command(raw, it->second, raw.size() - it->second); + } + Command getRaw() const & { + return Command(raw, 0, raw.size()); + } +}; + + +//============================================================================// +// Constraints // +//============================================================================// +template +class Bounds final { + bool hadMin, hadMax; // was value==lower/upper at some point + T min, max; // range of seen values + T lower, upper; // bounds for value +public: + constexpr explicit Bounds(T lower_, T upper_, T value_) : + hadMin(false), hadMax(false), + min(value_), max(value_), + lower(lower_), upper(upper_) { + update(lower_, upper_, value_); + } + + void update(T lower_, T upper_, T value_) { + if constexpr (std::is_same_v) { + hadMin |= details::floatEqual(value_, lower_, DEFAULT_EPS, DEFAULT_EPS); + hadMax |= details::floatEqual(value_, upper_, DEFAULT_EPS, DEFAULT_EPS); + } else { + hadMin |= value_ == lower_; + hadMax |= value_ == upper_; + } + min = std::min(min, value_); + max = std::max(max, value_); + lower = std::min(lower, lower_); + upper = std::max(upper, upper_); + } + + friend std::ostream& operator<<(std::ostream& os, const Bounds& bounds) { + os << bounds.hadMin << " " << bounds.hadMax << " "; + os << bounds.min << " " << bounds.max << " "; + return os << bounds.lower << " " << bounds.upper; + } + +}; + +namespace details { + //using typeIndex = std::type_index; + using typeIndex = void*; + + template + typeIndex getTypeIndex() { + //return std::type_index(type id(T)); + static T* uniqueTypeIndex = nullptr; + return &uniqueTypeIndex; + } +} + +class Constraint final { + friend class ConstraintsLogger; + std::variant< + std::monostate, // uninitialized + Bounds, // Integer or container bound + Bounds // Real bound + > bound; + std::optional type; + + template + void update(T lower, T upper, T value) { + if constexpr(std::is_integral_v) { + upper--; // for BAPCtools the range is closed but we use half open ranges! + } + if (!type) { + type = details::getTypeIndex(); + bound = Bounds(lower, upper, value); + } + judgeAssert(type == details::getTypeIndex(), "Constraint: type must not change!"); + std::get>(bound).update(lower, upper, value); + } +public: + Constraint() = default; + Constraint(Constraint&&) = default; + Constraint& operator=(Constraint&&) = default; + + Constraint(const Constraint&) = delete; + Constraint& operator=(const Constraint&) = delete; + + template, bool> = true> + void log(Integer lower, Integer upper, V value) { + update(lower, upper, value); + } + + template, bool> = true> + void log(Real lower, Real upper, V value) { + update(lower, upper, value); + } + + template, bool> = true> + void log(Integer lower, Integer upper, const C& container) { + update(lower, upper, static_cast(std::size(container))); + } +}; + +class ConstraintsLogger final { + std::optional fileName; + std::map byName; + std::vector> constraints; +public: + ConstraintsLogger() = default; + explicit ConstraintsLogger(std::string_view fileName_) : fileName(fileName_) {} + + ConstraintsLogger(ConstraintsLogger&&) = default; + ConstraintsLogger& operator=(ConstraintsLogger&&) = default; + + ConstraintsLogger(const ConstraintsLogger&) = delete; + ConstraintsLogger& operator=(const ConstraintsLogger&) = delete; + + Constraint& operator[](const std::string& name) & { + judgeAssert(details::isToken(name), "Constraint: name must not contain a space!"); + auto res = byName.try_emplace(name, constraints.size()); + if (res.second) constraints.emplace_back(std::make_unique()); + return *(constraints[res.first->second]); + } + + void write() const { + if (!fileName) return; + std::ofstream os(*fileName); + os << std::noboolalpha; + os << std::fixed; + os << std::setprecision(DEFAULT_PRECISION); + for (const auto& [name, id] : byName) { + const Constraint& c = *(constraints[id]); + if (c.type) { + os << "LocationNotSupported:" << name << " " << name << " "; + if (c.bound.index() == 1) os << std::get<1>(c.bound); + if (c.bound.index() == 2) os << std::get<2>(c.bound); + os << std::endl; + } + } + } + + ~ConstraintsLogger() noexcept { + write(); + } +}; + +//============================================================================// +// custom input stream // +//============================================================================// +class InputStream final { + std::unique_ptr managed; + std::istream* in; + bool spaceSensitive, caseSensitive; + Verdict onFail; + Real floatAbsTol; + Real floatRelTol; + + void init() { + if (spaceSensitive) *in >> std::noskipws; + else *in >> std::skipws; + } + + void checkIn() { + judgeAssert(in != nullptr, "InputStream: not initialized!"); + } + +public: + InputStream() = default; + explicit InputStream(const std::filesystem::path& path, + bool spaceSensitive_, + bool caseSensitive_, + Verdict onFail_, + Real floatAbsTol_ = DEFAULT_EPS, + Real floatRelTol_ = DEFAULT_EPS) : + managed(std::make_unique(path)), + in(managed.get()), + spaceSensitive(spaceSensitive_), + caseSensitive(caseSensitive_), + onFail(onFail_), + floatAbsTol(floatAbsTol_), + floatRelTol(floatRelTol_) { + judgeAssert(managed->good(), "InputStream: Could not open File: " + path.string()); + init(); + } + explicit InputStream(std::istream& in_, + bool spaceSensitive_, + bool caseSensitive_, + Verdict onFail_, + Real floatAbsTol_ = DEFAULT_EPS, + Real floatRelTol_ = DEFAULT_EPS) : + managed(), + in(&in_), + spaceSensitive(spaceSensitive_), + caseSensitive(caseSensitive_), + onFail(onFail_), + floatAbsTol(floatAbsTol_), + floatRelTol(floatRelTol_) { + init(); + } + + InputStream(InputStream&& other) = default; + InputStream& operator=(InputStream&& other) = default; + + InputStream(const InputStream&) = delete; + InputStream& operator=(const InputStream&) = delete; + + void eof() { + checkIn(); + if (!spaceSensitive) *in >> std::ws; + if (in->peek() != std::char_traits::eof()) { + in->get(); + ValidateBase::juryOut << "Missing EOF!"; + fail(); + } + } + + void noteof() { + checkIn(); + if (!spaceSensitive) *in >> std::ws; + if (in->peek() == std::char_traits::eof()) { + ValidateBase::juryOut << "Unexpected EOF!" << onFail; + } + } + + void space() { + if (spaceSensitive) { + noteof(); + if (in->get() != std::char_traits::to_int_type(SPACE)) { + ValidateBase::juryOut << "Missing space!"; + fail(); + } + } + } + + void newline() { + if (spaceSensitive) { + noteof(); + if (in->get() != std::char_traits::to_int_type(NEWLINE)) { + ValidateBase::juryOut << "Missing newline!"; + fail(); + } + } + } + +private: + void check(const std::string& token, const std::regex& pattern) { + if (!std::regex_match(token, pattern)) { + ValidateBase::juryOut << "Token \"" << token << "\" does not match pattern!"; + fail(); + } + } + + std::function checkSeparator(char separator) { + if (separator == SPACE) return [this](){space();}; + if (separator == NEWLINE) return [this](){newline();}; + judgeAssert(false, "InputStream: Separator must be ' ' or '\\n'!"); + return {}; + } + + template + T parse(const std::string& s) { + T res = {}; + if (!details::parse(s, res)) { + ValidateBase::juryOut << "Could not parse token \"" << s << "\"!"; + fail(); + } + return res; + } + +public: + std::string string() { + noteof(); + if (spaceSensitive and !std::isgraph(in->peek())) { + in->get(); + ValidateBase::juryOut << "Invalid whitespace!"; + fail(); + } + std::string res; + *in >> res; + if (res.empty()) { + ValidateBase::juryOut << "Unexpected EOF!" << onFail; + } + if (!caseSensitive) toDefaultCase(res); + return res; + } + + std::string string(Integer lower, Integer upper) { + std::string t = string(); + Integer length = static_cast(t.size()); + if (length < lower or length >= upper) { + ValidateBase::juryOut << "String length " << length << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return t; + } + + std::string string(Integer lower, Integer upper, Constraint& constraint) { + std::string res = string(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + std::string string(const std::regex& pattern) { + std::string t = string(); + check(t, pattern); + return t; + } + + std::string string(const std::regex& pattern, Integer lower, Integer upper) { + std::string t = string(lower, upper); + check(t, pattern); + return t; + } + + std::string string(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint) { + std::string res = string(pattern, lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector strings(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = string(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector strings(Integer count, char separator = DEFAULT_SEPARATOR) { + return strings<>(count, separator); + } + + std::vector strings(Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(lower, upper, count, separator); + } + + std::vector strings(Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(lower, upper, constraint, count, separator); + } + + std::vector strings(const std::regex& pattern, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, count, separator); + } + + std::vector strings(const std::regex& pattern, Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, lower, upper, count, separator); + } + + std::vector strings(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, lower, upper, constraint, count, separator); + } + + Integer integer() { + return parse(string(INTEGER_REGEX)); + } + + Integer integer(Integer lower, Integer upper) { + Integer res = integer(); + if (res < lower or res >= upper) { + ValidateBase::juryOut << "Integer " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } + + Integer integer(Integer lower, Integer upper, Constraint& constraint) { + Integer res = integer(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector integers(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = integer(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector integers(Integer count, char separator = DEFAULT_SEPARATOR) { + return integers<>(count, separator); + } + + std::vector integers(Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return integers(lower, upper, count, separator); + } + + std::vector integers(Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return integers(lower, upper, constraint, count, separator); + } + + // this does not allow NaN or Inf! + // However, those should never be desired. + Real real() { + return parse(string(REAL_REGEX)); + } + + Real real(Real lower, Real upper) {// uses eps + Real res = real(); + if (details::floatEqual(res, lower, floatAbsTol, floatRelTol)) return res; + if (details::floatEqual(res, upper, floatAbsTol, floatRelTol)) return res; + if (std::isnan(res) or !(res >= lower) or !(res < upper)) { + ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } + + Real real(Real lower, Real upper, Constraint& constraint) { + Real res = real(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector reals(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = real(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector reals(Integer count, char separator = DEFAULT_SEPARATOR) { + return reals<>(count, separator); + } + + std::vector reals(Real lower, Real upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return reals(lower, upper, count, separator); + } + + std::vector reals(Real lower, Real upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return reals(lower, upper, constraint, count, separator); + } + + Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals) {// does not use eps + std::string t = string(STRICT_REAL_REGEX); + auto dot = t.find('.'); + Integer decimals = dot == std::string::npos ? 0 : t.size() - dot - 1; + if (decimals < minDecimals or decimals >= maxDecimals) { + ValidateBase::juryOut << "Real " << t << " has wrong amount of decimals!"; + fail(); + return 0; + } + try { + Real res = parse(t); + if (std::isnan(res) or !(res >= lower) or !(res < upper)) { + ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } catch(...) { + ValidateBase::juryOut << "Could not parse token \"" << t << "\" as real!"; + fail(); + return 0; + } + } + + Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint) { + Real res = realStrict(lower, upper, minDecimals, maxDecimals); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector realsStrict(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = realStrict(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, + Integer count, char separator = DEFAULT_SEPARATOR) { + return realsStrict(lower, upper, minDecimals, maxDecimals, count, separator); + } + + std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return realsStrict(lower, upper, minDecimals, maxDecimals, constraint, count, separator); + } + + void expectString(std::string_view expected) { + judgeAssert(details::isToken(expected), "InputStream: expected must not contain a space!"); + std::string seen = string(); + auto [eq, pos] = details::stringEqual(seen, expected, caseSensitive); + if (!eq) { + if (seen.size() > 80) { + seen = seen.substr(0, 75) + "[...]"; + } + ValidateBase::juryOut << "Expected \"" << expected << "\" but got \"" << seen << "\"!"; + if (pos and *pos > 5) { + ValidateBase::juryOut << " (different at position: " << *pos+1 << ")"; + } + fail(); + } + } + + void expectInt(Integer expected) { + Integer seen = integer(); + if (seen != expected) { + ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!"; + fail(); + } + } + + void expectReal(Real expected) { + Real seen = real(); + if (details::floatEqual(seen, expected, floatAbsTol, floatRelTol)) { + ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!"; + if (std::isfinite(seen) and std::isfinite(expected)) { + Real absDiff = std::abs(seen-expected); + Real relDiff = std::abs((seen-expected)/expected); + ValidateBase::juryOut << " (abs: " << absDiff << ", rel: " << relDiff << ")"; + } + fail(); + } + } +private: + void fail() { + //try to find input position... + in->clear(); + auto originalPos = in->tellg(); + in->seekg(0); + if (originalPos != std::streamoff(-1) and *in) { + Integer line = 1; + std::size_t l = 0, r = 0; + std::string buffer; + bool extend = true; + while (*in and in->tellg() < originalPos) { + l = r = buffer.size(); + if (std::isgraph(in->peek())) { + std::string tmp; + *in >> tmp; + buffer += tmp; + } else if (in->peek() == std::char_traits::to_int_type(NEWLINE)) { + line++; + in->get(); + if (in->tellg() < originalPos) { + buffer.clear(); + } else { + buffer += ' '; + extend = false; + } + } else { + buffer += std::char_traits::to_char_type(in->get()); + } + if (*in and in->tellg() >= originalPos) { + r = buffer.size(); + } + } + if (l != r) { + ValidateBase::juryOut << " Line: " << line << ", Char: " << l << '\n'; + if (extend) { + char tmp; + while ((buffer.size() < 80 or buffer.size() < r + 80) and in->get(tmp) and tmp != NEWLINE) { + buffer += tmp; + } + } + if (r > 60 and l > 20) { + Integer offset = std::min(l - 20, r - 60); + l -= offset; + r -= offset; + buffer = "[...]" + buffer.substr(offset + 5); + } + if (buffer.size() > 80) { + buffer = buffer.substr(0, 75); + buffer += "[...]"; + r = std::min(r, buffer.size()); + } + ValidateBase::juryOut << buffer << '\n'; + ValidateBase::juryOut << std::string(l, ' ') << '^' << std::string(r - l - 1, '~'); + } + } + ValidateBase::juryOut << onFail; + } +}; + + +//============================================================================// +// state guard // +//============================================================================// +namespace details { + bool initialized(bool set = false) { + static bool value = false; + return std::exchange(value, value |= set); + } + + struct InitGuard final { + ~InitGuard() { + if (std::uncaught_exceptions() == 0) { + judgeAssert(initialized(), "validate.h: init(argc, argv) was never called!"); + } + } + } initGuard; +} + + +//============================================================================// +// Settings // +//============================================================================// +template +class SettingBase { + template + friend class Setting; + friend class SettingCaseSensitive; + + T value; + + SettingBase(T value_) : value(value_) {} + +public: + SettingBase(SettingBase&& other) = delete; + SettingBase(const SettingBase&) = delete; + SettingBase& operator=(SettingBase&& other) = delete; + SettingBase& operator=(const SettingBase&) = delete; + + operator T() const { + return value; + } + + SettingBase& operator=(T value_) { + judgeAssert(!details::initialized(), "validate.h: Cannot change setting after init(argc, argv) was called!"); + value = value_; + return *this; + } +}; + +template +class Setting final : public SettingBase { +public: + Setting(T value) : SettingBase(value) {} + using SettingBase::operator T; + using SettingBase::operator=; +}; + +class SettingCaseSensitive final : public SettingBase { +public: + SettingCaseSensitive(bool value) : SettingBase(value) {} + using SettingBase::operator bool; + using SettingBase::operator=; + + std::regex regex(std::string_view s, std::regex_constants::syntax_option_type f = std::regex_constants::ECMAScript) const { + if (!value) f |= std::regex_constants::icase; + return std::regex(s.data(), s.size(), f); + } +}; + + +//============================================================================// +// Validators and stuff // +//============================================================================// +namespace ValidateBase { + //OutputStream juryOut(std::cout); //already defined earlier + //OutputStream juryErr(std::cerr); + CommandParser arguments; + //you may change these values before calling::init() but not afterwards! + Setting floatAbsTol(DEFAULT_EPS); + Setting floatRelTol(DEFAULT_EPS); + Setting spaceSensitive(false); + SettingCaseSensitive caseSensitive(false); + + // Real r2 is considered the reference value for relative error. + bool floatEqual(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return details::floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + bool floatLess(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return given <= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + bool floatGreater(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return given >= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + constexpr boolean stringEqual(std::string_view a, std::string_view b, bool caseSensitive_ = caseSensitive) { + return details::stringEqual(a, b, caseSensitive_); + } + + namespace details { + void init(int argc, char** argv) { + judgeAssert(!::details::initialized(), "validate.h: init(argc, argv) was called twice!"); + + //std::ios_base::sync_with_stdio(false); + //cin.tie(nullptr); + + arguments = CommandParser(argc, argv); + if (auto seed = arguments[SEED_COMMAND]) Random::seed(seed.asInteger()); + // parse default flags manually, since they dont use '--' prefix + auto eps = arguments.getRaw(FLOAT_TOLERANCE); + floatAbsTol = eps.asReal(floatAbsTol); + floatRelTol = eps.asReal(floatRelTol); + floatAbsTol = arguments.getRaw(FLOAT_ABSOLUTE_TOLERANCE).asReal(floatAbsTol); + floatRelTol = arguments.getRaw(FLOAT_RELATIVE_TOLERANCE).asReal(floatRelTol); + + if (arguments.getRaw(SPACE_SENSITIVE)) spaceSensitive = true; + if (arguments.getRaw(CASE_SENSITIVE)) caseSensitive = true; + + ::details::initialized(true); + } + } + +} // namespace ValidateBase + +namespace ConstraintsBase { + ConstraintsLogger constraint; + + void initConstraints() { + if (auto file = ValidateBase::arguments[CONSTRAINT_COMMAND]) { + constraint = ConstraintsLogger(file.asString()); + } + } + +} // namespace ConstraintsBase + +//called as ./validator [arguments] < inputfile +namespace InputValidator { + using namespace ValidateBase; + using namespace ConstraintsBase; + + InputStream testIn; + + void init(int argc, char** argv) { + spaceSensitive = true; + caseSensitive = true; + + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::cout); + + testIn = InputStream(std::cin, spaceSensitive, caseSensitive, WA, floatAbsTol, floatRelTol); + initConstraints(); + } + +} // namespace InputValidator + +//called as ./validator input judgeanswer feedbackdir < teamoutput +namespace OutputValidator { + using namespace ValidateBase; + using namespace ConstraintsBase; + + InputStream testIn; + InputStream juryAns; + InputStream teamAns; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE); + + testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL); + juryAns = InputStream(std::filesystem::path(arguments[2]), false, caseSensitive, FAIL); + teamAns = InputStream(std::cin, spaceSensitive, caseSensitive, WA); + initConstraints(); + } + +} // namespace OutputValidator + +//called as ./interactor input judgeanswer feedbackdir <> teamoutput +namespace Interactor { + using namespace ValidateBase; + + OutputStream toTeam; + InputStream testIn; + InputStream fromTeam; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE); + toTeam = OutputStream(std::cout); + + testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL); + fromTeam = InputStream(std::cin, spaceSensitive, caseSensitive, WA); + } + +} // namespace Interactor + +//called as ./generator [arguments] +namespace Generator { + using namespace ValidateBase; + + OutputStream testOut; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::cerr); + testOut = OutputStream(std::cout); + } + +} // namespace Generator + +#endif diff --git a/ICPC/nwerc2023_G/data.zip b/ICPC/nwerc2023_G/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..7348520bf8dc8d343e32fdc20ddfb3abab2995aa --- /dev/null +++ b/ICPC/nwerc2023_G/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b249ebce9baacfa398b0ff98d8b596d8b9bf6bbe555580c7ef3ed1bd4d7bdd5c +size 48440558 diff --git a/ICPC/nwerc2023_G/init.yml b/ICPC/nwerc2023_G/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..27b6a1664fca0de9490e0fea21b4d748c63d9a6c --- /dev/null +++ b/ICPC/nwerc2023_G/init.yml @@ -0,0 +1,174 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 01-cancellation.in + out: 01-cancellation.ans + points: 1 +- in: 02-min.in + out: 02-min.ans + points: 1 +- in: 03-max.in + out: 03-max.ans + points: 1 +- in: 04-max.in + out: 04-max.ans + points: 1 +- in: 05-max.in + out: 05-max.ans + points: 1 +- in: 06-max.in + out: 06-max.ans + points: 1 +- in: 07-max.in + out: 07-max.ans + points: 1 +- in: 08-tree.in + out: 08-tree.ans + points: 1 +- in: 09-tree.in + out: 09-tree.ans + points: 1 +- in: 10-near-tree.in + out: 10-near-tree.ans + points: 1 +- in: 11-near-tree.in + out: 11-near-tree.ans + points: 1 +- in: 12-complete.in + out: 12-complete.ans + points: 1 +- in: 13-boundary.in + out: 13-boundary.ans + points: 1 +- in: 14-clusters.in + out: 14-clusters.ans + points: 1 +- in: 15-sphere.in + out: 15-sphere.ans + points: 1 +- in: 16-random-special.in + out: 16-random-special.ans + points: 1 +- in: 17-random-special.in + out: 17-random-special.ans + points: 1 +- in: 18-random-special.in + out: 18-random-special.ans + points: 1 +- in: 19-random-special.in + out: 19-random-special.ans + points: 1 +- in: 20-random-special.in + out: 20-random-special.ans + points: 1 +- in: 21-random-special.in + out: 21-random-special.ans + points: 1 +- in: 22-random-special.in + out: 22-random-special.ans + points: 1 +- in: 23-random-special.in + out: 23-random-special.ans + points: 1 +- in: 24-random-special.in + out: 24-random-special.ans + points: 1 +- in: 25-random-special.in + out: 25-random-special.ans + points: 1 +- in: 26-random-small.in + out: 26-random-small.ans + points: 1 +- in: 27-random-small.in + out: 27-random-small.ans + points: 1 +- in: 28-random-small.in + out: 28-random-small.ans + points: 1 +- in: 29-random-small.in + out: 29-random-small.ans + points: 1 +- in: 30-random-small.in + out: 30-random-small.ans + points: 1 +- in: 31-random-small.in + out: 31-random-small.ans + points: 1 +- in: 32-random-small.in + out: 32-random-small.ans + points: 1 +- in: 33-random-small.in + out: 33-random-small.ans + points: 1 +- in: 34-random-small.in + out: 34-random-small.ans + points: 1 +- in: 35-random-small.in + out: 35-random-small.ans + points: 1 +- in: 36-random.in + out: 36-random.ans + points: 1 +- in: 37-random.in + out: 37-random.ans + points: 1 +- in: 38-random.in + out: 38-random.ans + points: 1 +- in: 39-random.in + out: 39-random.ans + points: 1 +- in: 40-random.in + out: 40-random.ans + points: 1 +- in: 41-random.in + out: 41-random.ans + points: 1 +- in: 42-random.in + out: 42-random.ans + points: 1 +- in: 43-random.in + out: 43-random.ans + points: 1 +- in: 44-random.in + out: 44-random.ans + points: 1 +- in: 45-random.in + out: 45-random.ans + points: 1 +- in: 46-random-small-coords.in + out: 46-random-small-coords.ans + points: 1 +- in: 47-random-small-coords.in + out: 47-random-small-coords.ans + points: 1 +- in: 48-random-small-coords.in + out: 48-random-small-coords.ans + points: 1 +- in: 49-random-small-coords.in + out: 49-random-small-coords.ans + points: 1 +- in: 50-random-small-coords.in + out: 50-random-small-coords.ans + points: 1 +- in: 51-always-last.in + out: 51-always-last.ans + points: 1 +- in: 52-anti-quadratic.in + out: 52-anti-quadratic.ans + points: 1 +- in: 53-anti-quadratic.in + out: 53-anti-quadratic.ans + points: 1 +- in: 54-anti-quadratic.in + out: 54-anti-quadratic.ans + points: 1 +- in: 55-anti-quadratic.in + out: 55-anti-quadratic.ans + points: 1 +- in: 56-anti-quadratic.in + out: 56-anti-quadratic.ans + points: 1 diff --git a/ICPC/nwerc2023_H/data.zip b/ICPC/nwerc2023_H/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..f4266df9dbb045c5ba29c9c4f90634716a75dca7 --- /dev/null +++ b/ICPC/nwerc2023_H/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1598484270d0a1d303bae6e25009746205d0c0c321c25c153048aed8a141713f +size 12779418 diff --git a/ICPC/nwerc2023_H/init.yml b/ICPC/nwerc2023_H/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..80f6137740951ce3098501ce1f07f34ac56d8c0f --- /dev/null +++ b/ICPC/nwerc2023_H/init.yml @@ -0,0 +1,272 @@ +archive: data.zip +checker: + args: + files: + - output_validators/output_validator/validate.h + - output_validators/output_validator/validate_using_modulo.cpp + - output_validators/output_validator/validate_using_insights.cpp + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 01-random.in + out: 01-random.ans + points: 1 +- in: 02-gen1.in + out: 02-gen1.ans + points: 1 +- in: 03-gen2.in + out: 03-gen2.ans + points: 1 +- in: 04-manual.in + out: 04-manual.ans + points: 1 +- in: 05-manual.in + out: 05-manual.ans + points: 1 +- in: 06-manual.in + out: 06-manual.ans + points: 1 +- in: 07-manual.in + out: 07-manual.ans + points: 1 +- in: 08-manual.in + out: 08-manual.ans + points: 1 +- in: 09-max-a.in + out: 09-max-a.ans + points: 1 +- in: 10-max-a1.in + out: 10-max-a1.ans + points: 1 +- in: 11-max-a2.in + out: 11-max-a2.ans + points: 1 +- in: 12-max-a11.in + out: 12-max-a11.ans + points: 1 +- in: 13-max-a12.in + out: 13-max-a12.ans + points: 1 +- in: 14-max-a22.in + out: 14-max-a22.ans + points: 1 +- in: 15-max-a111.in + out: 15-max-a111.ans + points: 1 +- in: 16-max-a112.in + out: 16-max-a112.ans + points: 1 +- in: 17-max-a122.in + out: 17-max-a122.ans + points: 1 +- in: 18-max-a222.in + out: 18-max-a222.ans + points: 1 +- in: 19-max-a113.in + out: 19-max-a113.ans + points: 1 +- in: 20-max-a123.in + out: 20-max-a123.ans + points: 1 +- in: 21-max-a223.in + out: 21-max-a223.ans + points: 1 +- in: 22-max-a133.in + out: 22-max-a133.ans + points: 1 +- in: 23-max-a233.in + out: 23-max-a233.ans + points: 1 +- in: 24-max-a333.in + out: 24-max-a333.ans + points: 1 +- in: 25-onlyones.in + out: 25-onlyones.ans + points: 1 +- in: 26-manyonesnotwos.in + out: 26-manyonesnotwos.ans + points: 1 +- in: 27-manytwosnoones.in + out: 27-manytwosnoones.ans + points: 1 +- in: 28-manytwosnoones.in + out: 28-manytwosnoones.ans + points: 1 +- in: 29-onestwos.in + out: 29-onestwos.ans + points: 1 +- in: 30-onestwos.in + out: 30-onestwos.ans + points: 1 +- in: 31-onestwos.in + out: 31-onestwos.ans + points: 1 +- in: 32-onestwos.in + out: 32-onestwos.ans + points: 1 +- in: 33-onestwos.in + out: 33-onestwos.ans + points: 1 +- in: 34-onestwos.in + out: 34-onestwos.ans + points: 1 +- in: 35-onestwos.in + out: 35-onestwos.ans + points: 1 +- in: 36-onestwos.in + out: 36-onestwos.ans + points: 1 +- in: 37-onestwos.in + out: 37-onestwos.ans + points: 1 +- in: 38-onestwos.in + out: 38-onestwos.ans + points: 1 +- in: 39-onestwos.in + out: 39-onestwos.ans + points: 1 +- in: 40-onestwos.in + out: 40-onestwos.ans + points: 1 +- in: 41-onestwos.in + out: 41-onestwos.ans + points: 1 +- in: 42-onestwos.in + out: 42-onestwos.ans + points: 1 +- in: 43-onestwos.in + out: 43-onestwos.ans + points: 1 +- in: 44-onestwos.in + out: 44-onestwos.ans + points: 1 +- in: 45-onestwos.in + out: 45-onestwos.ans + points: 1 +- in: 46-onestwos.in + out: 46-onestwos.ans + points: 1 +- in: 47-onestwos.in + out: 47-onestwos.ans + points: 1 +- in: 48-onestwos.in + out: 48-onestwos.ans + points: 1 +- in: 49-onestwos.in + out: 49-onestwos.ans + points: 1 +- in: 50-onestwos.in + out: 50-onestwos.ans + points: 1 +- in: 51-onestwos.in + out: 51-onestwos.ans + points: 1 +- in: 52-onestwos.in + out: 52-onestwos.ans + points: 1 +- in: 53-onestwos.in + out: 53-onestwos.ans + points: 1 +- in: 54-onestwos.in + out: 54-onestwos.ans + points: 1 +- in: 55-onestwos.in + out: 55-onestwos.ans + points: 1 +- in: 56-onestwos.in + out: 56-onestwos.ans + points: 1 +- in: 57-onestwos.in + out: 57-onestwos.ans + points: 1 +- in: 58-onestwos.in + out: 58-onestwos.ans + points: 1 +- in: 59-onestwos.in + out: 59-onestwos.ans + points: 1 +- in: 60-onestwos.in + out: 60-onestwos.ans + points: 1 +- in: 61-onestwos.in + out: 61-onestwos.ans + points: 1 +- in: 62-onestwos.in + out: 62-onestwos.ans + points: 1 +- in: 63-random.in + out: 63-random.ans + points: 1 +- in: 64-random.in + out: 64-random.ans + points: 1 +- in: 65-random.in + out: 65-random.ans + points: 1 +- in: 66-random.in + out: 66-random.ans + points: 1 +- in: 67-random.in + out: 67-random.ans + points: 1 +- in: 68-gen1.in + out: 68-gen1.ans + points: 1 +- in: 69-gen1.in + out: 69-gen1.ans + points: 1 +- in: 70-gen1.in + out: 70-gen1.ans + points: 1 +- in: 71-gen1.in + out: 71-gen1.ans + points: 1 +- in: 72-gen1.in + out: 72-gen1.ans + points: 1 +- in: 73-gen1.in + out: 73-gen1.ans + points: 1 +- in: 74-gen1.in + out: 74-gen1.ans + points: 1 +- in: 75-gen2.in + out: 75-gen2.ans + points: 1 +- in: 76-gen2.in + out: 76-gen2.ans + points: 1 +- in: 77-gen2.in + out: 77-gen2.ans + points: 1 +- in: 78-gen2.in + out: 78-gen2.ans + points: 1 +- in: 79-gen2.in + out: 79-gen2.ans + points: 1 +- in: 80-gen2.in + out: 80-gen2.ans + points: 1 +- in: 81-gen2.in + out: 81-gen2.ans + points: 1 +- in: 82-gen2.in + out: 82-gen2.ans + points: 1 +- in: 83-gen2.in + out: 83-gen2.ans + points: 1 +- in: 84-gen2.in + out: 84-gen2.ans + points: 1 +- in: 85-gen2.in + out: 85-gen2.ans + points: 1 +- in: 86-gen2.in + out: 86-gen2.ans + points: 1 +- in: 87-gen2.in + out: 87-gen2.ans + points: 1 diff --git a/ICPC/nwerc2023_H/output_validators/output_validator/build b/ICPC/nwerc2023_H/output_validators/output_validator/build new file mode 100644 index 0000000000000000000000000000000000000000..70bdf304f7b275eca0bedcab61ee53c4b8d4c9f7 --- /dev/null +++ b/ICPC/nwerc2023_H/output_validators/output_validator/build @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +g++ -g -O2 -std=gnu++20 -Wall -Wfatal-errors validate_using_insights.cpp -o validate_using_insights +g++ -g -O2 -std=gnu++20 -Wall -Wfatal-errors validate_using_modulo.cpp -o validate_using_modulo diff --git a/ICPC/nwerc2023_H/output_validators/output_validator/run b/ICPC/nwerc2023_H/output_validators/output_validator/run new file mode 100644 index 0000000000000000000000000000000000000000..26d471c40fc69906987bef50bc3ea8a4f183df27 --- /dev/null +++ b/ICPC/nwerc2023_H/output_validators/output_validator/run @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set +e + +# called as: +# ./run in ans feedback_dir [additional arguments] < out [> interactive_input] +input=$1 +answer=$2 +feedbackdir=$3 + +# relevant files in feedback_dir: +# teammessage.txt (not in use for ICPC contests) +judgemessage=${feedbackdir}judgemessage.txt +scriptdir=${0%/*} + +# copy stdin to tempfile, so that we can reuse it +output=$(mktemp -p /tmp "NWERC-test-XXXXXX.out") +cat > $output + +"${scriptdir}/validate_using_insights" $input $answer $feedbackdir < $output +ret_insights=$? + +"${scriptdir}/validate_using_modulo" $input $answer $feedbackdir < $output +ret_modulo=$? + +rm $output + +if [ "$ret_insights" = "$ret_modulo" ] ; then + exit $ret_insights +else + echo "The two validators should have the same result!" >> $judgemessage + echo "validate_using_insights exited with $ret_insights" >> $judgemessage + echo "validate_using_modulo exited with $ret_modulo" >> $judgemessage + echo "PLEASE INVESTIGATE THIS" >> $judgemessage + cat $judgemessage >&2 + exit 1 +fi diff --git a/ICPC/nwerc2023_H/output_validators/output_validator/validate.h b/ICPC/nwerc2023_H/output_validators/output_validator/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..73a2289afda07cd2370d02439fb91fea2ee1743b --- /dev/null +++ b/ICPC/nwerc2023_H/output_validators/output_validator/validate.h @@ -0,0 +1,2662 @@ +//============================================================================// +// validate.h // +//============================================================================// +// This header can be used to safely parse team output tokenwise. We support: // +// - string tokens (get converted to lowercase) // +// - integer tokens in [-2^63, 2^63) // +// - float tokens (relative and absolute error of 10^6 is allowed by default) // +// Tokens need to be separated by whitespace (any amount). The following // +// command line flags allow stricter checking: // +// - caseSensitive: string tokens don't get converted to lowercase // +// - space_change_sensitive: tokens need to be separated by the corect // +// amount of whitespaces // +// - FLOAT_{RELATIVE|ABSOLUTE}_TOLERANCE: allowed relative/absolute error // +// // +// This header can also be used to safely verify input files. In this case // +// tokens are case sensitive and all whitespaces have to be checked. Also // +// whitespaces are not interchangeable. // +// // +// This header can be used to generate random numbers in a deterministic and // +// reproducable fashion. (The randomness is consistent across compilers and // +// machines) // +//============================================================================// +// version 2.3.2 // +// https://github.com/mzuenni/icpc-header // +//============================================================================// + +#ifndef VALIDATE_H +#define VALIDATE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//============================================================================// +// Basic definitions and constants // +//============================================================================// +// default types +using Integer = std::int64_t; +using Real = long double; + +// derived types +using UInteger = std::make_unsigned::type; +constexpr Integer operator ""_int(unsigned long long int value) {return static_cast(value);} +constexpr UInteger operator ""_uint(unsigned long long int value) {return static_cast(value);} +constexpr Real operator ""_real(unsigned long long int value) {return static_cast(value);} +constexpr Real operator ""_real(long double value) {return static_cast(value);} + +// settings which can be overwritten before the include! +//#define DOUBLE_FALLBACK +namespace Settings { + namespace details { + using RandomEngine = std::mt19937_64; + constexpr Integer LARGE = 0x3FFF'FFFF'FFFF'FFFF; + constexpr bool DEFAULT_CASE_LOWER = true; + constexpr int DEFAULT_PRECISION = 6; + constexpr Real DEFAULT_EPS = 1e-6_real; + + [[noreturn]] void exitVerdict(int exitCode) { + //throw exitCode; + //quick_exit(exitCode); + std::exit(exitCode); + } + } + using namespace details; +} +// make settings publically available +using Settings::RandomEngine; +using Settings::LARGE; +using Settings::DEFAULT_CASE_LOWER; +using Settings::DEFAULT_PRECISION; +using Settings::DEFAULT_EPS; +using Settings::exitVerdict; + +// useful constants +constexpr std::string_view LETTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view UPPER = LETTER.substr(0, 26); +constexpr std::string_view LOWER = LETTER.substr(26); +constexpr std::string_view VOWEL = "AEIOUaeiou"; +constexpr std::string_view UPPER_VOWELS = VOWEL.substr(0, 5); +constexpr std::string_view LOWER_VOWELS = VOWEL.substr(5); +constexpr std::string_view CONSONANT = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"; +constexpr std::string_view UPPER_CONSONANT = CONSONANT.substr(0, 26 - 5); +constexpr std::string_view LOWER_CONSONANT = CONSONANT.substr(26 - 5); +constexpr std::string_view ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view UPPER_ALPHA_NUMERIC = ALPHA_NUMERIC.substr(0, 10 + 26); +constexpr std::string_view LOWER_ALPHA_NUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz"; +constexpr std::string_view DIGITS = ALPHA_NUMERIC.substr(0, 10); +constexpr std::string_view BRACKETS = "()[]{}<>"; +constexpr char NEWLINE = '\n'; +constexpr char SPACE = ' '; +constexpr char NOSEP = '\0'; +constexpr Real PI = 3.1415926535897932384626433832795028_real; + + +//============================================================================// +// internal definitions and constants // +//============================================================================// +constexpr UInteger DEFAULT_SEED = 3141592653589793238_uint; +constexpr std::string_view CASE_SENSITIVE = "case_sensitive"; +constexpr std::string_view SPACE_SENSITIVE = "space_change_sensitive"; +constexpr std::string_view FLOAT_ABSOLUTE_TOLERANCE = "float_absolute_tolerance"; +constexpr std::string_view FLOAT_RELATIVE_TOLERANCE = "float_relative_tolerance"; +constexpr std::string_view FLOAT_TOLERANCE = "float_tolerance"; +constexpr std::string_view JUDGE_MESSAGE = "null"; +constexpr char DEFAULT_SEPARATOR = SPACE; +constexpr std::string_view EMPTY_COMMAND = ""; +constexpr std::string_view COMMAND_PREFIX = "--"; +constexpr std::string_view CONSTRAINT_COMMAND = "--constraints_file"; +constexpr std::string_view SEED_COMMAND = "--seed"; +constexpr auto REGEX_OPTIONS = std::regex::nosubs | std::regex::optimize; +inline const std::regex INTEGER_REGEX("0|-?[1-9][0-9]*", REGEX_OPTIONS); +inline const std::regex REAL_REGEX("-?(0|([1-9][0-9]*))(\\.[0-9]*)?([eE][+-]?(0|([1-9][0-9]*)))?", REGEX_OPTIONS); +inline const std::regex STRICT_REAL_REGEX("-?(0|([1-9][0-9]*))\\.?[0-9]*", REGEX_OPTIONS); + +static_assert(2'000'000'000'000'000'000_int < LARGE / 2, "LARGE too small"); +static_assert(LARGE <= std::numeric_limits::max() / 2, "LARGE too big"); + +static_assert(-1 == 0xFFFF'FFFF'FFFF'FFFF_int, "Two's complement for signed numbers is required" ); +static_assert(std::is_convertible_v, "Incompatible Integer and UInteger types?!"); +static_assert(std::is_convertible_v, "Incompatible Integer and UInteger types?!"); +static_assert(sizeof(Integer) == sizeof(UInteger), "Incompatible Integer and UInteger types?!"); + +template +constexpr void judgeAssert(bool asserted, std::string_view message) { + if (!asserted) throw T(message.data()); +} + + +//============================================================================// +// SFINAE // +//============================================================================// +namespace details { + template + struct IsContainer : std::false_type {}; + + template + struct IsContainer>()))>> : std::true_type { + using iterator_type = decltype(std::begin(std::declval>())); + using value_type = std::remove_reference_t>()))>; + }; + + template + struct IsStdArray : std::false_type {}; + + template + struct IsStdArray> : std::true_type {}; + + template + struct IsTupleLike : std::false_type {}; + + template + struct IsTupleLike))>> : std::true_type {}; + + template + struct HasOstreamOperator : std::false_type {}; + + template + struct HasOstreamOperator() << std::declval())>> : std::true_type {}; +} + + +//============================================================================// +// Verdicts // +//============================================================================// +struct Verdict final { + int exitCode; + + constexpr explicit Verdict(int exitCode_ = 1) : exitCode(exitCode_) {} + + constexpr operator int() const { + return exitCode; + } + + [[noreturn]] void exit() const { + exitVerdict(exitCode); + } + + friend void operator<<(std::ostream& os, const Verdict& v) { + os << std::endl; + v.exit(); + } +}; + +// default verdicts (we do not support scoring) +constexpr Verdict AC(42); +constexpr Verdict WA(43); +constexpr Verdict PE = WA; +constexpr Verdict FAIL(1); + + +//============================================================================// +// Output streams // +//============================================================================// +class NullStream final : public std::ostream { + class NullBuffer final : public std::streambuf { + protected: + std::streamsize xsputn(const char* /**/, std::streamsize n) override { + return n; + } + int overflow(int c = std::char_traits::eof()) override { + return std::char_traits::not_eof(c); + } + } nullBuffer; +public: + NullStream() : std::ostream(&nullBuffer) {} +}; + +namespace details { + NullStream nullStream; +} + +class OutputStream final { + std::unique_ptr managed; + std::ostream* os; + + void init() { + *os << std::boolalpha; + *os << std::fixed; + *os << std::setprecision(DEFAULT_PRECISION); + } + +public: + OutputStream() : os(&details::nullStream) {} + OutputStream(std::ostream& os_) : os(&os_) {init();} + explicit OutputStream(const std::filesystem::path& path) : managed(std::make_unique(path)), os(managed.get()) { + judgeAssert(managed->good(), "OutputStream: Could not open File: " + path.string()); + init(); + } + + OutputStream(OutputStream&& other) = default; + OutputStream& operator=(OutputStream&& other) = default; + + OutputStream(const OutputStream&) = delete; + OutputStream& operator=(const OutputStream&) = delete; + + + template + OutputStream& operator<<(const std::pair& t) { + return *this << t.first << DEFAULT_SEPARATOR << t.second; + } + + template + OutputStream& operator<<(const std::tuple& t) { + return join(t, std::index_sequence_for(), DEFAULT_SEPARATOR); + } + + template + OutputStream& operator<<(const T& x) { + if constexpr ((std::is_array_v and !std::is_same_v, char*>) or + (details::IsContainer{} and !details::HasOstreamOperator{})) { + return join(std::begin(x), std::end(x), DEFAULT_SEPARATOR); + } else { + *os << x; + return *this; + } + } + + OutputStream& operator<<(std::ostream& (*manip)(std::ostream&)) { + *os << manip; + return *this; + } + + template + OutputStream& join(const Tuple& t, std::index_sequence /**/, char separator) { + static_assert(std::tuple_size_v == sizeof...(Is)); + if (separator != NOSEP) ((*os << (Is == 0 ? std::string_view() : std::string_view(&separator, 1)), *this << std::get(t)), ...); + else ((*this << std::get(t)), ...); + return *this; + } + + template + OutputStream& join(T first, T last, char separator) { + for (auto it = first; it != last; it++) { + if (it != first and separator != NOSEP) *os << separator; + *this << *it; + } + return *this; + } +}; + +namespace ValidateBase { + // define this early so everyone can use it! + OutputStream juryErr(std::cerr); + OutputStream juryOut(std::cout); +} + +// allow printing colletions as: +// join(begin(), end(), [sep]) +namespace details { + template + class TempWriter final { + C callable; + public: + constexpr explicit TempWriter(const C& callable_) : callable(callable_) {} + + TempWriter(const TempWriter&) = delete; + TempWriter(TempWriter&&) = delete; + TempWriter& operator=(const TempWriter&) = delete; + TempWriter& operator=(TempWriter&&) = delete; + + std::string asString() const { + std::ostringstream os; + OutputStream tmp(os); + tmp << *this; + return os.str(); + } + + explicit operator std::string() const { + return asString(); + } + + friend OutputStream& operator<<(OutputStream& os, const TempWriter& writer) { + writer.callable(os); + return os; + } + + friend OutputStream& operator<<(std::ostream& os, const TempWriter& writer) = delete; //news OutputStream + }; + + struct JoinListCapture { + std::function callable; + + template + JoinListCapture(Args&&... args) + : callable([t = std::forward_as_tuple(args...)](OutputStream& os, char separator) { + os.join(t, std::index_sequence_for(), separator); + }) {} + }; +} + +template +constexpr auto join(T first, T last, char separator = DEFAULT_SEPARATOR) { + return details::TempWriter([=](OutputStream& os) { + os.join(first, last, separator); + }); +} + +template{}>, + typename = std::enable_if_t>>{}>> +constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) { + if constexpr(std::is_rvalue_reference_v) { + if constexpr (std::is_array_v) { + return details::TempWriter([c, separator](OutputStream& os) { + os.join(std::begin(c), std::end(c), separator); + }); + } else { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + os.join(std::begin(c), std::end(c), separator); + }); + } + } else { + return join(std::begin(c), std::end(c), separator); + } +} + +template>::value> +constexpr auto join(CR&& c, char separator = DEFAULT_SEPARATOR) { + if constexpr(std::is_rvalue_reference_v) { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + os.join(c, std::make_index_sequence{}, separator); + }); + } else { + return details::TempWriter([&c, separator](OutputStream& os) { + os.join(c, std::make_index_sequence{}, separator); + }); + } +} + +template, char>>> +constexpr auto join(T (&c)[N], char separator = DEFAULT_SEPARATOR) { + static_assert(N > 0, "c-strings should be null terminated!"); + return join(std::begin(c), std::prev(std::end(c)), separator); +} + +template, char>>> +constexpr auto join(T (&&c)[N], char separator = DEFAULT_SEPARATOR) { + static_assert(N > 0, "c-strings should be null terminated!"); + return details::TempWriter([c, separator](OutputStream& os) { + os.join(std::begin(c), std::prev(std::end(c)), separator); + }); +} + +template{}>, + typename = std::enable_if_t{}>, + typename = std::enable_if_t{}>> +constexpr auto join(const T& t, char separator = DEFAULT_SEPARATOR) = delete; + +auto join(details::JoinListCapture c, char separator = DEFAULT_SEPARATOR) { + return details::TempWriter([c = std::move(c), separator](OutputStream& os) { + c.callable(os, separator); + }); +} + + +//============================================================================// +// Basic datastructures // +//============================================================================// +// make usage of std::priority_queue easier... +namespace details { + template> + struct invertCompare { + constexpr bool operator()(const T &lhs, const T &rhs) const { + return Compare{}(rhs, lhs); + } + }; +} +template> +using MinPQ = std::priority_queue, details::invertCompare>; +template> +using MaxPQ = std::priority_queue, Compare>; + +template +bool contains(const C& container, const K& key) { + return container.find(key) != container.end(); +} + +template +void append(C1& c1, const C2& c2) { + static_assert(std::is_same_v::value_type, + typename details::IsContainer::value_type>, "cannot append container of different value type!"); + if (static_cast(&c1) != static_cast(&c2)) { + for (auto&& e : c2) c1.emplace(c1.end(), e); + } else { + C2 tmp = c2; + for (auto&& e : tmp) c1.emplace(c1.end(), e); + } +} + +template +void append(C1& c1, const typename C1::value_type(&c2)[N]) { + for (auto&& e : c2) c1.emplace(c1.end(), e); +} + +struct shorter { + template + bool operator()(const U& a, const V& b) const { + return std::size(a) < std::size(b); + } +}; + +struct longer { + template + bool operator()(const U& a, const V& b) const { + return std::size(b) < std::size(a); + } +}; + +namespace details { + template + struct Flatten {using value_type = T;}; + + template + struct Flatten{}>> : Flatten::value_type> {}; + + template + void flatAppend(CR&& c, std::vector& res) { + using C = std::remove_reference_t; + if constexpr(std::is_same_v) { + res.emplace_back(std::forward(c)); + } else if constexpr (!IsContainer{}) { + static_assert(IsContainer{}, "invalid base type for flatten()!"); + } else { + if constexpr (std::is_rvalue_reference_v) { + for (auto&& v : c) flatAppend(std::move(v), res); + } else { + for (auto&& v : c) flatAppend(v, res); + } + } + } +} + +template +auto flatten(CR&& c) { + std::vector res; + details::flatAppend(std::forward(c), res); + return res; +} + +template +auto flatten(CR&& c) { + using C = std::remove_reference_t; + return flatten::value_type, CR>(std::forward(c)); +} + +template +struct boolean { + bool value; + std::optional reason; + + constexpr boolean(bool value_) : value(value_) {} + constexpr boolean(bool value_, const T& reason_) : value(value_), reason(reason_) {} + + constexpr operator bool() const { + return value; + } + + constexpr bool hasReason() const { + return reason.has_value(); + } +}; + + +//============================================================================// +// Utility // +//============================================================================// +// for sequences +template::value_type>>> +auto isPerm(RandomIt first, RandomIt last, typename std::iterator_traits::value_type offset = 0) { + using T = typename std::iterator_traits::value_type; + auto count = std::distance(first, last); + std::vector seen(count, false); + for (; first != last; first++) { + const T& x = *first; + if (x < offset or x - offset >= count or seen[x - offset]) { + return boolean(false, x); + } + seen[x - offset] = true; + } + return boolean(true); +} +template::value_type>, bool> = true> +auto isPerm(const C& c, typename details::IsContainer::value_type offset = 0) { + return isPerm(std::begin(c), std::end(c), offset); +} + +template +auto isPerm(itA firstA, itA lastA, itB firstB, itB lastB) { + using T = typename std::iterator_traits::value_type; + std::vector::value_type> a(firstA, lastA); + std::vector::value_type> b(firstB, lastB); + if (a.size() != b.size()) return boolean(false); + std::sort(a.begin(), a.end()); + std::sort(b.begin(), b.end()); + for (std::size_t i = 0; i < a.size(); i++) { + if (a[i] != b[i]) return boolean(false, a[i]); + } + return boolean(true); +} +template{}>, + typename = std::enable_if_t{}>> +auto isPerm(const C1& c1, const C2& c2) { + return isPerm(std::begin(c1), std::end(c1), std::begin(c2), std::end(c2)); +} + +template +constexpr boolean anyAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + if (first != last) { + for (Integer i = 1; std::next(first) != last; first++, i++) { + if (p(*first, *std::next(first))) { + return boolean(true, i); + } + } + } + return boolean(false); +} +template +constexpr boolean anyAdjacent(const C& c, BinaryPredicate p) { + return anyAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean noneAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + auto res = anyAdjacent(first, last, p); + res.value = !res.value; + return res; +} +template +constexpr boolean noneAdjacent(const C& c, BinaryPredicate p) { + return noneAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean allAdjacent(RandomIt first, RandomIt last, BinaryPredicate p) { + return noneAdjacent(first, last, std::not_fn(p)); +} +template +constexpr boolean allAdjacent(const C& c, BinaryPredicate p) { + return noneAdjacent(std::begin(c), std::end(c), p); +} + +template +constexpr boolean areIncreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::less()); +} +template +constexpr boolean areIncreasing(const C& c) { + return areIncreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areNonDecreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::less_equal()); +} +template +constexpr boolean areNonDecreasing(const C& c) { + return areNonDecreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areDecreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::greater()); +} +template +constexpr boolean areDecreasing(const C& c) { + return areDecreasing(std::begin(c), std::end(c)); +} + +template +constexpr boolean areNonIncreasing(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + return allAdjacent(first, last, std::greater_equal()); +} +template +constexpr boolean areNonIncreasing(const C& c) { + return areNonIncreasing(std::begin(c), std::end(c)); +} + +template +constexpr auto areDistinct(RandomIt first, RandomIt last) { + using T = typename std::iterator_traits::value_type; + std::vector tmp(first, last); + std::sort(tmp.begin(), tmp.end()); + auto [b, v] = anyAdjacent(tmp, std::equal_to()); + if (v) return boolean(!b, tmp[*v]); + return boolean(!b); +} +template +constexpr auto areDistinct(const C& c) { + return areDistinct(std::begin(c), std::end(c)); +} + + +// for strings (cctype functions are not safe to use with char...) +constexpr bool isLower(char c) { + return c >= 'a' and c <= 'z'; +} + +constexpr bool isUpper(char c) { + return c >= 'A' and c <= 'Z'; +} + +constexpr bool isLetter(char c) { + return isLower(c) or isUpper(c); +} + +constexpr bool isDigit(char c) { + return c >= '0' and c <= '9'; +} + +constexpr char toLower(char c) { + if (isUpper(c)) c += 'a' - 'A'; + return c; +} + +constexpr bool isVowel(char c) { + c = toLower(c); + for (char x : LOWER_VOWELS) { + if (c == x) return true; + } + return false; +} + +constexpr bool isConsonant(char c) { + return isLetter(c) and !isVowel(c); +} + +constexpr char toUpper(char c) { + if (isLower(c)) c -= 'a' - 'A'; + return c; +} + +constexpr char toDefaultCase(char c) { + if constexpr (DEFAULT_CASE_LOWER) return toLower(c); + return toUpper(c); +} + +void toLower(std::string& s) { + for (char& c : s) c = toLower(c); +} + +void toUpper(std::string& s) { + for (char& c : s) c = toUpper(c); +} + +void toDefaultCase(std::string& s) { + if constexpr (DEFAULT_CASE_LOWER) return toLower(s); + return toUpper(s); +} + +constexpr bool isLower(std::string_view s) { + for (char c : s) if (!isLower(c)) return false; + return true; +} + +constexpr boolean isUpper(std::string_view s) { + for (char c : s) if (!isUpper(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isLetter(std::string_view s) { + for (char c : s) if (!isLetter(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isDigit(std::string_view s) { + for (char c : s) if (!isDigit(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isVowel(std::string_view s) { + for (char c : s) if (!isVowel(c)) return boolean(false, c); + return boolean(true); +} + +constexpr boolean isConsonant(std::string_view s) { + for (char c : s) if (!isConsonant(c)) return boolean(false, c); + return boolean(true); +} + +std::vector thueMorse(Integer lower, Integer upper) { + judgeAssert(lower < upper, "thueMorse(): Lower must be less than upper!"); + std::vector res(upper - lower); + for (Integer i = lower; i < upper; i++) { + res[i] = std::bitset<64>(i).count() % 2; + } + return res; +} + +std::vector thueMorse(Integer upper) { + return thueMorse(0, upper); +} + +// allow using std::pair and std::complex similiar +// (may be useful for geometric problem) +template +constexpr auto& getX(T& point) { + return std::get<0>(point); +} +template +constexpr auto& getY(T& point) { + return std::get<1>(point); +} +template +constexpr auto& getZ(T& point) { + return std::get<2>(point); +} +template +constexpr auto getX(const T& point) { + return std::get<0>(point); +} +template +constexpr auto getY(const T& point) { + return std::get<1>(point); +} +template +constexpr auto getZ(const T& point) { + return std::get<2>(point); +} + +template +constexpr auto& getX(std::complex& point) { + return reinterpret_cast(point)[0]; +} +template +constexpr auto& getY(std::complex& point) { + return reinterpret_cast(point)[1]; +} +template +constexpr auto getX(const std::complex& point) { + return reinterpret_cast(point)[0]; +} +template +constexpr auto getY(const std::complex& point) { + return reinterpret_cast(point)[1]; +} + +template +constexpr std::pair convert(const std::complex& t) { + return {getX(t), getY(t)}; +} + +template +constexpr std::complex::type> +convert(const std::pair& t) { + return {getX(t), getY(t)}; +} + + +namespace details { + // Test two numbers for equality, accounting for +/-INF, NaN and precision. + // Real expected is considered the reference value for relative error. + bool floatEqual(Real given, Real expected, Real floatAbsTol, Real floatRelTol) { + judgeAssert(floatAbsTol >= 0.0_real, "floatEqual(): floatAbsTol must be positive!"); + judgeAssert(floatRelTol >= 0.0_real, "floatEqual(): floatRelTol must be positive!"); + // Finite values are compared with some tolerance + if (std::isfinite(given) and std::isfinite(expected)) { + Real absDiff = std::abs(given-expected); + Real relDiff = std::abs((given-expected)/expected); + return absDiff <= floatAbsTol or relDiff <= floatRelTol; + } + // NaN is equal to NaN (-NaN is also equal NaN) + if (std::isnan(given) and std::isnan(expected)) { + return true; + } + // Infinite values are equal if their sign matches + if (std::isinf(given) and std::isinf(expected)) { + return std::signbit(given) == std::signbit(expected); + } + // Values in different classes are always different. + return false; + } + + constexpr boolean stringEqual(std::string_view a, std::string_view b, bool caseSensitive) { + std::size_t i = 0; + for (; i < a.size() and i < b.size(); i++) { + char aa = a[i]; + char bb = b[i]; + if (!caseSensitive) { + aa = toDefaultCase(aa); + bb = toDefaultCase(bb); + } + if (aa != bb) { + return boolean(false, i); + } + } + if (a.size() != b.size()) { + return boolean(false, i); + } else { + return boolean(true); + } + } + + constexpr bool isToken(std::string_view a) { + for (char c : a) { + if (c == ' ') return false; + if (c == '\n') return false; + if (c == '\r') return false; + if (c == '\t') return false; + if (c == '\f') return false; + if (c == '\v') return false; + } + return true; + } + + template + bool parse(std::string_view s, T& res) { + const char* begin = s.data(); + const char* end = s.data() + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, res); + return ptr == end and ec == std::errc(); + } + #ifdef DOUBLE_FALLBACK + template<> + bool parse(std::string_view s, Real& res) { + try { + std::size_t pos = 0; + res = std::stold(std::string(s), &pos); + return pos == s.size(); + } catch(...) { + return false; + } + } + #endif + +} + + +//============================================================================// +// Math // +//============================================================================// +namespace details { + constexpr std::array TRIAL_PRIMES = { + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, + }; + constexpr std::array MILLER_RABIN_WITNESS = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; + + // these operations are safe as long as the value would fit in Integer + constexpr UInteger mulMod(UInteger lhs, UInteger rhs, UInteger mod) { + UInteger res = 0; + while (rhs > 0) { + if (rhs & 1) res = (lhs + res) % mod; + lhs = (lhs + lhs) % mod; + rhs /= 2; + } + return res; + } + + constexpr UInteger powMod(UInteger base, UInteger exp, UInteger mod) { + UInteger res = 1; + if (mod <= 0x1'0000'0000) { + while (exp > 0) { + if (exp & 1) res = (base * res) % mod; + base = (base * base) % mod; + exp /= 2; + } + } else { + while (exp > 0) { + if (exp & 1) res = mulMod(base, res, mod); + base = mulMod(base, base, mod); + exp /= 2; + } + } + return res; + } + + constexpr Integer extendedEuclid(Integer a, Integer b, Integer& x, Integer& y) { + if (a == 0) { + x = 0; + y = 1; + return b; + } else { + Integer x1 = 0; + Integer y1 = 0; + Integer d = extendedEuclid(b % a, a, x1, y1); + x = y1 - (b / a) * x1; + y = x1; + return d; + } + } +} + +constexpr Integer applyMod(Integer x, Integer mod) { + x %= mod; + if (x < 0) x += mod; + return x; +} + +constexpr Integer mulMod(Integer lhs, Integer rhs, Integer mod) { + judgeAssert(mod > 0, "mulMod(): mod must be positive!"); + UInteger ul = static_cast(applyMod(lhs, mod)); + UInteger ur = static_cast(applyMod(rhs, mod)); + UInteger um = static_cast(mod); + return static_cast(details::mulMod(ul, ur, um)); +} + +constexpr Integer powMod(Integer base, Integer exp, Integer mod) { + judgeAssert(mod > 0, "powMod(): mod must be positive!"); + judgeAssert(exp >= 0, "powMod(): exp must be non negative!"); + UInteger ub = static_cast(applyMod(base, mod)); + UInteger ue = static_cast(exp); + UInteger um = static_cast(mod); + return static_cast(details::powMod(ub, ue, um)); +} + +constexpr Integer multInv(Integer n, Integer mod) { + judgeAssert(mod > 0, "multInv(): mod must be positive!"); + Integer x = 0; + Integer y = 0; + Integer g = details::extendedEuclid(n, mod, x, y); + if (g != 1) return -1; + else return applyMod(x, mod); +} + +constexpr bool isPrime(Integer n) { + for (Integer p : details::TRIAL_PRIMES) { + if (n <= p or n % p == 0) { + return n == p; + } + } + if (details::powMod(details::TRIAL_PRIMES.back() + 1, n - 1, n) != 1) { + return false; + } + UInteger un = static_cast(n); + UInteger d = un - 1; + UInteger j = 0; + while (d % 2 == 0) { + d /= 2; + j++; + } + for (UInteger a : details::MILLER_RABIN_WITNESS) { + if (a % un == 0) continue; + UInteger v = details::powMod(a, d, un); + if (v == 1 or v == un - 1) continue; + for (UInteger i = 1; i < j; i++) { + v = details::mulMod(v, v, un); + if (v == un - 1 or v <= 1) break; + } + if (v != un - 1) return false; + } + return true; +} + +std::vector primes(Integer lower, Integer upper) { + judgeAssert(lower < upper, "primes(): Lower must be less than upper!"); + lower = std::max(2, lower); + upper = std::max(2, upper); + Integer count = upper - lower; + Integer cache = (count + 1) / 2; + + std::vector notPrime(cache), notPrimeSegment(cache); + for (Integer i = 3; i < count; i += 2) { + if (!notPrime[i / 2]) { + for (Integer j = i * i; j < count; j += 2 * i) { + notPrime[j / 2] = true; + } + Integer lowest = lower - (lower % (2*i)) + i; + if (lowest < lower) lowest += 2*i; + for (Integer j = std::max(i * i, lowest); j < upper; j += 2 * i) { + notPrimeSegment[(j - lower) / 2] = true; + } + } + } + std::vector res; + if (lower <= 2 and 2 < upper) res.emplace_back(2); + for (Integer i = lower | 1; i < upper; i += 2) { + if (!notPrimeSegment[(i - lower) / 2] and (i < count*count or isPrime(i))) { + res.emplace_back(i); + } + } + return res; +} + +std::vector primes(Integer upper) { + return primes(0, upper); +} + +template +constexpr Integer sign(T x) { + return (T(0) < x) - (x < T(0)); +} + + +//============================================================================// +// Geometry (this is just for utility stuff...) // +//============================================================================// +namespace details { + template + constexpr Integer cross(Point a, Point b) { + return getX(a) * getY(b) - getY(a) * getX(b); + } + template + constexpr Integer cross(Point p, Point a, Point b) { + getX(a) -= getX(p); + getY(a) -= getY(p); + getX(b) -= getX(p); + getY(b) -= getY(p); + return cross(a, b); + } + + template + constexpr bool left(Point p) { + return getX(p) == 0 ? getY(p) < 0 : getX(p) < 0; + } + + template + void cyclicSort(std::vector& in) { + std::sort(in.begin(), in.end(), [](const Point& a, const Point& b){ + return left(a) != left(b) ? left(a) > left(b) : cross(a, b) > 0; + }); + } +} + + +template +constexpr bool areConvex(RandomIt first, RandomIt last) { + std::size_t n = 0; + for (auto it = first; it != last; it++) { + n++; + judgeAssert(std::abs(getX(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!"); + judgeAssert(std::abs(getY(*it)) <= 0x3FFF'FFFF, "areConvex(): coordinates too large!"); + } + if (n < 3) return false; + bool hasArea = false; + for (std::size_t i = 0; i < n; i++) { + if (first[i] == first[(i+1) % n]) return false; + if (details::cross(first[0], first[i], first[(i+1) % n]) < 0) return false; + if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) < 0) return false; + hasArea |= details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) != 0; + } + return hasArea; +} +template +constexpr bool areConvex(const C& c) { + return areConvex(std::begin(c), std::end(c)); +} + +template +constexpr bool areStrictlyConvex(RandomIt first, RandomIt last) { + if (!areConvex(first, last)) return false; + std::size_t n = std::distance(first, last); + for (std::size_t i = 0; i < n; i++) { + if (details::cross(first[i], first[(i+1) % n], first[(i+2) % n]) == 0) return false; + } + return true; +} +template +constexpr bool areStrictlyConvex(const C& c) { + return areStrictlyConvex(std::begin(c), std::end(c)); +} + +//============================================================================// +// Random // +//============================================================================// +namespace Random { + // You should not rely on the implementation in details! + // Especially you should never use randomNumberGenerator on your own. There is no function in + // c++ which uses a random engine and is not implementation defined. + namespace details { + constexpr Real PI = 3.141592653589793238462643383279502884_real; + constexpr Integer PRIME_TRIALS = 4*1600; + + RandomEngine randomNumberGenerator(DEFAULT_SEED); + static_assert(RandomEngine::max() == 0xFFFF'FFFF'FFFF'FFFF_uint, "Random Engine should produce 64bit of randomness"); + static_assert(RandomEngine::min() == 0_uint, "Random Engine should produce 64bit of randomness"); + + constexpr UInteger bitMask(UInteger x) { + static_assert(sizeof(UInteger) == 8, "bitMask requires 8byte UInteger!"); + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + x |= x >> 32; + return x; + } + } + + void seed(UInteger seed) { + details::randomNumberGenerator.seed(seed); + } + + //========================================================================// + // Distributions and generators // + //========================================================================// + bool bit() {// in {0, 1} + return std::bitset<64>(details::randomNumberGenerator()).count() & 1; + } + + Integer integer() {// in [-2^63, 2^63) + return static_cast(details::randomNumberGenerator()); + } + Integer integer(Integer lower, Integer upper) {// in [lower, upper) + judgeAssert(lower < upper, "Random::integer(): Lower must be less than upper!"); + UInteger ul = static_cast(lower); + UInteger uu = static_cast(upper); + UInteger mask = details::bitMask(uu - ul - 1_uint); + UInteger res; + do { + res = details::randomNumberGenerator() & mask; + } while (res >= uu - ul); + return static_cast(res + ul); + } + Integer integer(Integer upper) {// in [0, upper) + return integer(0, upper); + } + + Real real() {// in [0, 1) + while (true) { + Real res = details::randomNumberGenerator() / 0x1.0p64_real; + res += details::randomNumberGenerator() / 0x1.0p128_real; + if (0.0_real <= res and res < 1.0_real) return res; + } + } + Real real(Real upper) {// in [0, upper) + judgeAssert(std::isfinite(upper), "Random::real(): Upper must be finite!"); + judgeAssert(upper > 0.0_real, "Random::real(): Upper must be greater than zero!"); + while (true) { + Real res = real() * upper; + if (0.0_real <= res and res < upper) return res; + } + } + Real real(Real lower, Real upper) {// in [lower, upper) + judgeAssert(std::isfinite(lower), "Random::real(): Lower must be finite!"); + judgeAssert(std::isfinite(upper), "Random::real(): Upper must be finite!"); + judgeAssert(lower < upper, "Random::real(): Lower must be less than upper!"); + while (true) { + Real x = real(); + Real res = lower * (1.0_real - x) + upper * x; + if (lower <= res and res < upper) return res; + } + } + + Real normal(Real mean, Real stddev) {// theoretically in (-inf, inf) + judgeAssert(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!"); + Real u1 = real(); + Real u2 = real(); + Real res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2); + return std::sqrt(stddev) * res + mean; + } + Real normal(Real lower, Real upper, Real mean, Real stddev) {// in [lower, upper) + judgeAssert(!std::isnan(lower), "Random::normal(): Lower must not be NaN!"); + judgeAssert(!std::isnan(upper), "Random::normal(): Upper must not be NaN!"); + judgeAssert(lower < upper, "Random::normal(): Lower must be less than upper!"); + judgeAssert(stddev >= 0.0_real, "Random::normal(): Standard deviation must be non negative!"); + Real res; + while (true) { + Real u1 = real(); + Real u2 = real(); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + res = std::sqrt(-2.0_real * std::log(u1)) * std::cos(2.0_real * details::PI * u2); + res = std::sqrt(stddev) * res + mean; + if (lower <= res and res < upper) return res; + res = std::sqrt(-2.0_real * std::log(u1)) * std::sin(2.0_real * details::PI * u2); + res = std::sqrt(stddev) * res + mean; + if (lower <= res and res < upper) return res; + } + } + + Real exponential(Real lambda) {// theoretically in [0, inf) + judgeAssert(lambda > 0.0_real, "Random::lambda(): lambda must be positive!"); + return -std::log(real()) / lambda; + } + Real exponential(Real lower, Real upper, Real lambda) {// in [lower, upper) + judgeAssert(std::isfinite(lower), "Random::exponential(): Lower must be finite!"); + judgeAssert(!std::isnan(upper), "Random::exponential(): Upper must not be NaN!"); + judgeAssert(lower < upper, "Random::exponential(): Lower must be less than upper!"); + judgeAssert(lambda > 0.0_real, "Random::exponential(): Lambda must be positive!"); + while (true) { + Real res = lower - std::log(real()) / lambda; + if (res < upper) return res; + } + } + + Integer geometric(Real p) {// theoretically in [0, inf) + judgeAssert(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!"); + return std::llround(std::floor(std::log(real()) / std::log1p(-p))); + } + Integer geometric(Integer lower, Integer upper, Real p) {// in [lower, upper) + judgeAssert(lower < upper, "Random::geometric(): Lower must be less than upper!"); + judgeAssert(0.0_real <= p and p < 1.0_real, "Random::geometric(): p must be in [0,1)!"); + while (true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric distribution[...]" + Integer res = lower + std::llround(std::floor(std::log(real()) / std::log1p(-p))); + if (res < upper) return res; + } + } + + Integer binomial(Integer n, Real p) {// in [0, n] + judgeAssert(n >= 0, "Random::binomial(): n must be non negative!"); + judgeAssert(0.0_real <= p and p <= 1.0_real, "Random::binomial(): p must be in [0,1)!"); + bool swap = p > 0.5_real; + p = std::min(p, 1.0_real - p); + if (p*n < 10.0_real) { + // BG: Geometric method + // https://dl.acm.org/doi/pdf/10.1145/42372.42381 + Integer res = 0; + Integer y = 0; + Real lg = std::log1p(-p); + if (lg >= 0) return swap ? n : 0; + do { + y += std::llround(std::floor(std::log(real()) / lg)) + 1; + if (y > n) return swap ? n - res : res; + res++; + } while (true); + } else { + // BTRS algorithm + // https://epub.wu.ac.at/1242/1/document.pdf + // note that the original paper has an error + // the break condition at the end has to be log(v) < h[...] + Real q = 1.0_real - p; + Real spq = std::sqrt(n * p * q); + Real b = 1.15_real + 2.53_real * spq; + Real a = -0.0873_real + 0.0248_real * b + 0.01_real * p; + Real c = n * p + 0.5_real; + Real vr = 0.92_real - 4.2_real / b; + + bool initialized = false; + Real alpha, lpq, m, h; + do { + Real u = real() - 0.5_real; + Real us = 0.5_real - std::abs(u); + Integer res = std::llround(std::floor((2.0_real * a / us + b) * u + c)); + if (res < 0 or res > n) continue; + + Real v = real(); + if (us >= 0.07_real and v <= vr) { + return swap ? n - res : res; + } + + if (!initialized) { + alpha = (2.83_real + 5.1_real / b) * spq; + lpq = std::log(p / q); + m = std::llround(std::floor((n + 1) * p)); + h = std::lgamma(m + 1) + std::lgamma(n - m + 1); + initialized = true; + } + v *= alpha / (a / (us * us) + b); + if (std::log(v) <= h - std::lgamma(res + 1) - std::lgamma(n - res + 1) + (res - m) * lpq) { + return swap ? n - res : res; + } + } while (true); + } + } + Integer binomial(Integer lower, Integer upper, Integer n, Real p) {// in [lower, upper) + judgeAssert(lower < upper, "Random::binomial(): n Lower must be less than upper!"); + while (true) { + Integer res = binomial(n, p); + if (lower <= res and res < upper) return res; + } + } + + Integer maximum(Integer lower, Integer upper, Integer n) {// in [lower, upper) + judgeAssert(n > 0, "Random::maximum(): n musst be positive!"); + judgeAssert(lower < upper, "Random::maximum(): Lower must be less than upper!"); + if (n < 5) { + Integer res = lower; + for (Integer i = 0; i < n; i++) res = std::max(res, integer(lower, upper)); + return res; + } else {// such large n seem unlikely + UInteger ul = static_cast(lower); + UInteger uu = static_cast(upper); + UInteger res = (uu - ul) * std::exp2(std::log2(real()) / n); + return std::min(upper - 1, static_cast(res + ul)); + } + } + Integer maximum(Integer upper, Integer n) { + return maximum(0, upper, n); + } + + Integer minimum(Integer lower, Integer upper, Integer n) {// in [lower, upper) + return upper - 1 - maximum(0, upper - lower, n); + } + Integer minimum(Integer upper, Integer n) { + return minimum(0, upper, n); + } + + Integer prime(Integer lower, Integer upper) {// in [lower, upper) + judgeAssert(lower < upper, "Random::prime(): Lower must be less than upper!"); + Integer sampleL = lower <= 2 ? 0 : (lower / 2); + Integer sampleU = upper / 2; + if (sampleL < sampleU) { + for (Integer i = 0; i < details::PRIME_TRIALS and i < 4 * (upper - lower); i++) { + Integer res = std::max(2, 2*integer(sampleL, sampleU) | 1); + if (isPrime(res)) return res; + } + } + judgeAssert(false, "Random::prime(): range contains no primes?"); + return -1; + } + Integer prime(Integer upper) {// in [0, upper) + return prime(0, upper); + } + + + //========================================================================// + // utility // + //========================================================================// + template + typename std::iterator_traits::reference + select(RandomIt first, RandomIt last) { + judgeAssert(first < last, "Random::select(): Lower must be less than upper!"); + return first[integer(0, last - first)]; + } + + template + typename ::details::IsContainer::value_type select(const C& c) { + return select(std::begin(c), std::end(c)); + } + + template + typename C::reference select(C& c) { + return select(std::begin(c), std::end(c)); + } + + template + T select(const T(&c)[N]) { + return select(std::begin(c), std::end(c)); + } + + template + T& select(T(&c)[N]) { + return select(std::begin(c), std::end(c)); + } + + template + T select(const std::pair& t) { + return bit() ? getX(t) : getY(t); + } + + template + T select(const std::complex& t) { + return bit() ? getX(t) : getY(t); + } + + template + void shuffle(RandomIt first, RandomIt last) { + using std::swap; + auto n = last - first; + for (auto i = n-1; i > 0; i--) { + swap(first[i], first[integer(0, i+1)]); + } + } + + template + void shuffle(C& c) { + return shuffle(std::begin(c), std::end(c)); + } + + template + void shuffle(std::pair& t) { + using std::swap; + if (bit()) swap(getX(t), getY(t)); + } + + template + void shuffle(std::complex& t) { + using std::swap; + if (bit()) swap(getX(t), getY(t)); + } + + template + Integer rotate(RandomIt first, RandomIt last) { + Integer rotation = integer(0, last - first); + std::rotate(first, first + rotation, last); + return rotation; + } + + template + Integer rotate(C& c) { + return rotate(std::begin(c), std::end(c)); + } + + //========================================================================// + // sequences // + //========================================================================// + std::vector distinct(Integer count, Integer lower, Integer upper) { + judgeAssert(count >= 0, "Random::distinct(): Count must be non negative!"); + judgeAssert(lower + count <= upper, "Random::distinct(): Lower must be less than upper + count!"); + std::map used; + std::vector res; + for (Integer i = 0; i < count; i++) { + Integer x = integer(lower, upper - i); + auto it = used.find(x); + if (it != used.end()) res.emplace_back(it->second); + else res.emplace_back(x); + it = used.find(upper - i - 1); + if (it != used.end()) used[x] = it->second; + else used[x] = upper - i - 1; + } + return res; + } + std::vector distinct(Integer count, Integer upper) { + return distinct(count, 0, upper); + } + + std::vector perm(Integer count, Integer offset = 0) { + return distinct(count, offset, offset+count); + } + + std::vector perm(const std::vector& cycles, Integer offset = 0) { + auto p = perm(std::accumulate(cycles.begin(), cycles.end(), 0_int)); + std::vector res(p.size()); + Integer tmp = 0; + for (std::size_t i = 0; i < cycles.size(); tmp += cycles[i], i++) { + judgeAssert(cycles[i] > 0, "Random::perm(): Cycle lengths must be positive!"); + for (Integer j = tmp; j + 1 < tmp + cycles[i]; j++) { + res[p[j]] = p[j + 1] + offset; + } + res[p[tmp + cycles[i] - 1]] = p[tmp] + offset; + } + return res; + } + + std::vector perm(std::initializer_list cycles, Integer offset = 0) { + return perm(std::vector(cycles), offset); + } + + std::vector multiple(Integer count, Integer lower, Integer upper) { + std::vector res(count); + for (Integer& x : res) x = integer(lower, upper); + return res; + } + std::vector multiple(Integer count, Integer upper) { + return multiple(count, 0, upper); + } + + std::vector increasing(Integer count, Integer lower, Integer upper) { + std::vector res = distinct(count, lower, upper); + std::sort(res.begin(), res.end(), std::less()); + return res; + } + std::vector increasing(Integer count, Integer upper) { + return increasing(count, 0, upper); + } + + std::vector decreasing(Integer count, Integer lower, Integer upper) { + std::vector res = distinct(count, lower, upper); + std::sort(res.begin(), res.end(), std::greater()); + return res; + } + std::vector decreasing(Integer count, Integer upper) { + return decreasing(count, 0, upper); + } + + std::vector nonDecreasing(Integer count, Integer lower, Integer upper) { + std::vector res = multiple(count, lower, upper); + std::sort(res.begin(), res.end(), std::less()); + return res; + } + std::vector nonDecreasing(Integer count, Integer upper) { + return nonDecreasing(count, 0, upper); + } + + std::vector nonIncreasing(Integer count, Integer lower, Integer upper) { + std::vector res = multiple(count, lower, upper); + std::sort(res.begin(), res.end(), std::greater()); + return res; + } + std::vector nonIncreasing(Integer count, Integer upper) { + return nonIncreasing(count, 0, upper); + } + + std::vector partition(Integer n, Integer k, Integer min = 1) { + judgeAssert(n > 0, "Random::partition(): n must be positive!"); + judgeAssert(k > 0, "Random::partition(): k must be positive!"); + judgeAssert(min <= 0 or k <= n / min, "Random::partition(): k too large!"); + n -= (min - 1) * k; + std::vector res = increasing(k-1, 1, n); + res.emplace_back(n); + for (Integer i = 0, last = 0; i < k; i++) { + res[i] -= last; + last += res[i]; + res[i] += min - 1; + } + return res; + } + + std::string bracketSequence(Integer n, char open = '(', char close = ')') {//proper bracket sequence of length 2*n + judgeAssert(0 <= n and n <= 0x7FFF'FFFF, "Random::bracketSequence(): n out of range!"); + std::string res(2 * n, open); + for (Integer i = 0, diff = 0; i < 2 * n; i++) { + Integer opened = (i + diff) / 2; + if (integer((2 * n - i) * (diff + 1)) < (n - opened) * (diff + 2)) { + diff++; + } else { + res[i] = close; + diff--; + } + } + return res; + } + + //========================================================================// + // geometry // + //========================================================================// + template> + std::vector convex(Integer n, Integer dim) { + judgeAssert(dim <= 0x3FFF'FFFF, "Random::convex(): dim too large!"); + judgeAssert(dim > 0, "Random::convex(): dim must be positive!"); + judgeAssert(n <= 8*dim - 8, "Random::convex(): dim too small!"); + judgeAssert(n >= 3, "Random::convex(): n too small!"); + + while (true) { + Integer left = 1 + binomial(n - 2, 0.5); + Integer down = 1 + binomial(n - 2, 0.5); + auto x = partition(2 * dim - 2, left, 0); + auto y = partition(2 * dim - 2, down, 0); + for (auto& z : x) z = -z; + for (auto& z : y) z = -z; + append(x, partition(2 * dim - 2, n - left, 0)); + append(y, partition(2 * dim - 2, n - down, 0)); + auto itX = std::partition(x.begin(), x.end(), [](Integer z){return z == 0;}); + auto itY = std::partition(y.begin(), y.end(), [](Integer z){return z != 0;}); + if (std::distance(x.begin(), itX) + std::distance(itY, y.end()) > n) continue; + shuffle(itX, x.end()); + if (itX != x.begin()) shuffle(y.begin(), itY); + + std::vector dirs(n); + for (Integer i = 0; i < n; i++) { + dirs[i] = {x[i], y[i]}; + } + ::details::cyclicSort(dirs); + + std::vector res = {{0, 0}}; + Integer maxX = 0; + Integer maxY = 0; + for (auto dir : dirs) { + Point tmp = res.back(); + getX(tmp) += getX(dir); + getY(tmp) += getY(dir); + maxX = std::max(maxX, getX(tmp)); + maxY = std::max(maxY, getY(tmp)); + res.emplace_back(tmp); + } + res.pop_back(); + for (auto& point : res) { + getX(point) += dim - 1 - maxX; + getY(point) += dim - 1 - maxY; + } + return res; + } + } + + template> + std::vector nonCollinearPoints(Integer n, Integer dim) { + judgeAssert(dim <= 0x1FFF'FFFF, "Random::nonCollinearPoints(): dim too large!"); + judgeAssert(n >= 0, "Random::nonCollinearPoints(): dim must be non negative!"); + judgeAssert(dim > n, "Random::nonCollinearPoints(): dim too small!"); + Integer p = prime(dim - 1, 2*dim + 2); + Integer rotA = 0; + Integer rotB = 0; + while (rotA == 0 && rotB == 0) { + rotA = integer(0, p); + rotB = integer(0, p); + } + std::array abc = { + integer(1, p), + integer(0, p), + integer(0, p), + }; + Integer dx = integer(-dim + 1, dim - p); + Integer dy = integer(-dim + 1, dim - p); + + auto xs = distinct(n, p); + std::vector res; + for (auto tmpX : xs) { + Integer tmpY = 0; + for (Integer add : abc[0]) { + tmpY *= tmpX; + tmpY += add; + tmpY %= p; + } + + Integer x = applyMod(tmpX * rotA - tmpY * rotB, p); + Integer y = applyMod(tmpX * rotB + tmpY * rotA, p); + + res.emplace_back(x + dx, y + dy); + } + return res; + } + +} // namespace Random + + +//============================================================================// +// args parser // +//============================================================================// +class ParamaterBase { + friend class Command; + friend struct Paramater; + + std::optional token; + + template + T parse(std::string_view s) const { + T res = {}; + judgeAssert(details::parse(s, res), "Command: Could not parse args"); + return res; + } + + ParamaterBase() = default; + explicit ParamaterBase(std::string_view token_) : token(token_) {} + +public: + std::string asString() const { + return std::string(token.value()); + } + + std::string asString(std::string_view defaultValue) const { + return std::string(token.value_or(defaultValue)); + } + + Integer asInteger() const { + return parse(token.value()); + } + + Integer asInteger(Integer defaultValue) const { + return token ? asInteger() : defaultValue; + } + + Real asReal() const { + return parse(token.value()); + } + + Real asReal(Real defaultValue) const { + return token ? asReal() : defaultValue; + } +}; + +struct Paramater final : private ParamaterBase { + using ParamaterBase::ParamaterBase; + using ParamaterBase::asString; + using ParamaterBase::asInteger; + using ParamaterBase::asReal; + + bool exists() const { + return token.has_value(); + } + + explicit operator bool() const { + return exists(); + } +}; + +class Command final : private ParamaterBase { + const std::vector& raw; + const Integer first, count; + const bool found; +public: + explicit Command(const std::vector& raw_) : raw(raw_), first(0), count(0), found(false) {} + explicit Command(const std::vector& raw_, Integer first_, Integer count_) + : ParamaterBase(count_ == 0 ? ParamaterBase() : ParamaterBase(raw_[first_])), + raw(raw_), first(first_), count(count_), found(true) { + judgeAssert(count >= 0, "Command: Invalid command in args!"); + } + + bool exists() const { + return found; + } + + explicit operator bool() const { + return exists(); + } + + Integer parameterCount() const { + return count; + } + + Paramater operator[](Integer i) const { + if (i >= 0 and i < count) return Paramater(raw[first + i]); + return Paramater(); + } + + using ParamaterBase::asString; + using ParamaterBase::asInteger; + using ParamaterBase::asReal; + + std::vector asStrings() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [](const std::string& value) { + return std::string(value); + }); + return res; + } + + std::vector asIntegers() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [this](const std::string& value) { + return parse(value); + }); + return res; + } + + std::vector asReals() const { + std::vector res; + std::transform(raw.begin() + first, + raw.begin() + first + count, + std::back_inserter(res), [this](const std::string& value) { + return parse(value); + }); + return res; + } + +}; + +class CommandParser final { + std::vector raw; + std::map> commands; + std::map tokens; + + static bool isCommand(std::string_view s) { + return s.size() > 2 and s.substr(0, 2) == COMMAND_PREFIX; + } + void addCommand(std::string_view command, Integer first, Integer count = 0) { + judgeAssert(commands.count(command) == 0, "Command: Duplcated command in args!"); + commands.emplace(command, std::pair{first, count}); + } + +public: + CommandParser() = default; + explicit CommandParser(int argc, char** argv) { + raw.assign(argc, {}); + std::string_view command = EMPTY_COMMAND; + Integer first = 0; + Integer count = 0; + for (int i = 0; i < argc; i++) { + raw[i] = std::string(argv[i]); + tokens.emplace(raw[i], i+1); + if (isCommand(raw[i])) { + addCommand(command, first, count); + command = raw[i]; + first = i+1; + count = 0; + } else { + count++; + } + } + addCommand(command, first, count); + } + CommandParser(CommandParser&&) = default; + CommandParser& operator=(CommandParser&&) = default; + + CommandParser(const CommandParser&) = delete; + CommandParser& operator=(const CommandParser&) = delete; + + std::string_view operator[](Integer t) const { + judgeAssert(t >= 0 and t < static_cast(raw.size()), "Command: Index out of args!"); + return raw[t]; + } + Command operator[](std::string_view command) const & { + judgeAssert(details::isToken(command), "Command: must not contain a space!"); + auto it = commands.find(command); + if (it == commands.end()) return Command(raw); + return Command(raw, it->second.first, it->second.second); + } + Command getRaw(std::string_view command) const & { + judgeAssert(details::isToken(command), "Command: must not contain a space!"); + auto it = tokens.find(command); + if (it == tokens.end()) return Command(raw); + return Command(raw, it->second, raw.size() - it->second); + } + Command getRaw() const & { + return Command(raw, 0, raw.size()); + } +}; + + +//============================================================================// +// Constraints // +//============================================================================// +template +class Bounds final { + bool hadMin, hadMax; // was value==lower/upper at some point + T min, max; // range of seen values + T lower, upper; // bounds for value +public: + constexpr explicit Bounds(T lower_, T upper_, T value_) : + hadMin(false), hadMax(false), + min(value_), max(value_), + lower(lower_), upper(upper_) { + update(lower_, upper_, value_); + } + + void update(T lower_, T upper_, T value_) { + if constexpr (std::is_same_v) { + hadMin |= details::floatEqual(value_, lower_, DEFAULT_EPS, DEFAULT_EPS); + hadMax |= details::floatEqual(value_, upper_, DEFAULT_EPS, DEFAULT_EPS); + } else { + hadMin |= value_ == lower_; + hadMax |= value_ == upper_; + } + min = std::min(min, value_); + max = std::max(max, value_); + lower = std::min(lower, lower_); + upper = std::max(upper, upper_); + } + + friend std::ostream& operator<<(std::ostream& os, const Bounds& bounds) { + os << bounds.hadMin << " " << bounds.hadMax << " "; + os << bounds.min << " " << bounds.max << " "; + return os << bounds.lower << " " << bounds.upper; + } + +}; + +namespace details { + //using typeIndex = std::type_index; + using typeIndex = void*; + + template + typeIndex getTypeIndex() { + //return std::type_index(type id(T)); + static T* uniqueTypeIndex = nullptr; + return &uniqueTypeIndex; + } +} + +class Constraint final { + friend class ConstraintsLogger; + std::variant< + std::monostate, // uninitialized + Bounds, // Integer or container bound + Bounds // Real bound + > bound; + std::optional type; + + template + void update(T lower, T upper, T value) { + if constexpr(std::is_integral_v) { + upper--; // for BAPCtools the range is closed but we use half open ranges! + } + if (!type) { + type = details::getTypeIndex(); + bound = Bounds(lower, upper, value); + } + judgeAssert(type == details::getTypeIndex(), "Constraint: type must not change!"); + std::get>(bound).update(lower, upper, value); + } +public: + Constraint() = default; + Constraint(Constraint&&) = default; + Constraint& operator=(Constraint&&) = default; + + Constraint(const Constraint&) = delete; + Constraint& operator=(const Constraint&) = delete; + + template, bool> = true> + void log(Integer lower, Integer upper, V value) { + update(lower, upper, value); + } + + template, bool> = true> + void log(Real lower, Real upper, V value) { + update(lower, upper, value); + } + + template, bool> = true> + void log(Integer lower, Integer upper, const C& container) { + update(lower, upper, static_cast(std::size(container))); + } +}; + +class ConstraintsLogger final { + std::optional fileName; + std::map byName; + std::vector> constraints; +public: + ConstraintsLogger() = default; + explicit ConstraintsLogger(std::string_view fileName_) : fileName(fileName_) {} + + ConstraintsLogger(ConstraintsLogger&&) = default; + ConstraintsLogger& operator=(ConstraintsLogger&&) = default; + + ConstraintsLogger(const ConstraintsLogger&) = delete; + ConstraintsLogger& operator=(const ConstraintsLogger&) = delete; + + Constraint& operator[](const std::string& name) & { + judgeAssert(details::isToken(name), "Constraint: name must not contain a space!"); + auto res = byName.try_emplace(name, constraints.size()); + if (res.second) constraints.emplace_back(std::make_unique()); + return *(constraints[res.first->second]); + } + + void write() const { + if (!fileName) return; + std::ofstream os(*fileName); + os << std::noboolalpha; + os << std::fixed; + os << std::setprecision(DEFAULT_PRECISION); + for (const auto& [name, id] : byName) { + const Constraint& c = *(constraints[id]); + if (c.type) { + os << "LocationNotSupported:" << name << " " << name << " "; + if (c.bound.index() == 1) os << std::get<1>(c.bound); + if (c.bound.index() == 2) os << std::get<2>(c.bound); + os << std::endl; + } + } + } + + ~ConstraintsLogger() noexcept { + write(); + } +}; + +//============================================================================// +// custom input stream // +//============================================================================// +class InputStream final { + std::unique_ptr managed; + std::istream* in; + bool spaceSensitive, caseSensitive; + Verdict onFail; + Real floatAbsTol; + Real floatRelTol; + + void init() { + if (spaceSensitive) *in >> std::noskipws; + else *in >> std::skipws; + } + + void checkIn() { + judgeAssert(in != nullptr, "InputStream: not initialized!"); + } + +public: + InputStream() = default; + explicit InputStream(const std::filesystem::path& path, + bool spaceSensitive_, + bool caseSensitive_, + Verdict onFail_, + Real floatAbsTol_ = DEFAULT_EPS, + Real floatRelTol_ = DEFAULT_EPS) : + managed(std::make_unique(path)), + in(managed.get()), + spaceSensitive(spaceSensitive_), + caseSensitive(caseSensitive_), + onFail(onFail_), + floatAbsTol(floatAbsTol_), + floatRelTol(floatRelTol_) { + judgeAssert(managed->good(), "InputStream: Could not open File: " + path.string()); + init(); + } + explicit InputStream(std::istream& in_, + bool spaceSensitive_, + bool caseSensitive_, + Verdict onFail_, + Real floatAbsTol_ = DEFAULT_EPS, + Real floatRelTol_ = DEFAULT_EPS) : + managed(), + in(&in_), + spaceSensitive(spaceSensitive_), + caseSensitive(caseSensitive_), + onFail(onFail_), + floatAbsTol(floatAbsTol_), + floatRelTol(floatRelTol_) { + init(); + } + + InputStream(InputStream&& other) = default; + InputStream& operator=(InputStream&& other) = default; + + InputStream(const InputStream&) = delete; + InputStream& operator=(const InputStream&) = delete; + + void eof() { + checkIn(); + if (!spaceSensitive) *in >> std::ws; + if (in->peek() != std::char_traits::eof()) { + in->get(); + ValidateBase::juryOut << "Missing EOF!"; + fail(); + } + } + + void noteof() { + checkIn(); + if (!spaceSensitive) *in >> std::ws; + if (in->peek() == std::char_traits::eof()) { + ValidateBase::juryOut << "Unexpected EOF!" << onFail; + } + } + + void space() { + if (spaceSensitive) { + noteof(); + if (in->get() != std::char_traits::to_int_type(SPACE)) { + ValidateBase::juryOut << "Missing space!"; + fail(); + } + } + } + + void newline() { + if (spaceSensitive) { + noteof(); + if (in->get() != std::char_traits::to_int_type(NEWLINE)) { + ValidateBase::juryOut << "Missing newline!"; + fail(); + } + } + } + +private: + void check(const std::string& token, const std::regex& pattern) { + if (!std::regex_match(token, pattern)) { + ValidateBase::juryOut << "Token \"" << token << "\" does not match pattern!"; + fail(); + } + } + + std::function checkSeparator(char separator) { + if (separator == SPACE) return [this](){space();}; + if (separator == NEWLINE) return [this](){newline();}; + judgeAssert(false, "InputStream: Separator must be ' ' or '\\n'!"); + return {}; + } + + template + T parse(const std::string& s) { + T res = {}; + if (!details::parse(s, res)) { + ValidateBase::juryOut << "Could not parse token \"" << s << "\"!"; + fail(); + } + return res; + } + +public: + std::string string() { + noteof(); + if (spaceSensitive and !std::isgraph(in->peek())) { + in->get(); + ValidateBase::juryOut << "Invalid whitespace!"; + fail(); + } + std::string res; + *in >> res; + if (res.empty()) { + ValidateBase::juryOut << "Unexpected EOF!" << onFail; + } + if (!caseSensitive) toDefaultCase(res); + return res; + } + + std::string string(Integer lower, Integer upper) { + std::string t = string(); + Integer length = static_cast(t.size()); + if (length < lower or length >= upper) { + ValidateBase::juryOut << "String length " << length << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return t; + } + + std::string string(Integer lower, Integer upper, Constraint& constraint) { + std::string res = string(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + std::string string(const std::regex& pattern) { + std::string t = string(); + check(t, pattern); + return t; + } + + std::string string(const std::regex& pattern, Integer lower, Integer upper) { + std::string t = string(lower, upper); + check(t, pattern); + return t; + } + + std::string string(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint) { + std::string res = string(pattern, lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector strings(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = string(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector strings(Integer count, char separator = DEFAULT_SEPARATOR) { + return strings<>(count, separator); + } + + std::vector strings(Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(lower, upper, count, separator); + } + + std::vector strings(Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(lower, upper, constraint, count, separator); + } + + std::vector strings(const std::regex& pattern, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, count, separator); + } + + std::vector strings(const std::regex& pattern, Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, lower, upper, count, separator); + } + + std::vector strings(const std::regex& pattern, Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return strings(pattern, lower, upper, constraint, count, separator); + } + + Integer integer() { + return parse(string(INTEGER_REGEX)); + } + + Integer integer(Integer lower, Integer upper) { + Integer res = integer(); + if (res < lower or res >= upper) { + ValidateBase::juryOut << "Integer " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } + + Integer integer(Integer lower, Integer upper, Constraint& constraint) { + Integer res = integer(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector integers(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = integer(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector integers(Integer count, char separator = DEFAULT_SEPARATOR) { + return integers<>(count, separator); + } + + std::vector integers(Integer lower, Integer upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return integers(lower, upper, count, separator); + } + + std::vector integers(Integer lower, Integer upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return integers(lower, upper, constraint, count, separator); + } + + // this does not allow NaN or Inf! + // However, those should never be desired. + Real real() { + return parse(string(REAL_REGEX)); + } + + Real real(Real lower, Real upper) {// uses eps + Real res = real(); + if (details::floatEqual(res, lower, floatAbsTol, floatRelTol)) return res; + if (details::floatEqual(res, upper, floatAbsTol, floatRelTol)) return res; + if (std::isnan(res) or !(res >= lower) or !(res < upper)) { + ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } + + Real real(Real lower, Real upper, Constraint& constraint) { + Real res = real(lower, upper); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector reals(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = real(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector reals(Integer count, char separator = DEFAULT_SEPARATOR) { + return reals<>(count, separator); + } + + std::vector reals(Real lower, Real upper, + Integer count, char separator = DEFAULT_SEPARATOR) { + return reals(lower, upper, count, separator); + } + + std::vector reals(Real lower, Real upper, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return reals(lower, upper, constraint, count, separator); + } + + Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals) {// does not use eps + std::string t = string(STRICT_REAL_REGEX); + auto dot = t.find('.'); + Integer decimals = dot == std::string::npos ? 0 : t.size() - dot - 1; + if (decimals < minDecimals or decimals >= maxDecimals) { + ValidateBase::juryOut << "Real " << t << " has wrong amount of decimals!"; + fail(); + return 0; + } + try { + Real res = parse(t); + if (std::isnan(res) or !(res >= lower) or !(res < upper)) { + ValidateBase::juryOut << "Real " << res << " out of range [" << lower << ", " << upper << ")!"; + fail(); + } + return res; + } catch(...) { + ValidateBase::juryOut << "Could not parse token \"" << t << "\" as real!"; + fail(); + return 0; + } + } + + Real realStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint) { + Real res = realStrict(lower, upper, minDecimals, maxDecimals); + constraint.log(lower, upper, res); + return res; + } + + template + std::vector realsStrict(Args... args, Integer count, char separator) { + auto sepCall = checkSeparator(separator); + std::vector res(count); + for (Integer i = 0; i < count; i++) { + res[i] = realStrict(args...); + if (i + 1 < count) sepCall(); + } + return res; + } + + std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, + Integer count, char separator = DEFAULT_SEPARATOR) { + return realsStrict(lower, upper, minDecimals, maxDecimals, count, separator); + } + + std::vector realsStrict(Real lower, Real upper, Integer minDecimals, Integer maxDecimals, Constraint& constraint, + Integer count, char separator = DEFAULT_SEPARATOR) { + return realsStrict(lower, upper, minDecimals, maxDecimals, constraint, count, separator); + } + + void expectString(std::string_view expected) { + judgeAssert(details::isToken(expected), "InputStream: expected must not contain a space!"); + std::string seen = string(); + auto [eq, pos] = details::stringEqual(seen, expected, caseSensitive); + if (!eq) { + if (seen.size() > 80) { + seen = seen.substr(0, 75) + "[...]"; + } + ValidateBase::juryOut << "Expected \"" << expected << "\" but got \"" << seen << "\"!"; + if (pos and *pos > 5) { + ValidateBase::juryOut << " (different at position: " << *pos+1 << ")"; + } + fail(); + } + } + + void expectInt(Integer expected) { + Integer seen = integer(); + if (seen != expected) { + ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!"; + fail(); + } + } + + void expectReal(Real expected) { + Real seen = real(); + if (details::floatEqual(seen, expected, floatAbsTol, floatRelTol)) { + ValidateBase::juryOut << "Expected " << expected << " but got " << seen << "!"; + if (std::isfinite(seen) and std::isfinite(expected)) { + Real absDiff = std::abs(seen-expected); + Real relDiff = std::abs((seen-expected)/expected); + ValidateBase::juryOut << " (abs: " << absDiff << ", rel: " << relDiff << ")"; + } + fail(); + } + } +private: + void fail() { + //try to find input position... + in->clear(); + auto originalPos = in->tellg(); + in->seekg(0); + if (originalPos != std::streamoff(-1) and *in) { + Integer line = 1; + std::size_t l = 0, r = 0; + std::string buffer; + bool extend = true; + while (*in and in->tellg() < originalPos) { + l = r = buffer.size(); + if (std::isgraph(in->peek())) { + std::string tmp; + *in >> tmp; + buffer += tmp; + } else if (in->peek() == std::char_traits::to_int_type(NEWLINE)) { + line++; + in->get(); + if (in->tellg() < originalPos) { + buffer.clear(); + } else { + buffer += ' '; + extend = false; + } + } else { + buffer += std::char_traits::to_char_type(in->get()); + } + if (*in and in->tellg() >= originalPos) { + r = buffer.size(); + } + } + if (l != r) { + ValidateBase::juryOut << " Line: " << line << ", Char: " << l << '\n'; + if (extend) { + char tmp; + while ((buffer.size() < 80 or buffer.size() < r + 80) and in->get(tmp) and tmp != NEWLINE) { + buffer += tmp; + } + } + if (r > 60 and l > 20) { + Integer offset = std::min(l - 20, r - 60); + l -= offset; + r -= offset; + buffer = "[...]" + buffer.substr(offset + 5); + } + if (buffer.size() > 80) { + buffer = buffer.substr(0, 75); + buffer += "[...]"; + r = std::min(r, buffer.size()); + } + ValidateBase::juryOut << buffer << '\n'; + ValidateBase::juryOut << std::string(l, ' ') << '^' << std::string(r - l - 1, '~'); + } + } + ValidateBase::juryOut << onFail; + } +}; + + +//============================================================================// +// state guard // +//============================================================================// +namespace details { + bool initialized(bool set = false) { + static bool value = false; + return std::exchange(value, value |= set); + } + + struct InitGuard final { + ~InitGuard() { + if (std::uncaught_exceptions() == 0) { + judgeAssert(initialized(), "validate.h: init(argc, argv) was never called!"); + } + } + } initGuard; +} + + +//============================================================================// +// Settings // +//============================================================================// +template +class SettingBase { + template + friend class Setting; + friend class SettingCaseSensitive; + + T value; + + SettingBase(T value_) : value(value_) {} + +public: + SettingBase(SettingBase&& other) = delete; + SettingBase(const SettingBase&) = delete; + SettingBase& operator=(SettingBase&& other) = delete; + SettingBase& operator=(const SettingBase&) = delete; + + operator T() const { + return value; + } + + SettingBase& operator=(T value_) { + judgeAssert(!details::initialized(), "validate.h: Cannot change setting after init(argc, argv) was called!"); + value = value_; + return *this; + } +}; + +template +class Setting final : public SettingBase { +public: + Setting(T value) : SettingBase(value) {} + using SettingBase::operator T; + using SettingBase::operator=; +}; + +class SettingCaseSensitive final : public SettingBase { +public: + SettingCaseSensitive(bool value) : SettingBase(value) {} + using SettingBase::operator bool; + using SettingBase::operator=; + + std::regex regex(std::string_view s, std::regex_constants::syntax_option_type f = std::regex_constants::ECMAScript) const { + if (!value) f |= std::regex_constants::icase; + return std::regex(s.data(), s.size(), f); + } +}; + + +//============================================================================// +// Validators and stuff // +//============================================================================// +namespace ValidateBase { + //OutputStream juryOut(std::cout); //already defined earlier + //OutputStream juryErr(std::cerr); + CommandParser arguments; + //you may change these values before calling::init() but not afterwards! + Setting floatAbsTol(DEFAULT_EPS); + Setting floatRelTol(DEFAULT_EPS); + Setting spaceSensitive(false); + SettingCaseSensitive caseSensitive(false); + + // Real r2 is considered the reference value for relative error. + bool floatEqual(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return details::floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + bool floatLess(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return given <= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + bool floatGreater(Real given, + Real expected, + Real floatAbsTol_ = floatAbsTol, + Real floatRelTol_ = floatRelTol) { + return given >= expected or floatEqual(given, expected, floatAbsTol_, floatRelTol_); + } + + constexpr boolean stringEqual(std::string_view a, std::string_view b, bool caseSensitive_ = caseSensitive) { + return details::stringEqual(a, b, caseSensitive_); + } + + namespace details { + void init(int argc, char** argv) { + judgeAssert(!::details::initialized(), "validate.h: init(argc, argv) was called twice!"); + + //std::ios_base::sync_with_stdio(false); + //cin.tie(nullptr); + + arguments = CommandParser(argc, argv); + if (auto seed = arguments[SEED_COMMAND]) Random::seed(seed.asInteger()); + // parse default flags manually, since they dont use '--' prefix + auto eps = arguments.getRaw(FLOAT_TOLERANCE); + floatAbsTol = eps.asReal(floatAbsTol); + floatRelTol = eps.asReal(floatRelTol); + floatAbsTol = arguments.getRaw(FLOAT_ABSOLUTE_TOLERANCE).asReal(floatAbsTol); + floatRelTol = arguments.getRaw(FLOAT_RELATIVE_TOLERANCE).asReal(floatRelTol); + + if (arguments.getRaw(SPACE_SENSITIVE)) spaceSensitive = true; + if (arguments.getRaw(CASE_SENSITIVE)) caseSensitive = true; + + ::details::initialized(true); + } + } + +} // namespace ValidateBase + +namespace ConstraintsBase { + ConstraintsLogger constraint; + + void initConstraints() { + if (auto file = ValidateBase::arguments[CONSTRAINT_COMMAND]) { + constraint = ConstraintsLogger(file.asString()); + } + } + +} // namespace ConstraintsBase + +//called as ./validator [arguments] < inputfile +namespace InputValidator { + using namespace ValidateBase; + using namespace ConstraintsBase; + + InputStream testIn; + + void init(int argc, char** argv) { + spaceSensitive = true; + caseSensitive = true; + + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::cout); + + testIn = InputStream(std::cin, spaceSensitive, caseSensitive, WA, floatAbsTol, floatRelTol); + initConstraints(); + } + +} // namespace InputValidator + +//called as ./validator input judgeanswer feedbackdir < teamoutput +namespace OutputValidator { + using namespace ValidateBase; + using namespace ConstraintsBase; + + InputStream testIn; + InputStream juryAns; + InputStream teamAns; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE); + + testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL); + juryAns = InputStream(std::filesystem::path(arguments[2]), false, caseSensitive, FAIL); + teamAns = InputStream(std::cin, spaceSensitive, caseSensitive, WA); + initConstraints(); + } + +} // namespace OutputValidator + +//called as ./interactor input judgeanswer feedbackdir <> teamoutput +namespace Interactor { + using namespace ValidateBase; + + OutputStream toTeam; + InputStream testIn; + InputStream fromTeam; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::filesystem::path(arguments[3]) / JUDGE_MESSAGE); + toTeam = OutputStream(std::cout); + + testIn = InputStream(std::filesystem::path(arguments[1]), false, caseSensitive, FAIL); + fromTeam = InputStream(std::cin, spaceSensitive, caseSensitive, WA); + } + +} // namespace Interactor + +//called as ./generator [arguments] +namespace Generator { + using namespace ValidateBase; + + OutputStream testOut; + + void init(int argc, char** argv) { + ValidateBase::details::init(argc, argv); + juryOut = OutputStream(std::cerr); + testOut = OutputStream(std::cout); + } + +} // namespace Generator + +#endif diff --git a/ICPC/nwerc2023_H/output_validators/output_validator/validate_using_insights.cpp b/ICPC/nwerc2023_H/output_validators/output_validator/validate_using_insights.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba26101b404874c187da4c204b4a587a4c68baef --- /dev/null +++ b/ICPC/nwerc2023_H/output_validators/output_validator/validate_using_insights.cpp @@ -0,0 +1,186 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +/* + Copied from Slack: + + First, note that the optimal solution is always a product of sums (Proof: + Assume that an optimal solution contains a sub term of the shape a+b*c. Then, + one of the following three terms is strictly greater, contradicting the + optimality claim. If b > 1, we can use (a+c)*b instead. If c > 1, we can use + (a+b)*c. If b = c = 1, we can use a+b+c.). Therefore, we can walk over the AST + and collect the list of factors. Factorize each factor into primes, and then + compare the two lists of primes (for the jury answer and for the team output). + In fact, we don't really need to do the prime factorization for each number, + we only need to split each 4 into two 2s. + + Reason why we only need to factor the 4s: The only case where we need to form + a sum that exceeds 4 is when we only have a single 1 and no 2s, in which case + we must add the 1 to the smallest other number in the input. +*/ + +#include "validate.h" +#include +using namespace OutputValidator; + +struct state { // Result of a call to a parsing function. + Integer value; // Value of the parse. + bool seenMul; // Has there been a multiplication inside the parsed term? +}; + +struct parsed { + Verdict verdict; // The verdict to give when there is an issue. WA for team output, JE for jury output. + std::string ans; // The string to parse. + Integer pos; // Current index of parsing. + std::vector parts; // List of substrings that still need to be parsed. + std::vector factors; // List of factors that have been parsed. + + parsed(Verdict verdict_, const std::vector& numbers, const std::string& ans_) : verdict(verdict_), ans(ans_), pos(0) { + // Read all numbers in the string and check that they are the right multiset. + // As the numbers are treated as strings, this also catches leading zeroes. + for (Integer i = 0; i < ans.size(); i++) { + std::string tmp; + for (; i < ans.size() && isDigit(ans[i]); i++) { + tmp.push_back(ans[i]); + } + if (!tmp.empty()) parts.push_back(tmp); + } + std::sort(parts.begin(), parts.end()); + if (parts != numbers) juryOut << "invalid numbers" << verdict; + + // Parse the term and add it as a factor. + addFactor(parse(true).value); + // If we did not reach the end of the string while parsing, that's an error. + if (pos != ans.size()) juryOut << "invalid expression at: " << pos << verdict; + + // Replace every instance of 4 by two instances of 2, then sort. + for (Integer i = 0; i < factors.size(); i++) { + if (factors[i] == 4) { + factors[i] = 2; + factors.push_back(2); + } + } + std::sort(factors.begin(), factors.end()); + } + + void addFactor(Integer x) { + if (x > 1) factors.push_back(x); + } + + // Check that the character at `pos` is `c`, then increment `pos`. + void consume(char c) { + if (pos >= ans.size() || ans[pos] != c) juryOut << "invalid expression at: " << pos << verdict; + pos++; + } + + // Parse a term consisting of one or more terms separated by `+` or `*`. + // If `allowMul` is true, we are allowed to have multiplications. + state parse(bool allowMul) { + if (pos >= ans.size()) juryOut << "invalid expression at: " << pos << verdict; + // Parse the leftmost term, record whether it contains a multiplication. + auto [left, seenMul] = parseSingle(allowMul); + while (pos < ans.size() && (ans[pos] == '*' || ans[pos] == '+')) { + // While we only have summations, everything is fine and we can sum up in the variable `left`. + if (ans[pos] == '+') { + // There was a multiplication to the left, so this is not optimal. + if (seenMul) juryOut << "not max a" << verdict; + consume('+'); + // As we have seen a `+`, don't allow multiplications for future parses. + allowMul = false; + // As we don't allow multiplications, we don't need to inspect `seenMul` of the recursive call. + left += parseSingle(false).value; + } else { + // Multiplication after sum, also not optimal. + if (!allowMul) juryOut << "not max b" << verdict; + consume('*'); + seenMul = true; + // We have not seen a `+`, so `left` is just a single term and we add it as a factor. + addFactor(left); + // As we know that `allowMul` is true, we can allow multiplications in the recursive call. + // As we have already seen multiplications, we don't care whether we see more and thus ignore `seenMul`. + left = parseSingle(true).value; + } + } + if (seenMul) { + // Add the last remaining number as a factor. + addFactor(left); + // Because `seenMul` is true, we can return any value for `left`, it will never be inspected. + return {0, seenMul}; + } else { + // No multiplications here, so this sum could be part of a larger sum. + return {left, seenMul}; + } + } + + // Parse a single number or a term surrounded by parentheses. + state parseSingle(bool allowMul) { + if (pos >= ans.size()) juryOut << "invalid expression at: " << pos << verdict; + if (ans[pos] == '(') return parsePar(allowMul); + else if (isDigit(ans[pos])) return parseNumber(); + juryOut << "invalid expression at: " << pos << verdict; + return {-1, false}; + } + + state parsePar(bool allowMul) { + consume('('); + auto res = parse(allowMul); + consume(')'); + return res; + } + + // Parse an integer number. + // Overflow is not an issue, because we already checked that we have the correct multiset of numbers. + // The same goes for leading zeroes, see the comment above. + state parseNumber() { + Integer x = 0; + while (pos < ans.size() && isDigit(ans[pos])) { + x *= 10; + x += ans[pos] - '0'; + pos++; + } + return {x, false}; + } + +}; + +int main(int argc, char **argv) { + OutputValidator::init(argc, argv); + + Integer n = testIn.integer(); + std::vector numbers(n); + for (auto& s : numbers) s = testIn.string(); + sort(numbers.begin(), numbers.end()); + + parsed jAns(FAIL, numbers, juryAns.string(1, 1'000'001)); + parsed tAns(WA, numbers, teamAns.string(1, 1'000'001)); + teamAns.newline(); + teamAns.eof(); + + if (jAns.factors != tAns.factors) juryOut << "not max" << WA; + return AC; +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2023_H/output_validators/output_validator/validate_using_modulo.cpp b/ICPC/nwerc2023_H/output_validators/output_validator/validate_using_modulo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11ee6f2d983652d5c8e03ae37d0f2477db1dd4d7 --- /dev/null +++ b/ICPC/nwerc2023_H/output_validators/output_validator/validate_using_modulo.cpp @@ -0,0 +1,183 @@ +#include "validate.h" + +#define vl std::vector +#define sz(x) (Integer)(x).size() +#define f(i, s, k, l) for (Integer i = s; i < k; i += l) +#define for0(i, k) f(i, 0, k, 1) + +std::string parse; // The string to parse. +Integer curIndex; // The current index at which the parsing is. +Integer par = 0; // Current nesting depth of parentheses. + +vl parseTerm(Integer open, Verdict v); +// Some large prime numbers. +vl p = {1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093, 1000000097, 1000000103, 1000000123, 1000000181, 1000000207, 1000000223, 1000000241, 1000000271, 1000000289, 1000000297, 1000000321, 1000000349, 1000000363, 1000000403, 1000000409, 1000000411}; + +using namespace OutputValidator; + +bool isOperator(char c) { + return c == '*' || c == '+'; +} + +void parseError(Verdict v) { + juryOut << "parsing error" << v; +} + +// Reads one character and advances `curIndex` by 1. +// Also performs a sanity check on the next character after that. +char consume(Verdict v) { + char c = parse[curIndex]; + curIndex++; + // Note that we always surround the string to be parsed with parentheses, + // so that we only need to perform the out-of-bounds check for `curIndex` + // when `c` is `)`. + if(isOperator(c)) { + // Each `+` or `*` must be followed by a digit or an opening parenthesis. + if(parse[curIndex] != '(' && !isDigit(parse[curIndex])) parseError(v); + } else if(c == '(') { + // Each `(` must be followed by another `(` or a digit. + if(parse[curIndex] == ')' || isOperator(parse[curIndex])) { + parseError(v); + } + } else if(c == ')' ) { + // Each `)` must be followed by another `)` or an operator. + if(curIndex < sz(parse) && !isOperator(parse[curIndex]) && parse[curIndex] != ')') parseError(v); + } else if(isDigit(c)) { + // Digits may not be followed by a `(`. + if(parse[curIndex] == '(') parseError(v); + } + // Any other characters result in an error. + else parseError(v); + return c; +} + +// Parse a positive integer and compute it mod each prime. +vl parseNum(Verdict v) { + vl res(sz(p), 0); + while(isDigit(parse[curIndex])) { + char c = consume(v); + for0(i, sz(p)) res[i] = (10 * res[i] + (int) (c - '0')) % p[i]; + } + return res; +} + +// Parse a term after we just consumed a `*`, multiply the result together with `lval`. +vl parseStar(vl &lval, Integer open, Verdict v) { + vl rval(sz(p), 0); + char c = parse[curIndex]; + if(isDigit(c)) rval = parseNum(v); + else if(c == '(') rval = parseTerm(open, v); + for0(i, sz(p)) rval[i] = (lval[i] * rval[i]) % p[i]; + return rval; +} + +// Parse a term from the string `parse`, starting at `curIndex`, return value mod each prime. +// `open` is the nesting depth of parentheses at the time the function is called. +vl parseTerm(Integer open, Verdict v) { + vl num(sz(p), 0); // Number storing the current summand, which might be a product of multiple terms. + vl s(sz(p), 0); // Sum of all the summands that we parsed so far. + + // Run a loop over all the operator-separated summands. + // The loop ends when the string ends, or when we get back to the starting nesting depth. + do { + // If we are just starting, or the last character we read was a `+`, + // parse a new number or parenthesized term, and store it into `num`. + if(isDigit(parse[curIndex])) { + num = parseNum(v); + continue; + } + char c = consume(v); + // cout << c << curIndex << isDigit(c) << endl; + if(c == '(') { + par++; + // New sub term, recurse. + num = parseTerm(open + 1, v); + } else if(c == ')') { + par--; + // If we go below the starting depth while parsing, the term is invalid. + if(par < open) parseError(v); + } else if(isDigit(c)) num = parseNum(v); + // Found a product, multiply it together with the current value in `num`. + // Note that here we know that `num` holds some actual number, because + // of the sanity checks in `consume`. + else if(c == '*') num = parseStar(num, open, v); + else if(c == '+') { + // Found a sum, so add `num` to the current sum and reset it. + for0(i, sz(p)) s[i] = (s[i] + num[i]) % p[i]; + num = vl(sz(p), 0); + } + else { + // Any other character results in a parse error. + parseError(v); + } + } while(open != par && curIndex < sz(parse)); + // If the string ended before we got back to the starting depth, it's a parse error. + if(open != par) parseError(v); + // Add the last number to the sum. + for0(i, sz(p)) s[i] = (s[i] + num[i]) % p[i]; + return s; +} + +// Check that the numerical tokens in `ans` are equal to the tokens in `nums`. +void checkNumbers(std::string &ans, std::vector &nums, Verdict v) { + std::vector test = {""}; + for(char c : ans) { + if((isOperator(c) || c == '(')) { // At every operator or `(` start a new number. + if(sz(test.back()) != 0) test.push_back(""); + } + else if(isDigit(c)) test[sz(test) - 1].push_back(c); + // Note that this behaves weirdly if we get something like `123)456`, + // but in that case we will hit a parsing error later, so it's fine. + else if(c == ')') continue; + else parseError(v); + } + sort(nums.begin(), nums.end()); + sort(test.begin(), test.end()); + + if(sz(test) != sz(nums)) juryOut << "wrong numbers" << WA; + for0(i, sz(test)) { + if(test[i] != nums[i]) juryOut << "wrong numbers" << WA; + } +} + + + +int main(int argc, char **argv) { + OutputValidator::init(argc, argv); // initialize streams, rng and parse arguments + + std::string ans = teamAns.string(1, 1'000'001); + teamAns.newline(); + teamAns.eof(); + std::string correct = juryAns.string(1, 1'000'001); + + Integer n = testIn.integer(); + std::vector a(n); + for0(i, n) a[i] = testIn.string(); + + + parse = '(' + correct + ')'; + curIndex = 0; + par = 0; + + // Find the value of the jury expression mod each prime. + vl jury = parseTerm(0, FAIL); + if(curIndex != sz(parse)) parseError(FAIL); + + // Check that the multiset of numbers is the same as in the input. + parse = '(' + ans + ')'; + checkNumbers(parse, a, WA); + curIndex = 0; + par = 0; + + // Find the value of the team expression mod each prime. + vl team = parseTerm(0, WA); + if(curIndex != sz(parse)) parseError(WA); + + + // Check if all results are equal. Has a tiny probability to fail. + for0(i, sz(p)) { + if(jury[i] != team[i]) juryOut << "not max" << WA; + } + + juryOut << AC; +} diff --git a/ICPC/nwerc2023_I/data.zip b/ICPC/nwerc2023_I/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..e45a88b2744aa655b70892cb06e085324e3030a4 --- /dev/null +++ b/ICPC/nwerc2023_I/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58eeec7c7028ff623f69230d08e563af9d2d8843d2147cc68b22ae76f7387839 +size 419832 diff --git a/ICPC/nwerc2023_I/init.yml b/ICPC/nwerc2023_I/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e49c2aea892c88b005a965f3c948a61c090e55f8 --- /dev/null +++ b/ICPC/nwerc2023_I/init.yml @@ -0,0 +1,305 @@ +archive: data.zip +test_cases: +- in: 001-hashing.in + out: 001-hashing.ans + points: 1 +- in: 002-grid.in + out: 002-grid.ans + points: 1 +- in: 003-precision.in + out: 003-precision.ans + points: 1 +- in: 004-manual.in + out: 004-manual.ans + points: 1 +- in: 005-anti_unordered.in + out: 005-anti_unordered.ans + points: 1 +- in: 006-anti_reinier_hash.in + out: 006-anti_reinier_hash.ans + points: 1 +- in: 007-anti_reinier_hash.in + out: 007-anti_reinier_hash.ans + points: 1 +- in: 008-anti_reinier_hash.in + out: 008-anti_reinier_hash.ans + points: 1 +- in: 009-anti_reinier_hash.in + out: 009-anti_reinier_hash.ans + points: 1 +- in: 010-anti_reinier_hash.in + out: 010-anti_reinier_hash.ans + points: 1 +- in: 011-anti_reinier_hash.in + out: 011-anti_reinier_hash.ans + points: 1 +- in: 012-min.in + out: 012-min.ans + points: 1 +- in: 013-min.in + out: 013-min.ans + points: 1 +- in: 014-rnd_loop.in + out: 014-rnd_loop.ans + points: 1 +- in: 015-rnd_loop.in + out: 015-rnd_loop.ans + points: 1 +- in: 016-rnd_loop.in + out: 016-rnd_loop.ans + points: 1 +- in: 017-rnd_loop.in + out: 017-rnd_loop.ans + points: 1 +- in: 018-rnd_loop.in + out: 018-rnd_loop.ans + points: 1 +- in: 019-rnd.in + out: 019-rnd.ans + points: 1 +- in: 020-rnd.in + out: 020-rnd.ans + points: 1 +- in: 021-rnd.in + out: 021-rnd.ans + points: 1 +- in: 022-rnd.in + out: 022-rnd.ans + points: 1 +- in: 023-rot_tri.in + out: 023-rot_tri.ans + points: 1 +- in: 024-rot_tri.in + out: 024-rot_tri.ans + points: 1 +- in: 025-rot_tri.in + out: 025-rot_tri.ans + points: 1 +- in: 026-rot_tri.in + out: 026-rot_tri.ans + points: 1 +- in: 027-star.in + out: 027-star.ans + points: 1 +- in: 028-star.in + out: 028-star.ans + points: 1 +- in: 029-star.in + out: 029-star.ans + points: 1 +- in: 030-star.in + out: 030-star.ans + points: 1 +- in: 031-many_intersections.in + out: 031-many_intersections.ans + points: 1 +- in: 032-many_intersections.in + out: 032-many_intersections.ans + points: 1 +- in: 033-many_intersections.in + out: 033-many_intersections.ans + points: 1 +- in: 034-nested.in + out: 034-nested.ans + points: 1 +- in: 035-nested.in + out: 035-nested.ans + points: 1 +- in: 036-nested.in + out: 036-nested.ans + points: 1 +- in: 037-nested.in + out: 037-nested.ans + points: 1 +- in: 038-precision.in + out: 038-precision.ans + points: 1 +- in: 039-precision.in + out: 039-precision.ans + points: 1 +- in: 040-precision.in + out: 040-precision.ans + points: 1 +- in: 041-grid.in + out: 041-grid.ans + points: 1 +- in: 042-grid.in + out: 042-grid.ans + points: 1 +- in: 043-grid.in + out: 043-grid.ans + points: 1 +- in: 044-grid.in + out: 044-grid.ans + points: 1 +- in: 045-graph.in + out: 045-graph.ans + points: 1 +- in: 046-graph.in + out: 046-graph.ans + points: 1 +- in: 047-graph.in + out: 047-graph.ans + points: 1 +- in: 048-graph.in + out: 048-graph.ans + points: 1 +- in: 049-graph.in + out: 049-graph.ans + points: 1 +- in: 050-graph.in + out: 050-graph.ans + points: 1 +- in: 051-graph.in + out: 051-graph.ans + points: 1 +- in: 052-graph.in + out: 052-graph.ans + points: 1 +- in: 053-graph.in + out: 053-graph.ans + points: 1 +- in: 054-graph.in + out: 054-graph.ans + points: 1 +- in: 055-graph.in + out: 055-graph.ans + points: 1 +- in: 056-graph.in + out: 056-graph.ans + points: 1 +- in: 057-graph.in + out: 057-graph.ans + points: 1 +- in: 058-graph.in + out: 058-graph.ans + points: 1 +- in: 059-graph.in + out: 059-graph.ans + points: 1 +- in: 060-graph.in + out: 060-graph.ans + points: 1 +- in: 061-graph.in + out: 061-graph.ans + points: 1 +- in: 062-graph.in + out: 062-graph.ans + points: 1 +- in: 063-other_many_intersections.in + out: 063-other_many_intersections.ans + points: 1 +- in: 064-other_many_intersections.in + out: 064-other_many_intersections.ans + points: 1 +- in: 065-other_many_intersections.in + out: 065-other_many_intersections.ans + points: 1 +- in: 066-other_many_intersections.in + out: 066-other_many_intersections.ans + points: 1 +- in: 067-other_many_intersections.in + out: 067-other_many_intersections.ans + points: 1 +- in: 068-other_many_intersections.in + out: 068-other_many_intersections.ans + points: 1 +- in: 069-rectilinear_loop.in + out: 069-rectilinear_loop.ans + points: 1 +- in: 070-rectilinear_loop.in + out: 070-rectilinear_loop.ans + points: 1 +- in: 071-rectilinear_loop.in + out: 071-rectilinear_loop.ans + points: 1 +- in: 072-rectilinear_loop.in + out: 072-rectilinear_loop.ans + points: 1 +- in: 073-rectilinear_loop.in + out: 073-rectilinear_loop.ans + points: 1 +- in: 074-rectilinear_loop.in + out: 074-rectilinear_loop.ans + points: 1 +- in: 075-random_cliques.in + out: 075-random_cliques.ans + points: 1 +- in: 076-random_cliques.in + out: 076-random_cliques.ans + points: 1 +- in: 077-random_cliques.in + out: 077-random_cliques.ans + points: 1 +- in: 078-random_cliques.in + out: 078-random_cliques.ans + points: 1 +- in: 079-random_cliques.in + out: 079-random_cliques.ans + points: 1 +- in: 080-random_cliques.in + out: 080-random_cliques.ans + points: 1 +- in: 081-random_cliques.in + out: 081-random_cliques.ans + points: 1 +- in: 082-random_cliques.in + out: 082-random_cliques.ans + points: 1 +- in: 083-random_cliques.in + out: 083-random_cliques.ans + points: 1 +- in: 084-random_cliques.in + out: 084-random_cliques.ans + points: 1 +- in: 085-random_cliques.in + out: 085-random_cliques.ans + points: 1 +- in: 086-random_cliques.in + out: 086-random_cliques.ans + points: 1 +- in: 087-random_cliques.in + out: 087-random_cliques.ans + points: 1 +- in: 088-random_cliques.in + out: 088-random_cliques.ans + points: 1 +- in: 089-random_cliques.in + out: 089-random_cliques.ans + points: 1 +- in: 090-random_cliques.in + out: 090-random_cliques.ans + points: 1 +- in: 091-random_cliques.in + out: 091-random_cliques.ans + points: 1 +- in: 092-random_cliques.in + out: 092-random_cliques.ans + points: 1 +- in: 093-random_cliques.in + out: 093-random_cliques.ans + points: 1 +- in: 094-sample_3_modified.in + out: 094-sample_3_modified.ans + points: 1 +- in: 095-manual8.in + out: 095-manual8.ans + points: 1 +- in: 096-manual8.in + out: 096-manual8.ans + points: 1 +- in: 097-manual-tbox.in + out: 097-manual-tbox.ans + points: 1 +- in: 098-collinear.in + out: 098-collinear.ans + points: 1 +- in: 099-collinear.in + out: 099-collinear.ans + points: 1 +- in: 100-collinear.in + out: 100-collinear.ans + points: 1 +- in: 101-collinear.in + out: 101-collinear.ans + points: 1 diff --git a/ICPC/nwerc2023_J/data.zip b/ICPC/nwerc2023_J/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..a9325d22b2b2f7787dc0294065a5d104f4c1078b --- /dev/null +++ b/ICPC/nwerc2023_J/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33ae99662937f78d8c3e056211091ea03f79a276e25384f059c9188b4b0c89e3 +size 36015 diff --git a/ICPC/nwerc2023_J/init.yml b/ICPC/nwerc2023_J/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..722530a6a9be60146daea1ddc11539bafc1dc0dd --- /dev/null +++ b/ICPC/nwerc2023_J/init.yml @@ -0,0 +1,339 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 001-maximal.in + out: 001-maximal.ans + points: 1 +- in: 002-stairs-1.in + out: 002-stairs-1.ans + points: 1 +- in: 003-stairs-50000.in + out: 003-stairs-50000.ans + points: 1 +- in: 004-random-circle.in + out: 004-random-circle.ans + points: 1 +- in: 005-two-angles.in + out: 005-two-angles.ans + points: 1 +- in: 006-grid-90.in + out: 006-grid-90.ans + points: 1 +- in: 007-grid-45.in + out: 007-grid-45.ans + points: 1 +- in: 008-grid-85.in + out: 008-grid-85.ans + points: 1 +- in: 009-random.in + out: 009-random.ans + points: 1 +- in: 010-random.in + out: 010-random.ans + points: 1 +- in: 011-random.in + out: 011-random.ans + points: 1 +- in: 012-random.in + out: 012-random.ans + points: 1 +- in: 013-random.in + out: 013-random.ans + points: 1 +- in: 014-random.in + out: 014-random.ans + points: 1 +- in: 015-random.in + out: 015-random.ans + points: 1 +- in: 016-random.in + out: 016-random.ans + points: 1 +- in: 017-random.in + out: 017-random.ans + points: 1 +- in: 018-random.in + out: 018-random.ans + points: 1 +- in: 019-random.in + out: 019-random.ans + points: 1 +- in: 020-random.in + out: 020-random.ans + points: 1 +- in: 021-random.in + out: 021-random.ans + points: 1 +- in: 022-random.in + out: 022-random.ans + points: 1 +- in: 023-random.in + out: 023-random.ans + points: 1 +- in: 024-random.in + out: 024-random.ans + points: 1 +- in: 025-random.in + out: 025-random.ans + points: 1 +- in: 026-random.in + out: 026-random.ans + points: 1 +- in: 027-random.in + out: 027-random.ans + points: 1 +- in: 028-random.in + out: 028-random.ans + points: 1 +- in: 029-random.in + out: 029-random.ans + points: 1 +- in: 030-stairs-1.in + out: 030-stairs-1.ans + points: 1 +- in: 031-stairs-1.in + out: 031-stairs-1.ans + points: 1 +- in: 032-stairs-1.in + out: 032-stairs-1.ans + points: 1 +- in: 033-stairs-50000.in + out: 033-stairs-50000.ans + points: 1 +- in: 034-stairs-50000.in + out: 034-stairs-50000.ans + points: 1 +- in: 035-stairs-50000.in + out: 035-stairs-50000.ans + points: 1 +- in: 036-straight-1.in + out: 036-straight-1.ans + points: 1 +- in: 037-straight-1.in + out: 037-straight-1.ans + points: 1 +- in: 038-straight-5000.in + out: 038-straight-5000.ans + points: 1 +- in: 039-straight-5000.in + out: 039-straight-5000.ans + points: 1 +- in: 040-straight-angle.in + out: 040-straight-angle.ans + points: 1 +- in: 041-random-circle.in + out: 041-random-circle.ans + points: 1 +- in: 042-random-circle.in + out: 042-random-circle.ans + points: 1 +- in: 043-random-circle.in + out: 043-random-circle.ans + points: 1 +- in: 044-random-circle.in + out: 044-random-circle.ans + points: 1 +- in: 045-random-circle.in + out: 045-random-circle.ans + points: 1 +- in: 046-random-circle.in + out: 046-random-circle.ans + points: 1 +- in: 047-random-circle.in + out: 047-random-circle.ans + points: 1 +- in: 048-random-circle.in + out: 048-random-circle.ans + points: 1 +- in: 049-random-circle.in + out: 049-random-circle.ans + points: 1 +- in: 050-random-circle.in + out: 050-random-circle.ans + points: 1 +- in: 051-two-angles.in + out: 051-two-angles.ans + points: 1 +- in: 052-two-angles.in + out: 052-two-angles.ans + points: 1 +- in: 053-two-angles.in + out: 053-two-angles.ans + points: 1 +- in: 054-two-angles.in + out: 054-two-angles.ans + points: 1 +- in: 055-two-angles-90.in + out: 055-two-angles-90.ans + points: 1 +- in: 056-two-angles-90.in + out: 056-two-angles-90.ans + points: 1 +- in: 057-two-angles-90.in + out: 057-two-angles-90.ans + points: 1 +- in: 058-two-angles-almost-90.in + out: 058-two-angles-almost-90.ans + points: 1 +- in: 059-two-angles-almost-90.in + out: 059-two-angles-almost-90.ans + points: 1 +- in: 060-two-angles-almost-90.in + out: 060-two-angles-almost-90.ans + points: 1 +- in: 061-two-angles-almost-90.in + out: 061-two-angles-almost-90.ans + points: 1 +- in: 062-two-angles-almost-90.in + out: 062-two-angles-almost-90.ans + points: 1 +- in: 063-two-angles-almost-90.in + out: 063-two-angles-almost-90.ans + points: 1 +- in: 064-two-angles-almost-90.in + out: 064-two-angles-almost-90.ans + points: 1 +- in: 065-two-angles-almost-90.in + out: 065-two-angles-almost-90.ans + points: 1 +- in: 066-two-angles-almost-90.in + out: 066-two-angles-almost-90.ans + points: 1 +- in: 067-two-angles-45.in + out: 067-two-angles-45.ans + points: 1 +- in: 068-two-angles-almost-45.in + out: 068-two-angles-almost-45.ans + points: 1 +- in: 069-two-angles-almost-45.in + out: 069-two-angles-almost-45.ans + points: 1 +- in: 070-two-angles-almost-45.in + out: 070-two-angles-almost-45.ans + points: 1 +- in: 071-two-angles-almost-45.in + out: 071-two-angles-almost-45.ans + points: 1 +- in: 072-two-angles-almost-45.in + out: 072-two-angles-almost-45.ans + points: 1 +- in: 073-two-angles-almost-45.in + out: 073-two-angles-almost-45.ans + points: 1 +- in: 074-two-angles-almost-45.in + out: 074-two-angles-almost-45.ans + points: 1 +- in: 075-two-angles-almost-45.in + out: 075-two-angles-almost-45.ans + points: 1 +- in: 076-grid-90.in + out: 076-grid-90.ans + points: 1 +- in: 077-grid-90.in + out: 077-grid-90.ans + points: 1 +- in: 078-grid-90.in + out: 078-grid-90.ans + points: 1 +- in: 079-grid-90.in + out: 079-grid-90.ans + points: 1 +- in: 080-grid-89.in + out: 080-grid-89.ans + points: 1 +- in: 081-grid-89.in + out: 081-grid-89.ans + points: 1 +- in: 082-grid-89.in + out: 082-grid-89.ans + points: 1 +- in: 083-grid-89.in + out: 083-grid-89.ans + points: 1 +- in: 084-grid-89.in + out: 084-grid-89.ans + points: 1 +- in: 085-grid-45.in + out: 085-grid-45.ans + points: 1 +- in: 086-grid-45.in + out: 086-grid-45.ans + points: 1 +- in: 087-grid-45.in + out: 087-grid-45.ans + points: 1 +- in: 088-grid-45.in + out: 088-grid-45.ans + points: 1 +- in: 089-grid-30.in + out: 089-grid-30.ans + points: 1 +- in: 090-grid-30.in + out: 090-grid-30.ans + points: 1 +- in: 091-grid-30.in + out: 091-grid-30.ans + points: 1 +- in: 092-grid-30.in + out: 092-grid-30.ans + points: 1 +- in: 093-grid-30.in + out: 093-grid-30.ans + points: 1 +- in: 094-grid-85.in + out: 094-grid-85.ans + points: 1 +- in: 095-grid-85.in + out: 095-grid-85.ans + points: 1 +- in: 096-grid-85.in + out: 096-grid-85.ans + points: 1 +- in: 097-grid-85.in + out: 097-grid-85.ans + points: 1 +- in: 098-plus.in + out: 098-plus.ans + points: 1 +- in: 099-fuzz.in + out: 099-fuzz.ans + points: 1 +- in: 100-fuzz.in + out: 100-fuzz.ans + points: 1 +- in: 101-fuzz.in + out: 101-fuzz.ans + points: 1 +- in: 102-fuzz.in + out: 102-fuzz.ans + points: 1 +- in: 103-minimal.in + out: 103-minimal.ans + points: 1 +- in: 104-minimal.in + out: 104-minimal.ans + points: 1 +- in: 105-minimal.in + out: 105-minimal.ans + points: 1 +- in: 106-minimal.in + out: 106-minimal.ans + points: 1 +- in: 107-minimal.in + out: 107-minimal.ans + points: 1 +- in: 108-minimal.in + out: 108-minimal.ans + points: 1 +- in: 109-minimal.in + out: 109-minimal.ans + points: 1 +- in: 110-minimal.in + out: 110-minimal.ans + points: 1 +- in: 111-minimal.in + out: 111-minimal.ans + points: 1 diff --git a/ICPC/nwerc2023_K/data.zip b/ICPC/nwerc2023_K/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..90b9906463e6afc4192a1d89d1651543989f3561 --- /dev/null +++ b/ICPC/nwerc2023_K/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67939ac2ede041990fde713a8f0578eedcfc2e45cd741ede8c178c5215f81cee +size 17625 diff --git a/ICPC/nwerc2023_K/init.yml b/ICPC/nwerc2023_K/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..34073a5f229249341edb08a9d95ccef53d3f2297 --- /dev/null +++ b/ICPC/nwerc2023_K/init.yml @@ -0,0 +1,236 @@ +archive: data.zip +test_cases: +- in: 01-min.in + out: 01-min.ans + points: 1 +- in: 02-max.in + out: 02-max.ans + points: 1 +- in: 03-max-ans.in + out: 03-max-ans.ans + points: 1 +- in: 04-large-jumps-reach-all.in + out: 04-large-jumps-reach-all.ans + points: 1 +- in: 05-random.in + out: 05-random.ans + points: 1 +- in: 06-biased.in + out: 06-biased.ans + points: 1 +- in: 07-pretty.in + out: 07-pretty.ans + points: 1 +- in: 08-pretty.in + out: 08-pretty.ans + points: 1 +- in: 09-biased.in + out: 09-biased.ans + points: 1 +- in: 10-random.in + out: 10-random.ans + points: 1 +- in: 11-random.in + out: 11-random.ans + points: 1 +- in: 12-random.in + out: 12-random.ans + points: 1 +- in: 13-random.in + out: 13-random.ans + points: 1 +- in: 14-biased.in + out: 14-biased.ans + points: 1 +- in: 15-biased.in + out: 15-biased.ans + points: 1 +- in: 16-biased.in + out: 16-biased.ans + points: 1 +- in: 17-biased.in + out: 17-biased.ans + points: 1 +- in: 18-biased.in + out: 18-biased.ans + points: 1 +- in: 19-biased.in + out: 19-biased.ans + points: 1 +- in: 20-biased.in + out: 20-biased.ans + points: 1 +- in: 21-biased.in + out: 21-biased.ans + points: 1 +- in: 22-biased.in + out: 22-biased.ans + points: 1 +- in: 23-biased.in + out: 23-biased.ans + points: 1 +- in: 24-biased.in + out: 24-biased.ans + points: 1 +- in: 25-biased.in + out: 25-biased.ans + points: 1 +- in: 26-biased.in + out: 26-biased.ans + points: 1 +- in: 27-biased.in + out: 27-biased.ans + points: 1 +- in: 28-biased.in + out: 28-biased.ans + points: 1 +- in: 29-biased.in + out: 29-biased.ans + points: 1 +- in: 30-biased.in + out: 30-biased.ans + points: 1 +- in: 31-biased.in + out: 31-biased.ans + points: 1 +- in: 32-biased.in + out: 32-biased.ans + points: 1 +- in: 33-biased.in + out: 33-biased.ans + points: 1 +- in: 34-biased.in + out: 34-biased.ans + points: 1 +- in: 35-biased.in + out: 35-biased.ans + points: 1 +- in: 36-biased.in + out: 36-biased.ans + points: 1 +- in: 37-biased.in + out: 37-biased.ans + points: 1 +- in: 38-biased.in + out: 38-biased.ans + points: 1 +- in: 39-biased.in + out: 39-biased.ans + points: 1 +- in: 40-biased.in + out: 40-biased.ans + points: 1 +- in: 41-biased.in + out: 41-biased.ans + points: 1 +- in: 42-biased.in + out: 42-biased.ans + points: 1 +- in: 43-biased.in + out: 43-biased.ans + points: 1 +- in: 44-biased.in + out: 44-biased.ans + points: 1 +- in: 45-biased.in + out: 45-biased.ans + points: 1 +- in: 46-biased.in + out: 46-biased.ans + points: 1 +- in: 47-biased.in + out: 47-biased.ans + points: 1 +- in: 48-biased.in + out: 48-biased.ans + points: 1 +- in: 49-biased.in + out: 49-biased.ans + points: 1 +- in: 50-biased.in + out: 50-biased.ans + points: 1 +- in: 51-biased.in + out: 51-biased.ans + points: 1 +- in: 52-biased.in + out: 52-biased.ans + points: 1 +- in: 53-biased.in + out: 53-biased.ans + points: 1 +- in: 54-biased.in + out: 54-biased.ans + points: 1 +- in: 55-biased.in + out: 55-biased.ans + points: 1 +- in: 56-biased.in + out: 56-biased.ans + points: 1 +- in: 57-biased.in + out: 57-biased.ans + points: 1 +- in: 58-biased.in + out: 58-biased.ans + points: 1 +- in: 59-biased.in + out: 59-biased.ans + points: 1 +- in: 60-biased.in + out: 60-biased.ans + points: 1 +- in: 61-biased.in + out: 61-biased.ans + points: 1 +- in: 62-pretty.in + out: 62-pretty.ans + points: 1 +- in: 63-pretty.in + out: 63-pretty.ans + points: 1 +- in: 64-pretty.in + out: 64-pretty.ans + points: 1 +- in: 65-pretty.in + out: 65-pretty.ans + points: 1 +- in: 66-pretty.in + out: 66-pretty.ans + points: 1 +- in: 67-pretty.in + out: 67-pretty.ans + points: 1 +- in: 68-pretty.in + out: 68-pretty.ans + points: 1 +- in: 69-pretty.in + out: 69-pretty.ans + points: 1 +- in: 70-pretty.in + out: 70-pretty.ans + points: 1 +- in: 71-pretty.in + out: 71-pretty.ans + points: 1 +- in: 72-pretty.in + out: 72-pretty.ans + points: 1 +- in: 73-pretty.in + out: 73-pretty.ans + points: 1 +- in: 74-pretty.in + out: 74-pretty.ans + points: 1 +- in: 75-pretty.in + out: 75-pretty.ans + points: 1 +- in: 76-pretty.in + out: 76-pretty.ans + points: 1 +- in: 77-pretty.in + out: 77-pretty.ans + points: 1 +- in: 78-pretty.in + out: 78-pretty.ans + points: 1 diff --git a/ICPC/nwerc2023_L/data.zip b/ICPC/nwerc2023_L/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..69d6ef610fa08935db7ea2fe6cae70cfa1f0d562 --- /dev/null +++ b/ICPC/nwerc2023_L/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38fa415789e2a6e513a2ddd454c3723854632bb1a400298457bda22232bb404e +size 39550 diff --git a/ICPC/nwerc2023_L/init.yml b/ICPC/nwerc2023_L/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..08b7a4f49115bf950c1e443e04dc636df4b6bfc7 --- /dev/null +++ b/ICPC/nwerc2023_L/init.yml @@ -0,0 +1,411 @@ +archive: data.zip +interactive: + files: + - output_validators/output_validator/output_validator.cpp + - output_validators/output_validator/validation.h + lang: CPP17 + type: default +test_cases: +- in: 001-small-filled.in + out: 001-small-filled.ans + points: 1 +- in: 002-small-filled.in + out: 002-small-filled.ans + points: 1 +- in: 003-large-partially-fixed.in + out: 003-large-partially-fixed.ans + points: 1 +- in: 004-large-partially-fixed.in + out: 004-large-partially-fixed.ans + points: 1 +- in: 005-large-partially-fixed.in + out: 005-large-partially-fixed.ans + points: 1 +- in: 006-large-partially-fixed.in + out: 006-large-partially-fixed.ans + points: 1 +- in: 007-large-partially-fixed.in + out: 007-large-partially-fixed.ans + points: 1 +- in: 008-large-partially-fixed.in + out: 008-large-partially-fixed.ans + points: 1 +- in: 009-large-partially-fixed.in + out: 009-large-partially-fixed.ans + points: 1 +- in: 010-large-partially-fixed.in + out: 010-large-partially-fixed.ans + points: 1 +- in: 011-large-partially-fixed.in + out: 011-large-partially-fixed.ans + points: 1 +- in: 012-large-fixed.in + out: 012-large-fixed.ans + points: 1 +- in: 013-large-fixed-corners.in + out: 013-large-fixed-corners.ans + points: 1 +- in: 014-large-fixed-corners.in + out: 014-large-fixed-corners.ans + points: 1 +- in: 015-large-fixed-corners.in + out: 015-large-fixed-corners.ans + points: 1 +- in: 016-large-partially-fixed-corners.in + out: 016-large-partially-fixed-corners.ans + points: 1 +- in: 017-large-partially-fixed-corners.in + out: 017-large-partially-fixed-corners.ans + points: 1 +- in: 018-large-fixed-center.in + out: 018-large-fixed-center.ans + points: 1 +- in: 019-large-partially-fixed-center.in + out: 019-large-partially-fixed-center.ans + points: 1 +- in: 020-large-fixed-center.in + out: 020-large-fixed-center.ans + points: 1 +- in: 021-large-fixed-p.in + out: 021-large-fixed-p.ans + points: 1 +- in: 022-large-fixed-corners-p.in + out: 022-large-fixed-corners-p.ans + points: 1 +- in: 023-large-fixed-corners-p.in + out: 023-large-fixed-corners-p.ans + points: 1 +- in: 024-large-fixed-corners-p.in + out: 024-large-fixed-corners-p.ans + points: 1 +- in: 025-large-partially-fixed-corners-p.in + out: 025-large-partially-fixed-corners-p.ans + points: 1 +- in: 026-large-partially-fixed-corners-p.in + out: 026-large-partially-fixed-corners-p.ans + points: 1 +- in: 027-large-fixed-center-p.in + out: 027-large-fixed-center-p.ans + points: 1 +- in: 028-large-partially-fixed-center-p.in + out: 028-large-partially-fixed-center-p.ans + points: 1 +- in: 029-large-fixed-random.in + out: 029-large-fixed-random.ans + points: 1 +- in: 030-large-fixed-random.in + out: 030-large-fixed-random.ans + points: 1 +- in: 031-large-fixed-random.in + out: 031-large-fixed-random.ans + points: 1 +- in: 032-large-fixed-random.in + out: 032-large-fixed-random.ans + points: 1 +- in: 033-large-fixed-random.in + out: 033-large-fixed-random.ans + points: 1 +- in: 034-large-fixed-random.in + out: 034-large-fixed-random.ans + points: 1 +- in: 035-small-fixed-random.in + out: 035-small-fixed-random.ans + points: 1 +- in: 036-small-fixed-random.in + out: 036-small-fixed-random.ans + points: 1 +- in: 037-small-fixed-random.in + out: 037-small-fixed-random.ans + points: 1 +- in: 038-small-fixed-random.in + out: 038-small-fixed-random.ans + points: 1 +- in: 039-small-fixed-random.in + out: 039-small-fixed-random.ans + points: 1 +- in: 040-small-fixed-random.in + out: 040-small-fixed-random.ans + points: 1 +- in: 041-medium-fixed-random.in + out: 041-medium-fixed-random.ans + points: 1 +- in: 042-medium-fixed-random.in + out: 042-medium-fixed-random.ans + points: 1 +- in: 043-medium-fixed-random.in + out: 043-medium-fixed-random.ans + points: 1 +- in: 044-medium-fixed-random.in + out: 044-medium-fixed-random.ans + points: 1 +- in: 045-medium-fixed-random.in + out: 045-medium-fixed-random.ans + points: 1 +- in: 046-medium-fixed-random.in + out: 046-medium-fixed-random.ans + points: 1 +- in: 047-medium-fixed-random.in + out: 047-medium-fixed-random.ans + points: 1 +- in: 048-medium-fixed-random.in + out: 048-medium-fixed-random.ans + points: 1 +- in: 049-small-adaptive.in + out: 049-small-adaptive.ans + points: 1 +- in: 050-small-adaptive.in + out: 050-small-adaptive.ans + points: 1 +- in: 051-small-adaptive.in + out: 051-small-adaptive.ans + points: 1 +- in: 052-small-adaptive.in + out: 052-small-adaptive.ans + points: 1 +- in: 053-small-adaptive.in + out: 053-small-adaptive.ans + points: 1 +- in: 054-small-adaptive.in + out: 054-small-adaptive.ans + points: 1 +- in: 055-medium-adaptive.in + out: 055-medium-adaptive.ans + points: 1 +- in: 056-medium-adaptive.in + out: 056-medium-adaptive.ans + points: 1 +- in: 057-medium-adaptive.in + out: 057-medium-adaptive.ans + points: 1 +- in: 058-medium-adaptive.in + out: 058-medium-adaptive.ans + points: 1 +- in: 059-medium-adaptive.in + out: 059-medium-adaptive.ans + points: 1 +- in: 060-medium-adaptive.in + out: 060-medium-adaptive.ans + points: 1 +- in: 061-medium-adaptive.in + out: 061-medium-adaptive.ans + points: 1 +- in: 062-medium-adaptive.in + out: 062-medium-adaptive.ans + points: 1 +- in: 063-small-partially-fixed.in + out: 063-small-partially-fixed.ans + points: 1 +- in: 064-small-partially-fixed.in + out: 064-small-partially-fixed.ans + points: 1 +- in: 065-small-partially-fixed.in + out: 065-small-partially-fixed.ans + points: 1 +- in: 066-small-partially-fixed.in + out: 066-small-partially-fixed.ans + points: 1 +- in: 067-small-partially-fixed.in + out: 067-small-partially-fixed.ans + points: 1 +- in: 068-medium-partially-fixed.in + out: 068-medium-partially-fixed.ans + points: 1 +- in: 069-medium-partially-fixed.in + out: 069-medium-partially-fixed.ans + points: 1 +- in: 070-medium-partially-fixed.in + out: 070-medium-partially-fixed.ans + points: 1 +- in: 071-medium-partially-fixed.in + out: 071-medium-partially-fixed.ans + points: 1 +- in: 072-medium-partially-fixed.in + out: 072-medium-partially-fixed.ans + points: 1 +- in: 073-medium-partially-fixed.in + out: 073-medium-partially-fixed.ans + points: 1 +- in: 074-medium-partially-fixed.in + out: 074-medium-partially-fixed.ans + points: 1 +- in: 075-medium-partially-fixed.in + out: 075-medium-partially-fixed.ans + points: 1 +- in: 076-medium-partially-fixed.in + out: 076-medium-partially-fixed.ans + points: 1 +- in: 077-medium-partially-fixed.in + out: 077-medium-partially-fixed.ans + points: 1 +- in: 078-large-adaptive.in + out: 078-large-adaptive.ans + points: 1 +- in: 079-large-adaptive.in + out: 079-large-adaptive.ans + points: 1 +- in: 080-large-adaptive.in + out: 080-large-adaptive.ans + points: 1 +- in: 081-large-adaptive.in + out: 081-large-adaptive.ans + points: 1 +- in: 082-large-adaptive.in + out: 082-large-adaptive.ans + points: 1 +- in: 083-large-adaptive.in + out: 083-large-adaptive.ans + points: 1 +- in: 084-large-adaptive.in + out: 084-large-adaptive.ans + points: 1 +- in: 085-large-adaptive.in + out: 085-large-adaptive.ans + points: 1 +- in: 086-large-adaptive.in + out: 086-large-adaptive.ans + points: 1 +- in: 087-large-adaptive.in + out: 087-large-adaptive.ans + points: 1 +- in: 088-small-immediate-hit.in + out: 088-small-immediate-hit.ans + points: 1 +- in: 089-small-immediate-hit.in + out: 089-small-immediate-hit.ans + points: 1 +- in: 090-small-immediate-hit.in + out: 090-small-immediate-hit.ans + points: 1 +- in: 091-medium-immediate-hit.in + out: 091-medium-immediate-hit.ans + points: 1 +- in: 092-medium-immediate-hit.in + out: 092-medium-immediate-hit.ans + points: 1 +- in: 093-large-immediate-hit.in + out: 093-large-immediate-hit.ans + points: 1 +- in: 094-large-immediate-hit.in + out: 094-large-immediate-hit.ans + points: 1 +- in: 095-large-immediate-hit.in + out: 095-large-immediate-hit.ans + points: 1 +- in: 096-small-adaptive-early-hit.in + out: 096-small-adaptive-early-hit.ans + points: 1 +- in: 097-small-adaptive-early-hit.in + out: 097-small-adaptive-early-hit.ans + points: 1 +- in: 098-small-adaptive-early-hit.in + out: 098-small-adaptive-early-hit.ans + points: 1 +- in: 099-small-adaptive-early-hit.in + out: 099-small-adaptive-early-hit.ans + points: 1 +- in: 100-small-adaptive-early-hit.in + out: 100-small-adaptive-early-hit.ans + points: 1 +- in: 101-small-adaptive-early-hit.in + out: 101-small-adaptive-early-hit.ans + points: 1 +- in: 102-small-adaptive-early-hit.in + out: 102-small-adaptive-early-hit.ans + points: 1 +- in: 103-small-adaptive-early-hit.in + out: 103-small-adaptive-early-hit.ans + points: 1 +- in: 104-small-adaptive-early-hit.in + out: 104-small-adaptive-early-hit.ans + points: 1 +- in: 105-small-adaptive-early-hit.in + out: 105-small-adaptive-early-hit.ans + points: 1 +- in: 106-medium-adaptive-early-hit.in + out: 106-medium-adaptive-early-hit.ans + points: 1 +- in: 107-medium-adaptive-early-hit.in + out: 107-medium-adaptive-early-hit.ans + points: 1 +- in: 108-medium-adaptive-early-hit.in + out: 108-medium-adaptive-early-hit.ans + points: 1 +- in: 109-medium-adaptive-early-hit.in + out: 109-medium-adaptive-early-hit.ans + points: 1 +- in: 110-medium-adaptive-early-hit.in + out: 110-medium-adaptive-early-hit.ans + points: 1 +- in: 111-medium-adaptive-early-hit.in + out: 111-medium-adaptive-early-hit.ans + points: 1 +- in: 112-medium-adaptive-early-hit.in + out: 112-medium-adaptive-early-hit.ans + points: 1 +- in: 113-medium-adaptive-early-hit.in + out: 113-medium-adaptive-early-hit.ans + points: 1 +- in: 114-medium-adaptive-early-hit.in + out: 114-medium-adaptive-early-hit.ans + points: 1 +- in: 115-medium-adaptive-early-hit.in + out: 115-medium-adaptive-early-hit.ans + points: 1 +- in: 116-medium-adaptive-early-hit.in + out: 116-medium-adaptive-early-hit.ans + points: 1 +- in: 117-medium-adaptive-early-hit.in + out: 117-medium-adaptive-early-hit.ans + points: 1 +- in: 118-medium-adaptive-early-hit.in + out: 118-medium-adaptive-early-hit.ans + points: 1 +- in: 119-medium-adaptive-early-hit.in + out: 119-medium-adaptive-early-hit.ans + points: 1 +- in: 120-medium-adaptive-early-hit.in + out: 120-medium-adaptive-early-hit.ans + points: 1 +- in: 121-medium-adaptive-early-hit.in + out: 121-medium-adaptive-early-hit.ans + points: 1 +- in: 122-medium-adaptive-early-hit.in + out: 122-medium-adaptive-early-hit.ans + points: 1 +- in: 123-medium-adaptive-early-hit.in + out: 123-medium-adaptive-early-hit.ans + points: 1 +- in: 124-large-adaptive-early-hit.in + out: 124-large-adaptive-early-hit.ans + points: 1 +- in: 125-large-adaptive-early-hit.in + out: 125-large-adaptive-early-hit.ans + points: 1 +- in: 126-large-adaptive-early-hit.in + out: 126-large-adaptive-early-hit.ans + points: 1 +- in: 127-large-adaptive-early-hit.in + out: 127-large-adaptive-early-hit.ans + points: 1 +- in: 128-large-adaptive-early-hit.in + out: 128-large-adaptive-early-hit.ans + points: 1 +- in: 129-large-adaptive-early-hit.in + out: 129-large-adaptive-early-hit.ans + points: 1 +- in: 130-large-adaptive-early-hit.in + out: 130-large-adaptive-early-hit.ans + points: 1 +- in: 131-large-adaptive-early-hit.in + out: 131-large-adaptive-early-hit.ans + points: 1 +- in: 132-large-adaptive-early-hit.in + out: 132-large-adaptive-early-hit.ans + points: 1 +- in: 133-large-adaptive-early-hit.in + out: 133-large-adaptive-early-hit.ans + points: 1 +- in: 134-large-adaptive-early-hit.in + out: 134-large-adaptive-early-hit.ans + points: 1 +unbuffered: false diff --git a/ICPC/nwerc2023_L/output_validators/output_validator/output_validator.cpp b/ICPC/nwerc2023_L/output_validators/output_validator/output_validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c7db684d333688b986859f729b024b398f1e5c3 --- /dev/null +++ b/ICPC/nwerc2023_L/output_validators/output_validator/output_validator.cpp @@ -0,0 +1,255 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validation.h" +#include +#include +#include + +#define CARRIER_LENGTH 5 +#define MAX_QUERIES 2500 + +using namespace std; + +typedef pair point; + +// View on the grid for the adaptive validator, which tells us how many +// ships could still be potentially placed, in O(log n) time per update. +class Grid { +public: + int possibleCarriers; +private: + const int n; + // Swap x,y for the symmetry? + const bool swap; + // Points that are taken, either because of a miss or because we placed a ship + vector> taken; + +public: + Grid(int n, bool swap): n(n), swap(swap) { + possibleCarriers = 0; + for(int i = 1; i <= n; i++) { + // Insert outside boundaries, this makes checks later on easier + set row; + row.insert(0); + row.insert(n+1); + taken.push_back(row); + possibleCarriers += numCarriers(0, n + 1); + } + } + + // How many carriers fit between left and right? + static int numCarriers(int left, int right) { + return (right - left - 1) / CARRIER_LENGTH; + } + + // Take out point p, this updates possibleCarriers + void take(point p) { + int r = swap ? p.second : p.first; + int c = swap ? p.first : p.second; + + // Search the earliest value after this point in this row + auto it = taken[r-1].upper_bound(c); + int right = *it; + it--; + int left = *it; + + // If this point was hit before we don't update anything + if(left == c) return; + + // Update counts, we now split this interval + possibleCarriers -= numCarriers(left, right); + possibleCarriers += numCarriers(left, c); + possibleCarriers += numCarriers(c, right); + + // And insert the point + taken[r-1].insert(c); + } + + const void possiblePlacements(point p, vector>& places) { + int r = swap ? p.second : p.first; + int c = swap ? p.first : p.second; + + // Find the left and right, but the current point was already inserted, so ignore it + auto it = taken[r-1].upper_bound(c); + int right = *it; + it--; + if(*it != c) { + cerr << "Judge error: cell should already have been shot at: " << p.first << " " + << p.second << endl; + exit(1); + } + it--; + int left = *it; + + // Loop over the leftmost point of the carrier + for(int i = max(1, c - CARRIER_LENGTH + 1); i <= min(n - CARRIER_LENGTH + 1, c); i++) { + // Check that it fits + if(left >= i) continue; + if(right < i + CARRIER_LENGTH) continue; + + // Check that this won't change the amount of possible carriers + if(numCarriers(left, c) != numCarriers(left, i)) continue; + if(numCarriers(c, right) != numCarriers(i + CARRIER_LENGTH - 1, right)) continue; + + // It worked, so this is a possible carrier placement + places.push_back(make_pair(make_pair(swap ? i : r, swap ? r : i), swap)); + } + } +}; + +int main(int argc, char *argv[]) { + // Read the basic inputs + std::ifstream in(argv[1]); + OutputValidator v(argc, argv); + int n, k, f, seed; + double p; + in >> n >> k >> f >> seed >> p; + cout << n << ' ' << k << endl; + srand(seed); + + // Store the carrier locations + vector numHits(k, 0); + map carriers; + + // Make two gridviews, one for horizontal and one for vertical + auto grids = { new Grid(n, false), new Grid(n, true) }; + + // Place the fixed carriers + for (int i = 0; i < f; i++) { + string dir; + int x, y; + in >> dir >> x >> y; + bool hor = (dir=="h"); + for(int j = 0; j < CARRIER_LENGTH; j++) { + auto pt = make_pair(x + (hor?1:0)*j, y + (hor?0:1)*j); + if(carriers.find(pt) != carriers.end()) { + cerr << "Judge error: Trying to place second carrier at " << pt.first << "," << pt.second << endl; + exit(1); + } + carriers[pt] = i; + for(auto grid : grids) + grid->take(pt); + } + } + int carriersRemaining = k - f; + + // Store what we've hit so far + set hits; + set shots; + + // Go through the queries + for (int q = 1; q <= 2 * MAX_QUERIES; q++) { + // Get and check contestant input + int x = v.read_integer("x", 1, n); + v.space(); + int y = v.read_integer("y", 1, n); + v.newline(); + point shot = make_pair(x, y); + if (shot.first < 1 || shot.first > n || shot.second < 1 || shot.second > n) { + v.WA("Shot is out of bounds: ", x, ",", y); + } + + // Repeated shots are always misses + if(shots.find(shot) != shots.end()) { + cout << "miss" << endl; + continue; + } + shots.insert(shot); + + // Update the adaptive interactor, and check if we now need to place a carrier + if(carriersRemaining > 0 && carriers.find(shot) == carriers.end()) { + // If this is a miss but then none of the grids an fit the remaining carriers, + // we have to place it now and call this a hit. + bool mustPlace = true; + for(auto grid : grids) { + grid->take(shot); + if(grid->possibleCarriers >= carriersRemaining) + mustPlace = false; + } + + // Or maybe we randomly hit early + bool earlyHit = ((double)rand() / (double)RAND_MAX) <= p; + + // If needed we place it + if(mustPlace || earlyHit) { + vector> places; + for(auto grid : grids) + // Only consider the early hit when this grid allows placing enough carriers + if((earlyHit && grid->possibleCarriers >= carriersRemaining - 1) + || grid->possibleCarriers == carriersRemaining - 1) + grid->possiblePlacements(shot, places); + + // See if we found some places, this could be false when earlyHit = true + if(places.size() == 0) { + // Double check, when mustPlace = true this should never happen... + if(mustPlace) { + cerr << "Judge error: Cannot find carrier to place containing point " << shot.first << "," << shot.second << endl; + exit(1); + } + } else { + // Pick one of these at random + int pick = rand() % places.size(); + int x = places[pick].first.first; + int y = places[pick].first.second; + bool hor = places[pick].second; + cerr << "Placing at " << x << "," << y << " " << (hor?"h":"v") << endl; + for(int j = 0; j < CARRIER_LENGTH; j++) { + auto pt = make_pair(x + (hor?1:0)*j, y + (hor?0:1)*j); + if(carriers.find(pt) != carriers.end()) { + cerr << "Judge error: Trying to place second carrier at " << pt.first << "," << pt.second << endl; + exit(1); + } + carriers[pt] = k - carriersRemaining; + for(auto grid : grids) + grid->take(pt); + } + carriersRemaining--; + } + } + } + + // If we did not shoot before and we found a carrier, the shot hits + if(hits.find(shot) == hits.end() && carriers.find(shot) != carriers.end()) { + int carrier = carriers.find(shot)->second; + numHits[carrier]++; + cout << (numHits[carrier] == CARRIER_LENGTH ? "sunk" : "hit") << endl; + hits.insert(shot); + + if ((int)hits.size() == k * CARRIER_LENGTH) { + cerr << "Finished in " << q << " queries." << endl; + v.check(q <= MAX_QUERIES, "used more than ", MAX_QUERIES, " queries"); + break; + } + } else { + cout << "miss" << endl; + } + } + + v.check((int)hits.size() == k * CARRIER_LENGTH, "did not sink all ships within ", 2 * MAX_QUERIES, " queries (aborted)"); + return 0; +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[2], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2023_L/output_validators/output_validator/validation.h b/ICPC/nwerc2023_L/output_validators/output_validator/validation.h new file mode 100644 index 0000000000000000000000000000000000000000..3cf57451e6b4bc626684cb8496ed28eee8cd1bea --- /dev/null +++ b/ICPC/nwerc2023_L/output_validators/output_validator/validation.h @@ -0,0 +1,1471 @@ +#pragma once +// A header library to safely parse team input. +// It does not support floating points or big integers. +// Author: Ragnar Groot Koerkamp + +// The easiest way to use this is to symlink it from a validator directory, +// so that it will be picked up when creating a contest zip. + +// The default checking behaviour is lenient for both white space and case. +// When validating .in and .ans files, the case_sensitive and +// space_change_sensitive flags should be passed. When validating team output, +// the flags in problem.yaml should be used. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const std::string_view case_sensitive_flag = "case_sensitive"; +const std::string_view ws_sensitive_flag = "space_change_sensitive"; +const std::string_view constraints_file_flag = "--constraints_file"; +const std::string_view generate_flag = "--generate"; +const std::string_view generate_binary_substring = "generat"; + +inline struct ArbitraryTag { + static constexpr bool unique = false; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Arbitrary; +inline struct UniqueTag : ArbitraryTag { + static constexpr bool unique = true; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Unique; +inline struct IncreasingTag : ArbitraryTag { + static constexpr bool increasing = true; +} Increasing; +inline struct DecreasingTag : ArbitraryTag { + static constexpr bool decreasing = true; +} Decreasing; +inline struct StrictlyIncreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool increasing = true; +} StrictlyIncreasing; +inline struct StrictlyDecreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool decreasing = true; +} StrictlyDecreasing; + +template +struct Merge : T... { + static constexpr bool unique = (T::unique || ...); + static constexpr bool strict = (T::strict || ...); + static constexpr bool increasing = (T::increasing || ...); + static constexpr bool decreasing = (T::decreasing || ...); +}; + +template and std::is_base_of_v, int> = 0> +auto operator|(T1 /*unused*/, T2 /*unused*/) { + return Merge(); +} + +enum Separator { Space, Newline }; + +// this contains some specific code which emulates c++20 features +namespace cpp20 { + +constexpr int countl_zero(unsigned long long x) { + int res = 64; + for(int i = 32; i > 0; i >>= 1) { + if((x >> i) > 0) { + res -= i; + x >>= i; + } + } + if(x > 0) res--; + return res; +} + +int popcount(unsigned long long x) { + return static_cast(std::bitset<64>(x).count()); +} + +constexpr long double PI = 3.141592653589793238462643383279502884l; + +} // namespace cpp20 + +namespace Random { + +constexpr unsigned int default_seed = 3141592653; // some digits of PI + +unsigned long long bits64(std::mt19937_64& rng) { + static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull); + static_assert(std::mt19937_64::min() == 0ull); + return rng(); +} + +// generates a uniform real in [0, 1) +long double real64(std::mt19937_64& rng) { + // a long double can represent more than 2^64 values in the range [0, 1)... + // another problem is that real64() < 1.0/3.0 is technically biased. + long double res = bits64(rng) / 0x1.0p64l; + res += bits64(rng) / 0x1.0p128l; + assert(res < 1.0l); + return res; +} + +bool bit(std::mt19937_64& rng) { + return cpp20::popcount(bits64(rng)) & 1; +} + +} // namespace Random + +template +constexpr bool is_number_v = std::is_same_v or std::is_same_v; + +namespace Generators { + +template +struct ConstGenerator { + static_assert(is_number_v or std::is_same_v or std::is_same_v); + static constexpr std::string_view name = "const"; + using Args = std::tuple; + + const T const_; + + explicit ConstGenerator(T val) : const_(std::move(val)) {} + + // For char and string, the constant store has a different type than the min and max length + // passed in. + template + T operator()(U low, U high, std::mt19937_64& rng) const { + return std::clamp(const_, low, high); + } +}; + +struct MinGenerator { + static constexpr std::string_view name = "min"; + using Args = std::tuple<>; + + explicit MinGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return low; + } +}; + +struct MaxGenerator { + static constexpr std::string_view name = "max"; + using Args = std::tuple<>; + + explicit MaxGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return high; + } +}; + +struct UniformGenerator { + static constexpr std::string_view name = "uniform"; + using Args = std::tuple<>; + + explicit UniformGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + if(low == high) return low; + + if constexpr(std::is_same_v) { + assert(low < high); + // Since C++20 we can assume Two's Complement but any sane system used it before anyway. + // Rejection sampling is not as fast as possible but definitely unbiased. + auto ul = static_cast(low); + auto uh = static_cast(high); + int shitfs = cpp20::countl_zero(uh - ul); + unsigned long long res; + do { + res = Random::bits64(rng) >> shitfs; + } while(res > uh - ul); + return static_cast(res + ul); + } else { + assert(low < high); + return low + Random::real64(rng) * (high - low); + } + } +}; + +template +struct RangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "range"; + using Args = std::tuple; + + const T low_, high_; + + explicit RangeGenerator(T low, T high) : low_(low), high_(high) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng); + } +}; + +template +struct StepRangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "steprange"; + using Args = std::tuple; + + const T low_, high_, step_; + + explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + // round up low to the first multiple of step_. + T start; + if(low <= low_) { + start = low_; + } else { + // first multiple of low_+k*step_ >= low + start = low_ + (long long)((low - low_) / step_) * step_; + if(start < low) start += step_; + assert(low <= start && start < low + step_); + } + long long maxsteps = (std::min(high, high_) - start) / step_; + long long steps = UniformGenerator()(0ll, maxsteps, rng); + return start + steps * step_; + } +}; + +struct NormalDistributionGenerator { + static constexpr std::string_view name = "normal"; + using T = long double; + using Args = std::tuple; + + const T mean_, stddev_; + + explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) { + assert(stddev_ >= 0); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + T u1 = Random::real64(rng); + T u2 = Random::real64(rng); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + } + return v; + } +}; + +struct ExponentialDistributionGenerator { + static constexpr std::string_view name = "exponential"; + using T = long double; + using Args = std::tuple; + + T lambda_; + + explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + v = low - std::log(Random::real64(rng)) / lambda_; + if(v < high) return v; + } + } +}; + +struct GeometricDistributionGenerator { + static constexpr std::string_view name = "geometric"; + using T = long long; + using Args = std::tuple; + + double p_; + + explicit GeometricDistributionGenerator(double p) : p_(p) { + assert(p_ > 0); + assert(p_ < 1); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + T v; + while(true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric + // distribution[...]" + v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_)); + if(v <= high) return v; + } + } +}; + +struct BinomialDistributionGenerator { + static constexpr std::string_view name = "binomial"; + using T = long long; + using Args = std::tuple; + + long long n_; + double p_; + + explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) { + assert(p_ >= 0); + assert(p_ <= 1); + std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!" + << std::endl; + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + // this will be slow for large n + // (a faster implementation requires efficient poisson sampling) + while(true) { + T v = 0; + for(long long i = 0; i < n_; i++) { + v += Random::real64(rng) < p_ ? 1 : 0; + } + if(v >= low && v <= high) return v; + } + } +}; + +template +struct ChoiceGenerator { + using GeneratorType = std::conditional_t< + std::is_same_v, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, GeometricDistributionGenerator, + BinomialDistributionGenerator>, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, NormalDistributionGenerator, + ExponentialDistributionGenerator>>; + + std::vector> generators_; + double total_weight_; + + template + struct Pack {}; + + template + static A parse_number(std::string_view s) { + static_assert(is_number_v); + if constexpr(std::is_same_v) + return stoll(std::string(s)); + else + return stold(std::string(s)); + } + + template + static A parse_argument(std::string_view& s) { + auto end = s.find_first_of(",)"); + assert(end != std::string_view::npos); + auto v = parse_number(s.substr(0, end)); + s.remove_prefix(end); + // Pop the trailing , or ) + s.remove_prefix(1); + return v; + } + + template + static std::tuple parse_arguments(std::string_view& s, + Pack> /*unused*/) { + std::tuple args{parse_argument(s)...}; + return args; + } + + // Try parsing one generator type from the start of s. + template + static void parse_generator(std::string_view& s, std::optional& out) { + if(out) return; + if(s.substr(0, G::name.size()) != G::name) return; + + // Drop the name. + s.remove_prefix(G::name.size()); + if constexpr(std::tuple_size_v == 0) { + out.emplace(std::in_place_type_t{}); + return; + } + + // Drop the ( + assert(not s.empty() and s.front() == '('); + s.remove_prefix(1); + + auto args = parse_arguments(s, Pack{}); + // Construct the resulting generator in-place in the variant.. + std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t{}, _args...); }, + args); + } + + template + static std::optional parse_generators(std::string_view& s, + Pack> /*unused*/) { + std::optional out; + (parse_generator(s, out), ...); + return out; + } + + explicit ChoiceGenerator(std::string_view s) : total_weight_(0) { + // PARSE + while(not s.empty()) { + auto generator = parse_generators(s, Pack{}); + if(!generator) { + // Check for range syntax: + auto comma = s.find_first_of(",:"); + if(comma == std::string::npos) comma = s.size(); + auto dots = s.find(".."); + if(dots != std::string_view::npos and dots < comma) { + auto start = s.substr(0, dots); + auto end = s.substr(dots + 2, comma - dots - 2); + + generator.emplace(std::in_place_type_t>{}, + parse_number(start), parse_number(end)); + s.remove_prefix(comma); + } + + // Fall back to constant. + if(!generator) { + generator.emplace(std::in_place_type_t>{}, + parse_number(s.substr(0, comma))); + s.remove_prefix(comma); + } + } + + // Parse weight if given. + double weight = 1; + if(not s.empty() and s.front() == ':') { + s.remove_prefix(1); + auto comma = s.find(','); + if(comma == std::string_view::npos) comma = s.size(); + weight = parse_number(s.substr(0, comma)); + s.remove_prefix(comma); + } + + // should now be at , or end + assert(s.empty() or s.front() == ','); + if(not s.empty()) s.remove_prefix(1); + generators_.emplace_back(std::move(*generator), weight); + total_weight_ += weight; + } + } + + T operator()(T low, T high, std::mt19937_64& rng) const { + Generators::UniformGenerator uniform; + double x = uniform.operator()(0, total_weight_, rng); + for(size_t i = 0; i < generators_.size(); ++i) { + x -= generators_[i].second; + if(x <= 0) + return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first); + } + assert(false); + } +}; + +struct ParamGenerator { + std::variant, ChoiceGenerator> + generator; + explicit ParamGenerator(std::string_view s) : generator(s) {} + + template + T operator()(T low, T high, std::mt19937_64& rng) { + static_assert(is_number_v); + if(std::holds_alternative(generator)) { + generator = ChoiceGenerator(std::get(generator)); + } + return std::get>(generator)(low, high, rng); + } +}; + +} // namespace Generators + +using Generators::ParamGenerator; + +namespace Random { +template +void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) { + Generators::UniformGenerator uniform; + long long n = last - first; + for(long long i = n - 1; i > 0; i--) { + std::swap(first[i], first[uniform(0ll, i, rng)]); + } +} + +template +void shuffle(std::pair& in, std::mt19937_64& rng) { + if(bit(rng)) std::swap(in.first, in.second); +} + +template +auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) { + assert(first != last); + Generators::UniformGenerator uniform; + long long n = last - first; + return first[uniform(0ll, n - 1, rng)]; +} + +template +const T& select(const std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +template +T& select(std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +} // namespace Random + +class Validator { + protected: + Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "", + std::optional seed = std::nullopt, + std::unordered_map params_ = {}) + : in(in_), ws(ws_), case_sensitive(case_), + constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()), + rng(seed.value_or(Random::default_seed)), params(std::move(params_)) { + + std::ios_base::sync_with_stdio(false); + in.tie(nullptr); + + if(gen) return; + if(ws) + in >> std::noskipws; + else + in >> std::skipws; + } + + public: + // No copying, no moving. + Validator(const Validator&) = delete; + Validator(Validator&&) = delete; + void operator=(const Validator&) = delete; + void operator=(Validator&&) = delete; + + // At the end of the scope, check whether the EOF has been reached. + // If so, return AC. Otherwise, return WA. + ~Validator() { + eof(); + write_constraints(); + AC(); + } + + void space() { + if(gen) { + out << ' '; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected space, found EOF."); + if(c != ' ') + expected("space", std::string("\"") + + ((c == '\n' or c == '\r') ? std::string("newline") + : std::string(1, c)) + + "\""); + } + } + + void newline() { + if(gen) { + out << '\n'; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected newline, found EOF."); + if(c != '\n') { + if(c == '\r') + expected("newline", "DOS line ending (\\r)"); + else + expected("newline", std::string("\"") + c + "\""); + } + } + } + + private: + void separator(Separator s) { + switch(s) { + case Separator::Space: space(); break; + case Separator::Newline: newline(); break; + } + } + + template + auto& seen() { + static std::unordered_map> seen; + return seen; + } + template + auto& last_seen() { + static std::unordered_map last_seen; + return last_seen; + } + template + auto& integers_seen() { + static std::unordered_map, std::vector, bool>> + integers_seen; + return integers_seen; + } + template + void reset(std::string name) { + seen().erase(name); + last_seen().erase(name); + integers_seen().erase(name); + } + + template + void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/) { + static_assert(is_number_v); + if(v < low or v > high) { + std::string type_name; + if constexpr(std::is_integral_v) { + type_name = "integer"; + } + if constexpr(std::is_floating_point_v) { + type_name = "float"; + } + expected(name + ": " + type_name + " between " + std::to_string(low) + " and " + + std::to_string(high), + std::to_string(v)); + } + log_constraint(name, low, high, v); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[name].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else { + auto [it, inserted] = last_seen().emplace(name, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + template + void check_string(const std::string& name, int low, int high, const std::string& v, + Tag /*unused*/) { + using T = std::string; + if((int)v.size() < low or (int) v.size() > high) { + expected(name + ": " + "string with" + " length between " + std::to_string(low) + + " and " + std::to_string(high), + v); + } + log_constraint(name, low, high, static_cast(v.size())); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[name].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else if(Tag::increasing or Tag::decreasing) { + auto [it, inserted] = last_seen().emplace(name, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + // Generate a random integer in [low, high] or float in [low, high). + template + T uniform_number(T low, T high) { + assert(low <= high); + Generators::UniformGenerator uniform; + if constexpr(std::is_integral::value) + return uniform.operator()(low, high, rng); + else + return uniform.operator()(low, high, rng); + } + + template + T gen_number(const std::string& name, T low, T high, Tag /*unused*/) { + static_assert(is_number_v); + T v; + + if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + if constexpr(std::is_integral::value) { + auto& [seen_here, remaining_here, use_remaining] = integers_seen()[name]; + + if(use_remaining) { + check(!remaining_here.empty(), name, ": no unique values left"); + v = remaining_here.back(); + remaining_here.pop_back(); + } else { + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + + struct CountIterator { + T v; + T& operator*() { return v; } + T& operator++() { return ++v; } + T operator++(int) { return v++; } + bool operator!=(CountIterator r) { return v != r.v; } + }; + + if(seen_here.size() > (high - low) / 2) { + use_remaining = true; + set_difference(CountIterator{low}, CountIterator{high + 1}, + seen_here.begin(), seen_here.end(), + std::back_inserter(remaining_here)); + } + } + } else { + // For floats, just regenerate numbers until success. + auto& seen_here = seen()[name]; + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + } + + } else { + assert(not Tag::increasing && "Generating increasing sequences is not yet supported!"); + assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!"); + assert((std::is_same::value) && + "Only Unique and Arbitrary are supported!"); + + if(params.find(name) != params.end()) { + v = params.at(name).operator()(low, high, rng); + // This will be checked during input validation of the generated case. + // assert(low <= v and v <= high); + } else { + v = uniform_number(low, high); + } + } + + return v; + } + + std::string gen_string(const std::string& name, long long low, long long high, + std::string_view chars) { + assert(!chars.empty()); + + int len; + if(params.find(name + ".length") != params.end()) + len = params.at(name + ".length").operator()(low, high, rng); + else + len = uniform_number(low, high); + std::string s(len, ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s; + return s; + } + + public: + template + long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}) { + return gen_number(name, low, high, tag); + } + + template + long double gen_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}) { + return gen_number(name, low, high, tag); + } + + private: + template + std::vector gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/) { + static_assert(is_number_v); + std::vector v; + v.reserve(count); + if constexpr(std::is_same_v) { + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + } else if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + std::set seen_here; + if constexpr(std::is_integral_v) { + if(2 * count < high - low) { + for(int i = 0; i < count; ++i) { + // If density < 1/2: retry. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } else { + // If density >= 1/2, crop a random permutation. + v.resize(high - low + 1); + iota(begin(v), end(v), low); + Random::shuffle(begin(v), end(v), rng); + v.resize(count); + } + } else { + for(int i = 0; i < count; ++i) { + // For floats, just regenerate numbers until success. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + constexpr bool integral_strict = Tag::strict and std::is_integral::value; + if(integral_strict) { + assert(params.find(name) == params.end() && + "Parameters are not supported for strict integer values."); + high = high - count + 1; + } + + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + + sort(begin(v), end(v)); + + if(integral_strict) { + for(int i = 0; i < count; ++i) v[i] += i; + } + + if(Tag::decreasing) reverse(begin(v), end(v)); + } + + return v; + } + + public: + template + std::vector gen_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}) { + return gen_numbers(name, count, low, high, tag); + } + + template + std::vector gen_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}) { + return gen_numbers(name, count, low, high, tag); + } + + private: + template + T read_number(const std::string& name, T low, T high, Tag tag) { + if(gen) { + auto v = gen_number(name, low, high, tag); + out << std::setprecision(10) << std::fixed << v; + return v; + } + + const auto v = [&] { + if constexpr(std::is_integral::value) + return read_integer(name); + else + return read_float(name); + }(); + + check_number(name, low, high, v, tag); + return v; + } + + // Read a vector of numbers, separated by spaces and ended by a newline. + template + std::vector read_numbers(const std::string& name, int count, T low, T high, Tag tag, + Separator sep) { + if(gen) { + auto v = gen_numbers(name, count, low, high, tag); + + out << std::setprecision(10) << std::fixed; + for(int i = 0; i < count; ++i) { + out << v[i]; + if(i < count - 1) separator(sep); + } + newline(); + + return v; + } + reset(name); + std::vector v(count); + for(int i = 0; i < count; ++i) { + if constexpr(std::is_integral::value) + v[i] = read_integer(name); + else + v[i] = read_float(name); + check_number(name, low, high, v[i], tag); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + public: + template + long long read_integer(const std::string& name, long long low, long long high, + Tag tag = Tag{}) { + return read_number(name, low, high, tag); + } + template + std::vector read_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, Separator sep = Space) { + return read_numbers(name, count, low, high, tag, sep); + } + + template + long double read_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}) { + return read_number(name, low, high, tag); + } + template + std::vector read_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, Separator sep = Space) { + return read_numbers(name, count, low, high, tag, sep); + } + + // Read a vector of strings, separated by spaces and ended by a newline. + template + std::vector read_strings(const std::string& name, int count, int min, int max, + const std::string_view chars = "", Tag tag = Tag(), + Separator sep = Space) { + reset(name); + if(gen) return gen_strings(name, count, min, max, chars, tag, sep); + assert(!gen); + std::vector v(count); + for(int i = 0; i < count; ++i) { + v[i] = read_string(name, min, max, chars, tag); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + template + std::vector gen_strings(const std::string& name, int count, int min, int max, + const std::string_view chars, Tag /*unused*/, + Separator sep) { + assert(!chars.empty()); + + std::vector v(count); + if constexpr(std::is_same::value) { + for(int i = 0; i < count; ++i) { + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else if constexpr(Tag::unique) { + std::set seen_here; + for(int i = 0; i < count; ++i) { + // Just regenerate strings until success. + std::string s; + do { + s = std::string(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + } while(!seen_here.insert(s).second); + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + assert(false && "Generating increasing/decreasing lists of strings is not " + "supported!"); + } + + newline(); + + return v; + } + + // Check the next character. + bool peek(char c, const std::string& name = "") { + if(gen) { + // TODO + // if(not name.empty() and params.contains(name)) { + // return c == params.at(name).operator()(0, 0, rng); + //} + return Random::bit(rng); + } + if(!ws) in >> std::ws; + if(case_sensitive) return in.peek() == std::char_traits::to_int_type(c); + return tolower(in.peek()) == tolower(std::char_traits::to_int_type(c)); + } + + // Read a string and make sure it equals `expected`. + // Takes by value because it needs to lowercase its arguments. + std::string test_strings(std::vector expected, const std::string& name = "") { + if(gen) { + int index = 0; + // TODO + // if(not name.empty() and params.contains(name)) { + // auto s = params.at(name).operator()(0, 0, rng); + // index = std::find(expected.begin(), expected.end(), s) - expected.begin(); + // assert(0 <= index and index < expected.size()); + //} else { + index = expected.size() == 1 ? 0 : uniform_number(0, expected.size() - 1); + //} + out << expected[index]; + return expected[index]; + } + std::string s = get_string(); + lowercase(s); + + for(std::string e : expected) + if(s == lowercase(e)) return s; + + std::string error; + for(const auto& e : expected) { + if(not error.empty()) error += "|"; + error += e; + } + WA("Expected string \"", error, "\", but found ", s); + } + + // Read a string and make sure it equals `expected`. + std::string test_string(std::string expected, const std::string& name = "") { + return test_strings({std::move(expected)}, name); + } + + // Read an arbitrary string of a given length. + template + std::string read_string(const std::string& name, long long min, long long max, + const std::string_view chars = "", Tag tag = Tag()) { + if(gen) { + return gen_string(name, min, max, chars); + } + std::string s = get_string(); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + check_string(name, min, max, s, tag); + return s; + } + + // Read an arbitrary line of a given length. + std::string read_line(const std::string& name, long long min, long long max, + const std::string_view chars = "") { + if(gen) { + // TODO: Params for lines. + assert(!chars.empty()); + + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s << '\n'; + return s; + } + + if(ws) { + char next = in.peek(); + if(min > 0 and isspace(next)) + expected("non empty line", next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected("line", "EOF"); + } + std::string s; + if(!getline(in, s)) expected("line", "nothing"); + long long size = s.size(); + if(size < min || size > max) + expected(name + ": line of length between " + std::to_string(min) + " and " + + std::to_string(max), + s); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + log_constraint(name, min, max, size); + return s; + } + + // Return ACCEPTED verdict. + void eof_and_AC() { + eof(); + AC(); + } + + private: + std::function WA_handler = [] {}; + + public: + void set_WA_handler(std::function f) { WA_handler = std::move(f); } + + // Return WA with the given reason. + template + [[noreturn]] void WA(const Ts&... ts) { + static_assert(sizeof...(Ts) > 0); + + WA_handler(); + + auto pos = get_file_pos(); + std::cerr << pos.first << ":" << pos.second << ": "; + + WA_impl(ts...); + } + + // Check that the condition is true. + template + void check(bool b, const Ts&... ts) { + static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message."); + + if(!b) WA(ts...); + } + + // Log some value in a range. + template + void log_constraint(const std::string& name, T low, T high, T v) { + // All integer types get bounds as long long, all floating point types as long_double. + using U = Bounds, long long, long double>>; + + auto [it, inserted] = bounds.emplace(name, U(name, v, v, low, high)); + assert(std::holds_alternative(it->second)); + auto& done = std::get(it->second); + if(inserted) { + assert(!name.empty() && "Variable names must not be empty."); + assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces."); + } else { + assert(name == done.name && "Variable name must be constant."); + } + if(v < done.min) { + done.min = v; + done.low = low; + } + if(v > done.max) { + done.max = v; + done.high = high; + } + done.has_min |= v == low; + done.has_max |= v == high; + } + + private: + long long read_integer(const std::string& name) { + assert(!gen); + std::string s = get_string("integer"); + if(s.empty()) { + WA(name, ": Want integer, found nothing"); + } + long long v; + try { + auto begin = s.c_str(), end = begin + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, v); + if(ptr != end or ec != std::errc{}) + WA(name, ": Parsing " + s + " as long long failed! Did not process all characters"); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long long!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long long failed!"); + } + // Check for leading zero. + if(v == 0) { + if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s); + } + if(v > 0) { + if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + if(v < 0) { + if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s); + if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + return v; + } + + long double read_float(const std::string& name) { + assert(!gen); + std::string s = get_string("long double"); + long double v; + try { + size_t chars_processed; + v = stold(s, &chars_processed); + if(chars_processed != s.size()) + WA(name, ": Parsing ", s, + " as long double failed! Did not process all characters."); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long double!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long double failed!"); + } + return v; + } + + [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") { + assert(!gen && "Expected is not supported for generators."); + WA("Expected ", exp, ", found ", s.empty() ? "empty string" : s); + } + + template + [[noreturn]] void WA_impl(T t) { + std::cerr << t << std::endl; + exit(ret_WA); + } + + std::pair get_file_pos() { + int line = 1, col = 0; + in.clear(); + auto originalPos = in.tellg(); + if(originalPos < 0) return {-1, -1}; + in.seekg(0); + char c; + while((in.tellg() < originalPos) && in.get(c)) { + if(c == '\n') + ++line, col = 0; + else + ++col; + } + return {line, col}; + } + + template + [[noreturn]] void WA_impl(T t, Ts... ts) { + std::cerr << t; + WA_impl(ts...); + } + + std::string get_string(const std::string& wanted = "string") { + assert(!gen && "get_string is not supported for generators."); + if(ws) { + char next = in.peek(); + if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected(wanted, "EOF"); + } + + std::string s; + if(in >> s) { + return s; + } + expected(wanted, "nothing"); + } + + // Return ACCEPTED verdict. + void AC() const { + if(gen) { + // nothing + return; + } + + exit(ret_AC); + } + + void eof() { + if(gen) { + out.flush(); + fclose(stdout); + return; + } + if(in.eof()) return; + // Sometimes EOF hasn't been triggered yet. + if(!ws) in >> std::ws; + char c = in.get(); + if(c == std::char_traits::eof()) return; + std::string got = std::string("\"") + char(c) + '"'; + if(c == '\n') got = "newline"; + expected("EOF", got); + } + + public: + // Convert a string to lowercase is matching is not case sensitive. + std::string& lowercase(std::string& s) const { + if(case_sensitive) return s; + transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; + } + + private: + // Keep track of the min/max value read at every call site. + template + struct Bounds { + Bounds(std::string name_, T min_, T max_, T low_, T high_) + : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT + std::string name; + T min, max; // Smallest / largest value observed + T low, high; // Bounds + bool has_min = false, has_max = false; + }; + + std::unordered_map, Bounds>> bounds; + + void write_constraints() { + if(constraints_file_path.empty()) return; + + std::ofstream os(constraints_file_path); + + for(const auto& [name, bound] : bounds) { + std::visit( + [&](const auto& b) { + os << "LocationNotSupported:" << b.name << " " << b.name << " " << b.has_min + << " " << b.has_max << " " << b.min << " " << b.max << " " << b.low << " " + << b.high << std::endl; + }, + bound); + } + } + + static const int ret_AC = 42, ret_WA = 43; + std::istream& in = std::cin; + std::ostream& out = std::cout; + + public: + const bool ws = true; + const bool case_sensitive = true; + const std::string constraints_file_path; + const bool gen = false; + + std::mt19937_64 rng; + + private: + std::unordered_map params; + + public: + std::string_view get_param(std::string_view name, std::string_view default_) { + auto it = params.find(std::string(name)); + if(it == params.end()) return default_; + return std::get(it->second.generator); + } + + protected: + static std::string get_constraints_file(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == constraints_file_flag) { + if(i + 1 < argc) return argv[i + 1]; + std::cerr << constraints_file_flag << " should be followed by a file path!"; + exit(1); + } + } + return {}; + } +}; + +class Generator : public Validator { + public: + explicit Generator(unsigned int seed) + : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {} +}; + +class InputValidator : public Validator { + public: + // An InputValidator is always both whitespace and case sensitive. + explicit InputValidator(int argc = 0, char** argv = nullptr) + : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv), + get_params(argc, argv)) {} + + private: + static std::optional get_seed(int argc, char** argv) { + for(int i = 1; i < argc - 1; ++i) { + if(argv[i] == generate_flag) { + return std::stol(argv[i + 1]); + } + } + // If no --generate is given, but `generat` is a substring of the binary path, + // use the first argument as seed. + if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) { + return std::stol(argv[1]); + } + return std::nullopt; + } + + static std::unordered_map get_params(int argc, char** argv) { + std::unordered_map params; + for(int i = 1; i < argc - 1; ++i) { + if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue; + if(argv[i] == generate_flag) { + continue; + } + std::string_view name(argv[i] + 1); + std::string_view value(argv[i + 1]); + params.insert({std::string(name), ParamGenerator(value)}); + } + return params; + } +}; + +class OutputValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_, + get_constraints_file(argc, argv)) {} + + private: + static bool is_ws_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == ws_sensitive_flag) return true; + } + return false; + } + + static bool is_case_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == case_sensitive_flag) return true; + } + return false; + } +}; \ No newline at end of file diff --git a/ICPC/nwerc2024_A/data.zip b/ICPC/nwerc2024_A/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..200b6c85195e74dd89360b032e0a1ccfb8b4327d --- /dev/null +++ b/ICPC/nwerc2024_A/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f427b392a57c476a2dc77084d7bf49b72d1f78d314147cfac8907778411c0b7 +size 1089950 diff --git a/ICPC/nwerc2024_A/init.yml b/ICPC/nwerc2024_A/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f3dc1ff73e7f7a3f696666b323d69269ea052d96 --- /dev/null +++ b/ICPC/nwerc2024_A/init.yml @@ -0,0 +1,101 @@ +archive: data.zip +test_cases: +- in: 04-min.in + out: 04-min.ans + points: 1 +- in: 05-manual.in + out: 05-manual.ans + points: 1 +- in: 06-max.in + out: 06-max.ans + points: 1 +- in: 07-max.in + out: 07-max.ans + points: 1 +- in: 08-max.in + out: 08-max.ans + points: 1 +- in: 09-random.in + out: 09-random.ans + points: 1 +- in: 10-random.in + out: 10-random.ans + points: 1 +- in: 11-random.in + out: 11-random.ans + points: 1 +- in: 12-random.in + out: 12-random.ans + points: 1 +- in: 13-random.in + out: 13-random.ans + points: 1 +- in: 14-random.in + out: 14-random.ans + points: 1 +- in: 15-random.in + out: 15-random.ans + points: 1 +- in: 16-random.in + out: 16-random.ans + points: 1 +- in: 17-capsstart.in + out: 17-capsstart.ans + points: 1 +- in: 18-capsstart.in + out: 18-capsstart.ans + points: 1 +- in: 19-capsstart.in + out: 19-capsstart.ans + points: 1 +- in: 20-sorted.in + out: 20-sorted.ans + points: 1 +- in: 21-sorted.in + out: 21-sorted.ans + points: 1 +- in: 22-sorted.in + out: 22-sorted.ans + points: 1 +- in: 23-revsorted.in + out: 23-revsorted.ans + points: 1 +- in: 24-revsorted.in + out: 24-revsorted.ans + points: 1 +- in: 25-revsorted.in + out: 25-revsorted.ans + points: 1 +- in: 26-similar.in + out: 26-similar.ans + points: 1 +- in: 27-similar.in + out: 27-similar.ans + points: 1 +- in: 28-similar.in + out: 28-similar.ans + points: 1 +- in: 29-similar.in + out: 29-similar.ans + points: 1 +- in: 30-difflen.in + out: 30-difflen.ans + points: 1 +- in: 31-difflen.in + out: 31-difflen.ans + points: 1 +- in: 32-difflen.in + out: 32-difflen.ans + points: 1 +- in: 33-difflen.in + out: 33-difflen.ans + points: 1 +- in: 34-longcmp.in + out: 34-longcmp.ans + points: 1 +- in: 35-longcmp.in + out: 35-longcmp.ans + points: 1 +- in: 36-longcmp.in + out: 36-longcmp.ans + points: 1 diff --git a/ICPC/nwerc2024_B/data.zip b/ICPC/nwerc2024_B/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..fcdc1d0bff9e632e6ad12781a170e18c967e3451 --- /dev/null +++ b/ICPC/nwerc2024_B/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f25a84af021854766d974f9012e5d9427c190ee5e8cf14d7f2ca3fb3eb806705 +size 36613298 diff --git a/ICPC/nwerc2024_B/init.yml b/ICPC/nwerc2024_B/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac13f6407aac8f89c10f7d76e10633486358aef1 --- /dev/null +++ b/ICPC/nwerc2024_B/init.yml @@ -0,0 +1,314 @@ +archive: data.zip +test_cases: +- in: 004-min.in + out: 004-min.ans + points: 1 +- in: 005-min.in + out: 005-min.ans + points: 1 +- in: 006-min.in + out: 006-min.ans + points: 1 +- in: 007-min.in + out: 007-min.ans + points: 1 +- in: 008-tiny.in + out: 008-tiny.ans + points: 1 +- in: 009-tiny.in + out: 009-tiny.ans + points: 1 +- in: 010-tiny.in + out: 010-tiny.ans + points: 1 +- in: 011-tiny.in + out: 011-tiny.ans + points: 1 +- in: 012-tiny.in + out: 012-tiny.ans + points: 1 +- in: 013-tiny.in + out: 013-tiny.ans + points: 1 +- in: 014-tiny.in + out: 014-tiny.ans + points: 1 +- in: 015-tiny.in + out: 015-tiny.ans + points: 1 +- in: 016-disconnected.in + out: 016-disconnected.ans + points: 1 +- in: 017-disconnected.in + out: 017-disconnected.ans + points: 1 +- in: 018-disconnected.in + out: 018-disconnected.ans + points: 1 +- in: 019-disconnected.in + out: 019-disconnected.ans + points: 1 +- in: 020-disconnected.in + out: 020-disconnected.ans + points: 1 +- in: 021-disconnected.in + out: 021-disconnected.ans + points: 1 +- in: 022-disconnected.in + out: 022-disconnected.ans + points: 1 +- in: 023-random-small-01.in + out: 023-random-small-01.ans + points: 1 +- in: 024-random-small-02.in + out: 024-random-small-02.ans + points: 1 +- in: 025-random-small-03.in + out: 025-random-small-03.ans + points: 1 +- in: 026-random-small-04.in + out: 026-random-small-04.ans + points: 1 +- in: 027-random-small-05.in + out: 027-random-small-05.ans + points: 1 +- in: 028-random-small-06.in + out: 028-random-small-06.ans + points: 1 +- in: 029-random-small-07.in + out: 029-random-small-07.ans + points: 1 +- in: 030-random-small-08.in + out: 030-random-small-08.ans + points: 1 +- in: 031-random-small-09.in + out: 031-random-small-09.ans + points: 1 +- in: 032-random-small-10.in + out: 032-random-small-10.ans + points: 1 +- in: 033-random-small-11.in + out: 033-random-small-11.ans + points: 1 +- in: 034-random-small-12.in + out: 034-random-small-12.ans + points: 1 +- in: 035-random-small-13.in + out: 035-random-small-13.ans + points: 1 +- in: 036-random-small-14.in + out: 036-random-small-14.ans + points: 1 +- in: 037-random-small-15.in + out: 037-random-small-15.ans + points: 1 +- in: 038-random-small-16.in + out: 038-random-small-16.ans + points: 1 +- in: 039-random-small-17.in + out: 039-random-small-17.ans + points: 1 +- in: 040-random-small-18.in + out: 040-random-small-18.ans + points: 1 +- in: 041-random-small-19.in + out: 041-random-small-19.ans + points: 1 +- in: 042-random-small-20.in + out: 042-random-small-20.ans + points: 1 +- in: 043-fixed-solution-small.in + out: 043-fixed-solution-small.ans + points: 1 +- in: 044-fixed-solution-large.in + out: 044-fixed-solution-large.ans + points: 1 +- in: 045-disjoint-paths-of-length-8.in + out: 045-disjoint-paths-of-length-8.ans + points: 1 +- in: 046-disjoint-paths-of-length-13.in + out: 046-disjoint-paths-of-length-13.ans + points: 1 +- in: 047-random-01.in + out: 047-random-01.ans + points: 1 +- in: 048-random-02.in + out: 048-random-02.ans + points: 1 +- in: 049-random-03.in + out: 049-random-03.ans + points: 1 +- in: 050-random-04.in + out: 050-random-04.ans + points: 1 +- in: 051-random-05.in + out: 051-random-05.ans + points: 1 +- in: 052-random-06.in + out: 052-random-06.ans + points: 1 +- in: 053-random-07.in + out: 053-random-07.ans + points: 1 +- in: 054-random-08.in + out: 054-random-08.ans + points: 1 +- in: 055-random-09.in + out: 055-random-09.ans + points: 1 +- in: 056-random-10.in + out: 056-random-10.ans + points: 1 +- in: 057-small-random-1.in + out: 057-small-random-1.ans + points: 1 +- in: 058-small-random-2.in + out: 058-small-random-2.ans + points: 1 +- in: 059-large-random-01.in + out: 059-large-random-01.ans + points: 1 +- in: 060-large-random-02.in + out: 060-large-random-02.ans + points: 1 +- in: 061-large-random-03.in + out: 061-large-random-03.ans + points: 1 +- in: 062-large-random-04.in + out: 062-large-random-04.ans + points: 1 +- in: 063-large-random-05.in + out: 063-large-random-05.ans + points: 1 +- in: 064-large-random-06.in + out: 064-large-random-06.ans + points: 1 +- in: 065-large-random-07.in + out: 065-large-random-07.ans + points: 1 +- in: 066-large-random-08.in + out: 066-large-random-08.ans + points: 1 +- in: 067-large-random-09.in + out: 067-large-random-09.ans + points: 1 +- in: 068-large-random-10.in + out: 068-large-random-10.ans + points: 1 +- in: 069-all-same-bits-random-1.in + out: 069-all-same-bits-random-1.ans + points: 1 +- in: 070-all-same-bits-random-2.in + out: 070-all-same-bits-random-2.ans + points: 1 +- in: 071-multiple_components-1.in + out: 071-multiple_components-1.ans + points: 1 +- in: 072-multiple_components-2.in + out: 072-multiple_components-2.ans + points: 1 +- in: 073-multiple_components-3.in + out: 073-multiple_components-3.ans + points: 1 +- in: 074-multiple_components-4.in + out: 074-multiple_components-4.ans + points: 1 +- in: 075-multiple_components-5.in + out: 075-multiple_components-5.ans + points: 1 +- in: 076-bipartite_random.in + out: 076-bipartite_random.ans + points: 1 +- in: 077-bipartite_with_mutations-1.in + out: 077-bipartite_with_mutations-1.ans + points: 1 +- in: 078-bipartite_with_mutations-2.in + out: 078-bipartite_with_mutations-2.ans + points: 1 +- in: 079-bipartite_with_mutations-3.in + out: 079-bipartite_with_mutations-3.ans + points: 1 +- in: 080-bipartite_with_mutations-4.in + out: 080-bipartite_with_mutations-4.ans + points: 1 +- in: 081-bipartite_with_mutations-5.in + out: 081-bipartite_with_mutations-5.ans + points: 1 +- in: 082-perfect-path-1.in + out: 082-perfect-path-1.ans + points: 1 +- in: 083-path-with-mutations-1.in + out: 083-path-with-mutations-1.ans + points: 1 +- in: 084-path-with-mutations-2.in + out: 084-path-with-mutations-2.ans + points: 1 +- in: 085-perfect-cycle-1.in + out: 085-perfect-cycle-1.ans + points: 1 +- in: 086-cycle-with-nonzero-length-mod-four-1.in + out: 086-cycle-with-nonzero-length-mod-four-1.ans + points: 1 +- in: 087-cycle-with-mutations-1.in + out: 087-cycle-with-mutations-1.ans + points: 1 +- in: 088-biganswer.in + out: 088-biganswer.ans + points: 1 +- in: 089-bigcycle.in + out: 089-bigcycle.ans + points: 1 +- in: 090-dag.in + out: 090-dag.ans + points: 1 +- in: 091-dag.in + out: 091-dag.ans + points: 1 +- in: 092-dag.in + out: 092-dag.ans + points: 1 +- in: 093-dag.in + out: 093-dag.ans + points: 1 +- in: 094-dag.in + out: 094-dag.ans + points: 1 +- in: 095-dag.in + out: 095-dag.ans + points: 1 +- in: 096-dag.in + out: 096-dag.ans + points: 1 +- in: 097-dag.in + out: 097-dag.ans + points: 1 +- in: 098-dag.in + out: 098-dag.ans + points: 1 +- in: 099-tree.in + out: 099-tree.ans + points: 1 +- in: 100-tree.in + out: 100-tree.ans + points: 1 +- in: 101-tree.in + out: 101-tree.ans + points: 1 +- in: 102-tree.in + out: 102-tree.ans + points: 1 +- in: 103-tree.in + out: 103-tree.ans + points: 1 +- in: 104-tree.in + out: 104-tree.ans + points: 1 +- in: 105-no_edges_zeros.in + out: 105-no_edges_zeros.ans + points: 1 +- in: 106-no_edges_ones.in + out: 106-no_edges_ones.ans + points: 1 +- in: 107-no_edges_mix.in + out: 107-no_edges_mix.ans + points: 1 diff --git a/ICPC/nwerc2024_C/data.zip b/ICPC/nwerc2024_C/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..4523bab4216b10606de2ce1091bb3fe38eff1862 --- /dev/null +++ b/ICPC/nwerc2024_C/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:320bd1557366e3d9bf71edde99c5d647e612f6620238a99888ac3915502e91f2 +size 40243 diff --git a/ICPC/nwerc2024_C/init.yml b/ICPC/nwerc2024_C/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..dee6db441dd7042e0b5c657c2f093df149b7ec38 --- /dev/null +++ b/ICPC/nwerc2024_C/init.yml @@ -0,0 +1,431 @@ +archive: data.zip +test_cases: +- in: 003-uniform.in + out: 003-uniform.ans + points: 1 +- in: 004-uniform.in + out: 004-uniform.ans + points: 1 +- in: 005-uniform.in + out: 005-uniform.ans + points: 1 +- in: 006-uniform.in + out: 006-uniform.ans + points: 1 +- in: 007-uniform.in + out: 007-uniform.ans + points: 1 +- in: 008-uniform.in + out: 008-uniform.ans + points: 1 +- in: 009-uniform.in + out: 009-uniform.ans + points: 1 +- in: 010-uniform.in + out: 010-uniform.ans + points: 1 +- in: 011-uniform.in + out: 011-uniform.ans + points: 1 +- in: 012-uniform.in + out: 012-uniform.ans + points: 1 +- in: 013-uniform.in + out: 013-uniform.ans + points: 1 +- in: 014-clustered.in + out: 014-clustered.ans + points: 1 +- in: 015-clustered.in + out: 015-clustered.ans + points: 1 +- in: 016-clustered.in + out: 016-clustered.ans + points: 1 +- in: 017-clustered.in + out: 017-clustered.ans + points: 1 +- in: 018-clustered.in + out: 018-clustered.ans + points: 1 +- in: 019-clustered.in + out: 019-clustered.ans + points: 1 +- in: 020-clustered.in + out: 020-clustered.ans + points: 1 +- in: 021-clustered.in + out: 021-clustered.ans + points: 1 +- in: 022-clustered.in + out: 022-clustered.ans + points: 1 +- in: 023-clustered.in + out: 023-clustered.ans + points: 1 +- in: 024-clustered.in + out: 024-clustered.ans + points: 1 +- in: 025-clustered.in + out: 025-clustered.ans + points: 1 +- in: 026-1-081.in + out: 026-1-081.ans + points: 1 +- in: 027-1-086.in + out: 027-1-086.ans + points: 1 +- in: 028-minimum.in + out: 028-minimum.ans + points: 1 +- in: 029-minimum.in + out: 029-minimum.ans + points: 1 +- in: 030-maximum.in + out: 030-maximum.ans + points: 1 +- in: 031-pattern-001.in + out: 031-pattern-001.ans + points: 1 +- in: 032-pattern-002.in + out: 032-pattern-002.ans + points: 1 +- in: 033-pattern-017.in + out: 033-pattern-017.ans + points: 1 +- in: 034-pattern-025.in + out: 034-pattern-025.ans + points: 1 +- in: 035-pattern-042.in + out: 035-pattern-042.ans + points: 1 +- in: 036-pattern-044.in + out: 036-pattern-044.ans + points: 1 +- in: 037-pattern-050.in + out: 037-pattern-050.ans + points: 1 +- in: 038-pattern-066.in + out: 038-pattern-066.ans + points: 1 +- in: 039-pattern-070.in + out: 039-pattern-070.ans + points: 1 +- in: 040-pattern-075.in + out: 040-pattern-075.ans + points: 1 +- in: 041-pattern-078.in + out: 041-pattern-078.ans + points: 1 +- in: 042-pattern-090.in + out: 042-pattern-090.ans + points: 1 +- in: 043-pattern-097.in + out: 043-pattern-097.ans + points: 1 +- in: 044-pattern-119.in + out: 044-pattern-119.ans + points: 1 +- in: 045-pattern-120.in + out: 045-pattern-120.ans + points: 1 +- in: 046-pattern-121.in + out: 046-pattern-121.ans + points: 1 +- in: 047-pattern-127.in + out: 047-pattern-127.ans + points: 1 +- in: 048-pattern-147.in + out: 048-pattern-147.ans + points: 1 +- in: 049-pattern-149.in + out: 049-pattern-149.ans + points: 1 +- in: 050-pattern-155.in + out: 050-pattern-155.ans + points: 1 +- in: 051-pattern-162.in + out: 051-pattern-162.ans + points: 1 +- in: 052-pattern-163.in + out: 052-pattern-163.ans + points: 1 +- in: 053-pattern-164.in + out: 053-pattern-164.ans + points: 1 +- in: 054-pattern-174.in + out: 054-pattern-174.ans + points: 1 +- in: 055-pattern-175.in + out: 055-pattern-175.ans + points: 1 +- in: 056-pattern-201.in + out: 056-pattern-201.ans + points: 1 +- in: 057-pattern-222.in + out: 057-pattern-222.ans + points: 1 +- in: 058-pattern-224.in + out: 058-pattern-224.ans + points: 1 +- in: 059-pattern-231.in + out: 059-pattern-231.ans + points: 1 +- in: 060-pattern-237.in + out: 060-pattern-237.ans + points: 1 +- in: 061-pattern-239.in + out: 061-pattern-239.ans + points: 1 +- in: 062-pattern-246.in + out: 062-pattern-246.ans + points: 1 +- in: 063-pattern-282.in + out: 063-pattern-282.ans + points: 1 +- in: 064-random-pattern-01.in + out: 064-random-pattern-01.ans + points: 1 +- in: 065-random-pattern-02.in + out: 065-random-pattern-02.ans + points: 1 +- in: 066-random-pattern-03.in + out: 066-random-pattern-03.ans + points: 1 +- in: 067-random-pattern-04.in + out: 067-random-pattern-04.ans + points: 1 +- in: 068-random-pattern-05.in + out: 068-random-pattern-05.ans + points: 1 +- in: 069-random-pattern-06.in + out: 069-random-pattern-06.ans + points: 1 +- in: 070-random-pattern-07.in + out: 070-random-pattern-07.ans + points: 1 +- in: 071-random-pattern-08.in + out: 071-random-pattern-08.ans + points: 1 +- in: 072-random-pattern-09.in + out: 072-random-pattern-09.ans + points: 1 +- in: 073-random-pattern-10.in + out: 073-random-pattern-10.ans + points: 1 +- in: 074-random-pattern-11.in + out: 074-random-pattern-11.ans + points: 1 +- in: 075-random-pattern-12.in + out: 075-random-pattern-12.ans + points: 1 +- in: 076-random-pattern-13.in + out: 076-random-pattern-13.ans + points: 1 +- in: 077-random-pattern-14.in + out: 077-random-pattern-14.ans + points: 1 +- in: 078-random-pattern-15.in + out: 078-random-pattern-15.ans + points: 1 +- in: 079-random-pattern-16.in + out: 079-random-pattern-16.ans + points: 1 +- in: 080-random-pattern-17.in + out: 080-random-pattern-17.ans + points: 1 +- in: 081-random-pattern-18.in + out: 081-random-pattern-18.ans + points: 1 +- in: 082-random-pattern-19.in + out: 082-random-pattern-19.ans + points: 1 +- in: 083-random-pattern-20.in + out: 083-random-pattern-20.ans + points: 1 +- in: 084-random-pattern-21.in + out: 084-random-pattern-21.ans + points: 1 +- in: 085-random-pattern-22.in + out: 085-random-pattern-22.ans + points: 1 +- in: 086-random-pattern-23.in + out: 086-random-pattern-23.ans + points: 1 +- in: 087-random-pattern-24.in + out: 087-random-pattern-24.ans + points: 1 +- in: 088-random-pattern-25.in + out: 088-random-pattern-25.ans + points: 1 +- in: 089-random-pattern-26.in + out: 089-random-pattern-26.ans + points: 1 +- in: 090-random-pattern-27.in + out: 090-random-pattern-27.ans + points: 1 +- in: 091-random-pattern-28.in + out: 091-random-pattern-28.ans + points: 1 +- in: 092-random-pattern-29.in + out: 092-random-pattern-29.ans + points: 1 +- in: 093-random-pattern-30.in + out: 093-random-pattern-30.ans + points: 1 +- in: 094-random-pattern-31.in + out: 094-random-pattern-31.ans + points: 1 +- in: 095-random-pattern-32.in + out: 095-random-pattern-32.ans + points: 1 +- in: 096-random-pattern-33.in + out: 096-random-pattern-33.ans + points: 1 +- in: 097-random-pattern-34.in + out: 097-random-pattern-34.ans + points: 1 +- in: 098-random-pattern-35.in + out: 098-random-pattern-35.ans + points: 1 +- in: 099-random-pattern-36.in + out: 099-random-pattern-36.ans + points: 1 +- in: 100-random-pattern-37.in + out: 100-random-pattern-37.ans + points: 1 +- in: 101-random-pattern-38.in + out: 101-random-pattern-38.ans + points: 1 +- in: 102-random-pattern-39.in + out: 102-random-pattern-39.ans + points: 1 +- in: 103-random-pattern-40.in + out: 103-random-pattern-40.ans + points: 1 +- in: 104-random-pattern-41.in + out: 104-random-pattern-41.ans + points: 1 +- in: 105-random-pattern-42.in + out: 105-random-pattern-42.ans + points: 1 +- in: 106-random-pattern-43.in + out: 106-random-pattern-43.ans + points: 1 +- in: 107-random-pattern-44.in + out: 107-random-pattern-44.ans + points: 1 +- in: 108-random-pattern-45.in + out: 108-random-pattern-45.ans + points: 1 +- in: 109-random-pattern-46.in + out: 109-random-pattern-46.ans + points: 1 +- in: 110-random-pattern-47.in + out: 110-random-pattern-47.ans + points: 1 +- in: 111-random-pattern-48.in + out: 111-random-pattern-48.ans + points: 1 +- in: 112-random-pattern-49.in + out: 112-random-pattern-49.ans + points: 1 +- in: 113-random-pattern-50.in + out: 113-random-pattern-50.ans + points: 1 +- in: 114-random-pattern-clustered-01.in + out: 114-random-pattern-clustered-01.ans + points: 1 +- in: 115-random-pattern-clustered-02.in + out: 115-random-pattern-clustered-02.ans + points: 1 +- in: 116-random-pattern-clustered-03.in + out: 116-random-pattern-clustered-03.ans + points: 1 +- in: 117-random-pattern-clustered-04.in + out: 117-random-pattern-clustered-04.ans + points: 1 +- in: 118-random-pattern-clustered-05.in + out: 118-random-pattern-clustered-05.ans + points: 1 +- in: 119-random-pattern-clustered-06.in + out: 119-random-pattern-clustered-06.ans + points: 1 +- in: 120-random-pattern-clustered-07.in + out: 120-random-pattern-clustered-07.ans + points: 1 +- in: 121-random-pattern-clustered-08.in + out: 121-random-pattern-clustered-08.ans + points: 1 +- in: 122-random-pattern-clustered-09.in + out: 122-random-pattern-clustered-09.ans + points: 1 +- in: 123-random-pattern-clustered-10.in + out: 123-random-pattern-clustered-10.ans + points: 1 +- in: 124-random-pattern-clustered-11.in + out: 124-random-pattern-clustered-11.ans + points: 1 +- in: 125-random-pattern-clustered-12.in + out: 125-random-pattern-clustered-12.ans + points: 1 +- in: 126-random-pattern-clustered-13.in + out: 126-random-pattern-clustered-13.ans + points: 1 +- in: 127-random-pattern-clustered-14.in + out: 127-random-pattern-clustered-14.ans + points: 1 +- in: 128-random-pattern-clustered-15.in + out: 128-random-pattern-clustered-15.ans + points: 1 +- in: 129-random-pattern-clustered-16.in + out: 129-random-pattern-clustered-16.ans + points: 1 +- in: 130-random-pattern-clustered-17.in + out: 130-random-pattern-clustered-17.ans + points: 1 +- in: 131-random-pattern-clustered-18.in + out: 131-random-pattern-clustered-18.ans + points: 1 +- in: 132-random-pattern-clustered-19.in + out: 132-random-pattern-clustered-19.ans + points: 1 +- in: 133-random-pattern-clustered-20.in + out: 133-random-pattern-clustered-20.ans + points: 1 +- in: 134-tricky-pentagon-1.in + out: 134-tricky-pentagon-1.ans + points: 1 +- in: 135-tricky-pentagon-2.in + out: 135-tricky-pentagon-2.ans + points: 1 +- in: 136-tricky-pentagon-3.in + out: 136-tricky-pentagon-3.ans + points: 1 +- in: 137-tricky-pentagon-4.in + out: 137-tricky-pentagon-4.ans + points: 1 +- in: 138-tricky-pentagon-5.in + out: 138-tricky-pentagon-5.ans + points: 1 +- in: 139-tricky-pentagon-6.in + out: 139-tricky-pentagon-6.ans + points: 1 +- in: 140-middle-string-1.in + out: 140-middle-string-1.ans + points: 1 +- in: 141-middle-string-2.in + out: 141-middle-string-2.ans + points: 1 +- in: 142-middle-string-3.in + out: 142-middle-string-3.ans + points: 1 +- in: 143-middle-string-4.in + out: 143-middle-string-4.ans + points: 1 +- in: 144-middle-string-5.in + out: 144-middle-string-5.ans + points: 1 +- in: 145-middle-string-6.in + out: 145-middle-string-6.ans + points: 1 diff --git a/ICPC/nwerc2024_D/data.zip b/ICPC/nwerc2024_D/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..67160be7ef8784ac934f674c83b5facb9ab18f25 --- /dev/null +++ b/ICPC/nwerc2024_D/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:958dee059f4c5dd117c58110903a0f5e910db32d1db808a5b5a09b4ef98e3d06 +size 38579 diff --git a/ICPC/nwerc2024_D/init.yml b/ICPC/nwerc2024_D/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..11a6f6004c5fea1d64eaa86e08ce1017c2a4094e --- /dev/null +++ b/ICPC/nwerc2024_D/init.yml @@ -0,0 +1,386 @@ +archive: data.zip +test_cases: +- in: 004-random.in + out: 004-random.ans + points: 1 +- in: 005-random.in + out: 005-random.ans + points: 1 +- in: 006-random.in + out: 006-random.ans + points: 1 +- in: 007-random.in + out: 007-random.ans + points: 1 +- in: 008-random.in + out: 008-random.ans + points: 1 +- in: 009-random.in + out: 009-random.ans + points: 1 +- in: 010-random.in + out: 010-random.ans + points: 1 +- in: 011-manual.in + out: 011-manual.ans + points: 1 +- in: 012-manual.in + out: 012-manual.ans + points: 1 +- in: 013-manual.in + out: 013-manual.ans + points: 1 +- in: 014-manual.in + out: 014-manual.ans + points: 1 +- in: 015-manual.in + out: 015-manual.ans + points: 1 +- in: 016-manual.in + out: 016-manual.ans + points: 1 +- in: 017-manual.in + out: 017-manual.ans + points: 1 +- in: 018-manual.in + out: 018-manual.ans + points: 1 +- in: 019-linear.in + out: 019-linear.ans + points: 1 +- in: 020-linear.in + out: 020-linear.ans + points: 1 +- in: 021-linear.in + out: 021-linear.ans + points: 1 +- in: 022-linear.in + out: 022-linear.ans + points: 1 +- in: 023-linear.in + out: 023-linear.ans + points: 1 +- in: 024-linear.in + out: 024-linear.ans + points: 1 +- in: 025-linear.in + out: 025-linear.ans + points: 1 +- in: 026-linear.in + out: 026-linear.ans + points: 1 +- in: 027-linear.in + out: 027-linear.ans + points: 1 +- in: 028-linear.in + out: 028-linear.ans + points: 1 +- in: 029-linear.in + out: 029-linear.ans + points: 1 +- in: 030-linear-fuzzy.in + out: 030-linear-fuzzy.ans + points: 1 +- in: 031-linear-fuzzy.in + out: 031-linear-fuzzy.ans + points: 1 +- in: 032-linear-fuzzy.in + out: 032-linear-fuzzy.ans + points: 1 +- in: 033-linear-fuzzy.in + out: 033-linear-fuzzy.ans + points: 1 +- in: 034-exp-2.in + out: 034-exp-2.ans + points: 1 +- in: 035-exp-3.in + out: 035-exp-3.ans + points: 1 +- in: 036-exp-4.in + out: 036-exp-4.ans + points: 1 +- in: 037-exp-1_5.in + out: 037-exp-1_5.ans + points: 1 +- in: 038-exp-1_2.in + out: 038-exp-1_2.ans + points: 1 +- in: 039-exp-1_16.in + out: 039-exp-1_16.ans + points: 1 +- in: 040-exp-1_1.in + out: 040-exp-1_1.ans + points: 1 +- in: 041-exp-1_05.in + out: 041-exp-1_05.ans + points: 1 +- in: 042-rev-exp-2.in + out: 042-rev-exp-2.ans + points: 1 +- in: 043-rev-exp-3.in + out: 043-rev-exp-3.ans + points: 1 +- in: 044-rev-exp-4.in + out: 044-rev-exp-4.ans + points: 1 +- in: 045-rev-exp-1_5.in + out: 045-rev-exp-1_5.ans + points: 1 +- in: 046-rev-exp-1_2.in + out: 046-rev-exp-1_2.ans + points: 1 +- in: 047-rev-exp-1_16.in + out: 047-rev-exp-1_16.ans + points: 1 +- in: 048-rev-exp-1_1.in + out: 048-rev-exp-1_1.ans + points: 1 +- in: 049-rev-exp-1_05.in + out: 049-rev-exp-1_05.ans + points: 1 +- in: 050-exp-fuzz-2.in + out: 050-exp-fuzz-2.ans + points: 1 +- in: 051-exp-fuzz-3.in + out: 051-exp-fuzz-3.ans + points: 1 +- in: 052-exp-fuzz-4.in + out: 052-exp-fuzz-4.ans + points: 1 +- in: 053-exp-fuzz-1_5.in + out: 053-exp-fuzz-1_5.ans + points: 1 +- in: 054-exp-fuzz-1_2.in + out: 054-exp-fuzz-1_2.ans + points: 1 +- in: 055-exp-fuzz-1_16.in + out: 055-exp-fuzz-1_16.ans + points: 1 +- in: 056-exp-fuzz-1_1.in + out: 056-exp-fuzz-1_1.ans + points: 1 +- in: 057-exp-fuzz-1_05.in + out: 057-exp-fuzz-1_05.ans + points: 1 +- in: 058-inv-exp-2.in + out: 058-inv-exp-2.ans + points: 1 +- in: 059-inv-exp-3.in + out: 059-inv-exp-3.ans + points: 1 +- in: 060-inv-exp-4.in + out: 060-inv-exp-4.ans + points: 1 +- in: 061-inv-exp-1_5.in + out: 061-inv-exp-1_5.ans + points: 1 +- in: 062-inv-exp-1_2.in + out: 062-inv-exp-1_2.ans + points: 1 +- in: 063-inv-exp-1_16.in + out: 063-inv-exp-1_16.ans + points: 1 +- in: 064-inv-exp-1_1.in + out: 064-inv-exp-1_1.ans + points: 1 +- in: 065-inv-exp-1_05.in + out: 065-inv-exp-1_05.ans + points: 1 +- in: 066-inv-exp-fuzz-2.in + out: 066-inv-exp-fuzz-2.ans + points: 1 +- in: 067-inv-exp-fuzz-3.in + out: 067-inv-exp-fuzz-3.ans + points: 1 +- in: 068-inv-exp-fuzz-4.in + out: 068-inv-exp-fuzz-4.ans + points: 1 +- in: 069-inv-exp-fuzz-1_5.in + out: 069-inv-exp-fuzz-1_5.ans + points: 1 +- in: 070-inv-exp-fuzz-1_2.in + out: 070-inv-exp-fuzz-1_2.ans + points: 1 +- in: 071-inv-exp-fuzz-1_16.in + out: 071-inv-exp-fuzz-1_16.ans + points: 1 +- in: 072-inv-exp-fuzz-1_1.in + out: 072-inv-exp-fuzz-1_1.ans + points: 1 +- in: 073-inv-exp-fuzz-1_05.in + out: 073-inv-exp-fuzz-1_05.ans + points: 1 +- in: 074-random_small-01.in + out: 074-random_small-01.ans + points: 1 +- in: 075-random_small-02.in + out: 075-random_small-02.ans + points: 1 +- in: 076-random_small-03.in + out: 076-random_small-03.ans + points: 1 +- in: 077-random_small-04.in + out: 077-random_small-04.ans + points: 1 +- in: 078-random_small-05.in + out: 078-random_small-05.ans + points: 1 +- in: 079-random_small-06.in + out: 079-random_small-06.ans + points: 1 +- in: 080-random_small-07.in + out: 080-random_small-07.ans + points: 1 +- in: 081-random_small-08.in + out: 081-random_small-08.ans + points: 1 +- in: 082-random_small-09.in + out: 082-random_small-09.ans + points: 1 +- in: 083-random_small-10.in + out: 083-random_small-10.ans + points: 1 +- in: 084-random_small-11.in + out: 084-random_small-11.ans + points: 1 +- in: 085-random_small-12.in + out: 085-random_small-12.ans + points: 1 +- in: 086-random_small-13.in + out: 086-random_small-13.ans + points: 1 +- in: 087-random_small-14.in + out: 087-random_small-14.ans + points: 1 +- in: 088-random_small-15.in + out: 088-random_small-15.ans + points: 1 +- in: 089-random_small-16.in + out: 089-random_small-16.ans + points: 1 +- in: 090-random_small-17.in + out: 090-random_small-17.ans + points: 1 +- in: 091-random_small-18.in + out: 091-random_small-18.ans + points: 1 +- in: 092-random_small-19.in + out: 092-random_small-19.ans + points: 1 +- in: 093-random_small-20.in + out: 093-random_small-20.ans + points: 1 +- in: 094-random.in + out: 094-random.ans + points: 1 +- in: 095-random.in + out: 095-random.ans + points: 1 +- in: 096-random.in + out: 096-random.ans + points: 1 +- in: 097-random.in + out: 097-random.ans + points: 1 +- in: 098-random.in + out: 098-random.ans + points: 1 +- in: 099-random.in + out: 099-random.ans + points: 1 +- in: 100-random.in + out: 100-random.ans + points: 1 +- in: 101-random.in + out: 101-random.ans + points: 1 +- in: 102-random.in + out: 102-random.ans + points: 1 +- in: 103-random.in + out: 103-random.ans + points: 1 +- in: 104-random.in + out: 104-random.ans + points: 1 +- in: 105-random.in + out: 105-random.ans + points: 1 +- in: 106-random.in + out: 106-random.ans + points: 1 +- in: 107-random.in + out: 107-random.ans + points: 1 +- in: 108-random.in + out: 108-random.ans + points: 1 +- in: 109-random.in + out: 109-random.ans + points: 1 +- in: 110-random.in + out: 110-random.ans + points: 1 +- in: 111-random.in + out: 111-random.ans + points: 1 +- in: 112-random.in + out: 112-random.ans + points: 1 +- in: 113-random.in + out: 113-random.ans + points: 1 +- in: 114-random.in + out: 114-random.ans + points: 1 +- in: 115-random.in + out: 115-random.ans + points: 1 +- in: 116-random.in + out: 116-random.ans + points: 1 +- in: 117-random.in + out: 117-random.ans + points: 1 +- in: 118-random.in + out: 118-random.ans + points: 1 +- in: 119-random.in + out: 119-random.ans + points: 1 +- in: 120-random.in + out: 120-random.ans + points: 1 +- in: 121-random.in + out: 121-random.ans + points: 1 +- in: 122-random.in + out: 122-random.ans + points: 1 +- in: 123-random.in + out: 123-random.ans + points: 1 +- in: 124-random.in + out: 124-random.ans + points: 1 +- in: 125-random.in + out: 125-random.ans + points: 1 +- in: 126-random.in + out: 126-random.ans + points: 1 +- in: 127-random.in + out: 127-random.ans + points: 1 +- in: 128-random.in + out: 128-random.ans + points: 1 +- in: 129-random.in + out: 129-random.ans + points: 1 +- in: 130-random.in + out: 130-random.ans + points: 1 +- in: 131-random.in + out: 131-random.ans + points: 1 diff --git a/ICPC/nwerc2024_E/data.zip b/ICPC/nwerc2024_E/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..6432d84c708ac48749b1320e0677b34b09edfe96 --- /dev/null +++ b/ICPC/nwerc2024_E/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b73d65729dc9bd3062290f0f4eb5d12bb61cc81be8be80263becbefaeb552ce +size 3431317 diff --git a/ICPC/nwerc2024_E/init.yml b/ICPC/nwerc2024_E/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..cb5bfd94e435668b1ec8aa723321bc1a3ab0a9f0 --- /dev/null +++ b/ICPC/nwerc2024_E/init.yml @@ -0,0 +1,248 @@ +archive: data.zip +test_cases: +- in: 05-max.in + out: 05-max.ans + points: 1 +- in: 06-max.in + out: 06-max.ans + points: 1 +- in: 07-max.in + out: 07-max.ans + points: 1 +- in: 08-max.in + out: 08-max.ans + points: 1 +- in: 09-max.in + out: 09-max.ans + points: 1 +- in: 10-min.in + out: 10-min.ans + points: 1 +- in: 11-small.in + out: 11-small.ans + points: 1 +- in: 12-small-n2-k5-1.in + out: 12-small-n2-k5-1.ans + points: 1 +- in: 13-small-n2-k5-2.in + out: 13-small-n2-k5-2.ans + points: 1 +- in: 14-small-n2-k5-3.in + out: 14-small-n2-k5-3.ans + points: 1 +- in: 15-small-n2-k5-4.in + out: 15-small-n2-k5-4.ans + points: 1 +- in: 16-small-n2-k5-5.in + out: 16-small-n2-k5-5.ans + points: 1 +- in: 17-small-n5-k10-1.in + out: 17-small-n5-k10-1.ans + points: 1 +- in: 18-small-n5-k10-2.in + out: 18-small-n5-k10-2.ans + points: 1 +- in: 19-small-n5-k10-3.in + out: 19-small-n5-k10-3.ans + points: 1 +- in: 20-small-n5-k10-4.in + out: 20-small-n5-k10-4.ans + points: 1 +- in: 21-small-n5-k10-5.in + out: 21-small-n5-k10-5.ans + points: 1 +- in: 22-small-n10-k100-1.in + out: 22-small-n10-k100-1.ans + points: 1 +- in: 23-small-n10-k100-2.in + out: 23-small-n10-k100-2.ans + points: 1 +- in: 24-small-n10-k100-3.in + out: 24-small-n10-k100-3.ans + points: 1 +- in: 25-small-n10-k100-4.in + out: 25-small-n10-k100-4.ans + points: 1 +- in: 26-small-n20-k1000-1.in + out: 26-small-n20-k1000-1.ans + points: 1 +- in: 27-small-n20-k1000-2.in + out: 27-small-n20-k1000-2.ans + points: 1 +- in: 28-small-n20-k1000-3.in + out: 28-small-n20-k1000-3.ans + points: 1 +- in: 29-small-n20-k1000-4.in + out: 29-small-n20-k1000-4.ans + points: 1 +- in: 30-small-n50-k10000-1.in + out: 30-small-n50-k10000-1.ans + points: 1 +- in: 31-small-n50-k10000-2.in + out: 31-small-n50-k10000-2.ans + points: 1 +- in: 32-small-n50-k10000-3.in + out: 32-small-n50-k10000-3.ans + points: 1 +- in: 33-small-n100-k1M-1.in + out: 33-small-n100-k1M-1.ans + points: 1 +- in: 34-small-n100-k1M-2.in + out: 34-small-n100-k1M-2.ans + points: 1 +- in: 35-small-n100-k1M-3.in + out: 35-small-n100-k1M-3.ans + points: 1 +- in: 36-random.in + out: 36-random.ans + points: 1 +- in: 37-random-1.in + out: 37-random-1.ans + points: 1 +- in: 38-random-2.in + out: 38-random-2.ans + points: 1 +- in: 39-random-3.in + out: 39-random-3.ans + points: 1 +- in: 40-random-4.in + out: 40-random-4.ans + points: 1 +- in: 41-random-5.in + out: 41-random-5.ans + points: 1 +- in: 42-max-prime.in + out: 42-max-prime.ans + points: 1 +- in: 43-max-prime.in + out: 43-max-prime.ans + points: 1 +- in: 44-max-prime.in + out: 44-max-prime.ans + points: 1 +- in: 45-max-prime.in + out: 45-max-prime.ans + points: 1 +- in: 46-max-power-two.in + out: 46-max-power-two.ans + points: 1 +- in: 47-max-power-two.in + out: 47-max-power-two.ans + points: 1 +- in: 48-max-power-two.in + out: 48-max-power-two.ans + points: 1 +- in: 49-max-power-two.in + out: 49-max-power-two.ans + points: 1 +- in: 50-max-power-two.in + out: 50-max-power-two.ans + points: 1 +- in: 51-max-power-two.in + out: 51-max-power-two.ans + points: 1 +- in: 52-max-power-two.in + out: 52-max-power-two.ans + points: 1 +- in: 53-max-power-two.in + out: 53-max-power-two.ans + points: 1 +- in: 54-max-power-two.in + out: 54-max-power-two.ans + points: 1 +- in: 55-max-power-two.in + out: 55-max-power-two.ans + points: 1 +- in: 56-max-almost-power-two.in + out: 56-max-almost-power-two.ans + points: 1 +- in: 57-max-almost-power-two.in + out: 57-max-almost-power-two.ans + points: 1 +- in: 58-max-almost-power-two.in + out: 58-max-almost-power-two.ans + points: 1 +- in: 59-max-almost-power-two.in + out: 59-max-almost-power-two.ans + points: 1 +- in: 60-max-almost-power-two.in + out: 60-max-almost-power-two.ans + points: 1 +- in: 61-max-power-two.in + out: 61-max-power-two.ans + points: 1 +- in: 62-max-power-two.in + out: 62-max-power-two.ans + points: 1 +- in: 63-max-power-two.in + out: 63-max-power-two.ans + points: 1 +- in: 64-max-power-two.in + out: 64-max-power-two.ans + points: 1 +- in: 65-same-letter.in + out: 65-same-letter.ans + points: 1 +- in: 66-same-letter.in + out: 66-same-letter.ans + points: 1 +- in: 67-same-letter.in + out: 67-same-letter.ans + points: 1 +- in: 68-same-letter.in + out: 68-same-letter.ans + points: 1 +- in: 69-same-letter.in + out: 69-same-letter.ans + points: 1 +- in: 70-same-letters.in + out: 70-same-letters.ans + points: 1 +- in: 71-same-letters.in + out: 71-same-letters.ans + points: 1 +- in: 72-same-letters.in + out: 72-same-letters.ans + points: 1 +- in: 73-same-letters.in + out: 73-same-letters.ans + points: 1 +- in: 74-same-letters.in + out: 74-same-letters.ans + points: 1 +- in: 75-same-letters.in + out: 75-same-letters.ans + points: 1 +- in: 76-same-letters.in + out: 76-same-letters.ans + points: 1 +- in: 77-same-letters.in + out: 77-same-letters.ans + points: 1 +- in: 78-same-letters.in + out: 78-same-letters.ans + points: 1 +- in: 79-same-letters.in + out: 79-same-letters.ans + points: 1 +- in: 80-same-letters.in + out: 80-same-letters.ans + points: 1 +- in: 81-same-letters.in + out: 81-same-letters.ans + points: 1 +- in: 82-same-letters.in + out: 82-same-letters.ans + points: 1 +- in: 83-same-letters.in + out: 83-same-letters.ans + points: 1 +- in: 84-same-letters.in + out: 84-same-letters.ans + points: 1 +- in: 85-same-letters.in + out: 85-same-letters.ans + points: 1 +- in: 86-paul.in + out: 86-paul.ans + points: 1 diff --git a/ICPC/nwerc2024_F/data.zip b/ICPC/nwerc2024_F/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..0a5b4d11fa154765529466c3775d3733953d91df --- /dev/null +++ b/ICPC/nwerc2024_F/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a337af0248c03afae927f5b259f888001aa15f53c5124a9b43edf7a20619b2b +size 154538549 diff --git a/ICPC/nwerc2024_F/init.yml b/ICPC/nwerc2024_F/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..51343cb93ad7a6c1dce2be8860b4f00d898b061f --- /dev/null +++ b/ICPC/nwerc2024_F/init.yml @@ -0,0 +1,251 @@ +archive: data.zip +test_cases: +- in: 03-fill-from-top.in + out: 03-fill-from-top.ans + points: 1 +- in: 04-fill-from-top.in + out: 04-fill-from-top.ans + points: 1 +- in: 05-from_tree.in + out: 05-from_tree.ans + points: 1 +- in: 06-from_tree.in + out: 06-from_tree.ans + points: 1 +- in: 07-from_tree.in + out: 07-from_tree.ans + points: 1 +- in: 08-from_tree.in + out: 08-from_tree.ans + points: 1 +- in: 09-from_tree.in + out: 09-from_tree.ans + points: 1 +- in: 10-from_tree.in + out: 10-from_tree.ans + points: 1 +- in: 11-from_tree.in + out: 11-from_tree.ans + points: 1 +- in: 12-from_tree.in + out: 12-from_tree.ans + points: 1 +- in: 13-from_tree.in + out: 13-from_tree.ans + points: 1 +- in: 14-from_tree.in + out: 14-from_tree.ans + points: 1 +- in: 15-small.in + out: 15-small.ans + points: 1 +- in: 16-small.in + out: 16-small.ans + points: 1 +- in: 17-small.in + out: 17-small.ans + points: 1 +- in: 18-small.in + out: 18-small.ans + points: 1 +- in: 19-small.in + out: 19-small.ans + points: 1 +- in: 20-small.in + out: 20-small.ans + points: 1 +- in: 21-small.in + out: 21-small.ans + points: 1 +- in: 22-small.in + out: 22-small.ans + points: 1 +- in: 23-small.in + out: 23-small.ans + points: 1 +- in: 24-small.in + out: 24-small.ans + points: 1 +- in: 25-small.in + out: 25-small.ans + points: 1 +- in: 26-small.in + out: 26-small.ans + points: 1 +- in: 27-small.in + out: 27-small.ans + points: 1 +- in: 28-small.in + out: 28-small.ans + points: 1 +- in: 29-small.in + out: 29-small.ans + points: 1 +- in: 30-small.in + out: 30-small.ans + points: 1 +- in: 31-small.in + out: 31-small.ans + points: 1 +- in: 32-small.in + out: 32-small.ans + points: 1 +- in: 33-small.in + out: 33-small.ans + points: 1 +- in: 34-small.in + out: 34-small.ans + points: 1 +- in: 35-random-1k.in + out: 35-random-1k.ans + points: 1 +- in: 36-random-2k.in + out: 36-random-2k.ans + points: 1 +- in: 37-random-5k.in + out: 37-random-5k.ans + points: 1 +- in: 38-random-10k.in + out: 38-random-10k.ans + points: 1 +- in: 39-random-20k.in + out: 39-random-20k.ans + points: 1 +- in: 40-random-50k.in + out: 40-random-50k.ans + points: 1 +- in: 41-random-100k.in + out: 41-random-100k.ans + points: 1 +- in: 42-random-200k.in + out: 42-random-200k.ans + points: 1 +- in: 43-random.in + out: 43-random.ans + points: 1 +- in: 44-random.in + out: 44-random.ans + points: 1 +- in: 45-random.in + out: 45-random.ans + points: 1 +- in: 46-random.in + out: 46-random.ans + points: 1 +- in: 47-random.in + out: 47-random.ans + points: 1 +- in: 48-random.in + out: 48-random.ans + points: 1 +- in: 49-random.in + out: 49-random.ans + points: 1 +- in: 50-random.in + out: 50-random.ans + points: 1 +- in: 51-random.in + out: 51-random.ans + points: 1 +- in: 52-bucketed.in + out: 52-bucketed.ans + points: 1 +- in: 53-bucketed.in + out: 53-bucketed.ans + points: 1 +- in: 54-bucketed.in + out: 54-bucketed.ans + points: 1 +- in: 55-bucketed.in + out: 55-bucketed.ans + points: 1 +- in: 56-bucketed.in + out: 56-bucketed.ans + points: 1 +- in: 57-bucketed.in + out: 57-bucketed.ans + points: 1 +- in: 58-bucketed.in + out: 58-bucketed.ans + points: 1 +- in: 59-bucketed.in + out: 59-bucketed.ans + points: 1 +- in: 60-bucketed.in + out: 60-bucketed.ans + points: 1 +- in: 61-bucketed.in + out: 61-bucketed.ans + points: 1 +- in: 62-bucketed.in + out: 62-bucketed.ans + points: 1 +- in: 63-bucketed.in + out: 63-bucketed.ans + points: 1 +- in: 64-bucketed.in + out: 64-bucketed.ans + points: 1 +- in: 65-bucketed.in + out: 65-bucketed.ans + points: 1 +- in: 66-bucketed.in + out: 66-bucketed.ans + points: 1 +- in: 67-bucketed.in + out: 67-bucketed.ans + points: 1 +- in: 68-bucketed.in + out: 68-bucketed.ans + points: 1 +- in: 69-bucketed.in + out: 69-bucketed.ans + points: 1 +- in: 70-increasing.in + out: 70-increasing.ans + points: 1 +- in: 71-increasing.in + out: 71-increasing.ans + points: 1 +- in: 72-decreasing.in + out: 72-decreasing.ans + points: 1 +- in: 73-decreasing.in + out: 73-decreasing.ans + points: 1 +- in: 74-test.in + out: 74-test.ans + points: 1 +- in: 75-bounds.in + out: 75-bounds.ans + points: 1 +- in: 76-bounds.in + out: 76-bounds.ans + points: 1 +- in: 77-linear.in + out: 77-linear.ans + points: 1 +- in: 78-linear.in + out: 78-linear.ans + points: 1 +- in: 79-linear.in + out: 79-linear.ans + points: 1 +- in: 80-linear.in + out: 80-linear.ans + points: 1 +- in: 81-linear.in + out: 81-linear.ans + points: 1 +- in: 82-linear.in + out: 82-linear.ans + points: 1 +- in: 83-linear.in + out: 83-linear.ans + points: 1 +- in: 84-linear.in + out: 84-linear.ans + points: 1 +- in: 85-linear.in + out: 85-linear.ans + points: 1 diff --git a/ICPC/nwerc2024_G/data.zip b/ICPC/nwerc2024_G/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..bc22d7d7001d4c5c69a47788a6a62ec7cb648d09 --- /dev/null +++ b/ICPC/nwerc2024_G/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:333a7270ae974aa1a468e068f4c24870d94f0e9e6489ad77858a1e4e4ead3e0f +size 21258775 diff --git a/ICPC/nwerc2024_G/init.yml b/ICPC/nwerc2024_G/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7f7089b2c4ef02dff119c4400780fb681e9d0c53 --- /dev/null +++ b/ICPC/nwerc2024_G/init.yml @@ -0,0 +1,395 @@ +archive: data.zip +test_cases: +- in: 005-twoByTwo.in + out: 005-twoByTwo.ans + points: 1 +- in: 006-twoByTwo.in + out: 006-twoByTwo.ans + points: 1 +- in: 007-twoByTwo.in + out: 007-twoByTwo.ans + points: 1 +- in: 008-singleCell.in + out: 008-singleCell.ans + points: 1 +- in: 009-horizontalBarPossible.in + out: 009-horizontalBarPossible.ans + points: 1 +- in: 010-horizontalBarImpossible.in + out: 010-horizontalBarImpossible.ans + points: 1 +- in: 011-verticalBarPossible.in + out: 011-verticalBarPossible.ans + points: 1 +- in: 012-verticalBarImpossible.in + out: 012-verticalBarImpossible.ans + points: 1 +- in: 013-twoTranspositionsAcrossComponents.in + out: 013-twoTranspositionsAcrossComponents.ans + points: 1 +- in: 014-threeCycleAcrossComponents.in + out: 014-threeCycleAcrossComponents.ans + points: 1 +- in: 015-twoComponentsWithOddPermutations.in + out: 015-twoComponentsWithOddPermutations.ans + points: 1 +- in: 016-attributingCutVertexToWrongComponentImpossible.in + out: 016-attributingCutVertexToWrongComponentImpossible.ans + points: 1 +- in: 017-attributingCutVertexToWrongComponentPossible.in + out: 017-attributingCutVertexToWrongComponentPossible.ans + points: 1 +- in: 018-noBridge.in + out: 018-noBridge.ans + points: 1 +- in: 019-bridge.in + out: 019-bridge.ans + points: 1 +- in: 020-bridge_and_art-1.in + out: 020-bridge_and_art-1.ans + points: 1 +- in: 021-bridge_and_art-2.in + out: 021-bridge_and_art-2.ans + points: 1 +- in: 022-bridge_and_art-3.in + out: 022-bridge_and_art-3.ans + points: 1 +- in: 023-bridge_and_art-4.in + out: 023-bridge_and_art-4.ans + points: 1 +- in: 024-bridge_and_art-5.in + out: 024-bridge_and_art-5.ans + points: 1 +- in: 025-bridge_and_art-6.in + out: 025-bridge_and_art-6.ans + points: 1 +- in: 026-bridge_and_art-7.in + out: 026-bridge_and_art-7.ans + points: 1 +- in: 027-bridge_and_art-8.in + out: 027-bridge_and_art-8.ans + points: 1 +- in: 028-empty-shuffle-some-odd-small.in + out: 028-empty-shuffle-some-odd-small.ans + points: 1 +- in: 029-empty-shuffle-some-odd-large.in + out: 029-empty-shuffle-some-odd-large.ans + points: 1 +- in: 030-empty-shuffle-some-odd-max.in + out: 030-empty-shuffle-some-odd-max.ans + points: 1 +- in: 031-empty-shuffle-swaps-small.in + out: 031-empty-shuffle-swaps-small.ans + points: 1 +- in: 032-empty-shuffle-swaps-large.in + out: 032-empty-shuffle-swaps-large.ans + points: 1 +- in: 033-empty-shuffle-swaps-max.in + out: 033-empty-shuffle-swaps-max.ans + points: 1 +- in: 034-empty-shuffle-none-small.in + out: 034-empty-shuffle-none-small.ans + points: 1 +- in: 035-empty-shuffle-none-large.in + out: 035-empty-shuffle-none-large.ans + points: 1 +- in: 036-empty-shuffle-none-max.in + out: 036-empty-shuffle-none-max.ans + points: 1 +- in: 037-empty-possible-some-odd-small.in + out: 037-empty-possible-some-odd-small.ans + points: 1 +- in: 038-empty-possible-some-odd-large.in + out: 038-empty-possible-some-odd-large.ans + points: 1 +- in: 039-empty-possible-some-odd-max.in + out: 039-empty-possible-some-odd-max.ans + points: 1 +- in: 040-empty-possible-swaps-small.in + out: 040-empty-possible-swaps-small.ans + points: 1 +- in: 041-empty-possible-swaps-large.in + out: 041-empty-possible-swaps-large.ans + points: 1 +- in: 042-empty-possible-swaps-max.in + out: 042-empty-possible-swaps-max.ans + points: 1 +- in: 043-empty-possible-none-small.in + out: 043-empty-possible-none-small.ans + points: 1 +- in: 044-empty-possible-none-large.in + out: 044-empty-possible-none-large.ans + points: 1 +- in: 045-empty-possible-none-max.in + out: 045-empty-possible-none-max.ans + points: 1 +- in: 046-empty-sorted-some-odd-small.in + out: 046-empty-sorted-some-odd-small.ans + points: 1 +- in: 047-empty-sorted-some-odd-large.in + out: 047-empty-sorted-some-odd-large.ans + points: 1 +- in: 048-empty-sorted-some-odd-max.in + out: 048-empty-sorted-some-odd-max.ans + points: 1 +- in: 049-empty-sorted-swaps-small.in + out: 049-empty-sorted-swaps-small.ans + points: 1 +- in: 050-empty-sorted-swaps-large.in + out: 050-empty-sorted-swaps-large.ans + points: 1 +- in: 051-empty-sorted-swaps-max.in + out: 051-empty-sorted-swaps-max.ans + points: 1 +- in: 052-empty-sorted-none-small.in + out: 052-empty-sorted-none-small.ans + points: 1 +- in: 053-empty-sorted-none-large.in + out: 053-empty-sorted-none-large.ans + points: 1 +- in: 054-empty-sorted-none-max.in + out: 054-empty-sorted-none-max.ans + points: 1 +- in: 055-full-sorted-none-small.in + out: 055-full-sorted-none-small.ans + points: 1 +- in: 056-full-sorted-none-large.in + out: 056-full-sorted-none-large.ans + points: 1 +- in: 057-full-sorted-none-max.in + out: 057-full-sorted-none-max.ans + points: 1 +- in: 058-cross-shuffle-some-odd-small.in + out: 058-cross-shuffle-some-odd-small.ans + points: 1 +- in: 059-cross-shuffle-some-odd-large.in + out: 059-cross-shuffle-some-odd-large.ans + points: 1 +- in: 060-cross-shuffle-some-odd-max.in + out: 060-cross-shuffle-some-odd-max.ans + points: 1 +- in: 061-cross-shuffle-swaps-small.in + out: 061-cross-shuffle-swaps-small.ans + points: 1 +- in: 062-cross-shuffle-swaps-large.in + out: 062-cross-shuffle-swaps-large.ans + points: 1 +- in: 063-cross-shuffle-swaps-max.in + out: 063-cross-shuffle-swaps-max.ans + points: 1 +- in: 064-cross-shuffle-none-small.in + out: 064-cross-shuffle-none-small.ans + points: 1 +- in: 065-cross-shuffle-none-large.in + out: 065-cross-shuffle-none-large.ans + points: 1 +- in: 066-cross-shuffle-none-max.in + out: 066-cross-shuffle-none-max.ans + points: 1 +- in: 067-cross-possible-some-odd-small.in + out: 067-cross-possible-some-odd-small.ans + points: 1 +- in: 068-cross-possible-some-odd-large.in + out: 068-cross-possible-some-odd-large.ans + points: 1 +- in: 069-cross-possible-some-odd-max.in + out: 069-cross-possible-some-odd-max.ans + points: 1 +- in: 070-cross-possible-swaps-small.in + out: 070-cross-possible-swaps-small.ans + points: 1 +- in: 071-cross-possible-swaps-large.in + out: 071-cross-possible-swaps-large.ans + points: 1 +- in: 072-cross-possible-swaps-max.in + out: 072-cross-possible-swaps-max.ans + points: 1 +- in: 073-cross-possible-none-small.in + out: 073-cross-possible-none-small.ans + points: 1 +- in: 074-cross-possible-none-large.in + out: 074-cross-possible-none-large.ans + points: 1 +- in: 075-cross-possible-none-max.in + out: 075-cross-possible-none-max.ans + points: 1 +- in: 076-cross-sorted-some-odd-small.in + out: 076-cross-sorted-some-odd-small.ans + points: 1 +- in: 077-cross-sorted-some-odd-large.in + out: 077-cross-sorted-some-odd-large.ans + points: 1 +- in: 078-cross-sorted-some-odd-max.in + out: 078-cross-sorted-some-odd-max.ans + points: 1 +- in: 079-cross-sorted-swaps-small.in + out: 079-cross-sorted-swaps-small.ans + points: 1 +- in: 080-cross-sorted-swaps-large.in + out: 080-cross-sorted-swaps-large.ans + points: 1 +- in: 081-cross-sorted-swaps-max.in + out: 081-cross-sorted-swaps-max.ans + points: 1 +- in: 082-cross-sorted-none-small.in + out: 082-cross-sorted-none-small.ans + points: 1 +- in: 083-cross-sorted-none-large.in + out: 083-cross-sorted-none-large.ans + points: 1 +- in: 084-cross-sorted-none-max.in + out: 084-cross-sorted-none-max.ans + points: 1 +- in: 085-maze-shuffle-some-odd-small.in + out: 085-maze-shuffle-some-odd-small.ans + points: 1 +- in: 086-maze-shuffle-some-odd-large.in + out: 086-maze-shuffle-some-odd-large.ans + points: 1 +- in: 087-maze-shuffle-some-odd-max.in + out: 087-maze-shuffle-some-odd-max.ans + points: 1 +- in: 088-maze-shuffle-swaps-small.in + out: 088-maze-shuffle-swaps-small.ans + points: 1 +- in: 089-maze-shuffle-swaps-large.in + out: 089-maze-shuffle-swaps-large.ans + points: 1 +- in: 090-maze-shuffle-swaps-max.in + out: 090-maze-shuffle-swaps-max.ans + points: 1 +- in: 091-maze-shuffle-none-small.in + out: 091-maze-shuffle-none-small.ans + points: 1 +- in: 092-maze-shuffle-none-large.in + out: 092-maze-shuffle-none-large.ans + points: 1 +- in: 093-maze-shuffle-none-max.in + out: 093-maze-shuffle-none-max.ans + points: 1 +- in: 094-maze-possible-some-odd-small.in + out: 094-maze-possible-some-odd-small.ans + points: 1 +- in: 095-maze-possible-some-odd-large.in + out: 095-maze-possible-some-odd-large.ans + points: 1 +- in: 096-maze-possible-some-odd-max.in + out: 096-maze-possible-some-odd-max.ans + points: 1 +- in: 097-maze-possible-swaps-small.in + out: 097-maze-possible-swaps-small.ans + points: 1 +- in: 098-maze-possible-swaps-large.in + out: 098-maze-possible-swaps-large.ans + points: 1 +- in: 099-maze-possible-swaps-max.in + out: 099-maze-possible-swaps-max.ans + points: 1 +- in: 100-maze-possible-none-small.in + out: 100-maze-possible-none-small.ans + points: 1 +- in: 101-maze-possible-none-large.in + out: 101-maze-possible-none-large.ans + points: 1 +- in: 102-maze-possible-none-max.in + out: 102-maze-possible-none-max.ans + points: 1 +- in: 103-maze-sorted-some-odd-small.in + out: 103-maze-sorted-some-odd-small.ans + points: 1 +- in: 104-maze-sorted-some-odd-large.in + out: 104-maze-sorted-some-odd-large.ans + points: 1 +- in: 105-maze-sorted-some-odd-max.in + out: 105-maze-sorted-some-odd-max.ans + points: 1 +- in: 106-maze-sorted-swaps-small.in + out: 106-maze-sorted-swaps-small.ans + points: 1 +- in: 107-maze-sorted-swaps-large.in + out: 107-maze-sorted-swaps-large.ans + points: 1 +- in: 108-maze-sorted-swaps-max.in + out: 108-maze-sorted-swaps-max.ans + points: 1 +- in: 109-maze-sorted-none-small.in + out: 109-maze-sorted-none-small.ans + points: 1 +- in: 110-maze-sorted-none-large.in + out: 110-maze-sorted-none-large.ans + points: 1 +- in: 111-maze-sorted-none-max.in + out: 111-maze-sorted-none-max.ans + points: 1 +- in: 112-cross-possible-none-small-flipped.in + out: 112-cross-possible-none-small-flipped.ans + points: 1 +- in: 113-multiple-chained-components-impossible.in + out: 113-multiple-chained-components-impossible.ans + points: 1 +- in: 114-multiple-chained-components-possible.in + out: 114-multiple-chained-components-possible.ans + points: 1 +- in: 115-no-degrees-of-freedom-impossible.in + out: 115-no-degrees-of-freedom-impossible.ans + points: 1 +- in: 116-no-degrees-of-freedom-possible.in + out: 116-no-degrees-of-freedom-possible.ans + points: 1 +- in: 117-all-blocked-but-one.in + out: 117-all-blocked-but-one.ans + points: 1 +- in: 118-no-articulation-maze-impossible.in + out: 118-no-articulation-maze-impossible.ans + points: 1 +- in: 119-no-articulation-maze-possible.in + out: 119-no-articulation-maze-possible.ans + points: 1 +- in: 120-multiple-but-small-components-impossible.in + out: 120-multiple-but-small-components-impossible.ans + points: 1 +- in: 121-multiple-but-small-components-possible.in + out: 121-multiple-but-small-components-possible.ans + points: 1 +- in: 122-minimal-multi-component-impossible.in + out: 122-minimal-multi-component-impossible.ans + points: 1 +- in: 123-minimal-multi-component-possible.in + out: 123-minimal-multi-component-possible.ans + points: 1 +- in: 124-minimal-multi-component-impossible.in + out: 124-minimal-multi-component-impossible.ans + points: 1 +- in: 125-minimal-multi-component-possible.in + out: 125-minimal-multi-component-possible.ans + points: 1 +- in: 126-narrow-channel-impossible.in + out: 126-narrow-channel-impossible.ans + points: 1 +- in: 127-narrow-channel-possible.in + out: 127-narrow-channel-possible.ans + points: 1 +- in: 128-hourglass-impossible.in + out: 128-hourglass-impossible.ans + points: 1 +- in: 129-hourglass-possible.in + out: 129-hourglass-possible.ans + points: 1 +- in: 130-ornamental-impossible.in + out: 130-ornamental-impossible.ans + points: 1 +- in: 131-ornamental-possible.in + out: 131-ornamental-possible.ans + points: 1 +- in: 132-cut-vertex-permutation-impossible.in + out: 132-cut-vertex-permutation-impossible.ans + points: 1 +- in: 133-cut-vertex-permutation-possible.in + out: 133-cut-vertex-permutation-possible.ans + points: 1 +- in: 134-multiple-chained-components-flipped-possible.in + out: 134-multiple-chained-components-flipped-possible.ans + points: 1 +- in: 135-all-types-of-2x2-ears-possible.in + out: 135-all-types-of-2x2-ears-possible.ans + points: 1 diff --git a/ICPC/nwerc2024_H/data.zip b/ICPC/nwerc2024_H/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..3115b2eba6ff1851853756dd7e05777d2c658f2e --- /dev/null +++ b/ICPC/nwerc2024_H/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffa1f8c43270325db71aea459a55a1a17b47b0c700c1cbc8f20c37e9957e2b25 +size 60128267 diff --git a/ICPC/nwerc2024_H/init.yml b/ICPC/nwerc2024_H/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9aaff8ee2b8797ed2e0e765c38bf80b5ff41a954 --- /dev/null +++ b/ICPC/nwerc2024_H/init.yml @@ -0,0 +1,402 @@ +archive: data.zip +interactive: + files: + - output_validators/output_validator/output_validator.cpp + - output_validators/output_validator/validation.h + lang: CPP17 + type: default +test_cases: +- in: 003-minimum.in + out: 003-minimum.ans + points: 1 +- in: 004-one-one.in + out: 004-one-one.ans + points: 1 +- in: 005-one-two.in + out: 005-one-two.ans + points: 1 +- in: 006-two-one.in + out: 006-two-one.ans + points: 1 +- in: 007-two-two.in + out: 007-two-two.ans + points: 1 +- in: 008-identity.in + out: 008-identity.ans + points: 1 +- in: 009-constant.in + out: 009-constant.ans + points: 1 +- in: 010-cycle.in + out: 010-cycle.ans + points: 1 +- in: 011-plusone.in + out: 011-plusone.ans + points: 1 +- in: 012-random-small.in + out: 012-random-small.ans + points: 1 +- in: 013-random-small.in + out: 013-random-small.ans + points: 1 +- in: 014-random-small.in + out: 014-random-small.ans + points: 1 +- in: 015-random-small.in + out: 015-random-small.ans + points: 1 +- in: 016-random-small.in + out: 016-random-small.ans + points: 1 +- in: 017-random-small.in + out: 017-random-small.ans + points: 1 +- in: 018-random-small.in + out: 018-random-small.ans + points: 1 +- in: 019-random-small.in + out: 019-random-small.ans + points: 1 +- in: 020-random-small.in + out: 020-random-small.ans + points: 1 +- in: 021-random-small.in + out: 021-random-small.ans + points: 1 +- in: 022-random-small.in + out: 022-random-small.ans + points: 1 +- in: 023-random-small.in + out: 023-random-small.ans + points: 1 +- in: 024-random-small.in + out: 024-random-small.ans + points: 1 +- in: 025-random-small.in + out: 025-random-small.ans + points: 1 +- in: 026-random-small.in + out: 026-random-small.ans + points: 1 +- in: 027-random-small.in + out: 027-random-small.ans + points: 1 +- in: 028-random-small.in + out: 028-random-small.ans + points: 1 +- in: 029-random-large.in + out: 029-random-large.ans + points: 1 +- in: 030-random-large.in + out: 030-random-large.ans + points: 1 +- in: 031-random-large.in + out: 031-random-large.ans + points: 1 +- in: 032-single-path-small-cycle.in + out: 032-single-path-small-cycle.ans + points: 1 +- in: 033-single-path-small-cycle.in + out: 033-single-path-small-cycle.ans + points: 1 +- in: 034-single-path-small-cycle.in + out: 034-single-path-small-cycle.ans + points: 1 +- in: 035-single-path-small-cycle.in + out: 035-single-path-small-cycle.ans + points: 1 +- in: 036-single-path-medium-cycle.in + out: 036-single-path-medium-cycle.ans + points: 1 +- in: 037-single-path-large-cycle.in + out: 037-single-path-large-cycle.ans + points: 1 +- in: 038-single-path-large-cycle.in + out: 038-single-path-large-cycle.ans + points: 1 +- in: 039-single-path-large-cycle.in + out: 039-single-path-large-cycle.ans + points: 1 +- in: 040-single-path-random-01.in + out: 040-single-path-random-01.ans + points: 1 +- in: 041-single-path-random-02.in + out: 041-single-path-random-02.ans + points: 1 +- in: 042-single-path-random-03.in + out: 042-single-path-random-03.ans + points: 1 +- in: 043-single-path-random-04.in + out: 043-single-path-random-04.ans + points: 1 +- in: 044-single-path-random-05.in + out: 044-single-path-random-05.ans + points: 1 +- in: 045-single-path-random-06.in + out: 045-single-path-random-06.ans + points: 1 +- in: 046-single-path-random-07.in + out: 046-single-path-random-07.ans + points: 1 +- in: 047-single-path-random-08.in + out: 047-single-path-random-08.ans + points: 1 +- in: 048-single-path-random-09.in + out: 048-single-path-random-09.ans + points: 1 +- in: 049-single-path-random-10.in + out: 049-single-path-random-10.ans + points: 1 +- in: 050-single-cycle.in + out: 050-single-cycle.ans + points: 1 +- in: 051-single-cycle.in + out: 051-single-cycle.ans + points: 1 +- in: 052-single-cycle.in + out: 052-single-cycle.ans + points: 1 +- in: 053-single-cycle.in + out: 053-single-cycle.ans + points: 1 +- in: 054-single-cycle-random-01.in + out: 054-single-cycle-random-01.ans + points: 1 +- in: 055-single-cycle-random-02.in + out: 055-single-cycle-random-02.ans + points: 1 +- in: 056-single-cycle-random-03.in + out: 056-single-cycle-random-03.ans + points: 1 +- in: 057-single-cycle-random-04.in + out: 057-single-cycle-random-04.ans + points: 1 +- in: 058-single-cycle-random-05.in + out: 058-single-cycle-random-05.ans + points: 1 +- in: 059-single-cycle-random-06.in + out: 059-single-cycle-random-06.ans + points: 1 +- in: 060-single-cycle-random-07.in + out: 060-single-cycle-random-07.ans + points: 1 +- in: 061-single-cycle-random-08.in + out: 061-single-cycle-random-08.ans + points: 1 +- in: 062-single-cycle-random-09.in + out: 062-single-cycle-random-09.ans + points: 1 +- in: 063-single-cycle-random-10.in + out: 063-single-cycle-random-10.ans + points: 1 +- in: 064-single-cycle-random-11.in + out: 064-single-cycle-random-11.ans + points: 1 +- in: 065-single-cycle-random-12.in + out: 065-single-cycle-random-12.ans + points: 1 +- in: 066-single-cycle-random-13.in + out: 066-single-cycle-random-13.ans + points: 1 +- in: 067-single-cycle-random-14.in + out: 067-single-cycle-random-14.ans + points: 1 +- in: 068-single-cycle-random-15.in + out: 068-single-cycle-random-15.ans + points: 1 +- in: 069-single-cycle-random-16.in + out: 069-single-cycle-random-16.ans + points: 1 +- in: 070-single-cycle-random-17.in + out: 070-single-cycle-random-17.ans + points: 1 +- in: 071-single-cycle-random-18.in + out: 071-single-cycle-random-18.ans + points: 1 +- in: 072-single-cycle-random-19.in + out: 072-single-cycle-random-19.ans + points: 1 +- in: 073-single-cycle-random-20.in + out: 073-single-cycle-random-20.ans + points: 1 +- in: 074-single-cycle-random-21.in + out: 074-single-cycle-random-21.ans + points: 1 +- in: 075-single-cycle-random-22.in + out: 075-single-cycle-random-22.ans + points: 1 +- in: 076-single-cycle-random-23.in + out: 076-single-cycle-random-23.ans + points: 1 +- in: 077-single-cycle-random-24.in + out: 077-single-cycle-random-24.ans + points: 1 +- in: 078-single-cycle-random-25.in + out: 078-single-cycle-random-25.ans + points: 1 +- in: 079-single-cycle-random-26.in + out: 079-single-cycle-random-26.ans + points: 1 +- in: 080-single-cycle-random-27.in + out: 080-single-cycle-random-27.ans + points: 1 +- in: 081-single-cycle-random-28.in + out: 081-single-cycle-random-28.ans + points: 1 +- in: 082-single-cycle-random-29.in + out: 082-single-cycle-random-29.ans + points: 1 +- in: 083-single-cycle-random-30.in + out: 083-single-cycle-random-30.ans + points: 1 +- in: 084-single-cycle-random-31.in + out: 084-single-cycle-random-31.ans + points: 1 +- in: 085-single-cycle-random-32.in + out: 085-single-cycle-random-32.ans + points: 1 +- in: 086-single-cycle-random-33.in + out: 086-single-cycle-random-33.ans + points: 1 +- in: 087-single-cycle-random-34.in + out: 087-single-cycle-random-34.ans + points: 1 +- in: 088-single-cycle-random-35.in + out: 088-single-cycle-random-35.ans + points: 1 +- in: 089-single-cycle-random-36.in + out: 089-single-cycle-random-36.ans + points: 1 +- in: 090-single-cycle-random-37.in + out: 090-single-cycle-random-37.ans + points: 1 +- in: 091-single-cycle-random-38.in + out: 091-single-cycle-random-38.ans + points: 1 +- in: 092-single-cycle-random-39.in + out: 092-single-cycle-random-39.ans + points: 1 +- in: 093-single-cycle-random-40.in + out: 093-single-cycle-random-40.ans + points: 1 +- in: 094-single-cycle-random-41.in + out: 094-single-cycle-random-41.ans + points: 1 +- in: 095-single-cycle-random-42.in + out: 095-single-cycle-random-42.ans + points: 1 +- in: 096-single-cycle-random-43.in + out: 096-single-cycle-random-43.ans + points: 1 +- in: 097-single-cycle-random-44.in + out: 097-single-cycle-random-44.ans + points: 1 +- in: 098-single-cycle-random-45.in + out: 098-single-cycle-random-45.ans + points: 1 +- in: 099-single-cycle-random-46.in + out: 099-single-cycle-random-46.ans + points: 1 +- in: 100-single-cycle-random-47.in + out: 100-single-cycle-random-47.ans + points: 1 +- in: 101-single-cycle-random-48.in + out: 101-single-cycle-random-48.ans + points: 1 +- in: 102-single-cycle-random-49.in + out: 102-single-cycle-random-49.ans + points: 1 +- in: 103-single-cycle-random-50.in + out: 103-single-cycle-random-50.ans + points: 1 +- in: 104-single-cycle-random-51.in + out: 104-single-cycle-random-51.ans + points: 1 +- in: 105-single-cycle-random-52.in + out: 105-single-cycle-random-52.ans + points: 1 +- in: 106-single-cycle-random-53.in + out: 106-single-cycle-random-53.ans + points: 1 +- in: 107-single-cycle-random-54.in + out: 107-single-cycle-random-54.ans + points: 1 +- in: 108-single-cycle-random-55.in + out: 108-single-cycle-random-55.ans + points: 1 +- in: 109-single-cycle-random-56.in + out: 109-single-cycle-random-56.ans + points: 1 +- in: 110-single-cycle-random-57.in + out: 110-single-cycle-random-57.ans + points: 1 +- in: 111-single-cycle-random-58.in + out: 111-single-cycle-random-58.ans + points: 1 +- in: 112-single-cycle-random-59.in + out: 112-single-cycle-random-59.ans + points: 1 +- in: 113-single-cycle-random-60.in + out: 113-single-cycle-random-60.ans + points: 1 +- in: 114-single-cycle-random-61.in + out: 114-single-cycle-random-61.ans + points: 1 +- in: 115-single-cycle-random-62.in + out: 115-single-cycle-random-62.ans + points: 1 +- in: 116-single-cycle-random-63.in + out: 116-single-cycle-random-63.ans + points: 1 +- in: 117-single-cycle-random-64.in + out: 117-single-cycle-random-64.ans + points: 1 +- in: 118-single-cycle-random-65.in + out: 118-single-cycle-random-65.ans + points: 1 +- in: 119-single-cycle-random-66.in + out: 119-single-cycle-random-66.ans + points: 1 +- in: 120-single-cycle-random-67.in + out: 120-single-cycle-random-67.ans + points: 1 +- in: 121-single-cycle-random-68.in + out: 121-single-cycle-random-68.ans + points: 1 +- in: 122-single-cycle-random-69.in + out: 122-single-cycle-random-69.ans + points: 1 +- in: 123-single-cycle-random-70.in + out: 123-single-cycle-random-70.ans + points: 1 +- in: 124-single-cycle-random-71.in + out: 124-single-cycle-random-71.ans + points: 1 +- in: 125-single-cycle-random-72.in + out: 125-single-cycle-random-72.ans + points: 1 +- in: 126-single-cycle-random-73.in + out: 126-single-cycle-random-73.ans + points: 1 +- in: 127-single-cycle-random-74.in + out: 127-single-cycle-random-74.ans + points: 1 +- in: 128-single-cycle-random-75.in + out: 128-single-cycle-random-75.ans + points: 1 +- in: 129-single-cycle-random-76.in + out: 129-single-cycle-random-76.ans + points: 1 +- in: 130-single-cycle-random-77.in + out: 130-single-cycle-random-77.ans + points: 1 +- in: 131-single-cycle-random-78.in + out: 131-single-cycle-random-78.ans + points: 1 +- in: 132-single-cycle-random-79.in + out: 132-single-cycle-random-79.ans + points: 1 +- in: 133-single-cycle-random-80.in + out: 133-single-cycle-random-80.ans + points: 1 +unbuffered: false diff --git a/ICPC/nwerc2024_H/output_validators/output_validator/output_validator.cpp b/ICPC/nwerc2024_H/output_validators/output_validator/output_validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..409b965d089e184f69e6bc903fa047453255a4d4 --- /dev/null +++ b/ICPC/nwerc2024_H/output_validators/output_validator/output_validator.cpp @@ -0,0 +1,90 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validation.h" + +const int MAX_Q = 1000; +const int EXTRA_Q = 2000; + +int query(std::vector>& f, int c, int r) { + r--; + int k = 0; + while(c > 0) { + if(c % 2 == 1) r = f[k][r]; + c /= 2; + k++; + } + r++; + return r; +} + +int main(int argc, char* argv[]) { + // Set up the input and answer streams. + std::ifstream in(argv[1]); + // std::ifstream ans(argv[2]); // Only for custom checker. + OutputValidator v(argc, argv); + + int n; + in >> n; + std::cout << n << std::endl; + + std::vector> f(30, std::vector(n)); // f[i][j] = f^(2^i)(j) + for(int i = 0; i < n; i++) { + in >> f[0][i]; + f[0][i]--; + } + for(int i = 1; i < 30; i++) { + for(int j = 0; j < n; j++) { + f[i][j] = f[i - 1][f[i - 1][j]]; + } + } + + int used_q = 0; + while(true) { + std::string q = v.test_strings({"?", "!"}); + if(q == "?") { + used_q++; + v.check(used_q <= EXTRA_Q, "Used more than ", EXTRA_Q, " queries, aborting."); + v.space(); + int c = v.read_integer("c", 1, n); + v.space(); + int r = v.read_integer("r", 1, n); + v.newline(); + std::cout << query(f, c, r) << std::endl; + } else { + v.space(); + int c = v.read_integer("c", 1, n); + v.space(); + int r = v.read_integer("r", 1, n); + v.newline(); + std::cerr << "Used " << used_q << " queries. "; // No endl, so that a possible WA message ends up on the same line. + v.check(query(f, c, r) == c, "Answer is wrong."); + v.check(used_q <= MAX_Q, "Used more than ", MAX_Q, " queries."); + break; + } + } +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[2], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2024_H/output_validators/output_validator/validation.h b/ICPC/nwerc2024_H/output_validators/output_validator/validation.h new file mode 100644 index 0000000000000000000000000000000000000000..9dbc11931c68be348cbe730f4a033f6ee7ab1552 --- /dev/null +++ b/ICPC/nwerc2024_H/output_validators/output_validator/validation.h @@ -0,0 +1,1479 @@ +#pragma once +// A header library to safely parse team input. +// It does not support floating points or big integers. +// Author: Ragnar Groot Koerkamp + +// The easiest way to use this is to symlink it from a validator directory, +// so that it will be picked up when creating a contest zip. + +// The default checking behaviour is lenient for both white space and case. +// When validating .in and .ans files, the case_sensitive and +// space_change_sensitive flags should be passed. When validating team output, +// the flags in problem.yaml should be used. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const std::string_view case_sensitive_flag = "case_sensitive"; +const std::string_view ws_sensitive_flag = "space_change_sensitive"; +const std::string_view constraints_file_flag = "--constraints_file"; +const std::string_view generate_flag = "--generate"; +const std::string_view generate_binary_substring = "generat"; + +inline struct ArbitraryTag { + static constexpr bool unique = false; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Arbitrary; +inline struct UniqueTag : ArbitraryTag { + static constexpr bool unique = true; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Unique; +inline struct IncreasingTag : ArbitraryTag { + static constexpr bool increasing = true; +} Increasing; +inline struct DecreasingTag : ArbitraryTag { + static constexpr bool decreasing = true; +} Decreasing; +inline struct StrictlyIncreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool increasing = true; +} StrictlyIncreasing; +inline struct StrictlyDecreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool decreasing = true; +} StrictlyDecreasing; + +template +struct Merge : T... { + static constexpr bool unique = (T::unique || ...); + static constexpr bool strict = (T::strict || ...); + static constexpr bool increasing = (T::increasing || ...); + static constexpr bool decreasing = (T::decreasing || ...); +}; + +template and std::is_base_of_v, int> = 0> +auto operator|(T1 /*unused*/, T2 /*unused*/) { + return Merge(); +} + +enum Separator { Space, Newline }; + +// this contains some specific code which emulates c++20 features +namespace cpp20 { + +constexpr int countl_zero(unsigned long long x) { + int res = 64; + for(int i = 32; i > 0; i >>= 1) { + if((x >> i) > 0) { + res -= i; + x >>= i; + } + } + if(x > 0) res--; + return res; +} + +int popcount(unsigned long long x) { + return static_cast(std::bitset<64>(x).count()); +} + +constexpr long double PI = 3.141592653589793238462643383279502884l; + +} // namespace cpp20 + +namespace Random { + +constexpr unsigned int default_seed = 3141592653; // some digits of PI + +unsigned long long bits64(std::mt19937_64& rng) { + static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull); + static_assert(std::mt19937_64::min() == 0ull); + return rng(); +} + +// generates a uniform real in [0, 1) +long double real64(std::mt19937_64& rng) { + // a long double can represent more than 2^64 values in the range [0, 1)... + // another problem is that real64() < 1.0/3.0 is technically biased. + long double res = bits64(rng) / 0x1.0p64l; + res += bits64(rng) / 0x1.0p128l; + assert(res < 1.0l); + return res; +} + +bool bit(std::mt19937_64& rng) { + return cpp20::popcount(bits64(rng)) & 1; +} + +} // namespace Random + +template +constexpr bool is_number_v = std::is_same_v or std::is_same_v; + +namespace Generators { + +template +struct ConstGenerator { + static_assert(is_number_v or std::is_same_v or std::is_same_v); + static constexpr std::string_view name = "const"; + using Args = std::tuple; + + const T const_; + + explicit ConstGenerator(T val) : const_(std::move(val)) {} + + // For char and string, the constant store has a different type than the min and max length + // passed in. + template + T operator()(U low, U high, std::mt19937_64& rng) const { + return std::clamp(const_, low, high); + } +}; + +struct MinGenerator { + static constexpr std::string_view name = "min"; + using Args = std::tuple<>; + + explicit MinGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return low; + } +}; + +struct MaxGenerator { + static constexpr std::string_view name = "max"; + using Args = std::tuple<>; + + explicit MaxGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return high; + } +}; + +struct UniformGenerator { + static constexpr std::string_view name = "uniform"; + using Args = std::tuple<>; + + explicit UniformGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + if(low == high) return low; + + if constexpr(std::is_same_v) { + assert(low < high); + // Since C++20 we can assume Two's Complement but any sane system used it before anyway. + // Rejection sampling is not as fast as possible but definitely unbiased. + auto ul = static_cast(low); + auto uh = static_cast(high); + int shitfs = cpp20::countl_zero(uh - ul); + unsigned long long res; + do { + res = Random::bits64(rng) >> shitfs; + } while(res > uh - ul); + return static_cast(res + ul); + } else { + assert(low < high); + return low + Random::real64(rng) * (high - low); + } + } +}; + +template +struct RangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "range"; + using Args = std::tuple; + + const T low_, high_; + + explicit RangeGenerator(T low, T high) : low_(low), high_(high) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng); + } +}; + +template +struct StepRangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "steprange"; + using Args = std::tuple; + + const T low_, high_, step_; + + explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + // round up low to the first multiple of step_. + T start; + if(low <= low_) { + start = low_; + } else { + // first multiple of low_+k*step_ >= low + start = low_ + (long long)((low - low_) / step_) * step_; + if(start < low) start += step_; + assert(low <= start && start < low + step_); + } + long long maxsteps = (std::min(high, high_) - start) / step_; + long long steps = UniformGenerator()(0ll, maxsteps, rng); + return start + steps * step_; + } +}; + +struct NormalDistributionGenerator { + static constexpr std::string_view name = "normal"; + using T = long double; + using Args = std::tuple; + + const T mean_, stddev_; + + explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) { + assert(stddev_ >= 0); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + T u1 = Random::real64(rng); + T u2 = Random::real64(rng); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + } + return v; + } +}; + +struct ExponentialDistributionGenerator { + static constexpr std::string_view name = "exponential"; + using T = long double; + using Args = std::tuple; + + T lambda_; + + explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + v = low - std::log(Random::real64(rng)) / lambda_; + if(v < high) return v; + } + } +}; + +struct GeometricDistributionGenerator { + static constexpr std::string_view name = "geometric"; + using T = long long; + using Args = std::tuple; + + double p_; + + explicit GeometricDistributionGenerator(double p) : p_(p) { + assert(p_ > 0); + assert(p_ < 1); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + T v; + while(true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric + // distribution[...]" + v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_)); + if(v <= high) return v; + } + } +}; + +struct BinomialDistributionGenerator { + static constexpr std::string_view name = "binomial"; + using T = long long; + using Args = std::tuple; + + long long n_; + double p_; + + explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) { + assert(p_ >= 0); + assert(p_ <= 1); + std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!" + << std::endl; + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + // this will be slow for large n + // (a faster implementation requires efficient poisson sampling) + while(true) { + T v = 0; + for(long long i = 0; i < n_; i++) { + v += Random::real64(rng) < p_ ? 1 : 0; + } + if(v >= low && v <= high) return v; + } + } +}; + +template +struct ChoiceGenerator { + using GeneratorType = std::conditional_t< + std::is_same_v, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, GeometricDistributionGenerator, + BinomialDistributionGenerator>, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, NormalDistributionGenerator, + ExponentialDistributionGenerator>>; + + std::vector> generators_; + double total_weight_; + + template + struct Pack {}; + + template + static A parse_number(std::string_view s) { + static_assert(is_number_v); + if constexpr(std::is_same_v) + return stoll(std::string(s)); + else + return stold(std::string(s)); + } + + template + static A parse_argument(std::string_view& s) { + auto end = s.find_first_of(",)"); + assert(end != std::string_view::npos); + auto v = parse_number(s.substr(0, end)); + s.remove_prefix(end); + // Pop the trailing , or ) + s.remove_prefix(1); + return v; + } + + template + static std::tuple parse_arguments(std::string_view& s, + Pack> /*unused*/) { + std::tuple args{parse_argument(s)...}; + return args; + } + + // Try parsing one generator type from the start of s. + template + static void parse_generator(std::string_view& s, std::optional& out) { + if(out) return; + if(s.substr(0, G::name.size()) != G::name) return; + + // Drop the name. + s.remove_prefix(G::name.size()); + if constexpr(std::tuple_size_v == 0) { + out.emplace(std::in_place_type_t{}); + return; + } + + // Drop the ( + assert(not s.empty() and s.front() == '('); + s.remove_prefix(1); + + auto args = parse_arguments(s, Pack{}); + // Construct the resulting generator in-place in the variant.. + std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t{}, _args...); }, + args); + } + + template + static std::optional parse_generators(std::string_view& s, + Pack> /*unused*/) { + std::optional out; + (parse_generator(s, out), ...); + return out; + } + + explicit ChoiceGenerator(std::string_view s) : total_weight_(0) { + // PARSE + while(not s.empty()) { + auto generator = parse_generators(s, Pack{}); + if(!generator) { + // Check for range syntax: + auto comma = s.find_first_of(",:"); + if(comma == std::string::npos) comma = s.size(); + auto dots = s.find(".."); + if(dots != std::string_view::npos and dots < comma) { + auto start = s.substr(0, dots); + auto end = s.substr(dots + 2, comma - dots - 2); + + generator.emplace(std::in_place_type_t>{}, + parse_number(start), parse_number(end)); + s.remove_prefix(comma); + } + + // Fall back to constant. + if(!generator) { + generator.emplace(std::in_place_type_t>{}, + parse_number(s.substr(0, comma))); + s.remove_prefix(comma); + } + } + + // Parse weight if given. + double weight = 1; + if(not s.empty() and s.front() == ':') { + s.remove_prefix(1); + auto comma = s.find(','); + if(comma == std::string_view::npos) comma = s.size(); + weight = parse_number(s.substr(0, comma)); + s.remove_prefix(comma); + } + + // should now be at , or end + assert(s.empty() or s.front() == ','); + if(not s.empty()) s.remove_prefix(1); + generators_.emplace_back(std::move(*generator), weight); + total_weight_ += weight; + } + } + + T operator()(T low, T high, std::mt19937_64& rng) const { + Generators::UniformGenerator uniform; + double x = uniform.operator()(0, total_weight_, rng); + for(size_t i = 0; i < generators_.size(); ++i) { + x -= generators_[i].second; + if(x <= 0) + return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first); + } + assert(false); + } +}; + +struct ParamGenerator { + std::variant, ChoiceGenerator> + generator; + explicit ParamGenerator(std::string_view s) : generator(s) {} + + template + T operator()(T low, T high, std::mt19937_64& rng) { + static_assert(is_number_v); + if(std::holds_alternative(generator)) { + generator = ChoiceGenerator(std::get(generator)); + } + return std::get>(generator)(low, high, rng); + } +}; + +} // namespace Generators + +using Generators::ParamGenerator; + +namespace Random { +template +void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) { + Generators::UniformGenerator uniform; + long long n = last - first; + for(long long i = n - 1; i > 0; i--) { + std::swap(first[i], first[uniform(0ll, i, rng)]); + } +} + +template +void shuffle(std::pair& in, std::mt19937_64& rng) { + if(bit(rng)) std::swap(in.first, in.second); +} + +template +auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) { + assert(first != last); + Generators::UniformGenerator uniform; + long long n = last - first; + return first[uniform(0ll, n - 1, rng)]; +} + +template +const T& select(const std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +template +T& select(std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +} // namespace Random + +class Validator { + protected: + Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "", + std::optional seed = std::nullopt, + std::unordered_map params_ = {}) + : in(in_), ws(ws_), case_sensitive(case_), + constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()), + rng(seed.value_or(Random::default_seed)), params(std::move(params_)) { + + std::ios_base::sync_with_stdio(false); + in.tie(nullptr); + + if(gen) return; + if(ws) + in >> std::noskipws; + else + in >> std::skipws; + } + + public: + // No copying, no moving. + Validator(const Validator&) = delete; + Validator(Validator&&) = delete; + void operator=(const Validator&) = delete; + void operator=(Validator&&) = delete; + + // At the end of the scope, check whether the EOF has been reached. + // If so, return AC. Otherwise, return WA. + ~Validator() { + eof(); + write_constraints(); + AC(); + } + + void space() { + if(gen) { + out << ' '; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected space, found EOF."); + if(c != ' ') + expected("space", std::string("\"") + + ((c == '\n' or c == '\r') ? std::string("newline") + : std::string(1, c)) + + "\""); + } + } + + void newline() { + if(gen) { + out << '\n'; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected newline, found EOF."); + if(c != '\n') { + if(c == '\r') + expected("newline", "DOS line ending (\\r)"); + else + expected("newline", std::string("\"") + c + "\""); + } + } + } + + private: + void separator(Separator s) { + switch(s) { + case Separator::Space: space(); break; + case Separator::Newline: newline(); break; + } + } + + template + auto& seen() { + static std::unordered_map> seen; + return seen; + } + template + auto& last_seen() { + static std::unordered_map last_seen; + return last_seen; + } + template + auto& integers_seen() { + static std::unordered_map, std::vector, bool>> + integers_seen; + return integers_seen; + } + template + void reset(std::string name) { + seen().erase(name); + last_seen().erase(name); + integers_seen().erase(name); + } + + template + void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/) { + static_assert(is_number_v); + if(v < low or v > high) { + std::string type_name; + if constexpr(std::is_integral_v) { + type_name = "integer"; + } + if constexpr(std::is_floating_point_v) { + type_name = "float"; + } + expected(name + ": " + type_name + " between " + std::to_string(low) + " and " + + std::to_string(high), + std::to_string(v)); + } + log_constraint(name, low, high, v); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[name].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else { + auto [it, inserted] = last_seen().emplace(name, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + template + void check_string(const std::string& name, int low, int high, const std::string& v, + Tag /*unused*/) { + using T = std::string; + if((int)v.size() < low or (int) v.size() > high) { + expected(name + ": " + "string with" + " length between " + std::to_string(low) + + " and " + std::to_string(high), + v); + } + log_constraint("|" + name + "|", low, high, static_cast(v.size())); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[name].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else if(Tag::increasing or Tag::decreasing) { + auto [it, inserted] = last_seen().emplace(name, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + // Generate a random integer in [low, high] or float in [low, high). + template + T uniform_number(T low, T high) { + assert(low <= high); + Generators::UniformGenerator uniform; + if constexpr(std::is_integral::value) + return uniform.operator()(low, high, rng); + else + return uniform.operator()(low, high, rng); + } + + template + T gen_number(const std::string& name, T low, T high, Tag /*unused*/) { + static_assert(is_number_v); + T v; + + if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + if constexpr(std::is_integral::value) { + auto& [seen_here, remaining_here, use_remaining] = integers_seen()[name]; + + if(use_remaining) { + check(!remaining_here.empty(), name, ": no unique values left"); + v = remaining_here.back(); + remaining_here.pop_back(); + } else { + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + + struct CountIterator { + T v; + T& operator*() { return v; } + T& operator++() { return ++v; } + T operator++(int) { return v++; } + bool operator!=(CountIterator r) { return v != r.v; } + }; + + if(seen_here.size() > (high - low) / 2) { + use_remaining = true; + set_difference(CountIterator{low}, CountIterator{high + 1}, + seen_here.begin(), seen_here.end(), + std::back_inserter(remaining_here)); + } + } + } else { + // For floats, just regenerate numbers until success. + auto& seen_here = seen()[name]; + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + } + + } else { + assert(not Tag::increasing && "Generating increasing sequences is not yet supported!"); + assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!"); + assert((std::is_same::value) && + "Only Unique and Arbitrary are supported!"); + + if(params.find(name) != params.end()) { + v = params.at(name).operator()(low, high, rng); + // This will be checked during input validation of the generated case. + // assert(low <= v and v <= high); + } else { + v = uniform_number(low, high); + } + } + + return v; + } + + std::string gen_string(const std::string& name, long long low, long long high, + std::string_view chars) { + assert(!chars.empty()); + + int len; + if(params.find(name + ".length") != params.end()) + len = params.at(name + ".length").operator()(low, high, rng); + else + len = uniform_number(low, high); + std::string s(len, ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s; + return s; + } + + public: + template + long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}) { + return gen_number(name, low, high, tag); + } + + template + long double gen_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}) { + return gen_number(name, low, high, tag); + } + + private: + template + std::vector gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/) { + static_assert(is_number_v); + std::vector v; + v.reserve(count); + if constexpr(std::is_same_v) { + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + } else if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + std::set seen_here; + if constexpr(std::is_integral_v) { + if(2 * count < high - low) { + for(int i = 0; i < count; ++i) { + // If density < 1/2: retry. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } else { + // If density >= 1/2, crop a random permutation. + v.resize(high - low + 1); + iota(begin(v), end(v), low); + Random::shuffle(begin(v), end(v), rng); + v.resize(count); + } + } else { + for(int i = 0; i < count; ++i) { + // For floats, just regenerate numbers until success. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + constexpr bool integral_strict = Tag::strict and std::is_integral::value; + if(integral_strict) { + assert(params.find(name) == params.end() && + "Parameters are not supported for strict integer values."); + high = high - count + 1; + } + + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + + sort(begin(v), end(v)); + + if(integral_strict) { + for(int i = 0; i < count; ++i) v[i] += i; + } + + if(Tag::decreasing) reverse(begin(v), end(v)); + } + + return v; + } + + public: + template + std::vector gen_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}) { + return gen_numbers(name, count, low, high, tag); + } + + template + std::vector gen_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}) { + return gen_numbers(name, count, low, high, tag); + } + + private: + template + T read_number(const std::string& name, T low, T high, Tag tag) { + if(gen) { + auto v = gen_number(name, low, high, tag); + out << std::setprecision(10) << std::fixed << v; + return v; + } + + const auto v = [&] { + if constexpr(std::is_integral::value) + return read_integer(name); + else + return read_float(name); + }(); + + check_number(name, low, high, v, tag); + return v; + } + + // Read a vector of numbers, separated by spaces and ended by a newline. + template + std::vector read_numbers(const std::string& name, int count, T low, T high, Tag tag, + Separator sep) { + if(gen) { + auto v = gen_numbers(name, count, low, high, tag); + + out << std::setprecision(10) << std::fixed; + for(int i = 0; i < count; ++i) { + out << v[i]; + if(i < count - 1) separator(sep); + } + newline(); + + return v; + } + reset(name); + std::vector v(count); + for(int i = 0; i < count; ++i) { + if constexpr(std::is_integral::value) + v[i] = read_integer(name); + else + v[i] = read_float(name); + check_number(name, low, high, v[i], tag); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + public: + template + long long read_integer(const std::string& name, long long low, long long high, + Tag tag = Tag{}) { + return read_number(name, low, high, tag); + } + template + std::vector read_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, Separator sep = Space) { + return read_numbers(name, count, low, high, tag, sep); + } + + template + long double read_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}) { + return read_number(name, low, high, tag); + } + template + std::vector read_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, Separator sep = Space) { + return read_numbers(name, count, low, high, tag, sep); + } + + // Read a vector of strings, separated by spaces and ended by a newline. + template + std::vector read_strings(const std::string& name, int count, int min, int max, + const std::string_view chars = "", Tag tag = Tag(), + Separator sep = Space) { + reset(name); + if(gen) return gen_strings(name, count, min, max, chars, tag, sep); + assert(!gen); + std::vector v(count); + for(int i = 0; i < count; ++i) { + v[i] = read_string(name, min, max, chars, tag); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + template + std::vector gen_strings(const std::string& name, int count, int min, int max, + const std::string_view chars, Tag /*unused*/, + Separator sep) { + assert(!chars.empty()); + + std::vector v(count); + if constexpr(std::is_same::value) { + for(int i = 0; i < count; ++i) { + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else if constexpr(Tag::unique) { + std::set seen_here; + for(int i = 0; i < count; ++i) { + // Just regenerate strings until success. + std::string s; + do { + s = std::string(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + } while(!seen_here.insert(s).second); + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + assert(false && "Generating increasing/decreasing lists of strings is not " + "supported!"); + } + + newline(); + + return v; + } + + // Check the next character. + bool peek(char c, const std::string& name = "") { + if(gen) { + // TODO + // if(not name.empty() and params.contains(name)) { + // return c == params.at(name).operator()(0, 0, rng); + //} + return Random::bit(rng); + } + if(!ws) in >> std::ws; + if(case_sensitive) return in.peek() == std::char_traits::to_int_type(c); + return tolower(in.peek()) == tolower(std::char_traits::to_int_type(c)); + } + + // Read a string and make sure it equals `expected`. + // Takes by value because it needs to lowercase its arguments. + std::string test_strings(std::vector expected, const std::string& name = "") { + if(gen) { + int index = 0; + // TODO + // if(not name.empty() and params.contains(name)) { + // auto s = params.at(name).operator()(0, 0, rng); + // index = std::find(expected.begin(), expected.end(), s) - expected.begin(); + // assert(0 <= index and index < expected.size()); + //} else { + index = expected.size() == 1 ? 0 : uniform_number(0, expected.size() - 1); + //} + out << expected[index]; + return expected[index]; + } + std::string s = get_string(); + lowercase(s); + + for(std::string e : expected) + if(s == lowercase(e)) return s; + + std::string error; + for(const auto& e : expected) { + if(not error.empty()) error += "|"; + error += e; + } + WA("Expected string \"", error, "\", but found ", s); + } + + // Read a string and make sure it equals `expected`. + std::string test_string(std::string expected, const std::string& name = "") { + return test_strings({std::move(expected)}, name); + } + + // Read an arbitrary string of a given length. + template + std::string read_string(const std::string& name, long long min, long long max, + const std::string_view chars = "", Tag tag = Tag()) { + if(gen) { + return gen_string(name, min, max, chars); + } + std::string s = get_string(); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + check_string(name, min, max, s, tag); + return s; + } + + // Read an arbitrary line of a given length. + std::string read_line(const std::string& name, long long min, long long max, + const std::string_view chars = "") { + if(gen) { + // TODO: Params for lines. + assert(!chars.empty()); + + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s << '\n'; + return s; + } + + if(ws) { + char next = in.peek(); + if(min > 0 and isspace(next)) + expected("non empty line", next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected("line", "EOF"); + } + std::string s; + if(!getline(in, s)) expected("line", "nothing"); + long long size = s.size(); + if(size < min || size > max) + expected(name + ": line of length between " + std::to_string(min) + " and " + + std::to_string(max), + s); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + log_constraint("|" + name + "|", min, max, size); + return s; + } + + // Return ACCEPTED verdict. + void eof_and_AC() { + eof(); + AC(); + } + + private: + std::function WA_handler = [] {}; + + public: + void set_WA_handler(std::function f) { WA_handler = std::move(f); } + + // Return WA with the given reason. + template + [[noreturn]] void WA(const Ts&... ts) { + static_assert(sizeof...(Ts) > 0); + + WA_handler(); + + auto pos = get_file_pos(); + std::cerr << pos.first << ":" << pos.second << ": "; + + WA_impl(ts...); + } + + // Check that the condition is true. + template + void check(bool b, const Ts&... ts) { + static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message."); + + if(!b) WA(ts...); + } + + // Log some value in a range. + template + void log_constraint(const std::string& name, T low, T high, T v) { + // All integer types get bounds as long long, all floating point types as long_double. + using U = Bounds, long long, long double>>; + + auto [it, inserted] = bounds.emplace(name, U(name, v, v, low, high)); + assert(std::holds_alternative(it->second)); + auto& done = std::get(it->second); + if(inserted) { + assert(!name.empty() && "Variable names must not be empty."); + assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces."); + } else { + assert(name == done.name && "Variable name must be constant."); + } + if(v < done.min) { + done.min = v; + done.low = low; + } + if(v > done.max) { + done.max = v; + done.high = high; + } + done.has_min |= v == low; + done.has_max |= v == high; + } + + private: + long long read_integer(const std::string& name) { + assert(!gen); + std::string s = get_string("integer"); + if(s.empty()) { + WA(name, ": Want integer, found nothing"); + } + long long v; + try { + auto begin = s.c_str(), end = begin + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, v); + if(ptr != end or ec != std::errc{}) + WA(name, ": Parsing " + s + " as long long failed! Did not process all characters"); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long long!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long long failed!"); + } + // Check for leading zero. + if(v == 0) { + if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s); + } + if(v > 0) { + if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + if(v < 0) { + if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s); + if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + return v; + } + + long double read_float(const std::string& name) { + assert(!gen); + std::string s = get_string("long double"); + long double v; + try { + size_t chars_processed; + v = stold(s, &chars_processed); + if(chars_processed != s.size()) + WA(name, ": Parsing ", s, + " as long double failed! Did not process all characters."); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long double!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long double failed!"); + } + return v; + } + + [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") { + assert(!gen && "Expected is not supported for generators."); + WA("Expected ", exp, ", found ", s.empty() ? "empty string" : s); + } + + template + [[noreturn]] void WA_impl(T t) { + std::cerr << t << std::endl; + exit(ret_WA); + } + + std::pair get_file_pos() { + int line = 1, col = 0; + in.clear(); + auto originalPos = in.tellg(); + if(originalPos < 0) return {-1, -1}; + in.seekg(0); + char c; + while((in.tellg() < originalPos) && in.get(c)) { + if(c == '\n') + ++line, col = 0; + else + ++col; + } + return {line, col}; + } + + template + [[noreturn]] void WA_impl(T t, Ts... ts) { + std::cerr << t; + WA_impl(ts...); + } + + std::string get_string(const std::string& wanted = "string") { + assert(!gen && "get_string is not supported for generators."); + if(ws) { + char next = in.peek(); + if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected(wanted, "EOF"); + } + + std::string s; + if(in >> s) { + return s; + } + expected(wanted, "nothing"); + } + + // Return ACCEPTED verdict. + void AC() const { + if(gen) { + // nothing + return; + } + + exit(ret_AC); + } + + void eof() { + if(gen) { + out.flush(); + fclose(stdout); + return; + } + if(in.eof()) return; + // Sometimes EOF hasn't been triggered yet. + if(!ws) in >> std::ws; + int c = in.get(); + if(c == std::char_traits::eof()) return; + std::string got = std::string("\"") + char(c) + '"'; + if(c == '\n') got = "newline"; + expected("EOF", got); + } + + public: + // Convert a string to lowercase is matching is not case sensitive. + std::string& lowercase(std::string& s) const { + if(case_sensitive) return s; + transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; + } + + private: + // Keep track of the min/max value read at every call site. + template + struct Bounds { + Bounds(std::string name_, T min_, T max_, T low_, T high_) + : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT + std::string name; + T min, max; // Smallest / largest value observed + T low, high; // Bounds + bool has_min = false, has_max = false; + }; + + std::unordered_map, Bounds>> bounds; + + void write_constraints() { + if(constraints_file_path.empty()) return; + + std::ofstream os(constraints_file_path); + + for(const auto& [name, bound] : bounds) { + std::visit( + [&](const auto& b) { + os << "LocationNotSupported:" << b.name << " " << b.name << " " << b.has_min + << " " << b.has_max << " " << b.min << " " << b.max << " " << b.low << " " + << b.high << std::endl; + }, + bound); + } + } + + static const int ret_AC = 42, ret_WA = 43; + std::istream& in = std::cin; + std::ostream& out = std::cout; + + public: + const bool ws = true; + const bool case_sensitive = true; + const std::string constraints_file_path; + const bool gen = false; + + std::mt19937_64 rng; + + private: + std::unordered_map params; + + public: + std::string_view get_param(std::string_view name, std::string_view default_) { + auto it = params.find(std::string(name)); + if(it == params.end()) return default_; + return std::get(it->second.generator); + } + + protected: + static std::string get_constraints_file(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == constraints_file_flag) { + if(i + 1 < argc) return argv[i + 1]; + std::cerr << constraints_file_flag << " should be followed by a file path!"; + exit(1); + } + } + return {}; + } +}; + +class Generator : public Validator { + public: + explicit Generator(unsigned int seed) + : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {} +}; + +class InputValidator : public Validator { + public: + // An InputValidator is always both whitespace and case sensitive. + explicit InputValidator(int argc = 0, char** argv = nullptr) + : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv), + get_params(argc, argv)) {} + + private: + static std::optional get_seed(int argc, char** argv) { + for(int i = 1; i < argc - 1; ++i) { + if(argv[i] == generate_flag) { + return std::stol(argv[i + 1]); + } + } + // If no --generate is given, but `generat` is a substring of the binary path, + // use the first argument as seed. + if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) { + return std::stol(argv[1]); + } + return std::nullopt; + } + + static std::unordered_map get_params(int argc, char** argv) { + std::unordered_map params; + for(int i = 1; i < argc - 1; ++i) { + if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue; + if(argv[i] == generate_flag) { + continue; + } + std::string_view name(argv[i] + 1); + std::string_view value(argv[i + 1]); + params.insert({std::string(name), ParamGenerator(value)}); + } + return params; + } +}; + +class OutputValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_, + get_constraints_file(argc, argv)) {} + + private: + static bool is_ws_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == ws_sensitive_flag) return true; + } + return false; + } + + static bool is_case_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == case_sensitive_flag) return true; + } + return false; + } +}; + +class AnswerValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit AnswerValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(/*ws_sensitive=*/true, /*space sensitive*/ true, in_, + get_constraints_file(argc, argv)) {} +}; \ No newline at end of file diff --git a/ICPC/nwerc2024_I/data.zip b/ICPC/nwerc2024_I/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..8781ff93fc35b7f2dd6f463b4062c63119fa4415 --- /dev/null +++ b/ICPC/nwerc2024_I/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b1194d49cccf77de33b2a4becb3acf5983285d2fc4adbf29e3c6c983fd54de5 +size 36976137 diff --git a/ICPC/nwerc2024_I/init.yml b/ICPC/nwerc2024_I/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3decf6c624a101276881e7150a0964cece004e79 --- /dev/null +++ b/ICPC/nwerc2024_I/init.yml @@ -0,0 +1,131 @@ +archive: data.zip +test_cases: +- in: 02-range.in + out: 02-range.ans + points: 1 +- in: 03-range.in + out: 03-range.ans + points: 1 +- in: 04-range.in + out: 04-range.ans + points: 1 +- in: 05-random.in + out: 05-random.ans + points: 1 +- in: 06-random.in + out: 06-random.ans + points: 1 +- in: 07-random.in + out: 07-random.ans + points: 1 +- in: 08-random.in + out: 08-random.ans + points: 1 +- in: 09-random.in + out: 09-random.ans + points: 1 +- in: 10-random.in + out: 10-random.ans + points: 1 +- in: 11-random.in + out: 11-random.ans + points: 1 +- in: 12-random.in + out: 12-random.ans + points: 1 +- in: 13-random.in + out: 13-random.ans + points: 1 +- in: 14-random.in + out: 14-random.ans + points: 1 +- in: 15-random.in + out: 15-random.ans + points: 1 +- in: 16-random.in + out: 16-random.ans + points: 1 +- in: 17-random.in + out: 17-random.ans + points: 1 +- in: 18-cubes.in + out: 18-cubes.ans + points: 1 +- in: 19-cubes.in + out: 19-cubes.ans + points: 1 +- in: 20-cubes.in + out: 20-cubes.ans + points: 1 +- in: 21-cubes.in + out: 21-cubes.ans + points: 1 +- in: 22-cubes.in + out: 22-cubes.ans + points: 1 +- in: 23-cubes.in + out: 23-cubes.ans + points: 1 +- in: 24-cubes.in + out: 24-cubes.ans + points: 1 +- in: 25-cubes.in + out: 25-cubes.ans + points: 1 +- in: 26-cubes.in + out: 26-cubes.ans + points: 1 +- in: 27-cubes.in + out: 27-cubes.ans + points: 1 +- in: 28-cubesm1.in + out: 28-cubesm1.ans + points: 1 +- in: 29-cubesm1.in + out: 29-cubesm1.ans + points: 1 +- in: 30-cubesm1.in + out: 30-cubesm1.ans + points: 1 +- in: 31-cubesm1.in + out: 31-cubesm1.ans + points: 1 +- in: 32-cubesm1.in + out: 32-cubesm1.ans + points: 1 +- in: 33-cubesm1.in + out: 33-cubesm1.ans + points: 1 +- in: 34-cubesm1.in + out: 34-cubesm1.ans + points: 1 +- in: 35-cubesm1.in + out: 35-cubesm1.ans + points: 1 +- in: 36-cubesm1.in + out: 36-cubesm1.ans + points: 1 +- in: 37-cubesm1.in + out: 37-cubesm1.ans + points: 1 +- in: 38-minmin.in + out: 38-minmin.ans + points: 1 +- in: 39-maxmin.in + out: 39-maxmin.ans + points: 1 +- in: 40-maxmax.in + out: 40-maxmax.ans + points: 1 +- in: 41-minmax.in + out: 41-minmax.ans + points: 1 +- in: 42-equal_steps.in + out: 42-equal_steps.ans + points: 1 +- in: 43-cubes_equal_steps.in + out: 43-cubes_equal_steps.ans + points: 1 +- in: 44-cubesm1_equal_steps.in + out: 44-cubesm1_equal_steps.ans + points: 1 diff --git a/ICPC/nwerc2024_J/data.zip b/ICPC/nwerc2024_J/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..b5682f02acfa87cb433daea7b3c7a2addda5a77c --- /dev/null +++ b/ICPC/nwerc2024_J/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53027cc71ca2a13a84bb09c5840d53a9db409e7ddd60f4749e05ce713c9b49eb +size 143354 diff --git a/ICPC/nwerc2024_J/init.yml b/ICPC/nwerc2024_J/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2fdecd7667770eb734ea30d4d4c2e270b79c2912 --- /dev/null +++ b/ICPC/nwerc2024_J/init.yml @@ -0,0 +1,238 @@ +archive: data.zip +checker: + args: + files: + - output_validators/output_validator/output_validator.cpp + - output_validators/output_validator/validation.h + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 04-precision.in + out: 04-precision.ans + points: 1 +- in: 05-precision.in + out: 05-precision.ans + points: 1 +- in: 06-minimal.in + out: 06-minimal.ans + points: 1 +- in: 07-minimal.in + out: 07-minimal.ans + points: 1 +- in: 08-minimal.in + out: 08-minimal.ans + points: 1 +- in: 09-minimal.in + out: 09-minimal.ans + points: 1 +- in: 10-minimal.in + out: 10-minimal.ans + points: 1 +- in: 11-minimal-corners.in + out: 11-minimal-corners.ans + points: 1 +- in: 12-minimal-corners.in + out: 12-minimal-corners.ans + points: 1 +- in: 13-minimal-corners.in + out: 13-minimal-corners.ans + points: 1 +- in: 14-minimal-double-corners.in + out: 14-minimal-double-corners.ans + points: 1 +- in: 15-xeq0.in + out: 15-xeq0.ans + points: 1 +- in: 16-yeq0.in + out: 16-yeq0.ans + points: 1 +- in: 17-xeqy.in + out: 17-xeqy.ans + points: 1 +- in: 18-random.in + out: 18-random.ans + points: 1 +- in: 19-random.in + out: 19-random.ans + points: 1 +- in: 20-random.in + out: 20-random.ans + points: 1 +- in: 21-random.in + out: 21-random.ans + points: 1 +- in: 22-random.in + out: 22-random.ans + points: 1 +- in: 23-random.in + out: 23-random.ans + points: 1 +- in: 24-random.in + out: 24-random.ans + points: 1 +- in: 25-random.in + out: 25-random.ans + points: 1 +- in: 26-manual.in + out: 26-manual.ans + points: 1 +- in: 27-sorted.in + out: 27-sorted.ans + points: 1 +- in: 28-sorted.in + out: 28-sorted.ans + points: 1 +- in: 29-sorted.in + out: 29-sorted.ans + points: 1 +- in: 30-grid.in + out: 30-grid.ans + points: 1 +- in: 31-grid.in + out: 31-grid.ans + points: 1 +- in: 32-gridp.in + out: 32-gridp.ans + points: 1 +- in: 33-gridp.in + out: 33-gridp.ans + points: 1 +- in: 34-gridp.in + out: 34-gridp.ans + points: 1 +- in: 35-tiny-01.in + out: 35-tiny-01.ans + points: 1 +- in: 36-tiny-02.in + out: 36-tiny-02.ans + points: 1 +- in: 37-tiny-03.in + out: 37-tiny-03.ans + points: 1 +- in: 38-tiny-04.in + out: 38-tiny-04.ans + points: 1 +- in: 39-tiny-05.in + out: 39-tiny-05.ans + points: 1 +- in: 40-tiny-06.in + out: 40-tiny-06.ans + points: 1 +- in: 41-tiny-07.in + out: 41-tiny-07.ans + points: 1 +- in: 42-tiny-08.in + out: 42-tiny-08.ans + points: 1 +- in: 43-tiny-09.in + out: 43-tiny-09.ans + points: 1 +- in: 44-tiny-10.in + out: 44-tiny-10.ans + points: 1 +- in: 45-tiny-11.in + out: 45-tiny-11.ans + points: 1 +- in: 46-tiny-12.in + out: 46-tiny-12.ans + points: 1 +- in: 47-tiny-13.in + out: 47-tiny-13.ans + points: 1 +- in: 48-tiny-14.in + out: 48-tiny-14.ans + points: 1 +- in: 49-tiny-15.in + out: 49-tiny-15.ans + points: 1 +- in: 50-tiny-16.in + out: 50-tiny-16.ans + points: 1 +- in: 51-tiny-17.in + out: 51-tiny-17.ans + points: 1 +- in: 52-tiny-18.in + out: 52-tiny-18.ans + points: 1 +- in: 53-tiny-19.in + out: 53-tiny-19.ans + points: 1 +- in: 54-tiny-20.in + out: 54-tiny-20.ans + points: 1 +- in: 55-tiny-21.in + out: 55-tiny-21.ans + points: 1 +- in: 56-tiny-22.in + out: 56-tiny-22.ans + points: 1 +- in: 57-tiny-23.in + out: 57-tiny-23.ans + points: 1 +- in: 58-tiny-24.in + out: 58-tiny-24.ans + points: 1 +- in: 59-tiny-25.in + out: 59-tiny-25.ans + points: 1 +- in: 60-tiny-26.in + out: 60-tiny-26.ans + points: 1 +- in: 61-tiny-27.in + out: 61-tiny-27.ans + points: 1 +- in: 62-tiny-28.in + out: 62-tiny-28.ans + points: 1 +- in: 63-tiny-29.in + out: 63-tiny-29.ans + points: 1 +- in: 64-tiny-30.in + out: 64-tiny-30.ans + points: 1 +- in: 65-large-01.in + out: 65-large-01.ans + points: 1 +- in: 66-large-02.in + out: 66-large-02.ans + points: 1 +- in: 67-large-03.in + out: 67-large-03.ans + points: 1 +- in: 68-large-04.in + out: 68-large-04.ans + points: 1 +- in: 69-large-05.in + out: 69-large-05.ans + points: 1 +- in: 70-large-06.in + out: 70-large-06.ans + points: 1 +- in: 71-large-07.in + out: 71-large-07.ans + points: 1 +- in: 72-large-08.in + out: 72-large-08.ans + points: 1 +- in: 73-large-09.in + out: 73-large-09.ans + points: 1 +- in: 74-large-10.in + out: 74-large-10.ans + points: 1 +- in: 75-large-11.in + out: 75-large-11.ans + points: 1 +- in: 76-large-12.in + out: 76-large-12.ans + points: 1 +- in: 77-large-13.in + out: 77-large-13.ans + points: 1 +- in: 78-large-14.in + out: 78-large-14.ans + points: 1 +- in: 79-large-15.in + out: 79-large-15.ans + points: 1 diff --git a/ICPC/nwerc2024_J/output_validators/output_validator/output_validator.cpp b/ICPC/nwerc2024_J/output_validators/output_validator/output_validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed4e92dd10c719391e4e90cbbe18841e9ecfb999 --- /dev/null +++ b/ICPC/nwerc2024_J/output_validators/output_validator/output_validator.cpp @@ -0,0 +1,168 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validation.h" +#include +using namespace std; +using i64 = long long; + +const long double eps = 1.005e-6; +const long double pi = 2*acosl(0); + +// Normalizes an angle to the range [-pi,pi). +void normalize(long double &alpha) { + while (alpha >= pi) alpha -= 2*pi; + while (alpha < -pi) alpha += 2*pi; +} + +// Computes the area of the union of some given circular disks using +// Green's theorem. A good explanation of the method can be found here: +// https://discuss.codechef.com/t/chefpc-editorial/12282 +long double union_area(const vector &x, const vector& y, const vector &r) { + int n = x.size(); + // Find which parts of the boundary of circle i are part of the boundary + // of the overall figure using an angular sweep. + long double res = 0; + for (int i = 0; i < n; i++) { + int count = 0; // Number of other circles we are currently in. + vector> events; + // Loop over the other circles and for each of them find + // the interval of angles covered by that circle. + for (int j = 0; j < n; j++) if (j != i) { + long double dist = hypotl(x[j]-x[i], y[j]-y[i]); + + // If dist is near-integer, round it to the closest integer. + // This is safe, as the coordinates are small. + if (abs(dist-round(dist)) < 1e-9) dist = round(dist); + + // If the circles are disjoint, ignore. + if (dist >= r[i] + r[j]) continue; + + // If circle j is inside circle i, ignore. + if (r[j] + dist <= r[i]) continue; + + // If circle i is inside circle j, increment the count. + if (r[i] + dist <= r[j]) { + count++; + continue; // could also break here instead + } + + // Note that in the comparisons above we didn't need to use + // epsilons as equality can only happen when dist is an integer and + // near-equality cannot happen because the coordinates are small. + + // Intersection points are at angles alpha-beta and alpha+beta. + // Note that beta is always in [0,pi] by definition of acos. In + // fact, as the case of touching circles was eliminated above, we + // know that beta must be strictly inside this interval. + long double alpha = atan2l(y[j]-y[i], x[j]-x[i]); + long double num = dist*dist + r[i]*r[i] - r[j]*r[j]; + long double denom = 2 * dist * r[i]; + long double beta = acosl(num/denom); + + // Compute the covered interval, and add a +1 event for the start + // of the interval and a -1 event for the end of the interval. + long double gamma1 = alpha - beta; + long double gamma2 = alpha + beta; + normalize(gamma1), normalize(gamma2); + events.emplace_back(gamma1, 1); + events.emplace_back(gamma2, -1); + + // We start the sweep at -pi, and we need to increment the + // count when this starting point is inside circle j. + if (gamma1 > gamma2) count++; + } + + // Add a "sentinel" event to cover the final stretch of the boundary + // back to the starting point. + events.emplace_back(pi, 0); + + // Now go over the event queue in sorted order. Whenever the count + // drops to 0, this part of the boundary is also part of the boundary + // of the overall shape. + sort(begin(events), end(events)); + long double alpha = -pi; + for (auto [beta, add]: events) { + if (count == 0) { + complex c(x[i], y[i]); + complex a = polar((long double) r[i], alpha); + complex b = polar((long double) r[i], beta); + // Add the signed area of the circular sector and two + // triangles, where for the latter we use complex number + // multiplication to compute the relevant cross products. + res += 0.5 * (r[i]*r[i]*(beta-alpha) + imag(conj(c+a)*(c+b) - conj(a)*b)); + } + count += add; + alpha = beta; + } + } + return res; +} + +int main(int argc, char* argv[]) { + ifstream in(argv[1]); + OutputValidator v(argc, argv); + + // Read input. + int n; in >> n; + vector x(n), y(n), h(n); + for (int i = 0; i < n; i++) { + in >> x[i] >> y[i] >> h[i]; + } + + // Compute maximum possible length for each jib. + vector rmax(n); + for (int i = 0; i < n; i++) { + i64 r2max = h[i]*h[i]; + for (int j = 0; j < n; j++) { + if (h[j] <= h[i]) continue; + i64 dx = x[j]-x[i], dy = y[j]-y[i]; + r2max = min(r2max, dx*dx + dy*dy); + } + rmax[i] = sqrt(r2max); + assert(rmax[i] * rmax[i] <= r2max); + assert((rmax[i]+1)*(rmax[i]+1) > r2max); + } + + // Read output and check that no radius is too large. + vector r(n); + for (int i = 0; i < n; i++) { + r[i] = v.read_integer("r", 1, rmax[i]); + v.newline(); + } + + // Compute the resulting area, once assuming all radii are maximized and + // once for the radii given in the output. Then check that the absolute or + // relative error is at most 1.005e-6. + auto max_area = union_area(x, y, rmax); + auto area = union_area(x, y, r); + long double error = abs(area - max_area) / max(1.0L, max_area); + v.check(error < eps, + "Covered area is ", area, ", but the maximum possible area is ", max_area, + " (error: ", error, ")."); +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/nwerc2024_J/output_validators/output_validator/validation.h b/ICPC/nwerc2024_J/output_validators/output_validator/validation.h new file mode 100644 index 0000000000000000000000000000000000000000..60911fd56d5e788b38fc80b022335296221d05b1 --- /dev/null +++ b/ICPC/nwerc2024_J/output_validators/output_validator/validation.h @@ -0,0 +1,1479 @@ +#pragma once +// A header library to safely parse team input. +// It does not support floating points or big integers. +// Author: Ragnar Groot Koerkamp + +// The easiest way to use this is to symlink it from a validator directory, +// so that it will be picked up when creating a contest zip. + +// The default checking behaviour is lenient for both white space and case. +// When validating .in and .ans files, the case_sensitive and +// space_change_sensitive flags should be passed. When validating team output, +// the flags in problem.yaml should be used. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const std::string_view case_sensitive_flag = "case_sensitive"; +const std::string_view ws_sensitive_flag = "space_change_sensitive"; +const std::string_view constraints_file_flag = "--constraints_file"; +const std::string_view generate_flag = "--generate"; +const std::string_view generate_binary_substring = "generat"; + +inline struct ArbitraryTag { + static constexpr bool unique = false; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Arbitrary; +inline struct UniqueTag : ArbitraryTag { + static constexpr bool unique = true; + static constexpr bool strict = false; + static constexpr bool increasing = false; + static constexpr bool decreasing = false; +} Unique; +inline struct IncreasingTag : ArbitraryTag { + static constexpr bool increasing = true; +} Increasing; +inline struct DecreasingTag : ArbitraryTag { + static constexpr bool decreasing = true; +} Decreasing; +inline struct StrictlyIncreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool increasing = true; +} StrictlyIncreasing; +inline struct StrictlyDecreasingTag : ArbitraryTag { + static constexpr bool strict = true; + static constexpr bool decreasing = true; +} StrictlyDecreasing; + +template +struct Merge : T... { + static constexpr bool unique = (T::unique || ...); + static constexpr bool strict = (T::strict || ...); + static constexpr bool increasing = (T::increasing || ...); + static constexpr bool decreasing = (T::decreasing || ...); +}; + +template and std::is_base_of_v, int> = 0> +auto operator|(T1 /*unused*/, T2 /*unused*/) { + return Merge(); +} + +enum Separator { Space, Newline }; + +// this contains some specific code which emulates c++20 features +namespace cpp20 { + +constexpr int countl_zero(unsigned long long x) { + int res = 64; + for(int i = 32; i > 0; i >>= 1) { + if((x >> i) > 0) { + res -= i; + x >>= i; + } + } + if(x > 0) res--; + return res; +} + +int popcount(unsigned long long x) { + return static_cast(std::bitset<64>(x).count()); +} + +constexpr long double PI = 3.141592653589793238462643383279502884l; + +} // namespace cpp20 + +namespace Random { + +constexpr unsigned int default_seed = 3141592653; // some digits of PI + +unsigned long long bits64(std::mt19937_64& rng) { + static_assert(std::mt19937_64::max() == 0xFFFF'FFFF'FFFF'FFFFull); + static_assert(std::mt19937_64::min() == 0ull); + return rng(); +} + +// generates a uniform real in [0, 1) +long double real64(std::mt19937_64& rng) { + // a long double can represent more than 2^64 values in the range [0, 1)... + // another problem is that real64() < 1.0/3.0 is technically biased. + long double res = bits64(rng) / 0x1.0p64l; + res += bits64(rng) / 0x1.0p128l; + assert(res < 1.0l); + return res; +} + +bool bit(std::mt19937_64& rng) { + return cpp20::popcount(bits64(rng)) & 1; +} + +} // namespace Random + +template +constexpr bool is_number_v = std::is_same_v or std::is_same_v; + +namespace Generators { + +template +struct ConstGenerator { + static_assert(is_number_v or std::is_same_v or std::is_same_v); + static constexpr std::string_view name = "const"; + using Args = std::tuple; + + const T const_; + + explicit ConstGenerator(T val) : const_(std::move(val)) {} + + // For char and string, the constant store has a different type than the min and max length + // passed in. + template + T operator()(U low, U high, std::mt19937_64& rng) const { + return std::clamp(const_, low, high); + } +}; + +struct MinGenerator { + static constexpr std::string_view name = "min"; + using Args = std::tuple<>; + + explicit MinGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return low; + } +}; + +struct MaxGenerator { + static constexpr std::string_view name = "max"; + using Args = std::tuple<>; + + explicit MaxGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + return high; + } +}; + +struct UniformGenerator { + static constexpr std::string_view name = "uniform"; + using Args = std::tuple<>; + + explicit UniformGenerator() = default; + + template + T operator()(T low, T high, std::mt19937_64& rng) const { + static_assert(is_number_v); + if(low == high) return low; + + if constexpr(std::is_same_v) { + assert(low < high); + // Since C++20 we can assume Two's Complement but any sane system used it before anyway. + // Rejection sampling is not as fast as possible but definitely unbiased. + auto ul = static_cast(low); + auto uh = static_cast(high); + int shitfs = cpp20::countl_zero(uh - ul); + unsigned long long res; + do { + res = Random::bits64(rng) >> shitfs; + } while(res > uh - ul); + return static_cast(res + ul); + } else { + assert(low < high); + return low + Random::real64(rng) * (high - low); + } + } +}; + +template +struct RangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "range"; + using Args = std::tuple; + + const T low_, high_; + + explicit RangeGenerator(T low, T high) : low_(low), high_(high) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + return UniformGenerator()(std::max(low, low_), std::min(high, high_), rng); + } +}; + +template +struct StepRangeGenerator { + static_assert(is_number_v); + static constexpr std::string_view name = "steprange"; + using Args = std::tuple; + + const T low_, high_, step_; + + explicit StepRangeGenerator(T low, T high, T step) : low_(low), high_(high), step_(step) {} + + T operator()(T low, T high, std::mt19937_64& rng) const { + // round up low to the first multiple of step_. + T start; + if(low <= low_) { + start = low_; + } else { + // first multiple of low_+k*step_ >= low + start = low_ + (long long)((low - low_) / step_) * step_; + if(start < low) start += step_; + assert(low <= start && start < low + step_); + } + long long maxsteps = (std::min(high, high_) - start) / step_; + long long steps = UniformGenerator()(0ll, maxsteps, rng); + return start + steps * step_; + } +}; + +struct NormalDistributionGenerator { + static constexpr std::string_view name = "normal"; + using T = long double; + using Args = std::tuple; + + const T mean_, stddev_; + + explicit NormalDistributionGenerator(T mean, T stddev) : mean_(mean), stddev_(stddev) { + assert(stddev_ >= 0); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + T u1 = Random::real64(rng); + T u2 = Random::real64(rng); + // Box-Muller-Methode + // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform + v = std::sqrt(-2.0l * std::log(u1)) * std::cos(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + v = std::sqrt(-2.0l * std::log(u1)) * std::sin(2.0l * cpp20::PI * u2); + v = std::sqrt(stddev_) * v + mean_; + if(v >= low && v < high) return v; + } + return v; + } +}; + +struct ExponentialDistributionGenerator { + static constexpr std::string_view name = "exponential"; + using T = long double; + using Args = std::tuple; + + T lambda_; + + explicit ExponentialDistributionGenerator(T lambda) : lambda_(lambda) { assert(lambda_ > 0); } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low < high); + T v; + while(true) { + v = low - std::log(Random::real64(rng)) / lambda_; + if(v < high) return v; + } + } +}; + +struct GeometricDistributionGenerator { + static constexpr std::string_view name = "geometric"; + using T = long long; + using Args = std::tuple; + + double p_; + + explicit GeometricDistributionGenerator(double p) : p_(p) { + assert(p_ > 0); + assert(p_ < 1); + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + T v; + while(true) { + // https://en.wikipedia.org/wiki/Geometric_distribution + // "The exponential distribution is the continuous analogue of the geometric + // distribution[...]" + v = low + std::floor(std::log(Random::real64(rng)) / std::log1p(-p_)); + if(v <= high) return v; + } + } +}; + +struct BinomialDistributionGenerator { + static constexpr std::string_view name = "binomial"; + using T = long long; + using Args = std::tuple; + + long long n_; + double p_; + + explicit BinomialDistributionGenerator(long long n, double p) : n_(n), p_(p) { + assert(p_ >= 0); + assert(p_ <= 1); + std::cerr << "Warning: Large n (" << n_ << ") is slow for BinomialDistributionGenerator!" + << std::endl; + } + + // NOTE: Currently this retries instead of clamping to the interval. + T operator()(T low, T high, std::mt19937_64& rng) const { + assert(low <= high); + // this will be slow for large n + // (a faster implementation requires efficient poisson sampling) + while(true) { + T v = 0; + for(long long i = 0; i < n_; i++) { + v += Random::real64(rng) < p_ ? 1 : 0; + } + if(v >= low && v <= high) return v; + } + } +}; + +template +struct ChoiceGenerator { + using GeneratorType = std::conditional_t< + std::is_same_v, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, GeometricDistributionGenerator, + BinomialDistributionGenerator>, + std::variant, MinGenerator, MaxGenerator, UniformGenerator, + RangeGenerator, StepRangeGenerator, NormalDistributionGenerator, + ExponentialDistributionGenerator>>; + + std::vector> generators_; + double total_weight_; + + template + struct Pack {}; + + template + static A parse_number(std::string_view s) { + static_assert(is_number_v); + if constexpr(std::is_same_v) + return stoll(std::string(s)); + else + return stold(std::string(s)); + } + + template + static A parse_argument(std::string_view& s) { + auto end = s.find_first_of(",)"); + assert(end != std::string_view::npos); + auto v = parse_number(s.substr(0, end)); + s.remove_prefix(end); + // Pop the trailing , or ) + s.remove_prefix(1); + return v; + } + + template + static std::tuple parse_arguments(std::string_view& s, + Pack> /*unused*/) { + std::tuple args{parse_argument(s)...}; + return args; + } + + // Try parsing one generator type from the start of s. + template + static void parse_generator(std::string_view& s, std::optional& out) { + if(out) return; + if(s.substr(0, G::name.size()) != G::name) return; + + // Drop the name. + s.remove_prefix(G::name.size()); + if constexpr(std::tuple_size_v == 0) { + out.emplace(std::in_place_type_t{}); + return; + } + + // Drop the ( + assert(not s.empty() and s.front() == '('); + s.remove_prefix(1); + + auto args = parse_arguments(s, Pack{}); + // Construct the resulting generator in-place in the variant.. + std::apply([&](const auto&... _args) { out.emplace(std::in_place_type_t{}, _args...); }, + args); + } + + template + static std::optional parse_generators(std::string_view& s, + Pack> /*unused*/) { + std::optional out; + (parse_generator(s, out), ...); + return out; + } + + explicit ChoiceGenerator(std::string_view s) : total_weight_(0) { + // PARSE + while(not s.empty()) { + auto generator = parse_generators(s, Pack{}); + if(!generator) { + // Check for range syntax: + auto comma = s.find_first_of(",:"); + if(comma == std::string::npos) comma = s.size(); + auto dots = s.find(".."); + if(dots != std::string_view::npos and dots < comma) { + auto start = s.substr(0, dots); + auto end = s.substr(dots + 2, comma - dots - 2); + + generator.emplace(std::in_place_type_t>{}, + parse_number(start), parse_number(end)); + s.remove_prefix(comma); + } + + // Fall back to constant. + if(!generator) { + generator.emplace(std::in_place_type_t>{}, + parse_number(s.substr(0, comma))); + s.remove_prefix(comma); + } + } + + // Parse weight if given. + double weight = 1; + if(not s.empty() and s.front() == ':') { + s.remove_prefix(1); + auto comma = s.find(','); + if(comma == std::string_view::npos) comma = s.size(); + weight = parse_number(s.substr(0, comma)); + s.remove_prefix(comma); + } + + // should now be at , or end + assert(s.empty() or s.front() == ','); + if(not s.empty()) s.remove_prefix(1); + generators_.emplace_back(std::move(*generator), weight); + total_weight_ += weight; + } + } + + T operator()(T low, T high, std::mt19937_64& rng) const { + Generators::UniformGenerator uniform; + double x = uniform.operator()(0, total_weight_, rng); + for(size_t i = 0; i < generators_.size(); ++i) { + x -= generators_[i].second; + if(x <= 0) + return std::visit([&](auto& g) { return g(low, high, rng); }, generators_[i].first); + } + assert(false); + } +}; + +struct ParamGenerator { + std::variant, ChoiceGenerator> + generator; + explicit ParamGenerator(std::string_view s) : generator(s) {} + + template + T operator()(T low, T high, std::mt19937_64& rng) { + static_assert(is_number_v); + if(std::holds_alternative(generator)) { + generator = ChoiceGenerator(std::get(generator)); + } + return std::get>(generator)(low, high, rng); + } +}; + +} // namespace Generators + +using Generators::ParamGenerator; + +namespace Random { +template +void shuffle(RandomIt first, RandomIt last, std::mt19937_64& rng) { + Generators::UniformGenerator uniform; + long long n = last - first; + for(long long i = n - 1; i > 0; i--) { + std::swap(first[i], first[uniform(0ll, i, rng)]); + } +} + +template +void shuffle(std::pair& in, std::mt19937_64& rng) { + if(bit(rng)) std::swap(in.first, in.second); +} + +template +auto& select(RandomIt first, RandomIt last, std::mt19937_64& rng) { + assert(first != last); + Generators::UniformGenerator uniform; + long long n = last - first; + return first[uniform(0ll, n - 1, rng)]; +} + +template +const T& select(const std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +template +T& select(std::pair& in, std::mt19937_64& rng) { + return bit(rng) ? in.first : in.second; +} + +} // namespace Random + +class Validator { + protected: + Validator(bool ws_, bool case_, std::istream& in_, std::string constraints_file_path_ = "", + std::optional seed = std::nullopt, + std::unordered_map params_ = {}) + : in(in_), ws(ws_), case_sensitive(case_), + constraints_file_path(std::move(constraints_file_path_)), gen(seed.has_value()), + rng(seed.value_or(Random::default_seed)), params(std::move(params_)) { + + std::ios_base::sync_with_stdio(false); + in.tie(nullptr); + + if(gen) return; + if(ws) + in >> std::noskipws; + else + in >> std::skipws; + } + + public: + // No copying, no moving. + Validator(const Validator&) = delete; + Validator(Validator&&) = delete; + void operator=(const Validator&) = delete; + void operator=(Validator&&) = delete; + + // At the end of the scope, check whether the EOF has been reached. + // If so, return AC. Otherwise, return WA. + ~Validator() { + eof(); + write_constraints(); + AC(); + } + + void space() { + if(gen) { + out << ' '; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected space, found EOF."); + if(c != ' ') + expected("space", std::string("\"") + + ((c == '\n' or c == '\r') ? std::string("newline") + : std::string(1, c)) + + "\""); + } + } + + void newline() { + if(gen) { + out << '\n'; + return; + } + + if(ws) { + char c; + in >> c; + check(!in.eof(), "Expected newline, found EOF."); + if(c != '\n') { + if(c == '\r') + expected("newline", "DOS line ending (\\r)"); + else + expected("newline", std::string("\"") + c + "\""); + } + } + } + + private: + void separator(Separator s) { + switch(s) { + case Separator::Space: space(); break; + case Separator::Newline: newline(); break; + } + } + + template + auto& seen() { + static std::unordered_map> seen; + return seen; + } + template + auto& last_seen() { + static std::unordered_map last_seen; + return last_seen; + } + template + auto& integers_seen() { + static std::unordered_map, std::vector, bool>> + integers_seen; + return integers_seen; + } + template + void reset(std::string name) { + seen().erase(name); + last_seen().erase(name); + integers_seen().erase(name); + } + + template + void check_number(const std::string& name, T low, T high, T v, Tag /*unused*/) { + static_assert(is_number_v); + if(v < low or v > high) { + std::string type_name; + if constexpr(std::is_integral_v) { + type_name = "integer"; + } + if constexpr(std::is_floating_point_v) { + type_name = "float"; + } + expected(name + ": " + type_name + " between " + std::to_string(low) + " and " + + std::to_string(high), + std::to_string(v)); + } + log_constraint(name, low, high, v); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[name].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else { + auto [it, inserted] = last_seen().emplace(name, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + template + void check_string(const std::string& name, int low, int high, const std::string& v, + Tag /*unused*/) { + using T = std::string; + if((int)v.size() < low or (int) v.size() > high) { + expected(name + ": " + "string with" + " length between " + std::to_string(low) + + " and " + std::to_string(high), + v); + } + log_constraint("|" + name + "|", low, high, static_cast(v.size())); + if constexpr(Tag::unique) { + auto [it, inserted] = seen()[name].emplace(v); + check(inserted, name, ": Value ", v, " seen twice, but must be unique!"); + } else if(Tag::increasing or Tag::decreasing) { + auto [it, inserted] = last_seen().emplace(name, v); + if(inserted) return; + + auto last = it->second; + it->second = v; + + if constexpr(Tag::increasing) + check(v >= last, name, " is not increasing: value ", v, " follows ", last); + if constexpr(Tag::decreasing) + check(v <= last, name, " is not decreasing: value ", v, " follows ", last); + if constexpr(Tag::strict) + check(v != last, name, " is not strict: value ", v, " equals ", last); + } + } + + // Generate a random integer in [low, high] or float in [low, high). + template + T uniform_number(T low, T high) { + assert(low <= high); + Generators::UniformGenerator uniform; + if constexpr(std::is_integral::value) + return uniform.operator()(low, high, rng); + else + return uniform.operator()(low, high, rng); + } + + template + T gen_number(const std::string& name, T low, T high, Tag /*unused*/) { + static_assert(is_number_v); + T v; + + if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + if constexpr(std::is_integral::value) { + auto& [seen_here, remaining_here, use_remaining] = integers_seen()[name]; + + if(use_remaining) { + check(!remaining_here.empty(), name, ": no unique values left"); + v = remaining_here.back(); + remaining_here.pop_back(); + } else { + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + + struct CountIterator { + T v; + T& operator*() { return v; } + T& operator++() { return ++v; } + T operator++(int) { return v++; } + bool operator!=(CountIterator r) { return v != r.v; } + }; + + if(seen_here.size() > (high - low) / 2) { + use_remaining = true; + set_difference(CountIterator{low}, CountIterator{high + 1}, + seen_here.begin(), seen_here.end(), + std::back_inserter(remaining_here)); + } + } + } else { + // For floats, just regenerate numbers until success. + auto& seen_here = seen()[name]; + do { + v = uniform_number(low, high); + } while(!seen_here.insert(v).second); + } + + } else { + assert(not Tag::increasing && "Generating increasing sequences is not yet supported!"); + assert(not Tag::decreasing && "Generating decreasing sequences is not yet supported!"); + assert((std::is_same::value) && + "Only Unique and Arbitrary are supported!"); + + if(params.find(name) != params.end()) { + v = params.at(name).operator()(low, high, rng); + // This will be checked during input validation of the generated case. + // assert(low <= v and v <= high); + } else { + v = uniform_number(low, high); + } + } + + return v; + } + + std::string gen_string(const std::string& name, long long low, long long high, + std::string_view chars) { + assert(!chars.empty()); + + int len; + if(params.find(name + ".length") != params.end()) + len = params.at(name + ".length").operator()(low, high, rng); + else + len = uniform_number(low, high); + std::string s(len, ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s; + return s; + } + + public: + template + long long gen_integer(const std::string& name, long long low, long long high, Tag tag = Tag{}) { + return gen_number(name, low, high, tag); + } + + template + long double gen_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}) { + return gen_number(name, low, high, tag); + } + + private: + template + std::vector gen_numbers(const std::string& name, int count, T low, T high, Tag /*unused*/) { + static_assert(is_number_v); + std::vector v; + v.reserve(count); + if constexpr(std::is_same_v) { + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + } else if constexpr(Tag::unique) { + assert(params.find(name) == params.end() && + "Parameters are not supported for unique values."); + std::set seen_here; + if constexpr(std::is_integral_v) { + if(2 * count < high - low) { + for(int i = 0; i < count; ++i) { + // If density < 1/2: retry. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } else { + // If density >= 1/2, crop a random permutation. + v.resize(high - low + 1); + iota(begin(v), end(v), low); + Random::shuffle(begin(v), end(v), rng); + v.resize(count); + } + } else { + for(int i = 0; i < count; ++i) { + // For floats, just regenerate numbers until success. + T w; + do { + w = uniform_number(low, high); + } while(!seen_here.insert(w).second); + v.push_back(w); + } + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + constexpr bool integral_strict = Tag::strict and std::is_integral::value; + if(integral_strict) { + assert(params.find(name) == params.end() && + "Parameters are not supported for strict integer values."); + high = high - count + 1; + } + + if(params.find(name) != params.end()) { + auto& generator = params.at(name); + for(int i = 0; i < count; ++i) { + auto val = generator.operator()(low, high, rng); + assert(low <= val and val <= high); + v.push_back(val); + } + } else { + for(int i = 0; i < count; ++i) { + v.push_back(uniform_number(low, high)); + } + } + + sort(begin(v), end(v)); + + if(integral_strict) { + for(int i = 0; i < count; ++i) v[i] += i; + } + + if(Tag::decreasing) reverse(begin(v), end(v)); + } + + return v; + } + + public: + template + std::vector gen_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}) { + return gen_numbers(name, count, low, high, tag); + } + + template + std::vector gen_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}) { + return gen_numbers(name, count, low, high, tag); + } + + private: + template + T read_number(const std::string& name, T low, T high, Tag tag) { + if(gen) { + auto v = gen_number(name, low, high, tag); + out << std::setprecision(10) << std::fixed << v; + return v; + } + + const auto v = [&] { + if constexpr(std::is_integral::value) + return read_integer(name); + else + return read_float(name); + }(); + + check_number(name, low, high, v, tag); + return v; + } + + // Read a vector of numbers, separated by spaces and ended by a newline. + template + std::vector read_numbers(const std::string& name, int count, T low, T high, Tag tag, + Separator sep) { + if(gen) { + auto v = gen_numbers(name, count, low, high, tag); + + out << std::setprecision(10) << std::fixed; + for(int i = 0; i < count; ++i) { + out << v[i]; + if(i < count - 1) separator(sep); + } + newline(); + + return v; + } + reset(name); + std::vector v(count); + for(int i = 0; i < count; ++i) { + if constexpr(std::is_integral::value) + v[i] = read_integer(name); + else + v[i] = read_float(name); + check_number(name, low, high, v[i], tag); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + public: + template + long long read_integer(const std::string& name, long long low, long long high, + Tag tag = Tag{}) { + return read_number(name, low, high, tag); + } + template + std::vector read_integers(const std::string& name, int count, long long low, + long long high, Tag tag = Tag{}, Separator sep = Space) { + return read_numbers(name, count, low, high, tag, sep); + } + + template + long double read_float(const std::string& name, long double low, long double high, + Tag tag = Tag{}) { + return read_number(name, low, high, tag); + } + template + std::vector read_floats(const std::string& name, int count, long double low, + long double high, Tag tag = Tag{}, Separator sep = Space) { + return read_numbers(name, count, low, high, tag, sep); + } + + // Read a vector of strings, separated by spaces and ended by a newline. + template + std::vector read_strings(const std::string& name, int count, int min, int max, + const std::string_view chars = "", Tag tag = Tag(), + Separator sep = Space) { + reset(name); + if(gen) return gen_strings(name, count, min, max, chars, tag, sep); + assert(!gen); + std::vector v(count); + for(int i = 0; i < count; ++i) { + v[i] = read_string(name, min, max, chars, tag); + if(i < count - 1) separator(sep); + } + newline(); + return v; + } + + template + std::vector gen_strings(const std::string& name, int count, int min, int max, + const std::string_view chars, Tag /*unused*/, + Separator sep) { + assert(!chars.empty()); + + std::vector v(count); + if constexpr(std::is_same::value) { + for(int i = 0; i < count; ++i) { + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else if constexpr(Tag::unique) { + std::set seen_here; + for(int i = 0; i < count; ++i) { + // Just regenerate strings until success. + std::string s; + do { + s = std::string(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + } while(!seen_here.insert(s).second); + v.push_back(s); + out << s; + if(i < count - 1) separator(sep); + } + } else { + static_assert(Tag::increasing or Tag::decreasing); + + assert(false && "Generating increasing/decreasing lists of strings is not " + "supported!"); + } + + newline(); + + return v; + } + + // Check the next character. + bool peek(char c, const std::string& name = "") { + if(gen) { + // TODO + // if(not name.empty() and params.contains(name)) { + // return c == params.at(name).operator()(0, 0, rng); + //} + return Random::bit(rng); + } + if(!ws) in >> std::ws; + if(case_sensitive) return in.peek() == std::char_traits::to_int_type(c); + return tolower(in.peek()) == tolower(std::char_traits::to_int_type(c)); + } + + // Read a string and make sure it equals `expected`. + // Takes by value because it needs to lowercase its arguments. + std::string test_strings(std::vector expected, const std::string& name = "") { + if(gen) { + int index = 0; + // TODO + // if(not name.empty() and params.contains(name)) { + // auto s = params.at(name).operator()(0, 0, rng); + // index = std::find(expected.begin(), expected.end(), s) - expected.begin(); + // assert(0 <= index and index < expected.size()); + //} else { + index = expected.size() == 1 ? 0 : uniform_number(0, expected.size() - 1); + //} + out << expected[index]; + return expected[index]; + } + std::string s = get_string(); + lowercase(s); + + for(std::string e : expected) + if(s == lowercase(e)) return s; + + std::string error; + for(const auto& e : expected) { + if(not error.empty()) error += "|"; + error += e; + } + WA("Expected string \"", error, "\", but found ", s); + } + + // Read a string and make sure it equals `expected`. + std::string test_string(std::string expected, const std::string& name = "") { + return test_strings({std::move(expected)}, name); + } + + // Read an arbitrary string of a given length. + template + std::string read_string(const std::string& name, long long min, long long max, + const std::string_view chars = "", Tag tag = Tag()) { + if(gen) { + return gen_string(name, min, max, chars); + } + std::string s = get_string(); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + check_string(name, min, max, s, tag); + return s; + } + + // Read an arbitrary line of a given length. + std::string read_line(const std::string& name, long long min, long long max, + const std::string_view chars = "") { + if(gen) { + // TODO: Params for lines. + assert(!chars.empty()); + + std::string s(uniform_number(min, max), ' '); + for(auto& x : s) x = chars[uniform_number(0, chars.size() - 1)]; + + out << s << '\n'; + return s; + } + + if(ws) { + char next = in.peek(); + if(min > 0 and isspace(next)) + expected("non empty line", next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected("line", "EOF"); + } + std::string s; + if(!getline(in, s)) expected("line", "nothing"); + long long size = s.size(); + if(size < min || size > max) + expected(name + ": line of length between " + std::to_string(min) + " and " + + std::to_string(max), + s); + std::array ok_char{}; + if(!chars.empty()) { + for(auto c : chars) ok_char[c] = true; + for(auto c : s) + check(ok_char[c], name, ": expected characters in ", chars, " but found character ", + c, " in ", s); + } + log_constraint("|" + name + "|", min, max, size); + return s; + } + + // Return ACCEPTED verdict. + void eof_and_AC() { + eof(); + AC(); + } + + private: + std::function WA_handler = [] {}; + + public: + void set_WA_handler(std::function f) { WA_handler = std::move(f); } + + // Return WA with the given reason. + template + [[noreturn]] void WA(const Ts&... ts) { + static_assert(sizeof...(Ts) > 0); + + WA_handler(); + + auto pos = get_file_pos(); + std::cerr << pos.first << ":" << pos.second << ": "; + + WA_impl(ts...); + } + + // Check that the condition is true. + template + void check(bool b, const Ts&... ts) { + static_assert(sizeof...(Ts) > 0, "Provide a non-empty error message."); + + if(!b) WA(ts...); + } + + // Log some value in a range. + template + void log_constraint(const std::string& name, T low, T high, T v) { + // All integer types get bounds as long long, all floating point types as long_double. + using U = Bounds, long long, long double>>; + + auto [it, inserted] = bounds.emplace(name, U(name, v, v, low, high)); + assert(std::holds_alternative(it->second)); + auto& done = std::get(it->second); + if(inserted) { + assert(!name.empty() && "Variable names must not be empty."); + assert(name.find(' ') == std::string::npos && "Variable name must not contain spaces."); + } else { + assert(name == done.name && "Variable name must be constant."); + } + if(v < done.min) { + done.min = v; + done.low = low; + } + if(v > done.max) { + done.max = v; + done.high = high; + } + done.has_min |= v == low; + done.has_max |= v == high; + } + + private: + long long read_integer(const std::string& name) { + assert(!gen); + std::string s = get_string("integer"); + if(s.empty()) { + WA(name, ": Want integer, found nothing"); + } + long long v; + try { + auto begin = s.c_str(), end = begin + s.size(); + auto [ptr, ec] = std::from_chars(begin, end, v); + if(ptr != end or ec != std::errc{}) + WA(name, ": Parsing " + s + " as long long failed! Did not process all characters"); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long long!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long long failed!"); + } + // Check for leading zero. + if(v == 0) { + if(s.size() != 1) WA(name, ": Parsed 0, but has leading 0 or minus sign: ", s); + } + if(v > 0) { + if(s[0] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + if(v < 0) { + if(s.size() <= 1) WA(name, ": Parsed ", v, ", but string is: ", s); + if(s[1] == '0') WA(name, ": Parsed ", v, ", but has leading 0: ", s); + } + return v; + } + + long double read_float(const std::string& name) { + assert(!gen); + std::string s = get_string("long double"); + long double v; + try { + size_t chars_processed; + v = stold(s, &chars_processed); + if(chars_processed != s.size()) + WA(name, ": Parsing ", s, + " as long double failed! Did not process all characters."); + } catch(const std::out_of_range& e) { + WA(name, ": Number " + s + " does not fit in a long double!"); + } catch(const std::invalid_argument& e) { + WA("Parsing " + s + " as long double failed!"); + } + return v; + } + + [[noreturn]] void expected(const std::string& exp = "", const std::string& s = "") { + assert(!gen && "Expected is not supported for generators."); + WA("Expected ", exp, ", found ", s.empty() ? "empty string" : s); + } + + template + [[noreturn]] void WA_impl(T t) { + std::cerr << t << std::endl; + exit(ret_WA); + } + + std::pair get_file_pos() { + int line = 1, col = 0; + in.clear(); + auto originalPos = in.tellg(); + if(originalPos < 0) return {-1, -1}; + in.seekg(0); + char c; + while((in.tellg() < originalPos) && in.get(c)) { + if(c == '\n') + ++line, col = 0; + else + ++col; + } + return {line, col}; + } + + template + [[noreturn]] void WA_impl(T t, Ts... ts) { + std::cerr << t; + WA_impl(ts...); + } + + std::string get_string(const std::string& wanted = "string") { + assert(!gen && "get_string is not supported for generators."); + if(ws) { + char next = in.peek(); + if(isspace(next)) expected(wanted, next == '\n' ? "newline" : "whitespace"); + if(in.eof()) expected(wanted, "EOF"); + } + + std::string s; + if(in >> s) { + return s; + } + expected(wanted, "nothing"); + } + + // Return ACCEPTED verdict. + void AC() const { + if(gen) { + // nothing + return; + } + + exit(ret_AC); + } + + void eof() { + if(gen) { + out.flush(); + fclose(stdout); + return; + } + if(in.eof()) return; + // Sometimes EOF hasn't been triggered yet. + if(!ws) in >> std::ws; + int c = in.get(); + if(c == std::char_traits::eof()) return; + std::string got = std::string("\"") + char(c) + '"'; + if(c == '\n') got = "newline"; + expected("EOF", got); + } + + public: + // Convert a string to lowercase is matching is not case sensitive. + std::string& lowercase(std::string& s) const { + if(case_sensitive) return s; + transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; + } + + private: + // Keep track of the min/max value read at every call site. + template + struct Bounds { + Bounds(std::string name_, T min_, T max_, T low_, T high_) + : name(std::move(name_)), min(min_), max(max_), low(low_), high(high_) {} // NOLINT + std::string name; + T min, max; // Smallest / largest value observed + T low, high; // Bounds + bool has_min = false, has_max = false; + }; + + std::unordered_map, Bounds>> bounds; + + void write_constraints() { + if(constraints_file_path.empty()) return; + + std::ofstream os(constraints_file_path); + + for(const auto& [name, bound] : bounds) { + std::visit( + [&](const auto& b) { + os << "LocationNotSupported:" << b.name << " " << b.name << " " << b.has_min + << " " << b.has_max << " " << b.min << " " << b.max << " " << b.low << " " + << b.high << std::endl; + }, + bound); + } + } + + static const int ret_AC = 42, ret_WA = 43; + std::istream& in = std::cin; + std::ostream& out = std::cout; + + public: + const bool ws = true; + const bool case_sensitive = true; + const std::string constraints_file_path; + const bool gen = false; + + std::mt19937_64 rng; + + private: + std::unordered_map params; + + public: + std::string_view get_param(std::string_view name, std::string_view default_) { + auto it = params.find(std::string(name)); + if(it == params.end()) return default_; + return std::get(it->second.generator); + } + + protected: + static std::string get_constraints_file(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == constraints_file_flag) { + if(i + 1 < argc) return argv[i + 1]; + std::cerr << constraints_file_flag << " should be followed by a file path!"; + exit(1); + } + } + return {}; + } +}; + +class Generator : public Validator { + public: + explicit Generator(unsigned int seed) + : Validator(true, true, std::cin, /*constraints_file_path_=*/"", seed) {} +}; + +class InputValidator : public Validator { + public: + // An InputValidator is always both whitespace and case sensitive. + explicit InputValidator(int argc = 0, char** argv = nullptr) + : Validator(true, true, std::cin, get_constraints_file(argc, argv), get_seed(argc, argv), + get_params(argc, argv)) {} + + private: + static std::optional get_seed(int argc, char** argv) { + for(int i = 1; i < argc - 1; ++i) { + if(argv[i] == generate_flag) { + return std::stol(argv[i + 1]); + } + } + // If no --generate is given, but `generat` is a substring of the binary path, + // use the first argument as seed. + if(std::string(argv[0]).find(generate_binary_substring) != std::string::npos) { + return std::stol(argv[1]); + } + return std::nullopt; + } + + static std::unordered_map get_params(int argc, char** argv) { + std::unordered_map params; + for(int i = 1; i < argc - 1; ++i) { + if(std::strlen(argv[i]) == 0 or argv[i][0] != '-') continue; + if(argv[i] == generate_flag) { + continue; + } + std::string_view name(argv[i] + 1); + std::string_view value(argv[i + 1]); + params.insert({std::string(name), ParamGenerator(value)}); + } + return params; + } +}; + +class OutputValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit OutputValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(is_ws_sensitive(argc, argv), is_case_sensitive(argc, argv), in_, + get_constraints_file(argc, argv)) {} + + private: + static bool is_ws_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == ws_sensitive_flag) return true; + } + return false; + } + + static bool is_case_sensitive(int argc, char** argv) { + for(int i = 1; i < argc; ++i) { + if(argv[i] == case_sensitive_flag) return true; + } + return false; + } +}; + +class AnswerValidator : public Validator { + public: + // An OutputValidator can be run in different modes. + explicit AnswerValidator(int argc, char** argv, std::istream& in_ = std::cin) + : Validator(/*ws_sensitive=*/true, /*space sensitive*/ true, in_, + get_constraints_file(argc, argv)) {} +}; diff --git a/ICPC/nwerc2024_K/data.zip b/ICPC/nwerc2024_K/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..96f4ec399118f919d53655026ea524587854d737 --- /dev/null +++ b/ICPC/nwerc2024_K/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfbfa146de2c82d084664d2fab4b1ffe7a06c30bafed2635a39692b8ac1f2e38 +size 74967273 diff --git a/ICPC/nwerc2024_K/init.yml b/ICPC/nwerc2024_K/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f541f3c92f2f2c5934a935b4dbb2948937670d8d --- /dev/null +++ b/ICPC/nwerc2024_K/init.yml @@ -0,0 +1,255 @@ +archive: data.zip +checker: + args: + precision: 6 + name: floats +test_cases: +- in: 03-dijkstra-linear-killer.in + out: 03-dijkstra-linear-killer.ans + points: 1 +- in: 04-dijkstra-quadratic.in + out: 04-dijkstra-quadratic.ans + points: 1 +- in: 05-dijkstra-quadratic-sorted.in + out: 05-dijkstra-quadratic-sorted.ans + points: 1 +- in: 06-dijkstra-queue.in + out: 06-dijkstra-queue.ans + points: 1 +- in: 07-dijkstra-queue-sorted.in + out: 07-dijkstra-queue-sorted.ans + points: 1 +- in: 08-min.in + out: 08-min.ans + points: 1 +- in: 09-tiny.in + out: 09-tiny.ans + points: 1 +- in: 10-tiny.in + out: 10-tiny.ans + points: 1 +- in: 11-tiny.in + out: 11-tiny.ans + points: 1 +- in: 12-tiny.in + out: 12-tiny.ans + points: 1 +- in: 13-tiny.in + out: 13-tiny.ans + points: 1 +- in: 14-small.in + out: 14-small.ans + points: 1 +- in: 15-small.in + out: 15-small.ans + points: 1 +- in: 16-small.in + out: 16-small.ans + points: 1 +- in: 17-small.in + out: 17-small.ans + points: 1 +- in: 18-small.in + out: 18-small.ans + points: 1 +- in: 19-small.in + out: 19-small.ans + points: 1 +- in: 20-small.in + out: 20-small.ans + points: 1 +- in: 21-small.in + out: 21-small.ans + points: 1 +- in: 22-small.in + out: 22-small.ans + points: 1 +- in: 23-small.in + out: 23-small.ans + points: 1 +- in: 24-small.in + out: 24-small.ans + points: 1 +- in: 25-small.in + out: 25-small.ans + points: 1 +- in: 26-small.in + out: 26-small.ans + points: 1 +- in: 27-small.in + out: 27-small.ans + points: 1 +- in: 28-small.in + out: 28-small.ans + points: 1 +- in: 29-small.in + out: 29-small.ans + points: 1 +- in: 30-small.in + out: 30-small.ans + points: 1 +- in: 31-small.in + out: 31-small.ans + points: 1 +- in: 32-small.in + out: 32-small.ans + points: 1 +- in: 33-small.in + out: 33-small.ans + points: 1 +- in: 34-small.in + out: 34-small.ans + points: 1 +- in: 35-small.in + out: 35-small.ans + points: 1 +- in: 36-random.in + out: 36-random.ans + points: 1 +- in: 37-random.in + out: 37-random.ans + points: 1 +- in: 38-random.in + out: 38-random.ans + points: 1 +- in: 39-random.in + out: 39-random.ans + points: 1 +- in: 40-random.in + out: 40-random.ans + points: 1 +- in: 41-random.in + out: 41-random.ans + points: 1 +- in: 42-random.in + out: 42-random.ans + points: 1 +- in: 43-random.in + out: 43-random.ans + points: 1 +- in: 44-randommax.in + out: 44-randommax.ans + points: 1 +- in: 45-randommax.in + out: 45-randommax.ans + points: 1 +- in: 46-randommax.in + out: 46-randommax.ans + points: 1 +- in: 47-randommax.in + out: 47-randommax.ans + points: 1 +- in: 48-randommax.in + out: 48-randommax.ans + points: 1 +- in: 49-impossible.in + out: 49-impossible.ans + points: 1 +- in: 50-impossible.in + out: 50-impossible.ans + points: 1 +- in: 51-impossible.in + out: 51-impossible.ans + points: 1 +- in: 52-impossible.in + out: 52-impossible.ans + points: 1 +- in: 53-psmall.in + out: 53-psmall.ans + points: 1 +- in: 54-psmall.in + out: 54-psmall.ans + points: 1 +- in: 55-psmall.in + out: 55-psmall.ans + points: 1 +- in: 56-psmall.in + out: 56-psmall.ans + points: 1 +- in: 57-psmall.in + out: 57-psmall.ans + points: 1 +- in: 58-psmall.in + out: 58-psmall.ans + points: 1 +- in: 59-psmall.in + out: 59-psmall.ans + points: 1 +- in: 60-psmall.in + out: 60-psmall.ans + points: 1 +- in: 61-psmall.in + out: 61-psmall.ans + points: 1 +- in: 62-psmall.in + out: 62-psmall.ans + points: 1 +- in: 63-pmedium.in + out: 63-pmedium.ans + points: 1 +- in: 64-pmedium.in + out: 64-pmedium.ans + points: 1 +- in: 65-pmedium.in + out: 65-pmedium.ans + points: 1 +- in: 66-pmedium.in + out: 66-pmedium.ans + points: 1 +- in: 67-plarge.in + out: 67-plarge.ans + points: 1 +- in: 68-pmax.in + out: 68-pmax.ans + points: 1 +- in: 69-tree.in + out: 69-tree.ans + points: 1 +- in: 70-tree.in + out: 70-tree.ans + points: 1 +- in: 71-tree.in + out: 71-tree.ans + points: 1 +- in: 72-tree.in + out: 72-tree.ans + points: 1 +- in: 73-tree.in + out: 73-tree.ans + points: 1 +- in: 74-tree.in + out: 74-tree.ans + points: 1 +- in: 75-tree.in + out: 75-tree.ans + points: 1 +- in: 76-maxpath.in + out: 76-maxpath.ans + points: 1 +- in: 77-prec.in + out: 77-prec.ans + points: 1 +- in: 78-prec.in + out: 78-prec.ans + points: 1 +- in: 79-prec.in + out: 79-prec.ans + points: 1 +- in: 80-cutvtx.in + out: 80-cutvtx.ans + points: 1 +- in: 81-cutvtx.in + out: 81-cutvtx.ans + points: 1 +- in: 82-cutvtx.in + out: 82-cutvtx.ans + points: 1 +- in: 83-cutvtx.in + out: 83-cutvtx.ans + points: 1 +- in: 84-cutvtx.in + out: 84-cutvtx.ans + points: 1 +- in: 85-cutvtx.in + out: 85-cutvtx.ans + points: 1 diff --git a/ICPC/nwerc2024_L/data.zip b/ICPC/nwerc2024_L/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..f25ec7455e470a98a1fa9b2a8efdd446b4b7e57c --- /dev/null +++ b/ICPC/nwerc2024_L/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c40f6a9a495e5e2cee9406e99d704fbb03906e1ab53dc03a6f7898094046a4a +size 23849839 diff --git a/ICPC/nwerc2024_L/init.yml b/ICPC/nwerc2024_L/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a5a40fa51d3aa746b58a5cad8853611a21babe7a --- /dev/null +++ b/ICPC/nwerc2024_L/init.yml @@ -0,0 +1,464 @@ +archive: data.zip +test_cases: +- in: 005-min.in + out: 005-min.ans + points: 1 +- in: 006-min.in + out: 006-min.ans + points: 1 +- in: 007-min.in + out: 007-min.ans + points: 1 +- in: 008-min.in + out: 008-min.ans + points: 1 +- in: 009-min.in + out: 009-min.ans + points: 1 +- in: 010-min.in + out: 010-min.ans + points: 1 +- in: 011-min.in + out: 011-min.ans + points: 1 +- in: 012-small.in + out: 012-small.ans + points: 1 +- in: 013-small.in + out: 013-small.ans + points: 1 +- in: 014-possible_zero.in + out: 014-possible_zero.ans + points: 1 +- in: 015-impossible.in + out: 015-impossible.ans + points: 1 +- in: 016-impossible.in + out: 016-impossible.ans + points: 1 +- in: 017-possible.in + out: 017-possible.ans + points: 1 +- in: 018-possible.in + out: 018-possible.ans + points: 1 +- in: 019-possible_zero.in + out: 019-possible_zero.ans + points: 1 +- in: 020-all_books_one_shelf.in + out: 020-all_books_one_shelf.ans + points: 1 +- in: 021-all_books_one_shelf.in + out: 021-all_books_one_shelf.ans + points: 1 +- in: 022-all_books_one_shelf.in + out: 022-all_books_one_shelf.ans + points: 1 +- in: 023-all_books_one_shelf.in + out: 023-all_books_one_shelf.ans + points: 1 +- in: 024-all_books_one_shelf.in + out: 024-all_books_one_shelf.ans + points: 1 +- in: 025-planted-small.in + out: 025-planted-small.ans + points: 1 +- in: 026-planted-small.in + out: 026-planted-small.ans + points: 1 +- in: 027-planted-small.in + out: 027-planted-small.ans + points: 1 +- in: 028-planted-small.in + out: 028-planted-small.ans + points: 1 +- in: 029-planted-small.in + out: 029-planted-small.ans + points: 1 +- in: 030-planted-small.in + out: 030-planted-small.ans + points: 1 +- in: 031-planted-medium.in + out: 031-planted-medium.ans + points: 1 +- in: 032-planted-medium.in + out: 032-planted-medium.ans + points: 1 +- in: 033-planted-medium.in + out: 033-planted-medium.ans + points: 1 +- in: 034-planted-medium.in + out: 034-planted-medium.ans + points: 1 +- in: 035-planted-medium.in + out: 035-planted-medium.ans + points: 1 +- in: 036-planted-medium.in + out: 036-planted-medium.ans + points: 1 +- in: 037-planted-medium.in + out: 037-planted-medium.ans + points: 1 +- in: 038-planted-medium.in + out: 038-planted-medium.ans + points: 1 +- in: 039-planted-medium.in + out: 039-planted-medium.ans + points: 1 +- in: 040-planted-medium.in + out: 040-planted-medium.ans + points: 1 +- in: 041-planted-medium.in + out: 041-planted-medium.ans + points: 1 +- in: 042-planted-medium.in + out: 042-planted-medium.ans + points: 1 +- in: 043-planted-medium.in + out: 043-planted-medium.ans + points: 1 +- in: 044-planted-large-low-h-1.in + out: 044-planted-large-low-h-1.ans + points: 1 +- in: 045-planted-large-low-h-2.in + out: 045-planted-large-low-h-2.ans + points: 1 +- in: 046-planted-large-low-h-3.in + out: 046-planted-large-low-h-3.ans + points: 1 +- in: 047-planted-large-low-h-4.in + out: 047-planted-large-low-h-4.ans + points: 1 +- in: 048-planted-large-low-h-5.in + out: 048-planted-large-low-h-5.ans + points: 1 +- in: 049-planted-large-low-h-1.in + out: 049-planted-large-low-h-1.ans + points: 1 +- in: 050-planted-large-low-h-2.in + out: 050-planted-large-low-h-2.ans + points: 1 +- in: 051-planted-large-low-h-3.in + out: 051-planted-large-low-h-3.ans + points: 1 +- in: 052-planted-large-low-h-4.in + out: 052-planted-large-low-h-4.ans + points: 1 +- in: 053-planted-large-low-h-5.in + out: 053-planted-large-low-h-5.ans + points: 1 +- in: 054-planted-large-low-h-1.in + out: 054-planted-large-low-h-1.ans + points: 1 +- in: 055-planted-large-low-h-2.in + out: 055-planted-large-low-h-2.ans + points: 1 +- in: 056-planted-large-low-h-3.in + out: 056-planted-large-low-h-3.ans + points: 1 +- in: 057-planted-large-low-h-4.in + out: 057-planted-large-low-h-4.ans + points: 1 +- in: 058-planted-large-low-h-5.in + out: 058-planted-large-low-h-5.ans + points: 1 +- in: 059-planted-large-01.in + out: 059-planted-large-01.ans + points: 1 +- in: 060-planted-large-02.in + out: 060-planted-large-02.ans + points: 1 +- in: 061-planted-large-03.in + out: 061-planted-large-03.ans + points: 1 +- in: 062-planted-large-04.in + out: 062-planted-large-04.ans + points: 1 +- in: 063-planted-large-05.in + out: 063-planted-large-05.ans + points: 1 +- in: 064-planted-large-06.in + out: 064-planted-large-06.ans + points: 1 +- in: 065-planted-large-07.in + out: 065-planted-large-07.ans + points: 1 +- in: 066-planted-large-08.in + out: 066-planted-large-08.ans + points: 1 +- in: 067-planted-large-09.in + out: 067-planted-large-09.ans + points: 1 +- in: 068-planted-large-10.in + out: 068-planted-large-10.ans + points: 1 +- in: 069-planted-large-11.in + out: 069-planted-large-11.ans + points: 1 +- in: 070-planted-large-12.in + out: 070-planted-large-12.ans + points: 1 +- in: 071-planted-large-13.in + out: 071-planted-large-13.ans + points: 1 +- in: 072-planted-large-14.in + out: 072-planted-large-14.ans + points: 1 +- in: 073-planted-large-15.in + out: 073-planted-large-15.ans + points: 1 +- in: 074-planted-large-16.in + out: 074-planted-large-16.ans + points: 1 +- in: 075-planted-large-17.in + out: 075-planted-large-17.ans + points: 1 +- in: 076-planted-large-18.in + out: 076-planted-large-18.ans + points: 1 +- in: 077-planted-large-19.in + out: 077-planted-large-19.ans + points: 1 +- in: 078-planted-large-20.in + out: 078-planted-large-20.ans + points: 1 +- in: 079-possible_zero-01.in + out: 079-possible_zero-01.ans + points: 1 +- in: 080-possible_zero-02.in + out: 080-possible_zero-02.ans + points: 1 +- in: 081-possible_zero-03.in + out: 081-possible_zero-03.ans + points: 1 +- in: 082-possible_zero-04.in + out: 082-possible_zero-04.ans + points: 1 +- in: 083-possible_zero-05.in + out: 083-possible_zero-05.ans + points: 1 +- in: 084-possible_zero-06.in + out: 084-possible_zero-06.ans + points: 1 +- in: 085-possible_zero-07.in + out: 085-possible_zero-07.ans + points: 1 +- in: 086-possible_zero-08.in + out: 086-possible_zero-08.ans + points: 1 +- in: 087-possible_zero-09.in + out: 087-possible_zero-09.ans + points: 1 +- in: 088-possible_zero-10.in + out: 088-possible_zero-10.ans + points: 1 +- in: 089-random_with_max_constraints-01.in + out: 089-random_with_max_constraints-01.ans + points: 1 +- in: 090-random_with_max_constraints-02.in + out: 090-random_with_max_constraints-02.ans + points: 1 +- in: 091-random_with_max_constraints-03.in + out: 091-random_with_max_constraints-03.ans + points: 1 +- in: 092-random_with_max_constraints-04.in + out: 092-random_with_max_constraints-04.ans + points: 1 +- in: 093-random_with_max_constraints-05.in + out: 093-random_with_max_constraints-05.ans + points: 1 +- in: 094-random_with_max_constraints-06.in + out: 094-random_with_max_constraints-06.ans + points: 1 +- in: 095-random_with_max_constraints-07.in + out: 095-random_with_max_constraints-07.ans + points: 1 +- in: 096-random_with_max_constraints-08.in + out: 096-random_with_max_constraints-08.ans + points: 1 +- in: 097-random_with_max_constraints-09.in + out: 097-random_with_max_constraints-09.ans + points: 1 +- in: 098-random_with_max_constraints-10.in + out: 098-random_with_max_constraints-10.ans + points: 1 +- in: 099-random_with_lim_10_for_a_and_b-01.in + out: 099-random_with_lim_10_for_a_and_b-01.ans + points: 1 +- in: 100-random_with_lim_10_for_a_and_b-02.in + out: 100-random_with_lim_10_for_a_and_b-02.ans + points: 1 +- in: 101-random_with_lim_10_for_a_and_b-03.in + out: 101-random_with_lim_10_for_a_and_b-03.ans + points: 1 +- in: 102-random_with_lim_10_for_a_and_b-04.in + out: 102-random_with_lim_10_for_a_and_b-04.ans + points: 1 +- in: 103-random_with_lim_10_for_a_and_b-05.in + out: 103-random_with_lim_10_for_a_and_b-05.ans + points: 1 +- in: 104-random_with_lim_10_for_a_and_b-06.in + out: 104-random_with_lim_10_for_a_and_b-06.ans + points: 1 +- in: 105-random_with_lim_10_for_a_and_b-07.in + out: 105-random_with_lim_10_for_a_and_b-07.ans + points: 1 +- in: 106-random_with_lim_10_for_a_and_b-08.in + out: 106-random_with_lim_10_for_a_and_b-08.ans + points: 1 +- in: 107-random_with_lim_10_for_a_and_b-09.in + out: 107-random_with_lim_10_for_a_and_b-09.ans + points: 1 +- in: 108-random_with_lim_10_for_a_and_b-10.in + out: 108-random_with_lim_10_for_a_and_b-10.ans + points: 1 +- in: 109-random_with_max_constraints_small_enough_for_dp-01.in + out: 109-random_with_max_constraints_small_enough_for_dp-01.ans + points: 1 +- in: 110-random_with_max_constraints_small_enough_for_dp-02.in + out: 110-random_with_max_constraints_small_enough_for_dp-02.ans + points: 1 +- in: 111-random_with_max_constraints_small_enough_for_dp-03.in + out: 111-random_with_max_constraints_small_enough_for_dp-03.ans + points: 1 +- in: 112-random_with_max_constraints_small_enough_for_dp-04.in + out: 112-random_with_max_constraints_small_enough_for_dp-04.ans + points: 1 +- in: 113-random_with_max_constraints_small_enough_for_dp-05.in + out: 113-random_with_max_constraints_small_enough_for_dp-05.ans + points: 1 +- in: 114-random_with_max_constraints_small_enough_for_dp-06.in + out: 114-random_with_max_constraints_small_enough_for_dp-06.ans + points: 1 +- in: 115-random_with_max_constraints_small_enough_for_dp-07.in + out: 115-random_with_max_constraints_small_enough_for_dp-07.ans + points: 1 +- in: 116-random_with_max_constraints_small_enough_for_dp-08.in + out: 116-random_with_max_constraints_small_enough_for_dp-08.ans + points: 1 +- in: 117-random_with_max_constraints_small_enough_for_dp-09.in + out: 117-random_with_max_constraints_small_enough_for_dp-09.ans + points: 1 +- in: 118-random_with_max_constraints_small_enough_for_dp-10.in + out: 118-random_with_max_constraints_small_enough_for_dp-10.ans + points: 1 +- in: 119-random_with_lim_10_for_a_and_b_small_enough_for_dp-01.in + out: 119-random_with_lim_10_for_a_and_b_small_enough_for_dp-01.ans + points: 1 +- in: 120-random_with_lim_10_for_a_and_b_small_enough_for_dp-02.in + out: 120-random_with_lim_10_for_a_and_b_small_enough_for_dp-02.ans + points: 1 +- in: 121-random_with_lim_10_for_a_and_b_small_enough_for_dp-03.in + out: 121-random_with_lim_10_for_a_and_b_small_enough_for_dp-03.ans + points: 1 +- in: 122-random_with_lim_10_for_a_and_b_small_enough_for_dp-04.in + out: 122-random_with_lim_10_for_a_and_b_small_enough_for_dp-04.ans + points: 1 +- in: 123-random_with_lim_10_for_a_and_b_small_enough_for_dp-05.in + out: 123-random_with_lim_10_for_a_and_b_small_enough_for_dp-05.ans + points: 1 +- in: 124-random_with_lim_10_for_a_and_b_small_enough_for_dp-06.in + out: 124-random_with_lim_10_for_a_and_b_small_enough_for_dp-06.ans + points: 1 +- in: 125-random_with_lim_10_for_a_and_b_small_enough_for_dp-07.in + out: 125-random_with_lim_10_for_a_and_b_small_enough_for_dp-07.ans + points: 1 +- in: 126-random_with_lim_10_for_a_and_b_small_enough_for_dp-08.in + out: 126-random_with_lim_10_for_a_and_b_small_enough_for_dp-08.ans + points: 1 +- in: 127-random_with_lim_10_for_a_and_b_small_enough_for_dp-09.in + out: 127-random_with_lim_10_for_a_and_b_small_enough_for_dp-09.ans + points: 1 +- in: 128-random_with_lim_10_for_a_and_b_small_enough_for_dp-10.in + out: 128-random_with_lim_10_for_a_and_b_small_enough_for_dp-10.ans + points: 1 +- in: 129-random_with_lim_3_for_a_and_b_small_enough_for_dp-01.in + out: 129-random_with_lim_3_for_a_and_b_small_enough_for_dp-01.ans + points: 1 +- in: 130-random_with_lim_3_for_a_and_b_small_enough_for_dp-02.in + out: 130-random_with_lim_3_for_a_and_b_small_enough_for_dp-02.ans + points: 1 +- in: 131-random_with_lim_3_for_a_and_b_small_enough_for_dp-03.in + out: 131-random_with_lim_3_for_a_and_b_small_enough_for_dp-03.ans + points: 1 +- in: 132-random_with_lim_3_for_a_and_b_small_enough_for_dp-04.in + out: 132-random_with_lim_3_for_a_and_b_small_enough_for_dp-04.ans + points: 1 +- in: 133-random_with_lim_3_for_a_and_b_small_enough_for_dp-05.in + out: 133-random_with_lim_3_for_a_and_b_small_enough_for_dp-05.ans + points: 1 +- in: 134-random_with_lim_3_for_a_and_b_small_enough_for_dp-06.in + out: 134-random_with_lim_3_for_a_and_b_small_enough_for_dp-06.ans + points: 1 +- in: 135-random_with_lim_3_for_a_and_b_small_enough_for_dp-07.in + out: 135-random_with_lim_3_for_a_and_b_small_enough_for_dp-07.ans + points: 1 +- in: 136-random_with_lim_3_for_a_and_b_small_enough_for_dp-08.in + out: 136-random_with_lim_3_for_a_and_b_small_enough_for_dp-08.ans + points: 1 +- in: 137-random_with_lim_3_for_a_and_b_small_enough_for_dp-09.in + out: 137-random_with_lim_3_for_a_and_b_small_enough_for_dp-09.ans + points: 1 +- in: 138-random_with_lim_3_for_a_and_b_small_enough_for_dp-10.in + out: 138-random_with_lim_3_for_a_and_b_small_enough_for_dp-10.ans + points: 1 +- in: 139-fuzz.in + out: 139-fuzz.ans + points: 1 +- in: 140-fuzz.in + out: 140-fuzz.ans + points: 1 +- in: 141-fuzz.in + out: 141-fuzz.ans + points: 1 +- in: 142-fuzz.in + out: 142-fuzz.ans + points: 1 +- in: 143-fuzz.in + out: 143-fuzz.ans + points: 1 +- in: 144-fuzz.in + out: 144-fuzz.ans + points: 1 +- in: 145-fuzz.in + out: 145-fuzz.ans + points: 1 +- in: 146-fuzz.in + out: 146-fuzz.ans + points: 1 +- in: 147-fuzz.in + out: 147-fuzz.ans + points: 1 +- in: 148-fuzz.in + out: 148-fuzz.ans + points: 1 +- in: 149-fuzz.in + out: 149-fuzz.ans + points: 1 +- in: 150-fuzz.in + out: 150-fuzz.ans + points: 1 +- in: 151-fuzz.in + out: 151-fuzz.ans + points: 1 +- in: 152-fuzz.in + out: 152-fuzz.ans + points: 1 +- in: 153-fuzz.in + out: 153-fuzz.ans + points: 1 +- in: 154-fuzz.in + out: 154-fuzz.ans + points: 1 +- in: 155-fuzz.in + out: 155-fuzz.ans + points: 1 +- in: 156-fuzz.in + out: 156-fuzz.ans + points: 1 +- in: 157-fuzz.in + out: 157-fuzz.ans + points: 1 +- in: 158-fuzz.in + out: 158-fuzz.ans + points: 1 diff --git a/ICPC/nwerc2024_M/data.zip b/ICPC/nwerc2024_M/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..25a06771b333544cd20bc5addcb90f191032cb9e --- /dev/null +++ b/ICPC/nwerc2024_M/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ba9daa384aaf7b5b57201b1f5deea5ad01e825e3568c6059782e6a04c531d16 +size 20234464 diff --git a/ICPC/nwerc2024_M/init.yml b/ICPC/nwerc2024_M/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..036f0977c7219f8ad11281222de3a4f040204cb9 --- /dev/null +++ b/ICPC/nwerc2024_M/init.yml @@ -0,0 +1,276 @@ +archive: data.zip +checker: + args: + precision: 4 + name: floats +test_cases: +- in: 04-max-square.in + out: 04-max-square.ans + points: 1 +- in: 05-max-hexagon.in + out: 05-max-hexagon.ans + points: 1 +- in: 06-all-short-edges.in + out: 06-all-short-edges.ans + points: 1 +- in: 07-all-short-edges.in + out: 07-all-short-edges.ans + points: 1 +- in: 08-all-short-edges.in + out: 08-all-short-edges.ans + points: 1 +- in: 09-near-triangle-1.in + out: 09-near-triangle-1.ans + points: 1 +- in: 10-near-triangle-2.in + out: 10-near-triangle-2.ans + points: 1 +- in: 11-far-triangle-1.in + out: 11-far-triangle-1.ans + points: 1 +- in: 12-far-triangle-2.in + out: 12-far-triangle-2.ans + points: 1 +- in: 13-wide-triangle-1.in + out: 13-wide-triangle-1.ans + points: 1 +- in: 14-wide-triangle-2.in + out: 14-wide-triangle-2.ans + points: 1 +- in: 15-near-tiny-1.in + out: 15-near-tiny-1.ans + points: 1 +- in: 16-near-tiny-2.in + out: 16-near-tiny-2.ans + points: 1 +- in: 17-near-tiny-3.in + out: 17-near-tiny-3.ans + points: 1 +- in: 18-far-tiny-1.in + out: 18-far-tiny-1.ans + points: 1 +- in: 19-far-tiny-2.in + out: 19-far-tiny-2.ans + points: 1 +- in: 20-far-tiny-3.in + out: 20-far-tiny-3.ans + points: 1 +- in: 21-wide-tiny-1.in + out: 21-wide-tiny-1.ans + points: 1 +- in: 22-wide-tiny-2.in + out: 22-wide-tiny-2.ans + points: 1 +- in: 23-wide-tiny-3.in + out: 23-wide-tiny-3.ans + points: 1 +- in: 24-near-small-1.in + out: 24-near-small-1.ans + points: 1 +- in: 25-near-small-2.in + out: 25-near-small-2.ans + points: 1 +- in: 26-near-small-3.in + out: 26-near-small-3.ans + points: 1 +- in: 27-wide-small-1.in + out: 27-wide-small-1.ans + points: 1 +- in: 28-wide-small-2.in + out: 28-wide-small-2.ans + points: 1 +- in: 29-wide-small-3.in + out: 29-wide-small-3.ans + points: 1 +- in: 30-wide-medium-1.in + out: 30-wide-medium-1.ans + points: 1 +- in: 31-wide-medium-2.in + out: 31-wide-medium-2.ans + points: 1 +- in: 32-wide-medium-3.in + out: 32-wide-medium-3.ans + points: 1 +- in: 33-wide-large-1.in + out: 33-wide-large-1.ans + points: 1 +- in: 34-wide-large-2.in + out: 34-wide-large-2.ans + points: 1 +- in: 35-wide-large-3.in + out: 35-wide-large-3.ans + points: 1 +- in: 36-near-large-1.in + out: 36-near-large-1.ans + points: 1 +- in: 37-near-large-2.in + out: 37-near-large-2.ans + points: 1 +- in: 38-near-large-3.in + out: 38-near-large-3.ans + points: 1 +- in: 39-near-huge-1.in + out: 39-near-huge-1.ans + points: 1 +- in: 40-near-huge-2.in + out: 40-near-huge-2.ans + points: 1 +- in: 41-near-huge-3.in + out: 41-near-huge-3.ans + points: 1 +- in: 42-near-max-1.in + out: 42-near-max-1.ans + points: 1 +- in: 43-near-max-2.in + out: 43-near-max-2.ans + points: 1 +- in: 44-near-max-3.in + out: 44-near-max-3.ans + points: 1 +- in: 45-near-max-1.in + out: 45-near-max-1.ans + points: 1 +- in: 46-near-max-2.in + out: 46-near-max-2.ans + points: 1 +- in: 47-near-max-3.in + out: 47-near-max-3.ans + points: 1 +- in: 48-far-10.in + out: 48-far-10.ans + points: 1 +- in: 49-far-20.in + out: 49-far-20.ans + points: 1 +- in: 50-far-30.in + out: 50-far-30.ans + points: 1 +- in: 51-far-40.in + out: 51-far-40.ans + points: 1 +- in: 52-far-50.in + out: 52-far-50.ans + points: 1 +- in: 53-far-60.in + out: 53-far-60.ans + points: 1 +- in: 54-far-70.in + out: 54-far-70.ans + points: 1 +- in: 55-far-80.in + out: 55-far-80.ans + points: 1 +- in: 56-far-90.in + out: 56-far-90.ans + points: 1 +- in: 57-far-100.in + out: 57-far-100.ans + points: 1 +- in: 58-fuzz.in + out: 58-fuzz.ans + points: 1 +- in: 59-fuzz.in + out: 59-fuzz.ans + points: 1 +- in: 60-fuzz.in + out: 60-fuzz.ans + points: 1 +- in: 61-fuzz.in + out: 61-fuzz.ans + points: 1 +- in: 62-fuzz.in + out: 62-fuzz.ans + points: 1 +- in: 63-fuzz.in + out: 63-fuzz.ans + points: 1 +- in: 64-fuzz.in + out: 64-fuzz.ans + points: 1 +- in: 65-rounded-corners-1.in + out: 65-rounded-corners-1.ans + points: 1 +- in: 66-rounded-corners-2.in + out: 66-rounded-corners-2.ans + points: 1 +- in: 67-rounded-corners-3.in + out: 67-rounded-corners-3.ans + points: 1 +- in: 68-rounded-corners-4.in + out: 68-rounded-corners-4.ans + points: 1 +- in: 69-rounded-corners-5.in + out: 69-rounded-corners-5.ans + points: 1 +- in: 70-rounded-and-sharp-corners-1.in + out: 70-rounded-and-sharp-corners-1.ans + points: 1 +- in: 71-rounded-and-sharp-corners-2.in + out: 71-rounded-and-sharp-corners-2.ans + points: 1 +- in: 72-rounded-and-sharp-corners-3.in + out: 72-rounded-and-sharp-corners-3.ans + points: 1 +- in: 73-rounded-and-sharp-corners-4.in + out: 73-rounded-and-sharp-corners-4.ans + points: 1 +- in: 74-rounded-and-sharp-corners-5.in + out: 74-rounded-and-sharp-corners-5.ans + points: 1 +- in: 75-near-extremes.in + out: 75-near-extremes.ans + points: 1 +- in: 76-near-extremes.in + out: 76-near-extremes.ans + points: 1 +- in: 77-near-extremes.in + out: 77-near-extremes.ans + points: 1 +- in: 78-near-extremes.in + out: 78-near-extremes.ans + points: 1 +- in: 79-near-extremes.in + out: 79-near-extremes.ans + points: 1 +- in: 80-near-extremes.in + out: 80-near-extremes.ans + points: 1 +- in: 81-near-extremes.in + out: 81-near-extremes.ans + points: 1 +- in: 82-near-extremes.in + out: 82-near-extremes.ans + points: 1 +- in: 83-near-extremes.in + out: 83-near-extremes.ans + points: 1 +- in: 84-near-extremes.in + out: 84-near-extremes.ans + points: 1 +- in: 85-near-extremes.in + out: 85-near-extremes.ans + points: 1 +- in: 86-near-extremes.in + out: 86-near-extremes.ans + points: 1 +- in: 87-near-extremes.in + out: 87-near-extremes.ans + points: 1 +- in: 88-near-extremes.in + out: 88-near-extremes.ans + points: 1 +- in: 89-fuzz.in + out: 89-fuzz.ans + points: 1 +- in: 90-quadrant.in + out: 90-quadrant.ans + points: 1 +- in: 91-quadrant.in + out: 91-quadrant.ans + points: 1 +- in: 92-quadrant.in + out: 92-quadrant.ans + points: 1 +- in: 93-quadrant.in + out: 93-quadrant.ans + points: 1 diff --git a/ICPC/swerc2022_A/data.zip b/ICPC/swerc2022_A/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..14572ffabc3f8e76c79067cfc19f78d19d3fd6ee --- /dev/null +++ b/ICPC/swerc2022_A/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f17a3c6213bb7dbcc5be289da0d8b72cff6284edbb8b61a51eea6507f341fdfe +size 10249 diff --git a/ICPC/swerc2022_A/init.yml b/ICPC/swerc2022_A/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..07111ce6349ccf7fab6b2d473929607bc2d245cc --- /dev/null +++ b/ICPC/swerc2022_A/init.yml @@ -0,0 +1,5 @@ +archive: data.zip +test_cases: +- in: 2.in + out: 2.ans + points: 1 diff --git a/ICPC/swerc2022_B/data.zip b/ICPC/swerc2022_B/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..211a2496098973eeae1486eb38d44fe05fe4e57a --- /dev/null +++ b/ICPC/swerc2022_B/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33c947c76bebd29e00b44cbdc072bf8f32346c8c663c1443caf6170e40830bab +size 1922 diff --git a/ICPC/swerc2022_B/init.yml b/ICPC/swerc2022_B/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d3d1ead119b516dd7fd4aa54541bbc143c8d95ac --- /dev/null +++ b/ICPC/swerc2022_B/init.yml @@ -0,0 +1,31 @@ +archive: data.zip +checker: + args: + files: + - output_validators/testlib.h + - output_validators/checker.cpp + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_B/output_validators/checker.cpp b/ICPC/swerc2022_B/output_validators/checker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a612241d4680fbad5155ed95fd41abf8a71de98 --- /dev/null +++ b/ICPC/swerc2022_B/output_validators/checker.cpp @@ -0,0 +1,80 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +// This checker was obtained by modifying EPS and error messages in the standard doubles checker. +// I also added "-inf, inf" and variable names to readDouble to appease the Polygon warning. +// I did not want to set 0.0/1.0 as limits since that would make a solution outputting -1e-100 instead of 0 +// fail. + +#include "testlib.h" +#include +#include + +using namespace std; + +#define EPS 1.1e-8 + +string ending(int x) +{ + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +int main(int argc, char * argv[]) +{ + setName("compare two sequences of doubles, max absolute or relative error = %.9lf", EPS); + registerTestlibCmd(argc, argv); + + int n = 0; + double j, p; + double max_error = 0; + double inf = numeric_limits::infinity(); + + while (!ans.seekEof()) + { + n++; + j = ans.readDouble(-inf, inf, "answer"); + p = ouf.readDouble(-inf, inf, "output"); + if (!doubleCompare(j, p, EPS)) + quitf(_wa, "%d%s numbers differ - expected: '%.9lf', found: '%.9lf', error = '%.9lf'", n, ending(n).c_str(), j, p, doubleDelta(j, p)); + max_error = max(max_error, abs(j - p)); + } + + if (n == 1) + quitf(_ok, "found '%.9lf', expected '%.9lf', error '%.9lf'", p, j, doubleDelta(j, p)); + + quitf(_ok, "%d numbers, max absolute error %.9lg", n, max_error); +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2022_B/output_validators/testlib.h b/ICPC/swerc2022_B/output_validators/testlib.h new file mode 100644 index 0000000000000000000000000000000000000000..7f15d596b3531af62729aee5132df3bd29d675c7 --- /dev/null +++ b/ICPC/swerc2022_B/output_validators/testlib.h @@ -0,0 +1,5893 @@ +// Modified by a script to work with DOMjudge. +// Differences with the standard testlib.h: +// - The values of some exit codes. +// - The functions registerInteraction and registerTestlibCmd. + +/* + * It is strictly recommended to include "testlib.h" before any other include + * in your code. In this case testlib overrides compiler specific "random()". + * + * If you can't compile your code and compiler outputs something about + * ambiguous call of "random_shuffle", "rand" or "srand" it means that + * you shouldn't use them. Use "shuffle", and "rnd.next()" instead of them + * because these calls produce stable result for any C++ compiler. Read + * sample generator sources for clarification. + * + * Please read the documentation for class "random_t" and use "rnd" instance in + * generators. Probably, these sample calls will be usefull for you: + * rnd.next(); rnd.next(100); rnd.next(1, 2); + * rnd.next(3.14); rnd.next("[a-z]{1,100}"). + * + * Also read about wnext() to generate off-center random distribution. + * + * See https://github.com/MikeMirzayanov/testlib/ to get latest version or bug tracker. + */ + +#ifndef _TESTLIB_H_ +#define _TESTLIB_H_ + +/* + * Copyright (c) 2005-2022 + */ + +#define VERSION "0.9.40-SNAPSHOT" + +/* + * Mike Mirzayanov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* NOTE: This file contains testlib library for C++. + * + * Check, using testlib running format: + * check.exe [ [-appes]], + * If result file is specified it will contain results. + * + * Validator, using testlib running format: + * validator.exe < input.txt, + * It will return non-zero exit code and writes message to standard output. + * + * Generator, using testlib running format: + * gen.exe [parameter-1] [parameter-2] [... paramerter-n] + * You can write generated test(s) into standard output or into the file(s). + * + * Interactor, using testlib running format: + * interactor.exe [ [ [-appes]]], + * Reads test from inf (mapped to args[1]), writes result to tout (mapped to argv[2], + * can be judged by checker later), reads program output from ouf (mapped to stdin), + * writes output to program via stdout (use cout, printf, etc). + */ + +const char *latestFeatures[] = { + "Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators", + "Added opt defaults via opt(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt()).", + "For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values", + "Added quitpi(points_info, message) function to return with _points exit code 7 and given points_info", + "rnd.partition(size, sum[, min_part=1]) returns random (unsorted) partition which is a representation of the given `sum` as a sum of `size` positive integers (or >=min_part if specified)", + "rnd.distinct(size, n) and rnd.distinct(size, from, to)", + "opt(\"some_missing_key\") returns false now", + "has_opt(key)", + "Abort validator on validator.testset()/validator.group() if registered without using command line", + "Print integer range violations in a human readable way like `violates the range [1, 10^9]`", + "Opts supported: use them like n = opt(\"n\"), in a command line you can use an exponential notation", + "Reformatted", + "Use setTestCase(i) or unsetTestCase() to support test cases (you can use it in any type of program: generator, interactor, validator or checker)", + "Fixed issue #87: readStrictDouble accepts \"-0.00\"", + "Fixed issue #83: added InStream::quitif(condition, ...)", + "Fixed issue #79: fixed missed guard against repeated header include", + "Fixed issue #80: fixed UB in case of huge quitf message", + "Fixed issue #84: added readXs(size, indexBase = 1)", + "Fixed stringstream repeated usage issue", + "Fixed compilation in g++ (for std=c++03)", + "Batch of println functions (support collections, iterator ranges)", + "Introduced rnd.perm(size, first = 0) to generate a `first`-indexed permutation", + "Allow any whitespace in readInts-like functions for non-validators", + "Ignore 4+ command line arguments ifdef EJUDGE", + "Speed up of vtos", + "Show line number in validators in case of incorrect format", + "Truncate huge checker/validator/interactor message", + "Fixed issue with readTokenTo of very long tokens, now aborts with _pe/_fail depending of a stream type", + "Introduced InStream::ensure/ensuref checking a condition, returns wa/fail depending of a stream type", + "Fixed compilation in VS 2015+", + "Introduced space-separated read functions: readWords/readTokens, multilines read functions: readStrings/readLines", + "Introduced space-separated read functions: readInts/readIntegers/readLongs/readUnsignedLongs/readDoubles/readReals/readStrictDoubles/readStrictReals", + "Introduced split/tokenize functions to separate string by given char", + "Introduced InStream::readUnsignedLong and InStream::readLong with unsigned long long paramerters", + "Supported --testOverviewLogFileName for validator: bounds hits + features", + "Fixed UB (sequence points) in random_t", + "POINTS_EXIT_CODE returned back to 7 (instead of 0)", + "Removed disable buffers for interactive problems, because it works unexpectedly in wine", + "InStream over string: constructor of InStream from base InStream to inherit policies and std::string", + "Added expectedButFound quit function, examples: expectedButFound(_wa, 10, 20), expectedButFound(_fail, ja, pa, \"[n=%d,m=%d]\", n, m)", + "Fixed incorrect interval parsing in patterns", + "Use registerGen(argc, argv, 1) to develop new generator, use registerGen(argc, argv, 0) to compile old generators (originally created for testlib under 0.8.7)", + "Introduced disableFinalizeGuard() to switch off finalization checkings", + "Use join() functions to format a range of items as a single string (separated by spaces or other separators)", + "Use -DENABLE_UNEXPECTED_EOF to enable special exit code (by default, 8) in case of unexpected eof. It is good idea to use it in interactors", + "Use -DUSE_RND_AS_BEFORE_087 to compile in compatibility mode with random behavior of versions before 0.8.7", + "Fixed bug with nan in stringToDouble", + "Fixed issue around overloads for size_t on x64", + "Added attribute 'points' to the XML output in case of result=_points", + "Exit codes can be customized via macros, e.g. -DPE_EXIT_CODE=14", + "Introduced InStream function readWordTo/readTokenTo/readStringTo/readLineTo for faster reading", + "Introduced global functions: format(), englishEnding(), upperCase(), lowerCase(), compress()", + "Manual buffer in InStreams, some IO speed improvements", + "Introduced quitif(bool, const char* pattern, ...) which delegates to quitf() in case of first argument is true", + "Introduced guard against missed quitf() in checker or readEof() in validators", + "Supported readStrictReal/readStrictDouble - to use in validators to check strictly float numbers", + "Supported registerInteraction(argc, argv)", + "Print checker message to the stderr instead of stdout", + "Supported TResult _points to output calculated score, use quitp(...) functions", + "Fixed to be compilable on Mac", + "PC_BASE_EXIT_CODE=50 in case of defined TESTSYS", + "Fixed issues 19-21, added __attribute__ format printf", + "Some bug fixes", + "ouf.readInt(1, 100) and similar calls return WA", + "Modified random_t to avoid integer overflow", + "Truncated checker output [patch by Stepan Gatilov]", + "Renamed class random -> class random_t", + "Supported name parameter for read-and-validation methods, like readInt(1, 2, \"n\")", + "Fixed bug in readDouble()", + "Improved ensuref(), fixed nextLine to work in case of EOF, added startTest()", + "Supported \"partially correct\", example: quitf(_pc(13), \"result=%d\", result)", + "Added shuffle(begin, end), use it instead of random_shuffle(begin, end)", + "Added readLine(const string& ptrn), fixed the logic of readLine() in the validation mode", + "Package extended with samples of generators and validators", + "Written the documentation for classes and public methods in testlib.h", + "Implemented random routine to support generators, use registerGen() to switch it on", + "Implemented strict mode to validate tests, use registerValidation() to switch it on", + "Now ncmp.cpp and wcmp.cpp are return WA if answer is suffix or prefix of the output", + "Added InStream::readLong() and removed InStream::readLongint()", + "Now no footer added to each report by default (use directive FOOTER to switch on)", + "Now every checker has a name, use setName(const char* format, ...) to set it", + "Now it is compatible with TTS (by Kittens Computing)", + "Added \'ensure(condition, message = \"\")\' feature, it works like assert()", + "Fixed compatibility with MS C++ 7.1", + "Added footer with exit code information", + "Added compatibility with EJUDGE (compile with EJUDGE directive)", + "Added compatibility with Contester (compile with CONTESTER directive)" +}; + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NO_VA_START_VALIDATION +#endif + +/* Overrides random() for Borland C++. */ +#define random __random_deprecated +#include +#include +#include +#include +#undef random + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +# include +#endif + +#if (_WIN32 || __WIN32__ || __WIN32 || _WIN64 || __WIN64__ || __WIN64 || WINNT || __WINNT || __WINNT__ || __CYGWIN__) +# if !defined(_MSC_VER) || _MSC_VER > 1400 +# define NOMINMAX 1 +# include +# else +# define WORD unsigned short +# include +# endif +# include +# define ON_WINDOWS +# if defined(_MSC_VER) && _MSC_VER > 1400 +# pragma warning( disable : 4127 ) +# pragma warning( disable : 4146 ) +# pragma warning( disable : 4458 ) +# endif +#else +# define WORD unsigned short +# include +#endif + +#if defined(FOR_WINDOWS) && defined(FOR_LINUX) +#error Only one target system is allowed +#endif + +#ifndef LLONG_MIN +#define LLONG_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX (18446744073709551615) +#endif + +#define LF ((char)10) +#define CR ((char)13) +#define TAB ((char)9) +#define SPACE ((char)' ') +#define EOFC (255) + +#ifndef OK_EXIT_CODE +# ifdef CONTESTER +# define OK_EXIT_CODE 42 +# else +# define OK_EXIT_CODE 42 +# endif +#endif + +#ifndef WA_EXIT_CODE +# ifdef EJUDGE +# define WA_EXIT_CODE 43 +# elif defined(CONTESTER) +# define WA_EXIT_CODE 43 +# else +# define WA_EXIT_CODE 43 +# endif +#endif + +#ifndef PE_EXIT_CODE +# ifdef EJUDGE +# define PE_EXIT_CODE 43 +# elif defined(CONTESTER) +# define PE_EXIT_CODE 43 +# else +# define PE_EXIT_CODE 43 +# endif +#endif + +#ifndef FAIL_EXIT_CODE +# ifdef EJUDGE +# define FAIL_EXIT_CODE 6 +# elif defined(CONTESTER) +# define FAIL_EXIT_CODE 0xA3 +# else +# define FAIL_EXIT_CODE 3 +# endif +#endif + +#ifndef DIRT_EXIT_CODE +# ifdef EJUDGE +# define DIRT_EXIT_CODE 43 +# else +# define DIRT_EXIT_CODE 43 +# endif +#endif + +#ifndef POINTS_EXIT_CODE +# define POINTS_EXIT_CODE 7 +#endif + +#ifndef UNEXPECTED_EOF_EXIT_CODE +# define UNEXPECTED_EOF_EXIT_CODE 43 +#endif + +#ifndef PC_BASE_EXIT_CODE +# ifdef TESTSYS +# define PC_BASE_EXIT_CODE 50 +# else +# define PC_BASE_EXIT_CODE 0 +# endif +#endif + +#ifdef __GNUC__ +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] __attribute__((unused)) +#else +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] +#endif + +#ifdef ON_WINDOWS +#define I64 "%I64d" +#define U64 "%I64u" +#else +#define I64 "%lld" +#define U64 "%llu" +#endif + +#ifdef _MSC_VER +# define NORETURN __declspec(noreturn) +#elif defined __GNUC__ +# define NORETURN __attribute__ ((noreturn)) +#else +# define NORETURN +#endif + +static char __testlib_format_buffer[16777216]; +static int __testlib_format_buffer_usage_count = 0; + +#define FMT_TO_RESULT(fmt, cstr, result) std::string result; \ + if (__testlib_format_buffer_usage_count != 0) \ + __testlib_fail("FMT_TO_RESULT::__testlib_format_buffer_usage_count != 0"); \ + __testlib_format_buffer_usage_count++; \ + va_list ap; \ + va_start(ap, fmt); \ + vsnprintf(__testlib_format_buffer, sizeof(__testlib_format_buffer), cstr, ap); \ + va_end(ap); \ + __testlib_format_buffer[sizeof(__testlib_format_buffer) - 1] = 0; \ + result = std::string(__testlib_format_buffer); \ + __testlib_format_buffer_usage_count--; \ + +const long long __TESTLIB_LONGLONG_MAX = 9223372036854775807LL; +const int __TESTLIB_MAX_TEST_CASE = 1073741823; + +int __testlib_exitCode; + +bool __testlib_hasTestCase; +int __testlib_testCase = -1; + +void setTestCase(int testCase); + +void unsetTestCase() { + __testlib_hasTestCase = false; + __testlib_testCase = -1; +} + +NORETURN static void __testlib_fail(const std::string &message); + +template +static inline T __testlib_abs(const T &x) { + return x > 0 ? x : -x; +} + +template +static inline T __testlib_min(const T &a, const T &b) { + return a < b ? a : b; +} + +template +static inline T __testlib_max(const T &a, const T &b) { + return a > b ? a : b; +} + +template +static inline T __testlib_crop(T value, T a, T b) { + return __testlib_min(__testlib_max(value, a), --b); +} + +static inline double __testlib_crop(double value, double a, double b) { + value = __testlib_min(__testlib_max(value, a), b); + if (value >= b) + value = std::nexttoward(b, a); + return value; +} + +static bool __testlib_prelimIsNaN(double r) { + volatile double ra = r; +#ifndef __BORLANDC__ + return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); +#else + return std::_isnan(ra); +#endif +} + +static std::string removeDoubleTrailingZeroes(std::string value) { + while (!value.empty() && value[value.length() - 1] == '0' && value.find('.') != std::string::npos) + value = value.substr(0, value.length() - 1); + if (!value.empty() && value[value.length() - 1] == '.') + return value + '0'; + else + return value; +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +std::string format(const char *fmt, ...) { + FMT_TO_RESULT(fmt, fmt, result); + return result; +} + +std::string format(const std::string fmt, ...) { + FMT_TO_RESULT(fmt, fmt.c_str(), result); + return result; +} + +static std::string __testlib_part(const std::string &s); + +static bool __testlib_isNaN(double r) { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); + volatile double ra = r; + long long llr1, llr2; + std::memcpy((void *) &llr1, (void *) &ra, sizeof(double)); + ra = -ra; + std::memcpy((void *) &llr2, (void *) &ra, sizeof(double)); + long long llnan = 0xFFF8000000000000LL; + return __testlib_prelimIsNaN(r) || llnan == llr1 || llnan == llr2; +} + +static double __testlib_nan() { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); +#ifndef NAN + long long llnan = 0xFFF8000000000000LL; + double nan; + std::memcpy(&nan, &llnan, sizeof(double)); + return nan; +#else + return NAN; +#endif +} + +static bool __testlib_isInfinite(double r) { + volatile double ra = r; + return (ra > 1E300 || ra < -1E300); +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline bool doubleCompare(double expected, double result, double MAX_DOUBLE_ERROR) { + MAX_DOUBLE_ERROR += 1E-15; + if (__testlib_isNaN(expected)) { + return __testlib_isNaN(result); + } else if (__testlib_isInfinite(expected)) { + if (expected > 0) { + return result > 0 && __testlib_isInfinite(result); + } else { + return result < 0 && __testlib_isInfinite(result); + } + } else if (__testlib_isNaN(result) || __testlib_isInfinite(result)) { + return false; + } else if (__testlib_abs(result - expected) <= MAX_DOUBLE_ERROR) { + return true; + } else { + double minv = __testlib_min(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + double maxv = __testlib_max(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + return result >= minv && result <= maxv; + } +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline double doubleDelta(double expected, double result) { + double absolute = __testlib_abs(result - expected); + + if (__testlib_abs(expected) > 1E-9) { + double relative = __testlib_abs(absolute / expected); + return __testlib_min(absolute, relative); + } else + return absolute; +} + +/** It does nothing on non-windows and files differ from stdin/stdout/stderr. */ +static void __testlib_set_binary(std::FILE *file) { + if (NULL != file) { +#ifdef ON_WINDOWS +# ifdef _O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(_setmode(STDIN_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdin), _O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(_setmode(STDOUT_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdout), _O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(_setmode(STDERR_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stderr), _O_BINARY)); +# endif +# elif O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(setmode(STDIN_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdin), O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(setmode(STDOUT_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdout), O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(setmode(STDERR_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stderr), O_BINARY)); +# endif +# endif +#endif + } +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +static std::string vtos(const T &t, std::true_type) { + if (t == 0) + return "0"; + else { + T n(t); + bool negative = n < 0; + std::string s; + while (n != 0) { + T digit = n % 10; + if (digit < 0) + digit = -digit; + s += char('0' + digit); + n /= 10; + } + std::reverse(s.begin(), s.end()); + return negative ? "-" + s : s; + } +} + +template +static std::string vtos(const T &t, std::false_type) { + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string vtos(const T &t) { + return vtos(t, std::is_integral()); +} + +/* signed case. */ +template +static std::string toHumanReadableString(const T &n, std::false_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else if (n_ == -1) + return "-10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +/* unsigned case. */ +template +static std::string toHumanReadableString(const T &n, std::true_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +template +static std::string toHumanReadableString(const T &n) { + return toHumanReadableString(n, std::is_unsigned()); +} +#else +template +static std::string vtos(const T& t) +{ + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string toHumanReadableString(const T &n) { + return vtos(n); +} +#endif + +template +static std::string toString(const T &t) { + return vtos(t); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +/* opts */ +void prepareOpts(int argc, char* argv[]); +#endif + +/* + * Very simple regex-like pattern. + * It used for two purposes: validation and generation. + * + * For example, pattern("[a-z]{1,5}").next(rnd) will return + * random string from lowercase latin letters with length + * from 1 to 5. It is easier to call rnd.next("[a-z]{1,5}") + * for the same effect. + * + * Another samples: + * "mike|john" will generate (match) "mike" or "john"; + * "-?[1-9][0-9]{0,3}" will generate (match) non-zero integers from -9999 to 9999; + * "id-([ac]|b{2})" will generate (match) "id-a", "id-bb", "id-c"; + * "[^0-9]*" will match sequences (empty or non-empty) without digits, you can't + * use it for generations. + * + * You can't use pattern for generation if it contains meta-symbol '*'. Also it + * is not recommended to use it for char-sets with meta-symbol '^' like [^a-z]. + * + * For matching very simple greedy algorithm is used. For example, pattern + * "[0-9]?1" will not match "1", because of greedy nature of matching. + * Alternations (meta-symbols "|") are processed with brute-force algorithm, so + * do not use many alternations in one expression. + * + * If you want to use one expression many times it is better to compile it into + * a single pattern like "pattern p("[a-z]+")". Later you can use + * "p.matches(std::string s)" or "p.next(random_t& rd)" to check matching or generate + * new string by pattern. + * + * Simpler way to read token and check it for pattern matching is "inf.readToken("[a-z]+")". + * + * All spaces are ignored in regex, unless escaped with \. For example, ouf.readLine("NO SOLUTION") + * will expect "NOSOLUTION", the correct call should be ouf.readLine("NO\\ SOLUTION") or + * ouf.readLine(R"(NO\ SOLUTION)") if you prefer raw string literals from C++11. + */ +class random_t; + +class pattern { +public: + /* Create pattern instance by string. */ + pattern(std::string s); + + /* Generate new string by pattern and given random_t. */ + std::string next(random_t &rnd) const; + + /* Checks if given string match the pattern. */ + bool matches(const std::string &s) const; + + /* Returns source string of the pattern. */ + std::string src() const; + +private: + bool matches(const std::string &s, size_t pos) const; + + std::string s; + std::vector children; + std::vector chars; + int from; + int to; +}; + +/* + * Use random_t instances to generate random values. It is preffered + * way to use randoms instead of rand() function or self-written + * randoms. + * + * Testlib defines global variable "rnd" of random_t class. + * Use registerGen(argc, argv, 1) to setup random_t seed be command + * line (to use latest random generator version). + * + * Random generates uniformly distributed values if another strategy is + * not specified explicitly. + */ +class random_t { +private: + unsigned long long seed; + static const unsigned long long multiplier; + static const unsigned long long addend; + static const unsigned long long mask; + static const int lim; + + long long nextBits(int bits) { + if (bits <= 48) { + seed = (seed * multiplier + addend) & mask; + return (long long) (seed >> (48 - bits)); + } else { + if (bits > 63) + __testlib_fail("random_t::nextBits(int bits): n must be less than 64"); + + int lowerBitCount = (random_t::version == 0 ? 31 : 32); + + long long left = (nextBits(31) << 32); + long long right = nextBits(lowerBitCount); + + return left ^ right; + } + } + +public: + static int version; + + /* New random_t with fixed seed. */ + random_t() + : seed(3905348978240129619LL) { + } + + /* Sets seed by command line. */ + void setSeed(int argc, char *argv[]) { + random_t p; + + seed = 3905348978240129619LL; + for (int i = 1; i < argc; i++) { + std::size_t le = std::strlen(argv[i]); + for (std::size_t j = 0; j < le; j++) + seed = seed * multiplier + (unsigned int) (argv[i][j]) + addend; + seed += multiplier / addend; + } + + seed = seed & mask; + } + + /* Sets seed by given value. */ + void setSeed(long long _seed) { + _seed = (_seed ^ multiplier) & mask; + seed = _seed; + } + +#ifndef __BORLANDC__ + + /* Random string value by given pattern (see pattern documentation). */ + std::string next(const std::string &ptrn) { + pattern p(ptrn); + return p.next(*this); + } + +#else + /* Random string value by given pattern (see pattern documentation). */ + std::string next(std::string ptrn) + { + pattern p(ptrn); + return p.next(*this); + } +#endif + + /* Random value in range [0, n-1]. */ + int next(int n) { + if (n <= 0) + __testlib_fail("random_t::next(int n): n must be positive"); + + if ((n & -n) == n) // n is a power of 2 + return (int) ((n * (long long) nextBits(31)) >> 31); + + const long long limit = INT_MAX / n * n; + + long long bits; + do { + bits = nextBits(31); + } while (bits >= limit); + + return int(bits % n); + } + + /* Random value in range [0, n-1]. */ + unsigned int next(unsigned int n) { + if (n >= INT_MAX) + __testlib_fail("random_t::next(unsigned int n): n must be less INT_MAX"); + return (unsigned int) next(int(n)); + } + + /* Random value in range [0, n-1]. */ + long long next(long long n) { + if (n <= 0) + __testlib_fail("random_t::next(long long n): n must be positive"); + + const long long limit = __TESTLIB_LONGLONG_MAX / n * n; + + long long bits; + do { + bits = nextBits(63); + } while (bits >= limit); + + return bits % n; + } + + /* Random value in range [0, n-1]. */ + unsigned long long next(unsigned long long n) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::next(unsigned long long n): n must be less LONGLONG_MAX"); + return (unsigned long long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + long next(long n) { + return (long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + unsigned long next(unsigned long n) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX"); + return (unsigned long) next((unsigned long long) (n)); + } + + /* Returns random value in range [from,to]. */ + int next(int from, int to) { + return int(next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + unsigned int next(unsigned int from, unsigned int to) { + return (unsigned int) (next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + long long next(long long from, long long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long long next(unsigned long long from, unsigned long long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long long from, unsigned long long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + long next(long from, long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long next(unsigned long from, unsigned long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long from, unsigned long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Random double value in range [0, 1). */ + double next() { + long long left = ((long long) (nextBits(26)) << 27); + long long right = nextBits(27); + return __testlib_crop((double) (left + right) / (double) (1LL << 53), 0.0, 1.0); + } + + /* Random double value in range [0, n). */ + double next(double n) { + if (n <= 0.0) + __testlib_fail("random_t::next(double): n should be positive"); + return __testlib_crop(n * next(), 0.0, n); + } + + /* Random double value in range [from, to). */ + double next(double from, double to) { + if (from >= to) + __testlib_fail("random_t::next(double from, double to): from should be strictly less than to"); + return next(to - from) + from; + } + + /* Returns random element from container. */ + template + typename Container::value_type any(const Container &c) { + int size = int(c.size()); + if (size <= 0) + __testlib_fail("random_t::any(const Container& c): c.size() must be positive"); + return *(c.begin() + next(size)); + } + + /* Returns random element from iterator range. */ + template + typename Iter::value_type any(const Iter &begin, const Iter &end) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length"); + return *(begin + next(size)); + } + + /* Random string value by given pattern (see pattern documentation). */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + std::string next(const char *format, ...) { + FMT_TO_RESULT(format, format, ptrn); + return next(ptrn); + } + + /* + * Weighted next. If type == 0 than it is usual "next()". + * + * If type = 1, than it returns "max(next(), next())" + * (the number of "max" functions equals to "type"). + * + * If type < 0, than "max" function replaces with "min". + */ + int wnext(int n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(int n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + int result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((int) (double(n) * p), 0, n); + } + } + + /* See wnext(int, int). It uses the same algorithms. */ + long long wnext(long long n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(long long n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + long long result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((long long) (double(n) * p), 0LL, n); + } + } + + /* Returns value in [0, n). See wnext(int, int). It uses the same algorithms. */ + double wnext(double n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(double n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + double result = next(); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next()); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next()); + + return n * result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop(n * p, 0.0, n); + } + } + + /* Returns value in [0, 1). See wnext(int, int). It uses the same algorithms. */ + double wnext(int type) { + return wnext(1.0, type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned int wnext(unsigned int n, int type) { + if (n >= INT_MAX) + __testlib_fail("random_t::wnext(unsigned int n, int type): n must be less INT_MAX"); + return (unsigned int) wnext(int(n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long long wnext(unsigned long long n, int type) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long long n, int type): n must be less LONGLONG_MAX"); + + return (unsigned long long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + long wnext(long n, int type) { + return (long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long wnext(unsigned long n, int type) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long n, int type): n must be less LONG_MAX"); + + return (unsigned long) wnext((unsigned long long) (n), type); + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(int from, int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(int from, int to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(unsigned int from, unsigned int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned int from, unsigned int to, int type): from can't not exceed to"); + return int(wnext(to - from + 1, type) + from); + } + + /* Returns weighted random value in range [from, to]. */ + long long wnext(long long from, long long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long long from, long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long long wnext(unsigned long long from, unsigned long long to, int type) { + if (from > to) + __testlib_fail( + "random_t::wnext(unsigned long long from, unsigned long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + long wnext(long from, long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long from, long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long wnext(unsigned long from, unsigned long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned long from, unsigned long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random double value in range [from, to). */ + double wnext(double from, double to, int type) { + if (from >= to) + __testlib_fail("random_t::wnext(double from, double to, int type): from should be strictly less than to"); + return wnext(to - from, type) + from; + } + + /* Returns weighted random element from container. */ + template + typename Container::value_type wany(const Container &c, int type) { + size_t size = c.size(); + if (size <= 0) + __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive"); + return *(c.begin() + wnext(size, type)); + } + + /* Returns weighted random element from iterator range. */ + template + typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail( + "random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length"); + return *(begin + wnext(size, type)); + } + + /* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/ + template + std::vector perm(T size, E first) { + if (size < 0) + __testlib_fail("random_t::perm(T size, E first = 0): size must non-negative"); + else if (size == 0) + return std::vector(); + std::vector p(size); + E current = first; + for (T i = 0; i < size; i++) + p[i] = current++; + if (size > 1) + for (T i = 1; i < size; i++) + std::swap(p[i], p[next(i + 1)]); + return p; + } + + /* Returns random permutation of the given size (values are between 0 and size-1)*/ + template + std::vector perm(T size) { + return perm(size, T(0)); + } + + /* Returns `size` unordered (unsorted) distinct numbers between `from` and `to`. */ + template + std::vector distinct(int size, T from, T to) { + std::vector result; + if (size == 0) + return result; + + if (from > to) + __testlib_fail("random_t::distinct expected from <= to"); + + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + + uint64_t n = to - from + 1; + if (uint64_t(size) > n) + __testlib_fail("random_t::distinct expected size <= to - from + 1"); + + double expected = 0.0; + for (int i = 1; i <= size; i++) + expected += double(n) / double(n - i + 1); + + if (expected < double(n)) { + std::set vals; + while (int(vals.size()) < size) { + T x = T(next(from, to)); + if (vals.insert(x).second) + result.push_back(x); + } + } else { + if (n > 1000000000) + __testlib_fail("random_t::distinct here expected to - from + 1 <= 1000000000"); + std::vector p(perm(int(n), from)); + result.insert(result.end(), p.begin(), p.begin() + size); + } + + return result; + } + + /* Returns `size` unordered (unsorted) distinct numbers between `0` and `upper`-1. */ + template + std::vector distinct(int size, T upper) { + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + if (size == 0) + return std::vector(); + + if (upper <= 0) + __testlib_fail("random_t::distinct expected upper > 0"); + if (size > upper) + __testlib_fail("random_t::distinct expected size <= upper"); + + return distinct(size, T(0), upper - 1); + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of integers not less than min_part. */ + template + std::vector partition(int size, T sum, T min_part) { + if (size < 0) + __testlib_fail("random_t::partition: size < 0"); + if (size == 0 && sum != 0) + __testlib_fail("random_t::partition: size == 0 && sum != 0"); + if (min_part * size > sum) + __testlib_fail("random_t::partition: min_part * size > sum"); + if (size == 0 && sum == 0) + return std::vector(); + + T sum_ = sum; + sum -= min_part * size; + + std::vector septums(size); + std::vector d = distinct(size - 1, T(1), T(sum + size - 1)); + for (int i = 0; i + 1 < size; i++) + septums[i + 1] = d[i]; + sort(septums.begin(), septums.end()); + + std::vector result(size); + for (int i = 0; i + 1 < size; i++) + result[i] = septums[i + 1] - septums[i] - 1; + result[size - 1] = sum + size - 1 - septums.back(); + + for (std::size_t i = 0; i < result.size(); i++) + result[i] += min_part; + + T result_sum = 0; + for (std::size_t i = 0; i < result.size(); i++) + result_sum += result[i]; + if (result_sum != sum_) + __testlib_fail("random_t::partition: partition sum is expected to be the given sum"); + + if (*std::min_element(result.begin(), result.end()) < min_part) + __testlib_fail("random_t::partition: partition min is expected to be no less than the given min_part"); + + if (int(result.size()) != size || result.size() != (size_t) size) + __testlib_fail("random_t::partition: partition size is expected to be equal to the given size"); + + return result; + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of positive integers. */ + template + std::vector partition(int size, T sum) { + return partition(size, sum, T(1)); + } +}; + +const int random_t::lim = 25; +const unsigned long long random_t::multiplier = 0x5DEECE66DLL; +const unsigned long long random_t::addend = 0xBLL; +const unsigned long long random_t::mask = (1LL << 48) - 1; +int random_t::version = -1; + +/* Pattern implementation */ +bool pattern::matches(const std::string &s) const { + return matches(s, 0); +} + +static bool __pattern_isSlash(const std::string &s, size_t pos) { + return s[pos] == '\\'; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static bool __pattern_isCommandChar(const std::string &s, size_t pos, char value) { + if (pos >= s.length()) + return false; + + int slashes = 0; + + int before = int(pos) - 1; + while (before >= 0 && s[before] == '\\') + before--, slashes++; + + return slashes % 2 == 0 && s[pos] == value; +} + +static char __pattern_getChar(const std::string &s, size_t &pos) { + if (__pattern_isSlash(s, pos)) + pos += 2; + else + pos++; + + return s[pos - 1]; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static int __pattern_greedyMatch(const std::string &s, size_t pos, const std::vector chars) { + int result = 0; + + while (pos < s.length()) { + char c = s[pos++]; + if (!std::binary_search(chars.begin(), chars.end(), c)) + break; + else + result++; + } + + return result; +} + +std::string pattern::src() const { + return s; +} + +bool pattern::matches(const std::string &s, size_t pos) const { + std::string result; + + if (to > 0) { + int size = __pattern_greedyMatch(s, pos, chars); + if (size < from) + return false; + if (size > to) + size = to; + pos += size; + } + + if (children.size() > 0) { + for (size_t child = 0; child < children.size(); child++) + if (children[child].matches(s, pos)) + return true; + return false; + } else + return pos == s.length(); +} + +std::string pattern::next(random_t &rnd) const { + std::string result; + result.reserve(20); + + if (to == INT_MAX) + __testlib_fail("pattern::next(random_t& rnd): can't process character '*' for generation"); + + if (to > 0) { + int count = rnd.next(to - from + 1) + from; + for (int i = 0; i < count; i++) + result += chars[rnd.next(int(chars.size()))]; + } + + if (children.size() > 0) { + int child = rnd.next(int(children.size())); + result += children[child].next(rnd); + } + + return result; +} + +static void __pattern_scanCounts(const std::string &s, size_t &pos, int &from, int &to) { + if (pos >= s.length()) { + from = to = 1; + return; + } + + if (__pattern_isCommandChar(s, pos, '{')) { + std::vector parts; + std::string part; + + pos++; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, '}')) { + if (__pattern_isCommandChar(s, pos, ',')) + parts.push_back(part), part = "", pos++; + else + part += __pattern_getChar(s, pos); + } + + if (part != "") + parts.push_back(part); + + if (!__pattern_isCommandChar(s, pos, '}')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (parts.size() < 1 || parts.size() > 2) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector numbers; + + for (size_t i = 0; i < parts.size(); i++) { + if (parts[i].length() == 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + int number; + if (std::sscanf(parts[i].c_str(), "%d", &number) != 1) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + numbers.push_back(number); + } + + if (numbers.size() == 1) + from = to = numbers[0]; + else + from = numbers[0], to = numbers[1]; + + if (from > to) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + } else { + if (__pattern_isCommandChar(s, pos, '?')) { + from = 0, to = 1, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '*')) { + from = 0, to = INT_MAX, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '+')) { + from = 1, to = INT_MAX, pos++; + return; + } + + from = to = 1; + } +} + +static std::vector __pattern_scanCharSet(const std::string &s, size_t &pos) { + if (pos >= s.length()) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector result; + + if (__pattern_isCommandChar(s, pos, '[')) { + pos++; + bool negative = __pattern_isCommandChar(s, pos, '^'); + if (negative) + pos++; + + char prev = 0; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, ']')) { + if (__pattern_isCommandChar(s, pos, '-') && prev != 0) { + pos++; + + if (pos + 1 == s.length() || __pattern_isCommandChar(s, pos, ']')) { + result.push_back(prev); + prev = '-'; + continue; + } + + char next = __pattern_getChar(s, pos); + if (prev > next) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + for (char c = prev; c != next; c++) + result.push_back(c); + result.push_back(next); + + prev = 0; + } else { + if (prev != 0) + result.push_back(prev); + prev = __pattern_getChar(s, pos); + } + } + + if (prev != 0) + result.push_back(prev); + + if (!__pattern_isCommandChar(s, pos, ']')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (negative) { + std::sort(result.begin(), result.end()); + std::vector actuals; + for (int code = 0; code < 255; code++) { + char c = char(code); + if (!std::binary_search(result.begin(), result.end(), c)) + actuals.push_back(c); + } + result = actuals; + } + + std::sort(result.begin(), result.end()); + } else + result.push_back(__pattern_getChar(s, pos)); + + return result; +} + +pattern::pattern(std::string s) : s(s), from(0), to(0) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (!__pattern_isCommandChar(s, i, ' ')) + t += s[i]; + s = t; + + int opened = 0; + int firstClose = -1; + std::vector seps; + + for (size_t i = 0; i < s.length(); i++) { + if (__pattern_isCommandChar(s, i, '(')) { + opened++; + continue; + } + + if (__pattern_isCommandChar(s, i, ')')) { + opened--; + if (opened == 0 && firstClose == -1) + firstClose = int(i); + continue; + } + + if (opened < 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (__pattern_isCommandChar(s, i, '|') && opened == 0) + seps.push_back(int(i)); + } + + if (opened != 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (seps.size() == 0 && firstClose + 1 == (int) s.length() + && __pattern_isCommandChar(s, 0, '(') && __pattern_isCommandChar(s, s.length() - 1, ')')) { + children.push_back(pattern(s.substr(1, s.length() - 2))); + } else { + if (seps.size() > 0) { + seps.push_back(int(s.length())); + int last = 0; + + for (size_t i = 0; i < seps.size(); i++) { + children.push_back(pattern(s.substr(last, seps[i] - last))); + last = seps[i] + 1; + } + } else { + size_t pos = 0; + chars = __pattern_scanCharSet(s, pos); + __pattern_scanCounts(s, pos, from, to); + if (pos < s.length()) + children.push_back(pattern(s.substr(pos))); + } + } +} + +/* End of pattern implementation */ + +template +inline bool isEof(C c) { + return c == EOFC; +} + +template +inline bool isEoln(C c) { + return (c == LF || c == CR); +} + +template +inline bool isBlanks(C c) { + return (c == LF || c == CR || c == SPACE || c == TAB); +} + +inline std::string trim(const std::string &s) { + if (s.empty()) + return s; + + int left = 0; + while (left < int(s.length()) && isBlanks(s[left])) + left++; + if (left >= int(s.length())) + return ""; + + int right = int(s.length()) - 1; + while (right >= 0 && isBlanks(s[right])) + right--; + if (right < 0) + return ""; + + return s.substr(left, right - left + 1); +} + +enum TMode { + _input, _output, _answer +}; + +/* Outcomes 6-15 are reserved for future use. */ +enum TResult { + _ok = 0, + _wa = 1, + _pe = 2, + _fail = 3, + _dirt = 4, + _points = 5, + _unexpected_eof = 8, + _partially = 16 +}; + +enum TTestlibMode { + _unknown, _checker, _validator, _generator, _interactor, _scorer +}; + +#define _pc(exitCode) (TResult(_partially + (exitCode))) + +/* Outcomes 6-15 are reserved for future use. */ +const std::string outcomes[] = { + "accepted", + "wrong-answer", + "presentation-error", + "fail", + "fail", +#ifndef PCMS2 + "points", +#else + "relative-scoring", +#endif + "reserved", + "reserved", + "unexpected-eof", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "partially-correct" +}; + +class InputStreamReader { +public: + virtual void setTestCase(int testCase) = 0; + + virtual std::vector getReadChars() = 0; + + virtual int curChar() = 0; + + virtual int nextChar() = 0; + + virtual void skipChar() = 0; + + virtual void unreadChar(int c) = 0; + + virtual std::string getName() = 0; + + virtual bool eof() = 0; + + virtual void close() = 0; + + virtual int getLine() = 0; + + virtual ~InputStreamReader() = 0; +}; + +InputStreamReader::~InputStreamReader() { + // No operations. +} + +class StringInputStreamReader : public InputStreamReader { +private: + std::string s; + size_t pos; + +public: + StringInputStreamReader(const std::string &content) : s(content), pos(0) { + // No operations. + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in StringInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in StringInputStreamReader"); + } + + int curChar() { + if (pos >= s.length()) + return EOFC; + else + return s[pos]; + } + + int nextChar() { + if (pos >= s.length()) { + pos++; + return EOFC; + } else + return s[pos++]; + } + + void skipChar() { + pos++; + } + + void unreadChar(int c) { + if (pos == 0) + __testlib_fail("StringInputStreamReader::unreadChar(int): pos == 0."); + pos--; + if (pos < s.length()) + s[pos] = char(c); + } + + std::string getName() { + return __testlib_part(s); + } + + int getLine() { + return -1; + } + + bool eof() { + return pos >= s.length(); + } + + void close() { + // No operations. + } +}; + +class FileInputStreamReader : public InputStreamReader { +private: + std::FILE *file; + std::string name; + int line; + std::vector undoChars; + std::vector readChars; + std::vector undoReadChars; + + inline int postprocessGetc(int getcResult) { + if (getcResult != EOF) + return getcResult; + else + return EOFC; + } + + int getc(FILE *file) { + int c; + int rc; + + if (undoChars.empty()) { + c = rc = ::getc(file); + } else { + c = undoChars.back(); + undoChars.pop_back(); + rc = undoReadChars.back(); + undoReadChars.pop_back(); + } + + if (c == LF) + line++; + + readChars.push_back(rc); + return c; + } + + int ungetc(int c/*, FILE* file*/) { + if (!readChars.empty()) { + undoReadChars.push_back(readChars.back()); + readChars.pop_back(); + } + if (c == LF) + line--; + undoChars.push_back(c); + return c; + } + +public: + FileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + // No operations. + } + + void setTestCase(int testCase) { + if (testCase < 0 || testCase > __TESTLIB_MAX_TEST_CASE) + __testlib_fail(format("testCase expected fit in [1,%d], but %d doesn't", __TESTLIB_MAX_TEST_CASE, testCase)); + readChars.push_back(testCase + 256); + } + + std::vector getReadChars() { + return readChars; + } + + int curChar() { + if (feof(file)) + return EOFC; + else { + int c = getc(file); + ungetc(c/*, file*/); + return postprocessGetc(c); + } + } + + int nextChar() { + if (feof(file)) + return EOFC; + else + return postprocessGetc(getc(file)); + } + + void skipChar() { + getc(file); + } + + void unreadChar(int c) { + ungetc(c/*, file*/); + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + if (NULL == file || feof(file)) + return true; + else { + int c = nextChar(); + if (c == EOFC || (c == EOF && feof(file))) + return true; + unreadChar(c); + return false; + } + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +class BufferedFileInputStreamReader : public InputStreamReader { +private: + static const size_t BUFFER_SIZE; + static const size_t MAX_UNREAD_COUNT; + + std::FILE *file; + std::string name; + int line; + + char *buffer; + bool *isEof; + int bufferPos; + size_t bufferSize; + + bool refill() { + if (NULL == file) + __testlib_fail("BufferedFileInputStreamReader: file == NULL (" + getName() + ")"); + + if (bufferPos >= int(bufferSize)) { + size_t readSize = fread( + buffer + MAX_UNREAD_COUNT, + 1, + BUFFER_SIZE - MAX_UNREAD_COUNT, + file + ); + + if (readSize < BUFFER_SIZE - MAX_UNREAD_COUNT + && ferror(file)) + __testlib_fail("BufferedFileInputStreamReader: unable to read (" + getName() + ")"); + + bufferSize = MAX_UNREAD_COUNT + readSize; + bufferPos = int(MAX_UNREAD_COUNT); + std::memset(isEof + MAX_UNREAD_COUNT, 0, sizeof(isEof[0]) * readSize); + + return readSize > 0; + } else + return true; + } + + char increment() { + char c; + if ((c = buffer[bufferPos++]) == LF) + line++; + return c; + } + +public: + BufferedFileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + buffer = new char[BUFFER_SIZE]; + isEof = new bool[BUFFER_SIZE]; + bufferSize = MAX_UNREAD_COUNT; + bufferPos = int(MAX_UNREAD_COUNT); + } + + ~BufferedFileInputStreamReader() { + if (NULL != buffer) { + delete[] buffer; + buffer = NULL; + } + if (NULL != isEof) { + delete[] isEof; + isEof = NULL; + } + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in BufferedFileInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in BufferedFileInputStreamReader"); + } + + int curChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : buffer[bufferPos]; + } + + int nextChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : increment(); + } + + void skipChar() { + increment(); + } + + void unreadChar(int c) { + bufferPos--; + if (bufferPos < 0) + __testlib_fail("BufferedFileInputStreamReader::unreadChar(int): bufferPos < 0"); + isEof[bufferPos] = (c == EOFC); + buffer[bufferPos] = char(c); + if (c == LF) + line--; + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + return !refill() || EOFC == curChar(); + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +const size_t BufferedFileInputStreamReader::BUFFER_SIZE = 2000000; +const size_t BufferedFileInputStreamReader::MAX_UNREAD_COUNT = BufferedFileInputStreamReader::BUFFER_SIZE / 2; + +/* + * Streams to be used for reading data in checkers or validators. + * Each read*() method moves pointer to the next character after the + * read value. + */ +struct InStream { + /* Do not use them. */ + InStream(); + + ~InStream(); + + /* Wrap std::string with InStream. */ + InStream(const InStream &baseStream, std::string content); + + InputStreamReader *reader; + int lastLine; + + std::string name; + TMode mode; + bool opened; + bool stdfile; + bool strict; + + int wordReserveSize; + std::string _tmpReadToken; + + int readManyIteration; + size_t maxFileSize; + size_t maxTokenLength; + size_t maxMessageLength; + + void init(std::string fileName, TMode mode); + + void init(std::FILE *f, TMode mode); + + void setTestCase(int testCase); + std::vector getReadChars(); + + /* Moves stream pointer to the first non-white-space character or EOF. */ + void skipBlanks(); + + /* Returns current character in the stream. Doesn't remove it from stream. */ + char curChar(); + + /* Moves stream pointer one character forward. */ + void skipChar(); + + /* Returns current character and moves pointer one character forward. */ + char nextChar(); + + /* Returns current character and moves pointer one character forward. */ + char readChar(); + + /* As "readChar()" but ensures that the result is equal to given parameter. */ + char readChar(char c); + + /* As "readChar()" but ensures that the result is equal to the space (code=32). */ + char readSpace(); + + /* Puts back the character into the stream. */ + void unreadChar(char c); + + /* Reopens stream, you should not use it. */ + void reset(std::FILE *file = NULL); + + /* Checks that current position is EOF. If not it doesn't move stream pointer. */ + bool eof(); + + /* Moves pointer to the first non-white-space character and calls "eof()". */ + bool seekEof(); + + /* + * Checks that current position contains EOLN. + * If not it doesn't move stream pointer. + * In strict mode expects "#13#10" for windows or "#10" for other platforms. + */ + bool eoln(); + + /* Moves pointer to the first non-space and non-tab character and calls "eoln()". */ + bool seekEoln(); + + /* Moves stream pointer to the first character of the next line (if exists). */ + void nextLine(); + + /* + * Reads new token. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + std::string readWord(); + + /* The same as "readWord()", it is preffered to use "readToken()". */ + std::string readToken(); + + /* The same as "readWord()", but ensures that token matches to given pattern. */ + std::string readWord(const std::string &ptrn, const std::string &variableName = ""); + + std::string readWord(const pattern &p, const std::string &variableName = ""); + + std::vector + readWords(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readWords(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readWords(int size, int indexBase = 1); + + /* The same as "readToken()", but ensures that token matches to given pattern. */ + std::string readToken(const std::string &ptrn, const std::string &variableName = ""); + + std::string readToken(const pattern &p, const std::string &variableName = ""); + + std::vector + readTokens(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readTokens(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readTokens(int size, int indexBase = 1); + + void readWordTo(std::string &result); + + void readWordTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + void readTokenTo(std::string &result); + + void readTokenTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads new long long value. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + long long readLong(); + + unsigned long long readUnsignedLong(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInteger(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInt(); + + /* As "readLong()" but ensures that value in the range [minv,maxv]. */ + long long readLong(long long minv, long long maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of long longs. */ + std::vector + readLongs(int size, long long minv, long long maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of long longs. */ + std::vector readLongs(int size, int indexBase = 1); + + unsigned long long + readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + std::vector readUnsignedLongs(int size, int indexBase = 1); + + unsigned long long readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + /* As "readInteger()" but ensures that value in the range [minv,maxv]. */ + int readInteger(int minv, int maxv, const std::string &variableName = ""); + + /* As "readInt()" but ensures that value in the range [minv,maxv]. */ + int readInt(int minv, int maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of integers. */ + std::vector + readIntegers(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readIntegers(int size, int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int indexBase = 1); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readReal(); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readDouble(); + + /* As "readReal()" but ensures that value in the range [minv,maxv]. */ + double readReal(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readReals(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readReals(int size, int indexBase = 1); + + /* As "readDouble()" but ensures that value in the range [minv,maxv]. */ + double readDouble(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readDoubles(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readDoubles(int size, int indexBase = 1); + + /* + * As "readReal()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* + * As "readDouble()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* As readLine(). */ + std::string readString(); + + /* Read many lines. */ + std::vector readStrings(int size, int indexBase = 1); + + /* See readLine(). */ + void readStringTo(std::string &result); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readStrings(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readStrings(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads line from the current position to EOLN or EOF. Moves stream pointer to + * the first character of the new line (if possible). + */ + std::string readLine(); + + /* Read many lines. */ + std::vector readLines(int size, int indexBase = 1); + + /* See readLine(). */ + void readLineTo(std::string &result); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readLines(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readLines(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* Reads EOLN or fails. Use it in validators. Calls "eoln()" method internally. */ + void readEoln(); + + /* Reads EOF or fails. Use it in validators. Calls "eof()" method internally. */ + void readEof(); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quit(TResult result, const char *msg); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quitf(TResult result, const char *msg, ...); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + void quitif(bool condition, TResult result, const char *msg, ...); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quits(TResult result, std::string msg); + + /* + * Checks condition and aborts a program if codition is false. + * Returns _wa for ouf and _fail on any other streams. + */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void ensuref(bool cond, const char *format, ...); + + void __testlib_ensure(bool cond, std::string message); + + void close(); + + const static int NO_INDEX = INT_MAX; + const static char OPEN_BRACKET = char(11); + const static char CLOSE_BRACKET = char(17); + + const static WORD LightGray = 0x07; + const static WORD LightRed = 0x0c; + const static WORD LightCyan = 0x0b; + const static WORD LightGreen = 0x0a; + const static WORD LightYellow = 0x0e; + + static void textColor(WORD color); + + static void quitscr(WORD color, const char *msg); + + static void quitscrS(WORD color, std::string msg); + + void xmlSafeWrite(std::FILE *file, const char *msg); + + /* Skips UTF-8 Byte Order Mark. */ + void skipBom(); + +private: + InStream(const InStream &); + + InStream &operator=(const InStream &); +}; + +InStream inf; +InStream ouf; +InStream ans; +bool appesMode; +std::string resultName; +std::string checkerName = "untitled checker"; +random_t rnd; +TTestlibMode testlibMode = _unknown; +double __testlib_points = std::numeric_limits::infinity(); + +struct ValidatorBoundsHit { + static const double EPS; + bool minHit; + bool maxHit; + + ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) { + }; + + ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) { + return ValidatorBoundsHit( + __testlib_max(minHit, validatorBoundsHit.minHit), + __testlib_max(maxHit, validatorBoundsHit.maxHit) + ); + } +}; + +const double ValidatorBoundsHit::EPS = 1E-12; + +class Validator { +private: + const static std::string TEST_MARKUP_HEADER; + const static std::string TEST_CASE_OPEN_TAG; + const static std::string TEST_CASE_CLOSE_TAG; + + bool _initialized; + std::string _testset; + std::string _group; + + std::string _testOverviewLogFileName; + std::string _testMarkupFileName; + int _testCase = -1; + std::string _testCaseFileName; + + std::map _boundsHitByVariableName; + std::set _features; + std::set _hitFeatures; + + bool isVariableNameBoundsAnalyzable(const std::string &variableName) { + for (size_t i = 0; i < variableName.length(); i++) + if ((variableName[i] >= '0' && variableName[i] <= '9') || variableName[i] < ' ') + return false; + return true; + } + + bool isFeatureNameAnalyzable(const std::string &featureName) { + for (size_t i = 0; i < featureName.length(); i++) + if (featureName[i] < ' ') + return false; + return true; + } + +public: + Validator() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.group()"); + return _group; + } + + std::string testOverviewLogFileName() const { + return _testOverviewLogFileName; + } + + std::string testMarkupFileName() const { + return _testMarkupFileName; + } + + int testCase() const { + return _testCase; + } + + std::string testCaseFileName() const { + return _testCaseFileName; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } + + void setTestOverviewLogFileName(const char *const testOverviewLogFileName) { + _testOverviewLogFileName = testOverviewLogFileName; + } + + void setTestMarkupFileName(const char *const testMarkupFileName) { + _testMarkupFileName = testMarkupFileName; + } + + void setTestCase(int testCase) { + _testCase = testCase; + } + + void setTestCaseFileName(const char *const testCaseFileName) { + _testCaseFileName = testCaseFileName; + } + + void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) { + if (isVariableNameBoundsAnalyzable(variableName)) { + _boundsHitByVariableName[variableName] + = boundsHit.merge(_boundsHitByVariableName[variableName]); + } + } + + std::string getBoundsHitLog() { + std::string result; + for (std::map::iterator i = _boundsHitByVariableName.begin(); + i != _boundsHitByVariableName.end(); + i++) { + result += "\"" + i->first + "\":"; + if (i->second.minHit) + result += " min-value-hit"; + if (i->second.maxHit) + result += " max-value-hit"; + result += "\n"; + } + return result; + } + + std::string getFeaturesLog() { + std::string result; + for (std::set::iterator i = _features.begin(); + i != _features.end(); + i++) { + result += "feature \"" + *i + "\":"; + if (_hitFeatures.count(*i)) + result += " hit"; + result += "\n"; + } + return result; + } + + void writeTestOverviewLog() { + if (!_testOverviewLogFileName.empty()) { + std::string fileName(_testOverviewLogFileName); + _testOverviewLogFileName = ""; + FILE *testOverviewLogFile = fopen(fileName.c_str(), "w"); + if (NULL == testOverviewLogFile) + __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")"); + fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str()); + if (fclose(testOverviewLogFile)) + __testlib_fail( + "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")"); + } + } + + void writeTestMarkup() { + if (!_testMarkupFileName.empty()) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string markup(TEST_MARKUP_HEADER); + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) { + char cc = char(c); + if (cc == '\\' || cc == '!') + markup += '\\'; + markup += cc; + } else { + markup += TEST_CASE_OPEN_TAG; + markup += toString(c - 256); + markup += TEST_CASE_CLOSE_TAG; + } + } + FILE* f; + bool standard_file = false; + if (_testMarkupFileName == "stdout") + f = stdout, standard_file = true; + else if (_testMarkupFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testMarkupFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestMarkup: can't write test markup to (" + _testMarkupFileName + ")"); + } + std::fprintf(f, "%s", markup.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestMarkup: can't close test markup file (" + _testCaseFileName + ")"); + } + } + } + + void writeTestCase() { + if (_testCase > 0) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string content, testCaseContent; + bool matchedTestCase = false; + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) + content += char(c); + else { + if (matchedTestCase) { + testCaseContent = content; + matchedTestCase = false; + } + content = ""; + int testCase = c - 256; + if (testCase == _testCase) + matchedTestCase = true; + } + } + if (matchedTestCase) + testCaseContent = content; + + if (!testCaseContent.empty()) { + FILE* f; + bool standard_file = false; + if (_testCaseFileName.empty() || _testCaseFileName == "stdout") + f = stdout, standard_file = true; + else if (_testCaseFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testCaseFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestCase: can't write test case to (" + _testCaseFileName + ")"); + } + std::fprintf(f, "%s", testCaseContent.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestCase: can't close test case file (" + _testCaseFileName + ")"); + } + } + } + } + + void addFeature(const std::string &feature) { + if (_features.count(feature)) + __testlib_fail("Feature " + feature + " registered twice."); + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + _features.insert(feature); + } + + void feature(const std::string &feature) { + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + if (!_features.count(feature)) + __testlib_fail("Feature " + feature + " didn't registered via addFeature(feature)."); + + _hitFeatures.insert(feature); + } +} validator; + +const std::string Validator::TEST_MARKUP_HEADER = "MU\xF3\x01"; +const std::string Validator::TEST_CASE_OPEN_TAG = "!c"; +const std::string Validator::TEST_CASE_CLOSE_TAG = ";"; + +struct TestlibFinalizeGuard { + static bool alive; + static bool registered; + + int quitCount, readEofCount; + + TestlibFinalizeGuard() : quitCount(0), readEofCount(0) { + // No operations. + } + + ~TestlibFinalizeGuard() { + bool _alive = alive; + alive = false; + + if (_alive) { + if (testlibMode == _checker && quitCount == 0) + __testlib_fail("Checker must end with quit or quitf call."); + + if (testlibMode == _validator && readEofCount == 0 && quitCount == 0) + __testlib_fail("Validator must end with readEof call."); + + /* opts */ + autoEnsureNoUnusedOpts(); + + if (!registered) + __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)"); + } + + if (__testlib_exitCode == 0) { + validator.writeTestOverviewLog(); + validator.writeTestMarkup(); + validator.writeTestCase(); + } + } + +private: + /* opts */ + void autoEnsureNoUnusedOpts(); +}; + +bool TestlibFinalizeGuard::alive = true; +bool TestlibFinalizeGuard::registered = false; +extern TestlibFinalizeGuard testlibFinalizeGuard; + +/* + * Call it to disable checks on finalization. + */ +void disableFinalizeGuard() { + TestlibFinalizeGuard::alive = false; +} + +/* Interactor streams. + */ +std::fstream tout; + +/* implementation + */ + +InStream::InStream() { + reader = NULL; + lastLine = -1; + opened = false; + name = ""; + mode = _input; + strict = false; + stdfile = false; + wordReserveSize = 4; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::InStream(const InStream &baseStream, std::string content) { + reader = new StringInputStreamReader(content); + lastLine = -1; + opened = true; + strict = baseStream.strict; + stdfile = false; + mode = baseStream.mode; + name = "based on " + baseStream.name; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::~InStream() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } +} + +void InStream::setTestCase(int testCase) { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::setTestCase can be used only for inf in validator-mode." + " Actually, prefer setTestCase function instead of InStream member"); + reader->setTestCase(testCase); +} + +std::vector InStream::getReadChars() { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::getReadChars can be used only for inf in validator-mode."); + return reader == NULL ? std::vector() : reader->getReadChars(); +} + +void setTestCase(int testCase) { + static bool first_run = true; + static bool zero_based = false; + + if (first_run && testCase == 0) + zero_based = true; + + if (zero_based) + testCase++; + + __testlib_hasTestCase = true; + __testlib_testCase = testCase; + + if (testlibMode == _validator) + inf.setTestCase(testCase); + + first_run = false; +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int resultExitCode(TResult r) { + if (r == _ok) + return OK_EXIT_CODE; + if (r == _wa) + return WA_EXIT_CODE; + if (r == _pe) + return PE_EXIT_CODE; + if (r == _fail) + return FAIL_EXIT_CODE; + if (r == _dirt) + return DIRT_EXIT_CODE; + if (r == _points) + return POINTS_EXIT_CODE; + if (r == _unexpected_eof) +#ifdef ENABLE_UNEXPECTED_EOF + return UNEXPECTED_EOF_EXIT_CODE; +#else + return PE_EXIT_CODE; +#endif + if (r >= _partially) + return PC_BASE_EXIT_CODE + (r - _partially); + return FAIL_EXIT_CODE; +} + +void InStream::textColor( +#if !(defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)) && defined(__GNUC__) + __attribute__((unused)) +#endif + WORD color +) { +#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400) + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, color); +#endif +#if !defined(ON_WINDOWS) && defined(__GNUC__) + if (isatty(2)) + { + switch (color) + { + case LightRed: + fprintf(stderr, "\033[1;31m"); + break; + case LightCyan: + fprintf(stderr, "\033[1;36m"); + break; + case LightGreen: + fprintf(stderr, "\033[1;32m"); + break; + case LightYellow: + fprintf(stderr, "\033[1;33m"); + break; + case LightGray: + default: + fprintf(stderr, "\033[0m"); + } + } +#endif +} + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +class exit_exception: public std::exception { +private: + int exitCode; +public: + exit_exception(int exitCode): exitCode(exitCode) {} + int getExitCode() { return exitCode; } +}; +#endif + +NORETURN void halt(int exitCode) { +#ifdef FOOTER + InStream::textColor(InStream::LightGray); + std::fprintf(stderr, "Checker: \"%s\"\n", checkerName.c_str()); + std::fprintf(stderr, "Exit code: %d\n", exitCode); + InStream::textColor(InStream::LightGray); +#endif + __testlib_exitCode = exitCode; +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT + throw exit_exception(exitCode); +#endif + std::exit(exitCode); +} + +static bool __testlib_shouldCheckDirt(TResult result) { + return result == _ok || result == _points || result >= _partially; +} + +static std::string __testlib_appendMessage(const std::string &message, const std::string &extra) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + size_t index = message.find(extra, openPos); + if (index == std::string::npos || int(index) >= closePos) { + std::string result(message); + result.insert(closePos, ", " + extra); + return result; + } + return message; + } + + return message + " " + InStream::OPEN_BRACKET + extra + InStream::CLOSE_BRACKET; +} + +static std::string __testlib_toPrintableMessage(const std::string &message) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + std::string result(message); + result[openPos] = '('; + result[closePos] = ')'; + return result; + } + + return message; +} + +NORETURN void InStream::quit(TResult result, const char *msg) { + if (TestlibFinalizeGuard::alive) + testlibFinalizeGuard.quitCount++; + + std::string message(msg); + message = trim(message); + + if (__testlib_hasTestCase) { + if (result != _ok) + message = __testlib_appendMessage(message, "test case " + vtos(__testlib_testCase)); + else { + if (__testlib_testCase == 1) + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test case"); + else + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test cases"); + } + } + + // You can change maxMessageLength. + // Example: 'inf.maxMessageLength = 1024 * 1024;'. + if (message.length() > maxMessageLength) { + std::string warn = "message length exceeds " + vtos(maxMessageLength) + + ", the message is truncated: "; + message = warn + message.substr(0, maxMessageLength - warn.length()); + } + +#ifndef ENABLE_UNEXPECTED_EOF + if (result == _unexpected_eof) + result = _pe; +#endif + + if (testlibMode == _scorer && result != _fail) + quits(_fail, "Scorer should return points only. Don't use a quit function."); + + if (mode != _output && result != _fail) { + if (mode == _input && testlibMode == _validator && lastLine != -1) + quits(_fail, __testlib_appendMessage(__testlib_appendMessage(message, name), "line " + vtos(lastLine))); + else + quits(_fail, __testlib_appendMessage(message, name)); + } + + std::FILE *resultFile; + std::string errorName; + + if (__testlib_shouldCheckDirt(result)) { + if (testlibMode != _interactor && !ouf.seekEof()) + quit(_dirt, "Extra information in the output file"); + } + + int pctype = result - _partially; + bool isPartial = false; + + switch (result) { + case _ok: + errorName = "ok "; + quitscrS(LightGreen, errorName); + break; + case _wa: + errorName = "wrong answer "; + quitscrS(LightRed, errorName); + break; + case _pe: + errorName = "wrong output format "; + quitscrS(LightRed, errorName); + break; + case _fail: + errorName = "FAIL "; + quitscrS(LightRed, errorName); + break; + case _dirt: + errorName = "wrong output format "; + quitscrS(LightCyan, errorName); + result = _pe; + break; + case _points: + errorName = "points "; + quitscrS(LightYellow, errorName); + break; + case _unexpected_eof: + errorName = "unexpected eof "; + quitscrS(LightCyan, errorName); + break; + default: + if (result >= _partially) { + errorName = format("partially correct (%d) ", pctype); + isPartial = true; + quitscrS(LightYellow, errorName); + } else + quit(_fail, "What is the code ??? "); + } + + if (resultName != "") { + resultFile = std::fopen(resultName.c_str(), "w"); + if (resultFile == NULL) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + if (appesMode) { + std::fprintf(resultFile, ""); + if (isPartial) + std::fprintf(resultFile, "", + outcomes[(int) _partially].c_str(), pctype); + else { + if (result != _points) + std::fprintf(resultFile, "", outcomes[(int) result].c_str()); + else { + if (__testlib_points == std::numeric_limits::infinity()) + quit(_fail, "Expected points, but infinity found"); + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", __testlib_points)); + std::fprintf(resultFile, "", + outcomes[(int) result].c_str(), stringPoints.c_str()); + } + } + xmlSafeWrite(resultFile, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(resultFile, "\n"); + } else + std::fprintf(resultFile, "%s", __testlib_toPrintableMessage(message).c_str()); + if (NULL == resultFile || fclose(resultFile) != 0) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + } + + quitscr(LightGray, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(stderr, "\n"); + + inf.close(); + ouf.close(); + ans.close(); + if (tout.is_open()) + tout.close(); + + textColor(LightGray); + + if (resultName != "") + std::fprintf(stderr, "See file to check exit message\n"); + + halt(resultExitCode(result)); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +NORETURN void InStream::quitf(TResult result, const char *msg, ...) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +void InStream::quitif(bool condition, TResult result, const char *msg, ...) { + if (condition) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); + } +} + +NORETURN void InStream::quits(TResult result, std::string msg) { + InStream::quit(result, msg.c_str()); +} + +void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { + size_t lmsg = strlen(msg); + for (size_t i = 0; i < lmsg; i++) { + if (msg[i] == '&') { + std::fprintf(file, "%s", "&"); + continue; + } + if (msg[i] == '<') { + std::fprintf(file, "%s", "<"); + continue; + } + if (msg[i] == '>') { + std::fprintf(file, "%s", ">"); + continue; + } + if (msg[i] == '"') { + std::fprintf(file, "%s", """); + continue; + } + if (0 <= msg[i] && msg[i] <= 31) { + std::fprintf(file, "%c", '.'); + continue; + } + std::fprintf(file, "%c", msg[i]); + } +} + +void InStream::quitscrS(WORD color, std::string msg) { + quitscr(color, msg.c_str()); +} + +void InStream::quitscr(WORD color, const char *msg) { + if (resultName == "") { + textColor(color); + std::fprintf(stderr, "%s", msg); + textColor(LightGray); + } +} + +void InStream::reset(std::FILE *file) { + if (opened && stdfile) + quit(_fail, "Can't reset standard handle"); + + if (opened) + close(); + + if (!stdfile && NULL == file) + if (NULL == (file = std::fopen(name.c_str(), "rb"))) { + if (mode == _output) + quits(_pe, std::string("Output file not found: \"") + name + "\""); + + if (mode == _answer) + quits(_fail, std::string("Answer file not found: \"") + name + "\""); + } + + if (NULL != file) { + opened = true; + __testlib_set_binary(file); + + if (stdfile) + reader = new FileInputStreamReader(file, name); + else + reader = new BufferedFileInputStreamReader(file, name); + } else { + opened = false; + reader = NULL; + } +} + +void InStream::init(std::string fileName, TMode mode) { + opened = false; + name = fileName; + stdfile = false; + this->mode = mode; + + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + if (stream.is_open()) { + std::streampos start = stream.tellg(); + stream.seekg(0, std::ios::end); + std::streampos end = stream.tellg(); + size_t fileSize = size_t(end - start); + stream.close(); + + // You can change maxFileSize. + // Example: 'inf.maxFileSize = 256 * 1024 * 1024;'. + if (fileSize > maxFileSize) + quitf(_pe, "File size exceeds %d bytes, size is %d", int(maxFileSize), int(fileSize)); + } + + reset(); +} + +void InStream::init(std::FILE *f, TMode mode) { + opened = false; + name = "untitled"; + this->mode = mode; + + if (f == stdin) + name = "stdin", stdfile = true; + if (f == stdout) + name = "stdout", stdfile = true; + if (f == stderr) + name = "stderr", stdfile = true; + + reset(f); +} + +void InStream::skipBom() { + const std::string utf8Bom = "\xEF\xBB\xBF"; + size_t index = 0; + while (index < utf8Bom.size() && curChar() == utf8Bom[index]) { + index++; + skipChar(); + } + if (index < utf8Bom.size()) { + while (index != 0) { + unreadChar(utf8Bom[index - 1]); + index--; + } + } +} + +char InStream::curChar() { + return char(reader->curChar()); +} + +char InStream::nextChar() { + return char(reader->nextChar()); +} + +char InStream::readChar() { + return nextChar(); +} + +char InStream::readChar(char c) { + lastLine = reader->getLine(); + char found = readChar(); + if (c != found) { + if (!isEoln(found)) + quit(_pe, ("Unexpected character '" + std::string(1, found) + "', but '" + std::string(1, c) + + "' expected").c_str()); + else + quit(_pe, ("Unexpected character " + ("#" + vtos(int(found))) + ", but '" + std::string(1, c) + + "' expected").c_str()); + } + return found; +} + +char InStream::readSpace() { + return readChar(' '); +} + +void InStream::unreadChar(char c) { + reader->unreadChar(c); +} + +void InStream::skipChar() { + reader->skipChar(); +} + +void InStream::skipBlanks() { + while (isBlanks(reader->curChar())) + reader->skipChar(); +} + +std::string InStream::readWord() { + readWordTo(_tmpReadToken); + return _tmpReadToken; +} + +void InStream::readWordTo(std::string &result) { + if (!strict) + skipBlanks(); + + lastLine = reader->getLine(); + int cur = reader->nextChar(); + + if (cur == EOFC) + quit(_unexpected_eof, "Unexpected end of file - token expected"); + + if (isBlanks(cur)) + quit(_pe, "Unexpected white-space - token expected"); + + result.clear(); + + while (!(isBlanks(cur) || cur == EOFC)) { + result += char(cur); + + // You can change maxTokenLength. + // Example: 'inf.maxTokenLength = 128 * 1024 * 1024;'. + if (result.length() > maxTokenLength) + quitf(_pe, "Length of token exceeds %d, token is '%s...'", int(maxTokenLength), + __testlib_part(result).c_str()); + + cur = reader->nextChar(); + } + + reader->unreadChar(cur); + + if (result.length() == 0) + quit(_unexpected_eof, "Unexpected end of file or white-space - token expected"); +} + +std::string InStream::readToken() { + return readWord(); +} + +void InStream::readTokenTo(std::string &result) { + readWordTo(result); +} + +static std::string __testlib_part(const std::string &s) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (s[i] != '\0') + t += s[i]; + else + t += '~'; + if (t.length() <= 64) + return t; + else + return t.substr(0, 30) + "..." + t.substr(s.length() - 31, 31); +} + +#define __testlib_readMany(readMany, readOne, typeName, space) \ + if (size < 0) \ + quit(_fail, #readMany ": size should be non-negative."); \ + if (size > 100000000) \ + quit(_fail, #readMany ": size should be at most 100000000."); \ + \ + std::vector result(size); \ + readManyIteration = indexBase; \ + \ + for (int i = 0; i < size; i++) \ + { \ + result[i] = readOne; \ + readManyIteration++; \ + if (strict && space && i + 1 < size) \ + readSpace(); \ + } \ + \ + readManyIteration = NO_INDEX; \ + return result; \ + + +std::string InStream::readWord(const pattern &p, const std::string &variableName) { + readWordTo(_tmpReadToken); + if (!p.matches(_tmpReadToken)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Token \"" + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(_tmpReadToken) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Token element [index=" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token element " + variableName + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\", doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + } + } + return _tmpReadToken; +} + +std::vector +InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::vector InStream::readWords(int size, int indexBase) { + __testlib_readMany(readWords, readWord(), std::string, true); +} + +std::string InStream::readWord(const std::string &ptrn, const std::string &variableName) { + return readWord(pattern(ptrn), variableName); +} + +std::vector +InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::string InStream::readToken(const pattern &p, const std::string &variableName) { + return readWord(p, variableName); +} + +std::vector +InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readTokens, readToken(p, variablesName), std::string, true); +} + +std::vector InStream::readTokens(int size, int indexBase) { + __testlib_readMany(readTokens, readToken(), std::string, true); +} + +std::string InStream::readToken(const std::string &ptrn, const std::string &variableName) { + return readWord(ptrn, variableName); +} + +std::vector +InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readTokens, readWord(p, variablesName), std::string, true); +} + +void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) { + readWordTo(result); + if (!p.matches(result)) { + if (variableName.empty()) + quit(_wa, ("Token \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } +} + +void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, pattern(ptrn), variableName); +} + +void InStream::readTokenTo(std::string &result, const pattern &p, const std::string &variableName) { + return readWordTo(result, p, variableName); +} + +void InStream::readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, ptrn, variableName); +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(long long integer, const char *s) { + if (integer == LLONG_MIN) + return strcmp(s, "-9223372036854775808") == 0; + + if (integer == 0LL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + if (integer < 0 && s[0] != '-') + return false; + + if (integer < 0) + s++, length--, integer = -integer; + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(unsigned long long integer, const char *s) { + if (integer == ULLONG_MAX) + return strcmp(s, "18446744073709551615") == 0; + + if (integer == 0ULL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +static inline double stringToDouble(InStream &in, const char *buffer) { + double retval; + + size_t length = strlen(buffer); + + int minusCount = 0; + int plusCount = 0; + int decimalPointCount = 0; + int digitCount = 0; + int eCount = 0; + + for (size_t i = 0; i < length; i++) { + if (('0' <= buffer[i] && buffer[i] <= '9') || buffer[i] == '.' + || buffer[i] == 'e' || buffer[i] == 'E' + || buffer[i] == '-' || buffer[i] == '+') { + if ('0' <= buffer[i] && buffer[i] <= '9') + digitCount++; + if (buffer[i] == 'e' || buffer[i] == 'E') + eCount++; + if (buffer[i] == '-') + minusCount++; + if (buffer[i] == '+') + plusCount++; + if (buffer[i] == '.') + decimalPointCount++; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + // If for sure is not a number in standard notation or in e-notation. + if (digitCount == 0 || minusCount > 2 || plusCount > 2 || decimalPointCount > 1 || eCount > 1) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToDouble(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToDouble(in, buffer.c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const char *buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + if (minAfterPointDigitCount < 0) + in.quit(_fail, "stringToStrictDouble: minAfterPointDigitCount should be non-negative."); + + if (minAfterPointDigitCount > maxAfterPointDigitCount) + in.quit(_fail, + "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount."); + + double retval; + + size_t length = strlen(buffer); + + if (length == 0 || length > 1000) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[0] != '-' && (buffer[0] < '0' || buffer[0] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int pointPos = -1; + for (size_t i = 1; i + 1 < length; i++) { + if (buffer[i] == '.') { + if (pointPos > -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + pointPos = int(i); + } + if (buffer[i] != '.' && (buffer[i] < '0' || buffer[i] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + if (buffer[length - 1] < '0' || buffer[length - 1] > '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int afterDigitsCount = (pointPos == -1 ? 0 : int(length) - pointPos - 1); + if (afterDigitsCount < minAfterPointDigitCount || afterDigitsCount > maxAfterPointDigitCount) + in.quit(_pe, ("Expected strict double with number of digits after point in range [" + + vtos(minAfterPointDigitCount) + + "," + + vtos(maxAfterPointDigitCount) + + "], but \"" + __testlib_part(buffer) + "\" found").c_str() + ); + + int firstDigitPos = -1; + for (size_t i = 0; i < length; i++) + if (buffer[i] >= '0' && buffer[i] <= '9') { + firstDigitPos = int(i); + break; + } + + if (firstDigitPos > 1 || firstDigitPos == -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[firstDigitPos] == '0' && firstDigitPos + 1 < int(length) + && buffer[firstDigitPos + 1] >= '0' && buffer[firstDigitPos + 1] <= '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval) || __testlib_isInfinite(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (buffer[0] == '-' && retval >= 0) + in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const std::string& buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToStrictDouble(in, buffer.c_str(), minAfterPointDigitCount, maxAfterPointDigitCount); +} + +static inline long long stringToLongLong(InStream &in, const char *buffer) { + if (strcmp(buffer, "-9223372036854775808") == 0) + return LLONG_MIN; + + bool minus = false; + size_t length = strlen(buffer); + + if (length > 1 && buffer[0] == '-') + minus = true; + + if (length > 20) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + long long retval = 0LL; + + int zeroes = 0; + bool processingZeroes = true; + + for (int i = (minus ? 1 : 0); i < int(length); i++) { + if (buffer[i] == '0' && processingZeroes) + zeroes++; + else + processingZeroes = false; + + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (retval < 0) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if ((zeroes > 0 && (retval != 0 || minus)) || zeroes > 1) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + retval = (minus ? -retval : +retval); + + if (length < 19) + return retval; + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToLongLong(in, buffer.c_str()); +} + +static inline unsigned long long stringToUnsignedLongLong(InStream &in, const char *buffer) { + size_t length = strlen(buffer); + + if (length > 20) + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (length > 1 && buffer[0] == '0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + unsigned long long retval = 0LL; + for (int i = 0; i < int(length); i++) { + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (length < 19) + return retval; + + if (length == 20 && strcmp(buffer, "18446744073709551615") > 0) + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToUnsignedLongLong(in, buffer.c_str()); +} + +int InStream::readInteger() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int32 expected"); + + readWordTo(_tmpReadToken); + + long long value = stringToLongLong(*this, _tmpReadToken); + if (value < INT_MIN || value > INT_MAX) + quit(_pe, ("Expected int32, but \"" + __testlib_part(_tmpReadToken) + "\" found").c_str()); + + return int(value); +} + +long long InStream::readLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToLongLong(*this, _tmpReadToken); +} + +unsigned long long InStream::readUnsignedLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToUnsignedLongLong(*this, _tmpReadToken); +} + +long long InStream::readLong(long long minv, long long maxv, const std::string &variableName) { + long long result = readLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector +InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) +} + +std::vector InStream::readLongs(int size, int indexBase) { + __testlib_readMany(readLongs, readLong(), long long, true) +} + +unsigned long long +InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + unsigned long long result = readUnsignedLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, + ("Unsigned integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, ("Unsigned integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) +} + +std::vector InStream::readUnsignedLongs(int size, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) +} + +unsigned long long +InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + return readUnsignedLong(minv, maxv, variableName); +} + +int InStream::readInt() { + return readInteger(); +} + +int InStream::readInt(int minv, int maxv, const std::string &variableName) { + int result = readInt(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +int InStream::readInteger(int minv, int maxv, const std::string &variableName) { + return readInt(minv, maxv, variableName); +} + +std::vector InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readInts(int size, int indexBase) { + __testlib_readMany(readInts, readInt(), int, true) +} + +std::vector InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readIntegers(int size, int indexBase) { + __testlib_readMany(readIntegers, readInt(), int, true) +} + +double InStream::readReal() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - double expected"); + + return stringToDouble(*this, readWord()); +} + +double InStream::readDouble() { + return readReal(); +} + +double InStream::readReal(double minv, double maxv, const std::string &variableName) { + double result = readReal(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, ("Double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, + ("Double element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector +InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readReals(int size, int indexBase) { + __testlib_readMany(readReals, readReal(), double, true) +} + +double InStream::readDouble(double minv, double maxv, const std::string &variableName) { + return readReal(minv, maxv, variableName); +} + +std::vector +InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readDoubles(int size, int indexBase) { + __testlib_readMany(readDoubles, readDouble(), double, true) +} + +double InStream::readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - strict double expected"); + + double result = stringToStrictDouble(*this, readWord(), minAfterPointDigitCount, maxAfterPointDigitCount); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Strict double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, + ("Strict double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Strict double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, ("Strict double element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector InStream::readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictReals, + readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +double InStream::readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + return readStrictReal(minv, maxv, + minAfterPointDigitCount, maxAfterPointDigitCount, + variableName); +} + +std::vector InStream::readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictDoubles, + readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +bool InStream::eof() { + if (!strict && NULL == reader) + return true; + + return reader->eof(); +} + +bool InStream::seekEof() { + if (!strict && NULL == reader) + return true; + skipBlanks(); + return eof(); +} + +bool InStream::eoln() { + if (!strict && NULL == reader) + return true; + + int c = reader->nextChar(); + + if (!strict) { + if (c == EOFC) + return true; + + if (c == CR) { + c = reader->nextChar(); + + if (c != LF) { + reader->unreadChar(c); + reader->unreadChar(CR); + return false; + } else + return true; + } + + if (c == LF) + return true; + + reader->unreadChar(c); + return false; + } else { + bool returnCr = false; + +#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS) + if (c != CR) { + reader->unreadChar(c); + return false; + } else { + if (!returnCr) + returnCr = true; + c = reader->nextChar(); + } +#endif + if (c != LF) { + reader->unreadChar(c); + if (returnCr) + reader->unreadChar(CR); + return false; + } + + return true; + } +} + +void InStream::readEoln() { + lastLine = reader->getLine(); + if (!eoln()) + quit(_pe, "Expected EOLN"); +} + +void InStream::readEof() { + lastLine = reader->getLine(); + if (!eof()) + quit(_pe, "Expected EOF"); + + if (TestlibFinalizeGuard::alive && this == &inf) + testlibFinalizeGuard.readEofCount++; +} + +bool InStream::seekEoln() { + if (!strict && NULL == reader) + return true; + + int cur; + do { + cur = reader->nextChar(); + } while (cur == SPACE || cur == TAB); + + reader->unreadChar(cur); + return eoln(); +} + +void InStream::nextLine() { + readLine(); +} + +void InStream::readStringTo(std::string &result) { + if (NULL == reader) + quit(_pe, "Expected line"); + + result.clear(); + + for (;;) { + int cur = reader->curChar(); + + if (cur == LF || cur == EOFC) + break; + + if (cur == CR) { + cur = reader->nextChar(); + if (reader->curChar() == LF) { + reader->unreadChar(cur); + break; + } + } + + lastLine = reader->getLine(); + result += char(reader->nextChar()); + } + + if (strict) + readEoln(); + else + eoln(); +} + +std::string InStream::readString() { + readStringTo(_tmpReadToken); + return _tmpReadToken; +} + +std::vector InStream::readStrings(int size, int indexBase) { + __testlib_readMany(readStrings, readString(), std::string, false) +} + +void InStream::readStringTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result); + if (!p.matches(result)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Line \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Line [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Line element [index=" + vtos(readManyIteration) + "] equals to \"" + __testlib_part(result) + + "\" doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + else + quit(_wa, + ("Line element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } + } +} + +void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, pattern(ptrn), variableName); +} + +std::string InStream::readString(const pattern &p, const std::string &variableName) { + readStringTo(_tmpReadToken, p, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +std::string InStream::readString(const std::string &ptrn, const std::string &variableName) { + readStringTo(_tmpReadToken, ptrn, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +void InStream::readLineTo(std::string &result) { + readStringTo(result); +} + +std::string InStream::readLine() { + return readString(); +} + +std::vector InStream::readLines(int size, int indexBase) { + __testlib_readMany(readLines, readString(), std::string, false) +} + +void InStream::readLineTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result, p, variableName); +} + +void InStream::readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, ptrn, variableName); +} + +std::string InStream::readLine(const pattern &p, const std::string &variableName) { + return readString(p, variableName); +} + +std::vector +InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) { + return readString(ptrn, variableName); +} + +std::vector +InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void InStream::ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + this->__testlib_ensure(cond, message); + } +} + +void InStream::__testlib_ensure(bool cond, std::string message) { + if (!cond) + this->quit(_wa, message.c_str()); +} + +void InStream::close() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } + + opened = false; +} + +NORETURN void quit(TResult result, const std::string &msg) { + ouf.quit(result, msg.c_str()); +} + +NORETURN void quit(TResult result, const char *msg) { + ouf.quit(result, msg); +} + +NORETURN void __testlib_quitp(double points, const char *message) { + __testlib_points = points; + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", points)); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void __testlib_quitp(int points, const char *message) { + __testlib_points = points; + std::string stringPoints = format("%d", points); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void quitp(float points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(double points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitp(long double points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(int points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitpi(const std::string &points_info, const std::string &message = "") { + if (points_info.find(' ') != std::string::npos) + quit(_fail, "Parameter 'points_info' can't contain spaces"); + if (message.empty()) + quit(_points, ("points_info=" + points_info).c_str()); + else + quit(_points, ("points_info=" + points_info + " " + message).c_str()); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitp(F points, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quitp(points, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitf(TResult result, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quit(result, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void quitif(bool condition, TResult result, const char *format, ...) { + if (condition) { + FMT_TO_RESULT(format, format, message); + quit(result, message); + } +} + +NORETURN void __testlib_help() { + InStream::textColor(InStream::LightCyan); + std::fprintf(stderr, "TESTLIB %s, https://github.com/MikeMirzayanov/testlib/ ", VERSION); + std::fprintf(stderr, "by Mike Mirzayanov, copyright(c) 2005-2020\n"); + std::fprintf(stderr, "Checker name: \"%s\"\n", checkerName.c_str()); + InStream::textColor(InStream::LightGray); + + std::fprintf(stderr, "\n"); + std::fprintf(stderr, "Latest features: \n"); + for (size_t i = 0; i < sizeof(latestFeatures) / sizeof(char *); i++) { + std::fprintf(stderr, "*) %s\n", latestFeatures[i]); + } + std::fprintf(stderr, "\n"); + + std::fprintf(stderr, "Program must be run with the following arguments: \n"); + std::fprintf(stderr, " [--testset testset] [--group group] [ [<-appes>]]\n\n"); + + __testlib_exitCode = FAIL_EXIT_CODE; + std::exit(FAIL_EXIT_CODE); +} + +static void __testlib_ensuresPreconditions() { + // testlib assumes: sizeof(int) = 4. + __TESTLIB_STATIC_ASSERT(sizeof(int) == 4); + + // testlib assumes: INT_MAX == 2147483647. + __TESTLIB_STATIC_ASSERT(INT_MAX == 2147483647); + + // testlib assumes: sizeof(long long) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(long long) == 8); + + // testlib assumes: sizeof(double) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(double) == 8); + + // testlib assumes: no -ffast-math. + if (!__testlib_isNaN(+__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); + if (!__testlib_isNaN(-__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); +} + +std::string __testlib_testset; + +std::string getTestset() { + return __testlib_testset; +} + +std::string __testlib_group; + +std::string getGroup() { + return __testlib_group; +} + +static void __testlib_set_testset_and_group(int argc, char* argv[]) { + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + __testlib_testset = argv[++i]; + else + quit(_fail, std::string("Expected non-empty testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + __testlib_group = argv[++i]; + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } + } +} + +void registerGen(int argc, char *argv[], int randomGeneratorVersion) { + if (randomGeneratorVersion < 0 || randomGeneratorVersion > 1) + quitf(_fail, "Random generator version is expected to be 0 or 1."); + random_t::version = randomGeneratorVersion; + + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _generator; + __testlib_set_binary(stdin); + rnd.setSeed(argc, argv); + +#if __cplusplus > 199711L || defined(_MSC_VER) + prepareOpts(argc, argv); +#endif +} + +#ifdef USE_RND_AS_BEFORE_087 +void registerGen(int argc, char* argv[]) +{ + registerGen(argc, argv, 0); +} +#else +#ifdef __GNUC__ +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 4)) +__attribute__ ((deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." +" The third parameter stands for the random generator version." +" If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." +" Version 1 has been released on Spring, 2013. Use it to write new generators."))) +#else +__attribute__ ((deprecated)) +#endif +#endif +#ifdef _MSC_VER +__declspec(deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.")) +#endif +void registerGen(int argc, char *argv[]) { + std::fprintf(stderr, "Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.\n\n"); + registerGen(argc, argv, 0); +} +#endif + +void registerInteraction(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _interactor; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + tout.open(std::string(argv[3]) + "/teammessage.txt", + std::ios_base::out); + if (tout.fail() || !tout.is_open()) + quit(_fail, "Can not write to the test-output-file '" + + std::string(argv[2]) + "'"); + appesMode = false; + } + + inf.init(argv[1], _input); + + ouf.init(stdin, _output); + if (argc >= 3) + ans.init(argv[2], _answer); + else + ans.name = "unopened answer stream"; +} + +void registerValidation() { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _validator; + + __testlib_set_binary(stdin); + __testlib_set_binary(stdout); + __testlib_set_binary(stderr); + + inf.init(stdin, _input); + inf.strict = true; +} + +void registerValidation(int argc, char *argv[]) { + registerValidation(); + __testlib_set_testset_and_group(argc, argv); + + validator.initialize(); + TestlibFinalizeGuard::registered = true; + + std::string comment = "Validator must be run with the following arguments:" + " [--testset testset]" + " [--group group]" + " [--testOverviewLogFileName fileName]" + " [--testMarkupFileName fileName]" + " [--testCase testCase]" + " [--testCaseFileName fileName]" + ; + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + validator.setTestset(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + validator.setGroup(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testOverviewLogFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestOverviewLogFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testMarkupFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestMarkupFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testCase", argv[i])) { + if (i + 1 < argc) { + long long testCase = stringToLongLong(inf, argv[++i]); + if (testCase < 1 || testCase >= __TESTLIB_MAX_TEST_CASE) + quit(_fail, format("Argument testCase should be between 1 and %d, but ", __TESTLIB_MAX_TEST_CASE) + + toString(testCase) + " found"); + validator.setTestCase(int(testCase)); + } else + quit(_fail, comment); + } + if (!strcmp("--testCaseFileName", argv[i])) { + if (i + 1 < argc) { + validator.setTestCaseFileName(argv[++i]); + } else + quit(_fail, comment); + } + } +} + +void addFeature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.addFeature(feature); +} + +void feature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.feature(feature); +} + +class Checker { +private: + bool _initialized; + std::string _testset; + std::string _group; + +public: + Checker() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.group()"); + return _group; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } +} checker; + +void registerTestlibCmd(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _checker; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + + appesMode = false; + + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + appesMode = false; + } + + inf.init(argv[1], _input); + ouf.init(stdin, _output); + ans.init(argv[2], _answer); +} + +void registerTestlib(int argc, ...) { + if (argc < 3 || argc > 5) + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + + char **argv = new char *[argc + 1]; + + va_list ap; + va_start(ap, argc); + argv[0] = NULL; + for (int i = 0; i < argc; i++) { + argv[i + 1] = va_arg(ap, char*); + } + va_end(ap); + + registerTestlibCmd(argc + 1, argv); + delete[] argv; +} + +static inline void __testlib_ensure(bool cond, const std::string &msg) { + if (!cond) + quit(_fail, msg.c_str()); +} + +#ifdef __GNUC__ +__attribute__((unused)) +#endif +static inline void __testlib_ensure(bool cond, const char *msg) { + if (!cond) + quit(_fail, msg); +} + +#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) +#define ensure_ext(cond) __testlib_ensure(cond, "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"") + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +inline void ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + __testlib_ensure(cond, message); + } +} + +NORETURN static void __testlib_fail(const std::string &message) { + quitf(_fail, "%s", message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +void setName(const char *format, ...) { + FMT_TO_RESULT(format, format, name); + checkerName = name; +} + +/* + * Do not use random_shuffle, because it will produce different result + * for different C++ compilers. + * + * This implementation uses testlib random_t to produce random numbers, so + * it is stable. + */ +template +void shuffle(_RandomAccessIter __first, _RandomAccessIter __last) { + if (__first == __last) return; + for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) + std::iter_swap(__i, __first + rnd.next(int(__i - __first) + 1)); +} + + +template +#if defined(__GNUC__) && !defined(__clang__) +__attribute__ ((error("Don't use random_shuffle(), use shuffle() instead"))) +#endif +void random_shuffle(_RandomAccessIter, _RandomAccessIter) { + quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); +} + +#ifdef __GLIBC__ +# define RAND_THROW_STATEMENT throw() +#else +# define RAND_THROW_STATEMENT +#endif + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use rand(), use rnd.next() instead"))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +int rand() RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use rand(), use rnd.next() instead"); + + /* This line never runs. */ + //throw "Don't use rand(), use rnd.next() instead"; +} + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use srand(), you should use " +"'registerGen(argc, argv, 1);' to initialize generator seed " +"by hash code of the command line params. The third parameter " +"is randomGeneratorVersion (currently the latest is 1)."))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +void srand(unsigned int seed) RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use srand(), you should use " + "'registerGen(argc, argv, 1);' to initialize generator seed " + "by hash code of the command line params. The third parameter " + "is randomGeneratorVersion (currently the latest is 1) [ignored seed=%u].", seed); +} + +void startTest(int test) { + const std::string testFileName = vtos(test); + if (NULL == freopen(testFileName.c_str(), "wt", stdout)) + __testlib_fail("Unable to write file '" + testFileName + "'"); +} + +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + +inline std::string compress(const std::string &s) { + return __testlib_part(s); +} + +inline std::string englishEnding(int x) { + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separator) { + std::stringstream ss; + bool repeated = false; + for (_ForwardIterator i = first; i != last; i++) { + if (repeated) + ss << separator; + else + repeated = true; + ss << *i; + } + return ss.str(); +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last) { + return join(first, last, ' '); +} + +template +std::string join(const _Collection &collection, _Separator separator) { + return join(collection.begin(), collection.end(), separator); +} + +template +std::string join(const _Collection &collection) { + return join(collection, ' '); +} + +/** + * Splits string s by character separator returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separator returning non-empty items. + */ +std::vector tokenize(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + if (!item.empty()) + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning non-empty items. + */ +std::vector tokenize(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + + if (!item.empty()) + result.push_back(item); + + return result; +} + +NORETURN void __testlib_expectedButFound(TResult result, std::string expected, std::string found, const char *prepend) { + std::string message; + if (strlen(prepend) != 0) + message = format("%s: expected '%s', but found '%s'", + compress(prepend).c_str(), compress(expected).c_str(), compress(found).c_str()); + else + message = format("expected '%s', but found '%s'", + compress(expected).c_str(), compress(found).c_str()); + quit(result, message); +} + +NORETURN void __testlib_expectedButFound(TResult result, double expected, double found, const char *prepend) { + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, T expected, T found, const char *prependFormat = "", ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = vtos(expected); + std::string foundString = vtos(found); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, std::string expected, std::string found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, expected, found, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, double expected, double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, const char *expected, const char *found, const char *prependFormat, + ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, float expected, float found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, long double expected, long double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +struct is_iterable { + template + static char test(typename U::iterator *x); + + template + static long test(U *x); + + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct __testlib_enable_if { +}; + +template +struct __testlib_enable_if { + typedef T type; +}; + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + std::cout << t; +} + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + bool first = true; + for (typename T::const_iterator i = t.begin(); i != t.end(); i++) { + if (first) + first = false; + else + std::cout << " "; + std::cout << *i; + } +} + +template<> +typename __testlib_enable_if::value, void>::type +__testlib_print_one(const std::string &t) { + std::cout << t; +} + +template +void __println_range(A begin, B end) { + bool first = true; + for (B i = B(begin); i != end; i++) { + if (first) + first = false; + else + std::cout << " "; + __testlib_print_one(*i); + } + std::cout << std::endl; +} + +template +struct is_iterator { + static T makeT(); + + typedef void *twoptrs[2]; + + static twoptrs &test(...); + + template + static typename R::iterator_category *test(R); + + template + static void *test(R *); + + static const bool value = sizeof(test(makeT())) == sizeof(void *); +}; + +template +struct is_iterator::value>::type> { + static const bool value = false; +}; + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __println_range(a, b); +} + +template +void println(const A *a, const A *b) { + __println_range(a, b); +} + +template<> +void println(const char *a, const char *b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +void println(const T &x) { + __testlib_print_one(x); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << " "; + __testlib_print_one(g); + std::cout << std::endl; +} + +/* opts */ + +/** + * A struct for a singular testlib opt, containing the raw string value, + * and a boolean value for marking whether the opt is used. + */ +struct TestlibOpt { + std::string value; + bool used; + + TestlibOpt() : value(), used(false) {} +}; + +/** + * Get the type of opt based on the number of `-` at the beginning and the + * _validity_ of the key name. + * + * A valid key name must start with an alphabetical character. + * + * Returns: 1 if s has one `-` at the beginning, that is, "-keyName". + * 2 if s has two `-` at the beginning, that is, "--keyName". + * 0 otherwise. That is, if s has no `-` at the beginning, or has more + * than 2 at the beginning ("---keyName", "----keyName", ...), or the + * keyName is invalid (the first character is not an alphabetical + * character). + */ +size_t getOptType(char *s) { + if (!s || strlen(s) <= 1) + return 0; + + if (s[0] == '-') { + if (isalpha(s[1])) + return 1; + else if (s[1] == '-') + return isalpha(s[2]) ? 2 : 0; + } + + return 0; +} + +/** + * Parse the opt at a given index, and put it into the opts maps. + * + * An opt can has the following form: + * 1) -keyName=value or --keyName=value (ex. -n=10 --test-count=20) + * 2) -keyName value or --keyName value (ex. -n 10 --test-count 20) + * 3) -kNumval or --kNumval (ex. -n10 --t20) + * 4) -boolProperty or --boolProperty (ex. -sorted --tree-only) + * + * Only the second form consumes 2 arguments. The other consumes only 1 + * argument. + * + * In the third form, the key is a single character, and after the key is the + * value. The value _should_ be a number. + * + * In the forth form, the value is true. + * + * Params: + * - argc and argv: the number of command line arguments and the command line + * arguments themselves. + * - index: the starting index of the opts. + * - opts: the map containing the resulting opt. + * + * Returns: the number of consumed arguments to parse the opt. + * 0 if there is no arguments to parse. + * + * Algorithm details: + * TODO. Please refer to the implementation to see how the code handles the 3rd and 4th forms separately. + */ +size_t parseOpt(size_t argc, char *argv[], size_t index, std::map &opts) { + if (index >= argc) + return 0; + + size_t type = getOptType(argv[index]), inc = 1; + if (type > 0) { + std::string key(argv[index] + type), val; + size_t sep = key.find('='); + if (sep != std::string::npos) { + val = key.substr(sep + 1); + key = key.substr(0, sep); + } else { + if (index + 1 < argc && getOptType(argv[index + 1]) == 0) { + val = argv[index + 1]; + inc = 2; + } else { + if (key.length() > 1 && isdigit(key[1])) { + val = key.substr(1); + key = key.substr(0, 1); + } else { + val = "true"; + } + } + } + opts[key].value = val; + } else { + return inc; + } + + return inc; +} + +/** + * Global list containing all the arguments in the order given in the command line. + */ +std::vector __testlib_argv; + +/** + * Global dictionary containing all the parsed opts. + */ +std::map __testlib_opts; + +/** + * Whether automatic no unused opts ensurement should be done. This flag will + * be turned on when `has_opt` or `opt(key, default_value)` is called. + * + * The automatic ensurement can be suppressed when + * __testlib_ensureNoUnusedOptsSuppressed is true. + */ +bool __testlib_ensureNoUnusedOptsFlag = false; + +/** + * Suppress no unused opts automatic ensurement. Can be set to true with + * `suppressEnsureNoUnusedOpts()`. + */ +bool __testlib_ensureNoUnusedOptsSuppressed = false; + +/** + * Parse command line arguments into opts. + * The results are stored into __testlib_argv and __testlib_opts. + */ +void prepareOpts(int argc, char *argv[]) { + if (argc <= 0) + __testlib_fail("Opts: expected argc>=0 but found " + toString(argc)); + size_t n = static_cast(argc); // NOLINT(hicpp-use-auto,modernize-use-auto) + __testlib_opts = std::map(); + for (size_t index = 1; index < n; index += parseOpt(n, argv, index, __testlib_opts)); + __testlib_argv = std::vector(n); + for (size_t index = 0; index < n; index++) + __testlib_argv[index] = argv[index]; +} + +/** + * An utility function to get the argument with a given index. This function + * also print a readable message when no arguments are found. + */ +std::string __testlib_indexToArgv(int index) { + if (index < 0 || index >= int(__testlib_argv.size())) + __testlib_fail("Opts: index '" + toString(index) + "' is out of range [0," + + toString(__testlib_argv.size()) + ")"); + return __testlib_argv[size_t(index)]; +} + +/** + * An utility function to get the opt with a given key . This function + * also print a readable message when no opts are found. + */ +std::string __testlib_keyToOpts(const std::string &key) { + auto it = __testlib_opts.find(key); + if (it == __testlib_opts.end()) + __testlib_fail("Opts: unknown key '" + compress(key) + "'"); + it->second.used = true; + return it->second.value; +} + +template +T optValueToIntegral(const std::string &s, bool nonnegative); + +long double optValueToLongDouble(const std::string &s); + +std::string parseExponentialOptValue(const std::string &s) { + size_t pos = std::string::npos; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == 'e' || s[i] == 'E') { + if (pos != std::string::npos) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + pos = i; + } + if (pos == std::string::npos) + return s; + std::string e = s.substr(pos + 1); + if (!e.empty() && e[0] == '+') + e = e.substr(1); + if (e.empty()) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (e.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + int ne = optValueToIntegral(e, false); + std::string num = s.substr(0, pos); + if (num.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (!num.empty() && num[0] == '+') + num = num.substr(1); + optValueToLongDouble(num); + bool minus = false; + if (num[0] == '-') { + minus = true; + num = num.substr(1); + } + for (int i = 0; i < +ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num += '0'; + else { + if (sep + 1 == num.length()) + num[sep] = '0'; + else + std::swap(num[sep], num[sep + 1]); + } + } + for (int i = 0; i < -ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num.insert(num.begin() + int(num.length()) - 1, '.'); + else { + if (sep == 0) + num.insert(num.begin() + 1, '0'); + else + std::swap(num[sep - 1], num[sep]); + } + } + while (!num.empty() && num[0] == '0') + num = num.substr(1); + while (num.find('.') != std::string::npos && num.back() == '0') + num = num.substr(0, num.length() - 1); + if (!num.empty() && num.back() == '.') + num = num.substr(0, num.length() - 1); + if ((!num.empty() && num[0] == '.') || num.empty()) + num.insert(num.begin(), '0'); + return (minus ? "-" : "") + num; +} + +template +T optValueToIntegral(const std::string &s_, bool nonnegative) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + T value = 0; + long double about = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + if (nonnegative) + __testlib_fail("Opts: expected non-negative integer but '" + compress(s_) + "' found"); + sign = -1; + pos++; + } + for (size_t i = pos; i < s.length(); i++) { + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + value = value * 10 + s[i] - '0'; + about = about * 10 + s[i] - '0'; + } + value *= sign; + about *= sign; + if (fabsl(value - about) > 0.1) + __testlib_fail("Opts: integer overflow: expected integer but '" + compress(s_) + "' found"); + return value; +} + +long double optValueToLongDouble(const std::string &s_) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + long double value = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + sign = -1; + pos++; + } + bool period = false; + long double mul = 1.0; + for (size_t i = pos; i < s.length(); i++) { + if (s[i] == '.') { + if (period) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + else { + period = true; + continue; + } + } + if (period) + mul *= 10.0; + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + if (period) + value += (s[i] - '0') / mul; + else + value = value * 10 + s[i] - '0'; + } + value *= sign; + return value; +} + +/** + * Return true if there is an opt with a given key. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +bool has_opt(const std::string &key) { + __testlib_ensureNoUnusedOptsFlag = true; + return __testlib_opts.count(key) != 0; +} + +/* About the followings part for opt with 2 and 3 arguments. + * + * To parse the argv/opts correctly for a give type (integer, floating point or + * string), some meta programming must be done to determine the type of + * the type, and use the correct parsing function accordingly. + * + * The pseudo algorithm for determining the type of T and parse it accordingly + * is as follows: + * + * if (T is integral type) { + * if (T is unsigned) { + * parse the argv/opt as an **unsigned integer** of type T. + * } else { + * parse the argv/opt as an **signed integer** of type T. + * } else { + * if (T is floating point type) { + * parse the argv/opt as an **floating point** of type T. + * } else { + * // T should be std::string + * just the raw content of the argv/opts. + * } + * } + * + * To help with meta programming, some `opt` function with 2 or 3 arguments are + * defined. + * + * Opt with 3 arguments: T opt(true/false is_integral, true/false is_unsigned, index/key) + * + * + The first argument is for determining whether the type T is an integral + * type. That is, the result of std::is_integral() should be passed to + * this argument. When false, the type _should_ be either floating point or a + * std::string. + * + * + The second argument is for determining whether the signedness of the type + * T (if it is unsigned or signed). That is, the result of + * std::is_unsigned() should be passed to this argument. This argument can + * be ignored if the first one is false, because it only applies to integer. + * + * Opt with 2 arguments: T opt(true/false is_floating_point, index/key) + * + The first argument is for determining whether the type T is a floating + * point type. That is, the result of std::is_floating_point() should be + * passed to this argument. When false, the type _should_ be a std::string. + */ + +template +T opt(std::false_type is_floating_point, int index); + +template<> +std::string opt(std::false_type /*is_floating_point*/, int index) { + return __testlib_indexToArgv(index); +} + +template +T opt(std::true_type /*is_floating_point*/, int index) { + return T(optValueToLongDouble(__testlib_indexToArgv(index))); +} + +template +T opt(std::false_type /*is_integral*/, U /*is_unsigned*/, int index) { + return opt(std::is_floating_point(), index); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + std::string value = __testlib_indexToArgv(index); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: opt by index '" + toString(index) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed argv by a given index. + */ +template +T opt(int index) { + return opt(std::is_integral(), std::is_unsigned(), index); +} + +/** + * Return the raw string value of an argv by a given index. + */ +std::string opt(int index) { + return opt(index); +} + +/** + * Return the parsed argv by a given index. If the index is bigger than + * the number of argv, return the given default_value. + */ +template +T opt(int index, const T &default_value) { + if (index >= int(__testlib_argv.size())) { + return default_value; + } + return opt(index); +} + +/** + * Return the raw string value of an argv by a given index. If the index is + * bigger than the number of argv, return the given default_value. + */ +std::string opt(int index, const std::string &default_value) { + return opt(index, default_value); +} + +template +T opt(std::false_type is_floating_point, const std::string &key); + +template<> +std::string opt(std::false_type /*is_floating_point*/, const std::string &key) { + return __testlib_keyToOpts(key); +} + +template +T opt(std::true_type /*is_integral*/, const std::string &key) { + return T(optValueToLongDouble(__testlib_keyToOpts(key))); +} + +template +T opt(std::false_type /*is_integral*/, U, const std::string &key) { + return opt(std::is_floating_point(), key); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + if (!has_opt(key)) + return false; + std::string value = __testlib_keyToOpts(key); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: key '" + compress(key) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed opt by a given key. + */ +template +T opt(const std::string &key) { + return opt(std::is_integral(), std::is_unsigned(), key); +} + +/** + * Return the raw string value of an opt by a given key + */ +std::string opt(const std::string &key) { + return opt(key); +} + +/* Scorer started. */ + +enum TestResultVerdict { + SKIPPED, + OK, + WRONG_ANSWER, + RUNTIME_ERROR, + TIME_LIMIT_EXCEEDED, + IDLENESS_LIMIT_EXCEEDED, + MEMORY_LIMIT_EXCEEDED, + COMPILATION_ERROR, + CRASHED, + FAILED +}; + +std::string serializeVerdict(TestResultVerdict verdict) { + switch (verdict) { + case SKIPPED: return "SKIPPED"; + case OK: return "OK"; + case WRONG_ANSWER: return "WRONG_ANSWER"; + case RUNTIME_ERROR: return "RUNTIME_ERROR"; + case TIME_LIMIT_EXCEEDED: return "TIME_LIMIT_EXCEEDED"; + case IDLENESS_LIMIT_EXCEEDED: return "IDLENESS_LIMIT_EXCEEDED"; + case MEMORY_LIMIT_EXCEEDED: return "MEMORY_LIMIT_EXCEEDED"; + case COMPILATION_ERROR: return "COMPILATION_ERROR"; + case CRASHED: return "CRASHED"; + case FAILED: return "FAILED"; + } + throw "Unexpected verdict"; +} + +TestResultVerdict deserializeTestResultVerdict(std::string s) { + if (s == "SKIPPED") + return SKIPPED; + else if (s == "OK") + return OK; + else if (s == "WRONG_ANSWER") + return WRONG_ANSWER; + else if (s == "RUNTIME_ERROR") + return RUNTIME_ERROR; + else if (s == "TIME_LIMIT_EXCEEDED") + return TIME_LIMIT_EXCEEDED; + else if (s == "IDLENESS_LIMIT_EXCEEDED") + return IDLENESS_LIMIT_EXCEEDED; + else if (s == "MEMORY_LIMIT_EXCEEDED") + return MEMORY_LIMIT_EXCEEDED; + else if (s == "COMPILATION_ERROR") + return COMPILATION_ERROR; + else if (s == "CRASHED") + return CRASHED; + else if (s == "FAILED") + return FAILED; + ensuref(false, "Unexpected serialized TestResultVerdict"); + // No return actually. + return FAILED; +} + +struct TestResult { + int testIndex; + std::string testset; + std::string group; + TestResultVerdict verdict; + double points; + long long timeConsumed; + long long memoryConsumed; + std::string input; + std::string output; + std::string answer; + int exitCode; + std::string checkerComment; +}; + +std::string serializePoints(double points) { + if (std::isnan(points)) + return ""; + else { + char c[64]; + sprintf(c, "%.03lf", points); + return c; + } +} + +double deserializePoints(std::string s) { + if (s.empty()) + return std::numeric_limits::quiet_NaN(); + else { + double result; + ensuref(sscanf(s.c_str(), "%lf", &result) == 1, "Invalid serialized points"); + return result; + } +} + +std::string escapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\r') + continue; + if (s[i] == '\n') { + result += "\\n"; + continue; + } + if (s[i] == '\\' || s[i] == ';') + result += '\\'; + result += s[i]; + } + return result; +} + +std::string unescapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\' && i + 1 < s.length()) { + if (s[i + 1] == 'n') { + result += '\n'; + i++; + continue; + } else if (s[i + 1] == ';' || s[i + 1] == '\\') { + result += s[i + 1]; + i++; + continue; + } + } + result += s[i]; + } + return result; +} + +std::string serializeTestResult(TestResult tr) { + std::string result; + result += std::to_string(tr.testIndex); + result += ";"; + result += escapeTestResultString(tr.testset); + result += ";"; + result += escapeTestResultString(tr.group); + result += ";"; + result += serializeVerdict(tr.verdict); + result += ";"; + result += serializePoints(tr.points); + result += ";"; + result += std::to_string(tr.timeConsumed); + result += ";"; + result += std::to_string(tr.memoryConsumed); + result += ";"; + result += escapeTestResultString(tr.input); + result += ";"; + result += escapeTestResultString(tr.output); + result += ";"; + result += escapeTestResultString(tr.answer); + result += ";"; + result += std::to_string(tr.exitCode); + result += ";"; + result += escapeTestResultString(tr.checkerComment); + return result; +} + +TestResult deserializeTestResult(std::string s) { + std::vector items; + std::string t; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\') { + t += s[i]; + if (i + 1 < s.length()) + t += s[i + 1]; + i++; + continue; + } else { + if (s[i] == ';') { + items.push_back(t); + t = ""; + } else + t += s[i]; + } + } + items.push_back(t); + + ensuref(items.size() == 12, "Invalid TestResult serialization: expected exactly 12 items"); + + TestResult tr; + size_t pos = 0; + tr.testIndex = stoi(items[pos++]); + tr.testset = unescapeTestResultString(items[pos++]); + tr.group = unescapeTestResultString(items[pos++]); + tr.verdict = deserializeTestResultVerdict(items[pos++]); + tr.points = deserializePoints(items[pos++]); + tr.timeConsumed = stoll(items[pos++]); + tr.memoryConsumed = stoll(items[pos++]); + tr.input = unescapeTestResultString(items[pos++]); + tr.output = unescapeTestResultString(items[pos++]); + tr.answer = unescapeTestResultString(items[pos++]); + tr.exitCode = stoi(items[pos++]); + tr.checkerComment = unescapeTestResultString(items[pos++]); + + return tr; +} + +std::vector readTestResults(std::string fileName) { + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + ensuref(stream.is_open(), "Can't read test results file '%s'", fileName.c_str()); + std::vector result; + std::string line; + while (getline(stream, line)) + if (!line.empty()) + result.push_back(deserializeTestResult(line)); + stream.close(); + return result; +} + +std::function)> __testlib_scorer; + +struct TestlibScorerGuard { + ~TestlibScorerGuard() { + if (testlibMode == _scorer) { + std::vector testResults; + while (!inf.eof()) { + std::string line = inf.readLine(); + if (!line.empty()) + testResults.push_back(deserializeTestResult(line)); + } + inf.readEof(); + printf("%.3f\n", __testlib_scorer(testResults)); + } + } +} __testlib_scorer_guard; + +void registerScorer(int argc, char *argv[], std::function)> scorer) { + /* Supress unused. */ + (void)(argc), (void)(argv); + + __testlib_ensuresPreconditions(); + + testlibMode = _scorer; + __testlib_set_binary(stdin); + + inf.init(stdin, _input); + inf.strict = false; + + __testlib_scorer = scorer; +} + +/* Scorer ended. */ + +/** + * Return the parsed opt by a given key. If no opts with the given key are + * found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +template +T opt(const std::string &key, const T &default_value) { + if (!has_opt(key)) { + return default_value; + } + return opt(key); +} + +/** + * Return the raw string value of an opt by a given key. If no opts with the + * given key are found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +std::string opt(const std::string &key, const std::string &default_value) { + return opt(key, default_value); +} + +/** + * Check if all opts are used. If not, __testlib_fail is called. + * Should be used after calling all opt() function calls. + * + * This function is useful when opt() with default_value for checking typos + * in the opt's key. + */ +void ensureNoUnusedOpts() { + for (const auto &opt: __testlib_opts) { + if (!opt.second.used) { + __testlib_fail(format("Opts: unused key '%s'", compress(opt.first).c_str())); + } + } +} + +void suppressEnsureNoUnusedOpts() { + __testlib_ensureNoUnusedOptsSuppressed = true; +} + +void TestlibFinalizeGuard::autoEnsureNoUnusedOpts() { + if (__testlib_ensureNoUnusedOptsFlag && !__testlib_ensureNoUnusedOptsSuppressed) { + ensureNoUnusedOpts(); + } +} + +TestlibFinalizeGuard testlibFinalizeGuard; + +#endif +#endif diff --git a/ICPC/swerc2022_C/data.zip b/ICPC/swerc2022_C/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..9845a964de2ef5f4d868b6d35987e5d536afe7c4 --- /dev/null +++ b/ICPC/swerc2022_C/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53cb88ab4895a6f4e1ae22faaaca4b737b999a78e6c5611df0c103361aa7eec4 +size 3081451 diff --git a/ICPC/swerc2022_C/init.yml b/ICPC/swerc2022_C/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b216e50a9c7ab05e7fe604d8f657d199c54fcaa9 --- /dev/null +++ b/ICPC/swerc2022_C/init.yml @@ -0,0 +1,154 @@ +archive: data.zip +checker: + args: + files: + - output_validators/testlib.h + - output_validators/checker.cpp + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 3.in + out: 3.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 +- in: 31.in + out: 31.ans + points: 1 +- in: 32.in + out: 32.ans + points: 1 +- in: 33.in + out: 33.ans + points: 1 +- in: 34.in + out: 34.ans + points: 1 +- in: 35.in + out: 35.ans + points: 1 +- in: 36.in + out: 36.ans + points: 1 +- in: 37.in + out: 37.ans + points: 1 +- in: 38.in + out: 38.ans + points: 1 +- in: 39.in + out: 39.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 40.in + out: 40.ans + points: 1 +- in: 41.in + out: 41.ans + points: 1 +- in: 42.in + out: 42.ans + points: 1 +- in: 43.in + out: 43.ans + points: 1 +- in: 44.in + out: 44.ans + points: 1 +- in: 45.in + out: 45.ans + points: 1 +- in: 46.in + out: 46.ans + points: 1 +- in: 47.in + out: 47.ans + points: 1 +- in: 48.in + out: 48.ans + points: 1 +- in: 49.in + out: 49.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 50.in + out: 50.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_C/output_validators/checker.cpp b/ICPC/swerc2022_C/output_validators/checker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..289e6fac655f7521920aa879d42a35285d188ca2 --- /dev/null +++ b/ICPC/swerc2022_C/output_validators/checker.cpp @@ -0,0 +1,66 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "testlib.h" + +#include +#include + +int main(int argc, char **argv) { + registerTestlibCmd(argc, argv); + + int n = inf.readInt(); + std::string s = inf.readWord(); + + std::vector prefix_sums(2 * n, 0); + for (int i = 0; i < 2 * n - 1; ++i) { + prefix_sums[i + 1] = prefix_sums[i] + int(s[i] == 'W'); + } + + int x = ouf.readInt(0, 2 * n - 1, "x"); + + int cnt = 0; + int l = 0, r; + for (r = 0; r < 2 * n - 1 && prefix_sums[r + 1] < x; ++r); + while (cnt < n && r < 2 * n - 1) { + while (prefix_sums[r + 1] - prefix_sums[l] > x) ++l; + for ( + int i = l; + cnt < n + && r - i + 1 >= n + && prefix_sums[r + 1] - prefix_sums[i] == x; + ++i + ) { ++cnt; } + ++r; + } + + if (cnt == n) quitf(_ok, "At least n intervals"); + else quitf(_wa, "Not enough intervals"); + + return 0; +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2022_C/output_validators/testlib.h b/ICPC/swerc2022_C/output_validators/testlib.h new file mode 100644 index 0000000000000000000000000000000000000000..7f15d596b3531af62729aee5132df3bd29d675c7 --- /dev/null +++ b/ICPC/swerc2022_C/output_validators/testlib.h @@ -0,0 +1,5893 @@ +// Modified by a script to work with DOMjudge. +// Differences with the standard testlib.h: +// - The values of some exit codes. +// - The functions registerInteraction and registerTestlibCmd. + +/* + * It is strictly recommended to include "testlib.h" before any other include + * in your code. In this case testlib overrides compiler specific "random()". + * + * If you can't compile your code and compiler outputs something about + * ambiguous call of "random_shuffle", "rand" or "srand" it means that + * you shouldn't use them. Use "shuffle", and "rnd.next()" instead of them + * because these calls produce stable result for any C++ compiler. Read + * sample generator sources for clarification. + * + * Please read the documentation for class "random_t" and use "rnd" instance in + * generators. Probably, these sample calls will be usefull for you: + * rnd.next(); rnd.next(100); rnd.next(1, 2); + * rnd.next(3.14); rnd.next("[a-z]{1,100}"). + * + * Also read about wnext() to generate off-center random distribution. + * + * See https://github.com/MikeMirzayanov/testlib/ to get latest version or bug tracker. + */ + +#ifndef _TESTLIB_H_ +#define _TESTLIB_H_ + +/* + * Copyright (c) 2005-2022 + */ + +#define VERSION "0.9.40-SNAPSHOT" + +/* + * Mike Mirzayanov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* NOTE: This file contains testlib library for C++. + * + * Check, using testlib running format: + * check.exe [ [-appes]], + * If result file is specified it will contain results. + * + * Validator, using testlib running format: + * validator.exe < input.txt, + * It will return non-zero exit code and writes message to standard output. + * + * Generator, using testlib running format: + * gen.exe [parameter-1] [parameter-2] [... paramerter-n] + * You can write generated test(s) into standard output or into the file(s). + * + * Interactor, using testlib running format: + * interactor.exe [ [ [-appes]]], + * Reads test from inf (mapped to args[1]), writes result to tout (mapped to argv[2], + * can be judged by checker later), reads program output from ouf (mapped to stdin), + * writes output to program via stdout (use cout, printf, etc). + */ + +const char *latestFeatures[] = { + "Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators", + "Added opt defaults via opt(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt()).", + "For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values", + "Added quitpi(points_info, message) function to return with _points exit code 7 and given points_info", + "rnd.partition(size, sum[, min_part=1]) returns random (unsorted) partition which is a representation of the given `sum` as a sum of `size` positive integers (or >=min_part if specified)", + "rnd.distinct(size, n) and rnd.distinct(size, from, to)", + "opt(\"some_missing_key\") returns false now", + "has_opt(key)", + "Abort validator on validator.testset()/validator.group() if registered without using command line", + "Print integer range violations in a human readable way like `violates the range [1, 10^9]`", + "Opts supported: use them like n = opt(\"n\"), in a command line you can use an exponential notation", + "Reformatted", + "Use setTestCase(i) or unsetTestCase() to support test cases (you can use it in any type of program: generator, interactor, validator or checker)", + "Fixed issue #87: readStrictDouble accepts \"-0.00\"", + "Fixed issue #83: added InStream::quitif(condition, ...)", + "Fixed issue #79: fixed missed guard against repeated header include", + "Fixed issue #80: fixed UB in case of huge quitf message", + "Fixed issue #84: added readXs(size, indexBase = 1)", + "Fixed stringstream repeated usage issue", + "Fixed compilation in g++ (for std=c++03)", + "Batch of println functions (support collections, iterator ranges)", + "Introduced rnd.perm(size, first = 0) to generate a `first`-indexed permutation", + "Allow any whitespace in readInts-like functions for non-validators", + "Ignore 4+ command line arguments ifdef EJUDGE", + "Speed up of vtos", + "Show line number in validators in case of incorrect format", + "Truncate huge checker/validator/interactor message", + "Fixed issue with readTokenTo of very long tokens, now aborts with _pe/_fail depending of a stream type", + "Introduced InStream::ensure/ensuref checking a condition, returns wa/fail depending of a stream type", + "Fixed compilation in VS 2015+", + "Introduced space-separated read functions: readWords/readTokens, multilines read functions: readStrings/readLines", + "Introduced space-separated read functions: readInts/readIntegers/readLongs/readUnsignedLongs/readDoubles/readReals/readStrictDoubles/readStrictReals", + "Introduced split/tokenize functions to separate string by given char", + "Introduced InStream::readUnsignedLong and InStream::readLong with unsigned long long paramerters", + "Supported --testOverviewLogFileName for validator: bounds hits + features", + "Fixed UB (sequence points) in random_t", + "POINTS_EXIT_CODE returned back to 7 (instead of 0)", + "Removed disable buffers for interactive problems, because it works unexpectedly in wine", + "InStream over string: constructor of InStream from base InStream to inherit policies and std::string", + "Added expectedButFound quit function, examples: expectedButFound(_wa, 10, 20), expectedButFound(_fail, ja, pa, \"[n=%d,m=%d]\", n, m)", + "Fixed incorrect interval parsing in patterns", + "Use registerGen(argc, argv, 1) to develop new generator, use registerGen(argc, argv, 0) to compile old generators (originally created for testlib under 0.8.7)", + "Introduced disableFinalizeGuard() to switch off finalization checkings", + "Use join() functions to format a range of items as a single string (separated by spaces or other separators)", + "Use -DENABLE_UNEXPECTED_EOF to enable special exit code (by default, 8) in case of unexpected eof. It is good idea to use it in interactors", + "Use -DUSE_RND_AS_BEFORE_087 to compile in compatibility mode with random behavior of versions before 0.8.7", + "Fixed bug with nan in stringToDouble", + "Fixed issue around overloads for size_t on x64", + "Added attribute 'points' to the XML output in case of result=_points", + "Exit codes can be customized via macros, e.g. -DPE_EXIT_CODE=14", + "Introduced InStream function readWordTo/readTokenTo/readStringTo/readLineTo for faster reading", + "Introduced global functions: format(), englishEnding(), upperCase(), lowerCase(), compress()", + "Manual buffer in InStreams, some IO speed improvements", + "Introduced quitif(bool, const char* pattern, ...) which delegates to quitf() in case of first argument is true", + "Introduced guard against missed quitf() in checker or readEof() in validators", + "Supported readStrictReal/readStrictDouble - to use in validators to check strictly float numbers", + "Supported registerInteraction(argc, argv)", + "Print checker message to the stderr instead of stdout", + "Supported TResult _points to output calculated score, use quitp(...) functions", + "Fixed to be compilable on Mac", + "PC_BASE_EXIT_CODE=50 in case of defined TESTSYS", + "Fixed issues 19-21, added __attribute__ format printf", + "Some bug fixes", + "ouf.readInt(1, 100) and similar calls return WA", + "Modified random_t to avoid integer overflow", + "Truncated checker output [patch by Stepan Gatilov]", + "Renamed class random -> class random_t", + "Supported name parameter for read-and-validation methods, like readInt(1, 2, \"n\")", + "Fixed bug in readDouble()", + "Improved ensuref(), fixed nextLine to work in case of EOF, added startTest()", + "Supported \"partially correct\", example: quitf(_pc(13), \"result=%d\", result)", + "Added shuffle(begin, end), use it instead of random_shuffle(begin, end)", + "Added readLine(const string& ptrn), fixed the logic of readLine() in the validation mode", + "Package extended with samples of generators and validators", + "Written the documentation for classes and public methods in testlib.h", + "Implemented random routine to support generators, use registerGen() to switch it on", + "Implemented strict mode to validate tests, use registerValidation() to switch it on", + "Now ncmp.cpp and wcmp.cpp are return WA if answer is suffix or prefix of the output", + "Added InStream::readLong() and removed InStream::readLongint()", + "Now no footer added to each report by default (use directive FOOTER to switch on)", + "Now every checker has a name, use setName(const char* format, ...) to set it", + "Now it is compatible with TTS (by Kittens Computing)", + "Added \'ensure(condition, message = \"\")\' feature, it works like assert()", + "Fixed compatibility with MS C++ 7.1", + "Added footer with exit code information", + "Added compatibility with EJUDGE (compile with EJUDGE directive)", + "Added compatibility with Contester (compile with CONTESTER directive)" +}; + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NO_VA_START_VALIDATION +#endif + +/* Overrides random() for Borland C++. */ +#define random __random_deprecated +#include +#include +#include +#include +#undef random + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +# include +#endif + +#if (_WIN32 || __WIN32__ || __WIN32 || _WIN64 || __WIN64__ || __WIN64 || WINNT || __WINNT || __WINNT__ || __CYGWIN__) +# if !defined(_MSC_VER) || _MSC_VER > 1400 +# define NOMINMAX 1 +# include +# else +# define WORD unsigned short +# include +# endif +# include +# define ON_WINDOWS +# if defined(_MSC_VER) && _MSC_VER > 1400 +# pragma warning( disable : 4127 ) +# pragma warning( disable : 4146 ) +# pragma warning( disable : 4458 ) +# endif +#else +# define WORD unsigned short +# include +#endif + +#if defined(FOR_WINDOWS) && defined(FOR_LINUX) +#error Only one target system is allowed +#endif + +#ifndef LLONG_MIN +#define LLONG_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX (18446744073709551615) +#endif + +#define LF ((char)10) +#define CR ((char)13) +#define TAB ((char)9) +#define SPACE ((char)' ') +#define EOFC (255) + +#ifndef OK_EXIT_CODE +# ifdef CONTESTER +# define OK_EXIT_CODE 42 +# else +# define OK_EXIT_CODE 42 +# endif +#endif + +#ifndef WA_EXIT_CODE +# ifdef EJUDGE +# define WA_EXIT_CODE 43 +# elif defined(CONTESTER) +# define WA_EXIT_CODE 43 +# else +# define WA_EXIT_CODE 43 +# endif +#endif + +#ifndef PE_EXIT_CODE +# ifdef EJUDGE +# define PE_EXIT_CODE 43 +# elif defined(CONTESTER) +# define PE_EXIT_CODE 43 +# else +# define PE_EXIT_CODE 43 +# endif +#endif + +#ifndef FAIL_EXIT_CODE +# ifdef EJUDGE +# define FAIL_EXIT_CODE 6 +# elif defined(CONTESTER) +# define FAIL_EXIT_CODE 0xA3 +# else +# define FAIL_EXIT_CODE 3 +# endif +#endif + +#ifndef DIRT_EXIT_CODE +# ifdef EJUDGE +# define DIRT_EXIT_CODE 43 +# else +# define DIRT_EXIT_CODE 43 +# endif +#endif + +#ifndef POINTS_EXIT_CODE +# define POINTS_EXIT_CODE 7 +#endif + +#ifndef UNEXPECTED_EOF_EXIT_CODE +# define UNEXPECTED_EOF_EXIT_CODE 43 +#endif + +#ifndef PC_BASE_EXIT_CODE +# ifdef TESTSYS +# define PC_BASE_EXIT_CODE 50 +# else +# define PC_BASE_EXIT_CODE 0 +# endif +#endif + +#ifdef __GNUC__ +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] __attribute__((unused)) +#else +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] +#endif + +#ifdef ON_WINDOWS +#define I64 "%I64d" +#define U64 "%I64u" +#else +#define I64 "%lld" +#define U64 "%llu" +#endif + +#ifdef _MSC_VER +# define NORETURN __declspec(noreturn) +#elif defined __GNUC__ +# define NORETURN __attribute__ ((noreturn)) +#else +# define NORETURN +#endif + +static char __testlib_format_buffer[16777216]; +static int __testlib_format_buffer_usage_count = 0; + +#define FMT_TO_RESULT(fmt, cstr, result) std::string result; \ + if (__testlib_format_buffer_usage_count != 0) \ + __testlib_fail("FMT_TO_RESULT::__testlib_format_buffer_usage_count != 0"); \ + __testlib_format_buffer_usage_count++; \ + va_list ap; \ + va_start(ap, fmt); \ + vsnprintf(__testlib_format_buffer, sizeof(__testlib_format_buffer), cstr, ap); \ + va_end(ap); \ + __testlib_format_buffer[sizeof(__testlib_format_buffer) - 1] = 0; \ + result = std::string(__testlib_format_buffer); \ + __testlib_format_buffer_usage_count--; \ + +const long long __TESTLIB_LONGLONG_MAX = 9223372036854775807LL; +const int __TESTLIB_MAX_TEST_CASE = 1073741823; + +int __testlib_exitCode; + +bool __testlib_hasTestCase; +int __testlib_testCase = -1; + +void setTestCase(int testCase); + +void unsetTestCase() { + __testlib_hasTestCase = false; + __testlib_testCase = -1; +} + +NORETURN static void __testlib_fail(const std::string &message); + +template +static inline T __testlib_abs(const T &x) { + return x > 0 ? x : -x; +} + +template +static inline T __testlib_min(const T &a, const T &b) { + return a < b ? a : b; +} + +template +static inline T __testlib_max(const T &a, const T &b) { + return a > b ? a : b; +} + +template +static inline T __testlib_crop(T value, T a, T b) { + return __testlib_min(__testlib_max(value, a), --b); +} + +static inline double __testlib_crop(double value, double a, double b) { + value = __testlib_min(__testlib_max(value, a), b); + if (value >= b) + value = std::nexttoward(b, a); + return value; +} + +static bool __testlib_prelimIsNaN(double r) { + volatile double ra = r; +#ifndef __BORLANDC__ + return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); +#else + return std::_isnan(ra); +#endif +} + +static std::string removeDoubleTrailingZeroes(std::string value) { + while (!value.empty() && value[value.length() - 1] == '0' && value.find('.') != std::string::npos) + value = value.substr(0, value.length() - 1); + if (!value.empty() && value[value.length() - 1] == '.') + return value + '0'; + else + return value; +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +std::string format(const char *fmt, ...) { + FMT_TO_RESULT(fmt, fmt, result); + return result; +} + +std::string format(const std::string fmt, ...) { + FMT_TO_RESULT(fmt, fmt.c_str(), result); + return result; +} + +static std::string __testlib_part(const std::string &s); + +static bool __testlib_isNaN(double r) { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); + volatile double ra = r; + long long llr1, llr2; + std::memcpy((void *) &llr1, (void *) &ra, sizeof(double)); + ra = -ra; + std::memcpy((void *) &llr2, (void *) &ra, sizeof(double)); + long long llnan = 0xFFF8000000000000LL; + return __testlib_prelimIsNaN(r) || llnan == llr1 || llnan == llr2; +} + +static double __testlib_nan() { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); +#ifndef NAN + long long llnan = 0xFFF8000000000000LL; + double nan; + std::memcpy(&nan, &llnan, sizeof(double)); + return nan; +#else + return NAN; +#endif +} + +static bool __testlib_isInfinite(double r) { + volatile double ra = r; + return (ra > 1E300 || ra < -1E300); +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline bool doubleCompare(double expected, double result, double MAX_DOUBLE_ERROR) { + MAX_DOUBLE_ERROR += 1E-15; + if (__testlib_isNaN(expected)) { + return __testlib_isNaN(result); + } else if (__testlib_isInfinite(expected)) { + if (expected > 0) { + return result > 0 && __testlib_isInfinite(result); + } else { + return result < 0 && __testlib_isInfinite(result); + } + } else if (__testlib_isNaN(result) || __testlib_isInfinite(result)) { + return false; + } else if (__testlib_abs(result - expected) <= MAX_DOUBLE_ERROR) { + return true; + } else { + double minv = __testlib_min(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + double maxv = __testlib_max(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + return result >= minv && result <= maxv; + } +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline double doubleDelta(double expected, double result) { + double absolute = __testlib_abs(result - expected); + + if (__testlib_abs(expected) > 1E-9) { + double relative = __testlib_abs(absolute / expected); + return __testlib_min(absolute, relative); + } else + return absolute; +} + +/** It does nothing on non-windows and files differ from stdin/stdout/stderr. */ +static void __testlib_set_binary(std::FILE *file) { + if (NULL != file) { +#ifdef ON_WINDOWS +# ifdef _O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(_setmode(STDIN_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdin), _O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(_setmode(STDOUT_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdout), _O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(_setmode(STDERR_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stderr), _O_BINARY)); +# endif +# elif O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(setmode(STDIN_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdin), O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(setmode(STDOUT_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdout), O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(setmode(STDERR_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stderr), O_BINARY)); +# endif +# endif +#endif + } +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +static std::string vtos(const T &t, std::true_type) { + if (t == 0) + return "0"; + else { + T n(t); + bool negative = n < 0; + std::string s; + while (n != 0) { + T digit = n % 10; + if (digit < 0) + digit = -digit; + s += char('0' + digit); + n /= 10; + } + std::reverse(s.begin(), s.end()); + return negative ? "-" + s : s; + } +} + +template +static std::string vtos(const T &t, std::false_type) { + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string vtos(const T &t) { + return vtos(t, std::is_integral()); +} + +/* signed case. */ +template +static std::string toHumanReadableString(const T &n, std::false_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else if (n_ == -1) + return "-10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +/* unsigned case. */ +template +static std::string toHumanReadableString(const T &n, std::true_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +template +static std::string toHumanReadableString(const T &n) { + return toHumanReadableString(n, std::is_unsigned()); +} +#else +template +static std::string vtos(const T& t) +{ + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string toHumanReadableString(const T &n) { + return vtos(n); +} +#endif + +template +static std::string toString(const T &t) { + return vtos(t); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +/* opts */ +void prepareOpts(int argc, char* argv[]); +#endif + +/* + * Very simple regex-like pattern. + * It used for two purposes: validation and generation. + * + * For example, pattern("[a-z]{1,5}").next(rnd) will return + * random string from lowercase latin letters with length + * from 1 to 5. It is easier to call rnd.next("[a-z]{1,5}") + * for the same effect. + * + * Another samples: + * "mike|john" will generate (match) "mike" or "john"; + * "-?[1-9][0-9]{0,3}" will generate (match) non-zero integers from -9999 to 9999; + * "id-([ac]|b{2})" will generate (match) "id-a", "id-bb", "id-c"; + * "[^0-9]*" will match sequences (empty or non-empty) without digits, you can't + * use it for generations. + * + * You can't use pattern for generation if it contains meta-symbol '*'. Also it + * is not recommended to use it for char-sets with meta-symbol '^' like [^a-z]. + * + * For matching very simple greedy algorithm is used. For example, pattern + * "[0-9]?1" will not match "1", because of greedy nature of matching. + * Alternations (meta-symbols "|") are processed with brute-force algorithm, so + * do not use many alternations in one expression. + * + * If you want to use one expression many times it is better to compile it into + * a single pattern like "pattern p("[a-z]+")". Later you can use + * "p.matches(std::string s)" or "p.next(random_t& rd)" to check matching or generate + * new string by pattern. + * + * Simpler way to read token and check it for pattern matching is "inf.readToken("[a-z]+")". + * + * All spaces are ignored in regex, unless escaped with \. For example, ouf.readLine("NO SOLUTION") + * will expect "NOSOLUTION", the correct call should be ouf.readLine("NO\\ SOLUTION") or + * ouf.readLine(R"(NO\ SOLUTION)") if you prefer raw string literals from C++11. + */ +class random_t; + +class pattern { +public: + /* Create pattern instance by string. */ + pattern(std::string s); + + /* Generate new string by pattern and given random_t. */ + std::string next(random_t &rnd) const; + + /* Checks if given string match the pattern. */ + bool matches(const std::string &s) const; + + /* Returns source string of the pattern. */ + std::string src() const; + +private: + bool matches(const std::string &s, size_t pos) const; + + std::string s; + std::vector children; + std::vector chars; + int from; + int to; +}; + +/* + * Use random_t instances to generate random values. It is preffered + * way to use randoms instead of rand() function or self-written + * randoms. + * + * Testlib defines global variable "rnd" of random_t class. + * Use registerGen(argc, argv, 1) to setup random_t seed be command + * line (to use latest random generator version). + * + * Random generates uniformly distributed values if another strategy is + * not specified explicitly. + */ +class random_t { +private: + unsigned long long seed; + static const unsigned long long multiplier; + static const unsigned long long addend; + static const unsigned long long mask; + static const int lim; + + long long nextBits(int bits) { + if (bits <= 48) { + seed = (seed * multiplier + addend) & mask; + return (long long) (seed >> (48 - bits)); + } else { + if (bits > 63) + __testlib_fail("random_t::nextBits(int bits): n must be less than 64"); + + int lowerBitCount = (random_t::version == 0 ? 31 : 32); + + long long left = (nextBits(31) << 32); + long long right = nextBits(lowerBitCount); + + return left ^ right; + } + } + +public: + static int version; + + /* New random_t with fixed seed. */ + random_t() + : seed(3905348978240129619LL) { + } + + /* Sets seed by command line. */ + void setSeed(int argc, char *argv[]) { + random_t p; + + seed = 3905348978240129619LL; + for (int i = 1; i < argc; i++) { + std::size_t le = std::strlen(argv[i]); + for (std::size_t j = 0; j < le; j++) + seed = seed * multiplier + (unsigned int) (argv[i][j]) + addend; + seed += multiplier / addend; + } + + seed = seed & mask; + } + + /* Sets seed by given value. */ + void setSeed(long long _seed) { + _seed = (_seed ^ multiplier) & mask; + seed = _seed; + } + +#ifndef __BORLANDC__ + + /* Random string value by given pattern (see pattern documentation). */ + std::string next(const std::string &ptrn) { + pattern p(ptrn); + return p.next(*this); + } + +#else + /* Random string value by given pattern (see pattern documentation). */ + std::string next(std::string ptrn) + { + pattern p(ptrn); + return p.next(*this); + } +#endif + + /* Random value in range [0, n-1]. */ + int next(int n) { + if (n <= 0) + __testlib_fail("random_t::next(int n): n must be positive"); + + if ((n & -n) == n) // n is a power of 2 + return (int) ((n * (long long) nextBits(31)) >> 31); + + const long long limit = INT_MAX / n * n; + + long long bits; + do { + bits = nextBits(31); + } while (bits >= limit); + + return int(bits % n); + } + + /* Random value in range [0, n-1]. */ + unsigned int next(unsigned int n) { + if (n >= INT_MAX) + __testlib_fail("random_t::next(unsigned int n): n must be less INT_MAX"); + return (unsigned int) next(int(n)); + } + + /* Random value in range [0, n-1]. */ + long long next(long long n) { + if (n <= 0) + __testlib_fail("random_t::next(long long n): n must be positive"); + + const long long limit = __TESTLIB_LONGLONG_MAX / n * n; + + long long bits; + do { + bits = nextBits(63); + } while (bits >= limit); + + return bits % n; + } + + /* Random value in range [0, n-1]. */ + unsigned long long next(unsigned long long n) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::next(unsigned long long n): n must be less LONGLONG_MAX"); + return (unsigned long long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + long next(long n) { + return (long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + unsigned long next(unsigned long n) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX"); + return (unsigned long) next((unsigned long long) (n)); + } + + /* Returns random value in range [from,to]. */ + int next(int from, int to) { + return int(next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + unsigned int next(unsigned int from, unsigned int to) { + return (unsigned int) (next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + long long next(long long from, long long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long long next(unsigned long long from, unsigned long long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long long from, unsigned long long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + long next(long from, long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long next(unsigned long from, unsigned long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long from, unsigned long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Random double value in range [0, 1). */ + double next() { + long long left = ((long long) (nextBits(26)) << 27); + long long right = nextBits(27); + return __testlib_crop((double) (left + right) / (double) (1LL << 53), 0.0, 1.0); + } + + /* Random double value in range [0, n). */ + double next(double n) { + if (n <= 0.0) + __testlib_fail("random_t::next(double): n should be positive"); + return __testlib_crop(n * next(), 0.0, n); + } + + /* Random double value in range [from, to). */ + double next(double from, double to) { + if (from >= to) + __testlib_fail("random_t::next(double from, double to): from should be strictly less than to"); + return next(to - from) + from; + } + + /* Returns random element from container. */ + template + typename Container::value_type any(const Container &c) { + int size = int(c.size()); + if (size <= 0) + __testlib_fail("random_t::any(const Container& c): c.size() must be positive"); + return *(c.begin() + next(size)); + } + + /* Returns random element from iterator range. */ + template + typename Iter::value_type any(const Iter &begin, const Iter &end) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length"); + return *(begin + next(size)); + } + + /* Random string value by given pattern (see pattern documentation). */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + std::string next(const char *format, ...) { + FMT_TO_RESULT(format, format, ptrn); + return next(ptrn); + } + + /* + * Weighted next. If type == 0 than it is usual "next()". + * + * If type = 1, than it returns "max(next(), next())" + * (the number of "max" functions equals to "type"). + * + * If type < 0, than "max" function replaces with "min". + */ + int wnext(int n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(int n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + int result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((int) (double(n) * p), 0, n); + } + } + + /* See wnext(int, int). It uses the same algorithms. */ + long long wnext(long long n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(long long n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + long long result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((long long) (double(n) * p), 0LL, n); + } + } + + /* Returns value in [0, n). See wnext(int, int). It uses the same algorithms. */ + double wnext(double n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(double n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + double result = next(); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next()); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next()); + + return n * result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop(n * p, 0.0, n); + } + } + + /* Returns value in [0, 1). See wnext(int, int). It uses the same algorithms. */ + double wnext(int type) { + return wnext(1.0, type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned int wnext(unsigned int n, int type) { + if (n >= INT_MAX) + __testlib_fail("random_t::wnext(unsigned int n, int type): n must be less INT_MAX"); + return (unsigned int) wnext(int(n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long long wnext(unsigned long long n, int type) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long long n, int type): n must be less LONGLONG_MAX"); + + return (unsigned long long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + long wnext(long n, int type) { + return (long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long wnext(unsigned long n, int type) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long n, int type): n must be less LONG_MAX"); + + return (unsigned long) wnext((unsigned long long) (n), type); + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(int from, int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(int from, int to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(unsigned int from, unsigned int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned int from, unsigned int to, int type): from can't not exceed to"); + return int(wnext(to - from + 1, type) + from); + } + + /* Returns weighted random value in range [from, to]. */ + long long wnext(long long from, long long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long long from, long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long long wnext(unsigned long long from, unsigned long long to, int type) { + if (from > to) + __testlib_fail( + "random_t::wnext(unsigned long long from, unsigned long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + long wnext(long from, long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long from, long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long wnext(unsigned long from, unsigned long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned long from, unsigned long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random double value in range [from, to). */ + double wnext(double from, double to, int type) { + if (from >= to) + __testlib_fail("random_t::wnext(double from, double to, int type): from should be strictly less than to"); + return wnext(to - from, type) + from; + } + + /* Returns weighted random element from container. */ + template + typename Container::value_type wany(const Container &c, int type) { + size_t size = c.size(); + if (size <= 0) + __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive"); + return *(c.begin() + wnext(size, type)); + } + + /* Returns weighted random element from iterator range. */ + template + typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail( + "random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length"); + return *(begin + wnext(size, type)); + } + + /* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/ + template + std::vector perm(T size, E first) { + if (size < 0) + __testlib_fail("random_t::perm(T size, E first = 0): size must non-negative"); + else if (size == 0) + return std::vector(); + std::vector p(size); + E current = first; + for (T i = 0; i < size; i++) + p[i] = current++; + if (size > 1) + for (T i = 1; i < size; i++) + std::swap(p[i], p[next(i + 1)]); + return p; + } + + /* Returns random permutation of the given size (values are between 0 and size-1)*/ + template + std::vector perm(T size) { + return perm(size, T(0)); + } + + /* Returns `size` unordered (unsorted) distinct numbers between `from` and `to`. */ + template + std::vector distinct(int size, T from, T to) { + std::vector result; + if (size == 0) + return result; + + if (from > to) + __testlib_fail("random_t::distinct expected from <= to"); + + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + + uint64_t n = to - from + 1; + if (uint64_t(size) > n) + __testlib_fail("random_t::distinct expected size <= to - from + 1"); + + double expected = 0.0; + for (int i = 1; i <= size; i++) + expected += double(n) / double(n - i + 1); + + if (expected < double(n)) { + std::set vals; + while (int(vals.size()) < size) { + T x = T(next(from, to)); + if (vals.insert(x).second) + result.push_back(x); + } + } else { + if (n > 1000000000) + __testlib_fail("random_t::distinct here expected to - from + 1 <= 1000000000"); + std::vector p(perm(int(n), from)); + result.insert(result.end(), p.begin(), p.begin() + size); + } + + return result; + } + + /* Returns `size` unordered (unsorted) distinct numbers between `0` and `upper`-1. */ + template + std::vector distinct(int size, T upper) { + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + if (size == 0) + return std::vector(); + + if (upper <= 0) + __testlib_fail("random_t::distinct expected upper > 0"); + if (size > upper) + __testlib_fail("random_t::distinct expected size <= upper"); + + return distinct(size, T(0), upper - 1); + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of integers not less than min_part. */ + template + std::vector partition(int size, T sum, T min_part) { + if (size < 0) + __testlib_fail("random_t::partition: size < 0"); + if (size == 0 && sum != 0) + __testlib_fail("random_t::partition: size == 0 && sum != 0"); + if (min_part * size > sum) + __testlib_fail("random_t::partition: min_part * size > sum"); + if (size == 0 && sum == 0) + return std::vector(); + + T sum_ = sum; + sum -= min_part * size; + + std::vector septums(size); + std::vector d = distinct(size - 1, T(1), T(sum + size - 1)); + for (int i = 0; i + 1 < size; i++) + septums[i + 1] = d[i]; + sort(septums.begin(), septums.end()); + + std::vector result(size); + for (int i = 0; i + 1 < size; i++) + result[i] = septums[i + 1] - septums[i] - 1; + result[size - 1] = sum + size - 1 - septums.back(); + + for (std::size_t i = 0; i < result.size(); i++) + result[i] += min_part; + + T result_sum = 0; + for (std::size_t i = 0; i < result.size(); i++) + result_sum += result[i]; + if (result_sum != sum_) + __testlib_fail("random_t::partition: partition sum is expected to be the given sum"); + + if (*std::min_element(result.begin(), result.end()) < min_part) + __testlib_fail("random_t::partition: partition min is expected to be no less than the given min_part"); + + if (int(result.size()) != size || result.size() != (size_t) size) + __testlib_fail("random_t::partition: partition size is expected to be equal to the given size"); + + return result; + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of positive integers. */ + template + std::vector partition(int size, T sum) { + return partition(size, sum, T(1)); + } +}; + +const int random_t::lim = 25; +const unsigned long long random_t::multiplier = 0x5DEECE66DLL; +const unsigned long long random_t::addend = 0xBLL; +const unsigned long long random_t::mask = (1LL << 48) - 1; +int random_t::version = -1; + +/* Pattern implementation */ +bool pattern::matches(const std::string &s) const { + return matches(s, 0); +} + +static bool __pattern_isSlash(const std::string &s, size_t pos) { + return s[pos] == '\\'; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static bool __pattern_isCommandChar(const std::string &s, size_t pos, char value) { + if (pos >= s.length()) + return false; + + int slashes = 0; + + int before = int(pos) - 1; + while (before >= 0 && s[before] == '\\') + before--, slashes++; + + return slashes % 2 == 0 && s[pos] == value; +} + +static char __pattern_getChar(const std::string &s, size_t &pos) { + if (__pattern_isSlash(s, pos)) + pos += 2; + else + pos++; + + return s[pos - 1]; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static int __pattern_greedyMatch(const std::string &s, size_t pos, const std::vector chars) { + int result = 0; + + while (pos < s.length()) { + char c = s[pos++]; + if (!std::binary_search(chars.begin(), chars.end(), c)) + break; + else + result++; + } + + return result; +} + +std::string pattern::src() const { + return s; +} + +bool pattern::matches(const std::string &s, size_t pos) const { + std::string result; + + if (to > 0) { + int size = __pattern_greedyMatch(s, pos, chars); + if (size < from) + return false; + if (size > to) + size = to; + pos += size; + } + + if (children.size() > 0) { + for (size_t child = 0; child < children.size(); child++) + if (children[child].matches(s, pos)) + return true; + return false; + } else + return pos == s.length(); +} + +std::string pattern::next(random_t &rnd) const { + std::string result; + result.reserve(20); + + if (to == INT_MAX) + __testlib_fail("pattern::next(random_t& rnd): can't process character '*' for generation"); + + if (to > 0) { + int count = rnd.next(to - from + 1) + from; + for (int i = 0; i < count; i++) + result += chars[rnd.next(int(chars.size()))]; + } + + if (children.size() > 0) { + int child = rnd.next(int(children.size())); + result += children[child].next(rnd); + } + + return result; +} + +static void __pattern_scanCounts(const std::string &s, size_t &pos, int &from, int &to) { + if (pos >= s.length()) { + from = to = 1; + return; + } + + if (__pattern_isCommandChar(s, pos, '{')) { + std::vector parts; + std::string part; + + pos++; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, '}')) { + if (__pattern_isCommandChar(s, pos, ',')) + parts.push_back(part), part = "", pos++; + else + part += __pattern_getChar(s, pos); + } + + if (part != "") + parts.push_back(part); + + if (!__pattern_isCommandChar(s, pos, '}')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (parts.size() < 1 || parts.size() > 2) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector numbers; + + for (size_t i = 0; i < parts.size(); i++) { + if (parts[i].length() == 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + int number; + if (std::sscanf(parts[i].c_str(), "%d", &number) != 1) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + numbers.push_back(number); + } + + if (numbers.size() == 1) + from = to = numbers[0]; + else + from = numbers[0], to = numbers[1]; + + if (from > to) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + } else { + if (__pattern_isCommandChar(s, pos, '?')) { + from = 0, to = 1, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '*')) { + from = 0, to = INT_MAX, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '+')) { + from = 1, to = INT_MAX, pos++; + return; + } + + from = to = 1; + } +} + +static std::vector __pattern_scanCharSet(const std::string &s, size_t &pos) { + if (pos >= s.length()) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector result; + + if (__pattern_isCommandChar(s, pos, '[')) { + pos++; + bool negative = __pattern_isCommandChar(s, pos, '^'); + if (negative) + pos++; + + char prev = 0; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, ']')) { + if (__pattern_isCommandChar(s, pos, '-') && prev != 0) { + pos++; + + if (pos + 1 == s.length() || __pattern_isCommandChar(s, pos, ']')) { + result.push_back(prev); + prev = '-'; + continue; + } + + char next = __pattern_getChar(s, pos); + if (prev > next) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + for (char c = prev; c != next; c++) + result.push_back(c); + result.push_back(next); + + prev = 0; + } else { + if (prev != 0) + result.push_back(prev); + prev = __pattern_getChar(s, pos); + } + } + + if (prev != 0) + result.push_back(prev); + + if (!__pattern_isCommandChar(s, pos, ']')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (negative) { + std::sort(result.begin(), result.end()); + std::vector actuals; + for (int code = 0; code < 255; code++) { + char c = char(code); + if (!std::binary_search(result.begin(), result.end(), c)) + actuals.push_back(c); + } + result = actuals; + } + + std::sort(result.begin(), result.end()); + } else + result.push_back(__pattern_getChar(s, pos)); + + return result; +} + +pattern::pattern(std::string s) : s(s), from(0), to(0) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (!__pattern_isCommandChar(s, i, ' ')) + t += s[i]; + s = t; + + int opened = 0; + int firstClose = -1; + std::vector seps; + + for (size_t i = 0; i < s.length(); i++) { + if (__pattern_isCommandChar(s, i, '(')) { + opened++; + continue; + } + + if (__pattern_isCommandChar(s, i, ')')) { + opened--; + if (opened == 0 && firstClose == -1) + firstClose = int(i); + continue; + } + + if (opened < 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (__pattern_isCommandChar(s, i, '|') && opened == 0) + seps.push_back(int(i)); + } + + if (opened != 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (seps.size() == 0 && firstClose + 1 == (int) s.length() + && __pattern_isCommandChar(s, 0, '(') && __pattern_isCommandChar(s, s.length() - 1, ')')) { + children.push_back(pattern(s.substr(1, s.length() - 2))); + } else { + if (seps.size() > 0) { + seps.push_back(int(s.length())); + int last = 0; + + for (size_t i = 0; i < seps.size(); i++) { + children.push_back(pattern(s.substr(last, seps[i] - last))); + last = seps[i] + 1; + } + } else { + size_t pos = 0; + chars = __pattern_scanCharSet(s, pos); + __pattern_scanCounts(s, pos, from, to); + if (pos < s.length()) + children.push_back(pattern(s.substr(pos))); + } + } +} + +/* End of pattern implementation */ + +template +inline bool isEof(C c) { + return c == EOFC; +} + +template +inline bool isEoln(C c) { + return (c == LF || c == CR); +} + +template +inline bool isBlanks(C c) { + return (c == LF || c == CR || c == SPACE || c == TAB); +} + +inline std::string trim(const std::string &s) { + if (s.empty()) + return s; + + int left = 0; + while (left < int(s.length()) && isBlanks(s[left])) + left++; + if (left >= int(s.length())) + return ""; + + int right = int(s.length()) - 1; + while (right >= 0 && isBlanks(s[right])) + right--; + if (right < 0) + return ""; + + return s.substr(left, right - left + 1); +} + +enum TMode { + _input, _output, _answer +}; + +/* Outcomes 6-15 are reserved for future use. */ +enum TResult { + _ok = 0, + _wa = 1, + _pe = 2, + _fail = 3, + _dirt = 4, + _points = 5, + _unexpected_eof = 8, + _partially = 16 +}; + +enum TTestlibMode { + _unknown, _checker, _validator, _generator, _interactor, _scorer +}; + +#define _pc(exitCode) (TResult(_partially + (exitCode))) + +/* Outcomes 6-15 are reserved for future use. */ +const std::string outcomes[] = { + "accepted", + "wrong-answer", + "presentation-error", + "fail", + "fail", +#ifndef PCMS2 + "points", +#else + "relative-scoring", +#endif + "reserved", + "reserved", + "unexpected-eof", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "partially-correct" +}; + +class InputStreamReader { +public: + virtual void setTestCase(int testCase) = 0; + + virtual std::vector getReadChars() = 0; + + virtual int curChar() = 0; + + virtual int nextChar() = 0; + + virtual void skipChar() = 0; + + virtual void unreadChar(int c) = 0; + + virtual std::string getName() = 0; + + virtual bool eof() = 0; + + virtual void close() = 0; + + virtual int getLine() = 0; + + virtual ~InputStreamReader() = 0; +}; + +InputStreamReader::~InputStreamReader() { + // No operations. +} + +class StringInputStreamReader : public InputStreamReader { +private: + std::string s; + size_t pos; + +public: + StringInputStreamReader(const std::string &content) : s(content), pos(0) { + // No operations. + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in StringInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in StringInputStreamReader"); + } + + int curChar() { + if (pos >= s.length()) + return EOFC; + else + return s[pos]; + } + + int nextChar() { + if (pos >= s.length()) { + pos++; + return EOFC; + } else + return s[pos++]; + } + + void skipChar() { + pos++; + } + + void unreadChar(int c) { + if (pos == 0) + __testlib_fail("StringInputStreamReader::unreadChar(int): pos == 0."); + pos--; + if (pos < s.length()) + s[pos] = char(c); + } + + std::string getName() { + return __testlib_part(s); + } + + int getLine() { + return -1; + } + + bool eof() { + return pos >= s.length(); + } + + void close() { + // No operations. + } +}; + +class FileInputStreamReader : public InputStreamReader { +private: + std::FILE *file; + std::string name; + int line; + std::vector undoChars; + std::vector readChars; + std::vector undoReadChars; + + inline int postprocessGetc(int getcResult) { + if (getcResult != EOF) + return getcResult; + else + return EOFC; + } + + int getc(FILE *file) { + int c; + int rc; + + if (undoChars.empty()) { + c = rc = ::getc(file); + } else { + c = undoChars.back(); + undoChars.pop_back(); + rc = undoReadChars.back(); + undoReadChars.pop_back(); + } + + if (c == LF) + line++; + + readChars.push_back(rc); + return c; + } + + int ungetc(int c/*, FILE* file*/) { + if (!readChars.empty()) { + undoReadChars.push_back(readChars.back()); + readChars.pop_back(); + } + if (c == LF) + line--; + undoChars.push_back(c); + return c; + } + +public: + FileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + // No operations. + } + + void setTestCase(int testCase) { + if (testCase < 0 || testCase > __TESTLIB_MAX_TEST_CASE) + __testlib_fail(format("testCase expected fit in [1,%d], but %d doesn't", __TESTLIB_MAX_TEST_CASE, testCase)); + readChars.push_back(testCase + 256); + } + + std::vector getReadChars() { + return readChars; + } + + int curChar() { + if (feof(file)) + return EOFC; + else { + int c = getc(file); + ungetc(c/*, file*/); + return postprocessGetc(c); + } + } + + int nextChar() { + if (feof(file)) + return EOFC; + else + return postprocessGetc(getc(file)); + } + + void skipChar() { + getc(file); + } + + void unreadChar(int c) { + ungetc(c/*, file*/); + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + if (NULL == file || feof(file)) + return true; + else { + int c = nextChar(); + if (c == EOFC || (c == EOF && feof(file))) + return true; + unreadChar(c); + return false; + } + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +class BufferedFileInputStreamReader : public InputStreamReader { +private: + static const size_t BUFFER_SIZE; + static const size_t MAX_UNREAD_COUNT; + + std::FILE *file; + std::string name; + int line; + + char *buffer; + bool *isEof; + int bufferPos; + size_t bufferSize; + + bool refill() { + if (NULL == file) + __testlib_fail("BufferedFileInputStreamReader: file == NULL (" + getName() + ")"); + + if (bufferPos >= int(bufferSize)) { + size_t readSize = fread( + buffer + MAX_UNREAD_COUNT, + 1, + BUFFER_SIZE - MAX_UNREAD_COUNT, + file + ); + + if (readSize < BUFFER_SIZE - MAX_UNREAD_COUNT + && ferror(file)) + __testlib_fail("BufferedFileInputStreamReader: unable to read (" + getName() + ")"); + + bufferSize = MAX_UNREAD_COUNT + readSize; + bufferPos = int(MAX_UNREAD_COUNT); + std::memset(isEof + MAX_UNREAD_COUNT, 0, sizeof(isEof[0]) * readSize); + + return readSize > 0; + } else + return true; + } + + char increment() { + char c; + if ((c = buffer[bufferPos++]) == LF) + line++; + return c; + } + +public: + BufferedFileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + buffer = new char[BUFFER_SIZE]; + isEof = new bool[BUFFER_SIZE]; + bufferSize = MAX_UNREAD_COUNT; + bufferPos = int(MAX_UNREAD_COUNT); + } + + ~BufferedFileInputStreamReader() { + if (NULL != buffer) { + delete[] buffer; + buffer = NULL; + } + if (NULL != isEof) { + delete[] isEof; + isEof = NULL; + } + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in BufferedFileInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in BufferedFileInputStreamReader"); + } + + int curChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : buffer[bufferPos]; + } + + int nextChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : increment(); + } + + void skipChar() { + increment(); + } + + void unreadChar(int c) { + bufferPos--; + if (bufferPos < 0) + __testlib_fail("BufferedFileInputStreamReader::unreadChar(int): bufferPos < 0"); + isEof[bufferPos] = (c == EOFC); + buffer[bufferPos] = char(c); + if (c == LF) + line--; + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + return !refill() || EOFC == curChar(); + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +const size_t BufferedFileInputStreamReader::BUFFER_SIZE = 2000000; +const size_t BufferedFileInputStreamReader::MAX_UNREAD_COUNT = BufferedFileInputStreamReader::BUFFER_SIZE / 2; + +/* + * Streams to be used for reading data in checkers or validators. + * Each read*() method moves pointer to the next character after the + * read value. + */ +struct InStream { + /* Do not use them. */ + InStream(); + + ~InStream(); + + /* Wrap std::string with InStream. */ + InStream(const InStream &baseStream, std::string content); + + InputStreamReader *reader; + int lastLine; + + std::string name; + TMode mode; + bool opened; + bool stdfile; + bool strict; + + int wordReserveSize; + std::string _tmpReadToken; + + int readManyIteration; + size_t maxFileSize; + size_t maxTokenLength; + size_t maxMessageLength; + + void init(std::string fileName, TMode mode); + + void init(std::FILE *f, TMode mode); + + void setTestCase(int testCase); + std::vector getReadChars(); + + /* Moves stream pointer to the first non-white-space character or EOF. */ + void skipBlanks(); + + /* Returns current character in the stream. Doesn't remove it from stream. */ + char curChar(); + + /* Moves stream pointer one character forward. */ + void skipChar(); + + /* Returns current character and moves pointer one character forward. */ + char nextChar(); + + /* Returns current character and moves pointer one character forward. */ + char readChar(); + + /* As "readChar()" but ensures that the result is equal to given parameter. */ + char readChar(char c); + + /* As "readChar()" but ensures that the result is equal to the space (code=32). */ + char readSpace(); + + /* Puts back the character into the stream. */ + void unreadChar(char c); + + /* Reopens stream, you should not use it. */ + void reset(std::FILE *file = NULL); + + /* Checks that current position is EOF. If not it doesn't move stream pointer. */ + bool eof(); + + /* Moves pointer to the first non-white-space character and calls "eof()". */ + bool seekEof(); + + /* + * Checks that current position contains EOLN. + * If not it doesn't move stream pointer. + * In strict mode expects "#13#10" for windows or "#10" for other platforms. + */ + bool eoln(); + + /* Moves pointer to the first non-space and non-tab character and calls "eoln()". */ + bool seekEoln(); + + /* Moves stream pointer to the first character of the next line (if exists). */ + void nextLine(); + + /* + * Reads new token. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + std::string readWord(); + + /* The same as "readWord()", it is preffered to use "readToken()". */ + std::string readToken(); + + /* The same as "readWord()", but ensures that token matches to given pattern. */ + std::string readWord(const std::string &ptrn, const std::string &variableName = ""); + + std::string readWord(const pattern &p, const std::string &variableName = ""); + + std::vector + readWords(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readWords(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readWords(int size, int indexBase = 1); + + /* The same as "readToken()", but ensures that token matches to given pattern. */ + std::string readToken(const std::string &ptrn, const std::string &variableName = ""); + + std::string readToken(const pattern &p, const std::string &variableName = ""); + + std::vector + readTokens(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readTokens(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readTokens(int size, int indexBase = 1); + + void readWordTo(std::string &result); + + void readWordTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + void readTokenTo(std::string &result); + + void readTokenTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads new long long value. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + long long readLong(); + + unsigned long long readUnsignedLong(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInteger(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInt(); + + /* As "readLong()" but ensures that value in the range [minv,maxv]. */ + long long readLong(long long minv, long long maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of long longs. */ + std::vector + readLongs(int size, long long minv, long long maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of long longs. */ + std::vector readLongs(int size, int indexBase = 1); + + unsigned long long + readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + std::vector readUnsignedLongs(int size, int indexBase = 1); + + unsigned long long readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + /* As "readInteger()" but ensures that value in the range [minv,maxv]. */ + int readInteger(int minv, int maxv, const std::string &variableName = ""); + + /* As "readInt()" but ensures that value in the range [minv,maxv]. */ + int readInt(int minv, int maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of integers. */ + std::vector + readIntegers(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readIntegers(int size, int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int indexBase = 1); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readReal(); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readDouble(); + + /* As "readReal()" but ensures that value in the range [minv,maxv]. */ + double readReal(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readReals(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readReals(int size, int indexBase = 1); + + /* As "readDouble()" but ensures that value in the range [minv,maxv]. */ + double readDouble(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readDoubles(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readDoubles(int size, int indexBase = 1); + + /* + * As "readReal()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* + * As "readDouble()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* As readLine(). */ + std::string readString(); + + /* Read many lines. */ + std::vector readStrings(int size, int indexBase = 1); + + /* See readLine(). */ + void readStringTo(std::string &result); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readStrings(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readStrings(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads line from the current position to EOLN or EOF. Moves stream pointer to + * the first character of the new line (if possible). + */ + std::string readLine(); + + /* Read many lines. */ + std::vector readLines(int size, int indexBase = 1); + + /* See readLine(). */ + void readLineTo(std::string &result); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readLines(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readLines(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* Reads EOLN or fails. Use it in validators. Calls "eoln()" method internally. */ + void readEoln(); + + /* Reads EOF or fails. Use it in validators. Calls "eof()" method internally. */ + void readEof(); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quit(TResult result, const char *msg); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quitf(TResult result, const char *msg, ...); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + void quitif(bool condition, TResult result, const char *msg, ...); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quits(TResult result, std::string msg); + + /* + * Checks condition and aborts a program if codition is false. + * Returns _wa for ouf and _fail on any other streams. + */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void ensuref(bool cond, const char *format, ...); + + void __testlib_ensure(bool cond, std::string message); + + void close(); + + const static int NO_INDEX = INT_MAX; + const static char OPEN_BRACKET = char(11); + const static char CLOSE_BRACKET = char(17); + + const static WORD LightGray = 0x07; + const static WORD LightRed = 0x0c; + const static WORD LightCyan = 0x0b; + const static WORD LightGreen = 0x0a; + const static WORD LightYellow = 0x0e; + + static void textColor(WORD color); + + static void quitscr(WORD color, const char *msg); + + static void quitscrS(WORD color, std::string msg); + + void xmlSafeWrite(std::FILE *file, const char *msg); + + /* Skips UTF-8 Byte Order Mark. */ + void skipBom(); + +private: + InStream(const InStream &); + + InStream &operator=(const InStream &); +}; + +InStream inf; +InStream ouf; +InStream ans; +bool appesMode; +std::string resultName; +std::string checkerName = "untitled checker"; +random_t rnd; +TTestlibMode testlibMode = _unknown; +double __testlib_points = std::numeric_limits::infinity(); + +struct ValidatorBoundsHit { + static const double EPS; + bool minHit; + bool maxHit; + + ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) { + }; + + ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) { + return ValidatorBoundsHit( + __testlib_max(minHit, validatorBoundsHit.minHit), + __testlib_max(maxHit, validatorBoundsHit.maxHit) + ); + } +}; + +const double ValidatorBoundsHit::EPS = 1E-12; + +class Validator { +private: + const static std::string TEST_MARKUP_HEADER; + const static std::string TEST_CASE_OPEN_TAG; + const static std::string TEST_CASE_CLOSE_TAG; + + bool _initialized; + std::string _testset; + std::string _group; + + std::string _testOverviewLogFileName; + std::string _testMarkupFileName; + int _testCase = -1; + std::string _testCaseFileName; + + std::map _boundsHitByVariableName; + std::set _features; + std::set _hitFeatures; + + bool isVariableNameBoundsAnalyzable(const std::string &variableName) { + for (size_t i = 0; i < variableName.length(); i++) + if ((variableName[i] >= '0' && variableName[i] <= '9') || variableName[i] < ' ') + return false; + return true; + } + + bool isFeatureNameAnalyzable(const std::string &featureName) { + for (size_t i = 0; i < featureName.length(); i++) + if (featureName[i] < ' ') + return false; + return true; + } + +public: + Validator() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.group()"); + return _group; + } + + std::string testOverviewLogFileName() const { + return _testOverviewLogFileName; + } + + std::string testMarkupFileName() const { + return _testMarkupFileName; + } + + int testCase() const { + return _testCase; + } + + std::string testCaseFileName() const { + return _testCaseFileName; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } + + void setTestOverviewLogFileName(const char *const testOverviewLogFileName) { + _testOverviewLogFileName = testOverviewLogFileName; + } + + void setTestMarkupFileName(const char *const testMarkupFileName) { + _testMarkupFileName = testMarkupFileName; + } + + void setTestCase(int testCase) { + _testCase = testCase; + } + + void setTestCaseFileName(const char *const testCaseFileName) { + _testCaseFileName = testCaseFileName; + } + + void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) { + if (isVariableNameBoundsAnalyzable(variableName)) { + _boundsHitByVariableName[variableName] + = boundsHit.merge(_boundsHitByVariableName[variableName]); + } + } + + std::string getBoundsHitLog() { + std::string result; + for (std::map::iterator i = _boundsHitByVariableName.begin(); + i != _boundsHitByVariableName.end(); + i++) { + result += "\"" + i->first + "\":"; + if (i->second.minHit) + result += " min-value-hit"; + if (i->second.maxHit) + result += " max-value-hit"; + result += "\n"; + } + return result; + } + + std::string getFeaturesLog() { + std::string result; + for (std::set::iterator i = _features.begin(); + i != _features.end(); + i++) { + result += "feature \"" + *i + "\":"; + if (_hitFeatures.count(*i)) + result += " hit"; + result += "\n"; + } + return result; + } + + void writeTestOverviewLog() { + if (!_testOverviewLogFileName.empty()) { + std::string fileName(_testOverviewLogFileName); + _testOverviewLogFileName = ""; + FILE *testOverviewLogFile = fopen(fileName.c_str(), "w"); + if (NULL == testOverviewLogFile) + __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")"); + fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str()); + if (fclose(testOverviewLogFile)) + __testlib_fail( + "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")"); + } + } + + void writeTestMarkup() { + if (!_testMarkupFileName.empty()) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string markup(TEST_MARKUP_HEADER); + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) { + char cc = char(c); + if (cc == '\\' || cc == '!') + markup += '\\'; + markup += cc; + } else { + markup += TEST_CASE_OPEN_TAG; + markup += toString(c - 256); + markup += TEST_CASE_CLOSE_TAG; + } + } + FILE* f; + bool standard_file = false; + if (_testMarkupFileName == "stdout") + f = stdout, standard_file = true; + else if (_testMarkupFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testMarkupFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestMarkup: can't write test markup to (" + _testMarkupFileName + ")"); + } + std::fprintf(f, "%s", markup.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestMarkup: can't close test markup file (" + _testCaseFileName + ")"); + } + } + } + + void writeTestCase() { + if (_testCase > 0) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string content, testCaseContent; + bool matchedTestCase = false; + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) + content += char(c); + else { + if (matchedTestCase) { + testCaseContent = content; + matchedTestCase = false; + } + content = ""; + int testCase = c - 256; + if (testCase == _testCase) + matchedTestCase = true; + } + } + if (matchedTestCase) + testCaseContent = content; + + if (!testCaseContent.empty()) { + FILE* f; + bool standard_file = false; + if (_testCaseFileName.empty() || _testCaseFileName == "stdout") + f = stdout, standard_file = true; + else if (_testCaseFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testCaseFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestCase: can't write test case to (" + _testCaseFileName + ")"); + } + std::fprintf(f, "%s", testCaseContent.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestCase: can't close test case file (" + _testCaseFileName + ")"); + } + } + } + } + + void addFeature(const std::string &feature) { + if (_features.count(feature)) + __testlib_fail("Feature " + feature + " registered twice."); + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + _features.insert(feature); + } + + void feature(const std::string &feature) { + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + if (!_features.count(feature)) + __testlib_fail("Feature " + feature + " didn't registered via addFeature(feature)."); + + _hitFeatures.insert(feature); + } +} validator; + +const std::string Validator::TEST_MARKUP_HEADER = "MU\xF3\x01"; +const std::string Validator::TEST_CASE_OPEN_TAG = "!c"; +const std::string Validator::TEST_CASE_CLOSE_TAG = ";"; + +struct TestlibFinalizeGuard { + static bool alive; + static bool registered; + + int quitCount, readEofCount; + + TestlibFinalizeGuard() : quitCount(0), readEofCount(0) { + // No operations. + } + + ~TestlibFinalizeGuard() { + bool _alive = alive; + alive = false; + + if (_alive) { + if (testlibMode == _checker && quitCount == 0) + __testlib_fail("Checker must end with quit or quitf call."); + + if (testlibMode == _validator && readEofCount == 0 && quitCount == 0) + __testlib_fail("Validator must end with readEof call."); + + /* opts */ + autoEnsureNoUnusedOpts(); + + if (!registered) + __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)"); + } + + if (__testlib_exitCode == 0) { + validator.writeTestOverviewLog(); + validator.writeTestMarkup(); + validator.writeTestCase(); + } + } + +private: + /* opts */ + void autoEnsureNoUnusedOpts(); +}; + +bool TestlibFinalizeGuard::alive = true; +bool TestlibFinalizeGuard::registered = false; +extern TestlibFinalizeGuard testlibFinalizeGuard; + +/* + * Call it to disable checks on finalization. + */ +void disableFinalizeGuard() { + TestlibFinalizeGuard::alive = false; +} + +/* Interactor streams. + */ +std::fstream tout; + +/* implementation + */ + +InStream::InStream() { + reader = NULL; + lastLine = -1; + opened = false; + name = ""; + mode = _input; + strict = false; + stdfile = false; + wordReserveSize = 4; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::InStream(const InStream &baseStream, std::string content) { + reader = new StringInputStreamReader(content); + lastLine = -1; + opened = true; + strict = baseStream.strict; + stdfile = false; + mode = baseStream.mode; + name = "based on " + baseStream.name; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::~InStream() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } +} + +void InStream::setTestCase(int testCase) { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::setTestCase can be used only for inf in validator-mode." + " Actually, prefer setTestCase function instead of InStream member"); + reader->setTestCase(testCase); +} + +std::vector InStream::getReadChars() { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::getReadChars can be used only for inf in validator-mode."); + return reader == NULL ? std::vector() : reader->getReadChars(); +} + +void setTestCase(int testCase) { + static bool first_run = true; + static bool zero_based = false; + + if (first_run && testCase == 0) + zero_based = true; + + if (zero_based) + testCase++; + + __testlib_hasTestCase = true; + __testlib_testCase = testCase; + + if (testlibMode == _validator) + inf.setTestCase(testCase); + + first_run = false; +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int resultExitCode(TResult r) { + if (r == _ok) + return OK_EXIT_CODE; + if (r == _wa) + return WA_EXIT_CODE; + if (r == _pe) + return PE_EXIT_CODE; + if (r == _fail) + return FAIL_EXIT_CODE; + if (r == _dirt) + return DIRT_EXIT_CODE; + if (r == _points) + return POINTS_EXIT_CODE; + if (r == _unexpected_eof) +#ifdef ENABLE_UNEXPECTED_EOF + return UNEXPECTED_EOF_EXIT_CODE; +#else + return PE_EXIT_CODE; +#endif + if (r >= _partially) + return PC_BASE_EXIT_CODE + (r - _partially); + return FAIL_EXIT_CODE; +} + +void InStream::textColor( +#if !(defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)) && defined(__GNUC__) + __attribute__((unused)) +#endif + WORD color +) { +#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400) + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, color); +#endif +#if !defined(ON_WINDOWS) && defined(__GNUC__) + if (isatty(2)) + { + switch (color) + { + case LightRed: + fprintf(stderr, "\033[1;31m"); + break; + case LightCyan: + fprintf(stderr, "\033[1;36m"); + break; + case LightGreen: + fprintf(stderr, "\033[1;32m"); + break; + case LightYellow: + fprintf(stderr, "\033[1;33m"); + break; + case LightGray: + default: + fprintf(stderr, "\033[0m"); + } + } +#endif +} + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +class exit_exception: public std::exception { +private: + int exitCode; +public: + exit_exception(int exitCode): exitCode(exitCode) {} + int getExitCode() { return exitCode; } +}; +#endif + +NORETURN void halt(int exitCode) { +#ifdef FOOTER + InStream::textColor(InStream::LightGray); + std::fprintf(stderr, "Checker: \"%s\"\n", checkerName.c_str()); + std::fprintf(stderr, "Exit code: %d\n", exitCode); + InStream::textColor(InStream::LightGray); +#endif + __testlib_exitCode = exitCode; +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT + throw exit_exception(exitCode); +#endif + std::exit(exitCode); +} + +static bool __testlib_shouldCheckDirt(TResult result) { + return result == _ok || result == _points || result >= _partially; +} + +static std::string __testlib_appendMessage(const std::string &message, const std::string &extra) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + size_t index = message.find(extra, openPos); + if (index == std::string::npos || int(index) >= closePos) { + std::string result(message); + result.insert(closePos, ", " + extra); + return result; + } + return message; + } + + return message + " " + InStream::OPEN_BRACKET + extra + InStream::CLOSE_BRACKET; +} + +static std::string __testlib_toPrintableMessage(const std::string &message) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + std::string result(message); + result[openPos] = '('; + result[closePos] = ')'; + return result; + } + + return message; +} + +NORETURN void InStream::quit(TResult result, const char *msg) { + if (TestlibFinalizeGuard::alive) + testlibFinalizeGuard.quitCount++; + + std::string message(msg); + message = trim(message); + + if (__testlib_hasTestCase) { + if (result != _ok) + message = __testlib_appendMessage(message, "test case " + vtos(__testlib_testCase)); + else { + if (__testlib_testCase == 1) + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test case"); + else + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test cases"); + } + } + + // You can change maxMessageLength. + // Example: 'inf.maxMessageLength = 1024 * 1024;'. + if (message.length() > maxMessageLength) { + std::string warn = "message length exceeds " + vtos(maxMessageLength) + + ", the message is truncated: "; + message = warn + message.substr(0, maxMessageLength - warn.length()); + } + +#ifndef ENABLE_UNEXPECTED_EOF + if (result == _unexpected_eof) + result = _pe; +#endif + + if (testlibMode == _scorer && result != _fail) + quits(_fail, "Scorer should return points only. Don't use a quit function."); + + if (mode != _output && result != _fail) { + if (mode == _input && testlibMode == _validator && lastLine != -1) + quits(_fail, __testlib_appendMessage(__testlib_appendMessage(message, name), "line " + vtos(lastLine))); + else + quits(_fail, __testlib_appendMessage(message, name)); + } + + std::FILE *resultFile; + std::string errorName; + + if (__testlib_shouldCheckDirt(result)) { + if (testlibMode != _interactor && !ouf.seekEof()) + quit(_dirt, "Extra information in the output file"); + } + + int pctype = result - _partially; + bool isPartial = false; + + switch (result) { + case _ok: + errorName = "ok "; + quitscrS(LightGreen, errorName); + break; + case _wa: + errorName = "wrong answer "; + quitscrS(LightRed, errorName); + break; + case _pe: + errorName = "wrong output format "; + quitscrS(LightRed, errorName); + break; + case _fail: + errorName = "FAIL "; + quitscrS(LightRed, errorName); + break; + case _dirt: + errorName = "wrong output format "; + quitscrS(LightCyan, errorName); + result = _pe; + break; + case _points: + errorName = "points "; + quitscrS(LightYellow, errorName); + break; + case _unexpected_eof: + errorName = "unexpected eof "; + quitscrS(LightCyan, errorName); + break; + default: + if (result >= _partially) { + errorName = format("partially correct (%d) ", pctype); + isPartial = true; + quitscrS(LightYellow, errorName); + } else + quit(_fail, "What is the code ??? "); + } + + if (resultName != "") { + resultFile = std::fopen(resultName.c_str(), "w"); + if (resultFile == NULL) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + if (appesMode) { + std::fprintf(resultFile, ""); + if (isPartial) + std::fprintf(resultFile, "", + outcomes[(int) _partially].c_str(), pctype); + else { + if (result != _points) + std::fprintf(resultFile, "", outcomes[(int) result].c_str()); + else { + if (__testlib_points == std::numeric_limits::infinity()) + quit(_fail, "Expected points, but infinity found"); + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", __testlib_points)); + std::fprintf(resultFile, "", + outcomes[(int) result].c_str(), stringPoints.c_str()); + } + } + xmlSafeWrite(resultFile, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(resultFile, "\n"); + } else + std::fprintf(resultFile, "%s", __testlib_toPrintableMessage(message).c_str()); + if (NULL == resultFile || fclose(resultFile) != 0) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + } + + quitscr(LightGray, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(stderr, "\n"); + + inf.close(); + ouf.close(); + ans.close(); + if (tout.is_open()) + tout.close(); + + textColor(LightGray); + + if (resultName != "") + std::fprintf(stderr, "See file to check exit message\n"); + + halt(resultExitCode(result)); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +NORETURN void InStream::quitf(TResult result, const char *msg, ...) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +void InStream::quitif(bool condition, TResult result, const char *msg, ...) { + if (condition) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); + } +} + +NORETURN void InStream::quits(TResult result, std::string msg) { + InStream::quit(result, msg.c_str()); +} + +void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { + size_t lmsg = strlen(msg); + for (size_t i = 0; i < lmsg; i++) { + if (msg[i] == '&') { + std::fprintf(file, "%s", "&"); + continue; + } + if (msg[i] == '<') { + std::fprintf(file, "%s", "<"); + continue; + } + if (msg[i] == '>') { + std::fprintf(file, "%s", ">"); + continue; + } + if (msg[i] == '"') { + std::fprintf(file, "%s", """); + continue; + } + if (0 <= msg[i] && msg[i] <= 31) { + std::fprintf(file, "%c", '.'); + continue; + } + std::fprintf(file, "%c", msg[i]); + } +} + +void InStream::quitscrS(WORD color, std::string msg) { + quitscr(color, msg.c_str()); +} + +void InStream::quitscr(WORD color, const char *msg) { + if (resultName == "") { + textColor(color); + std::fprintf(stderr, "%s", msg); + textColor(LightGray); + } +} + +void InStream::reset(std::FILE *file) { + if (opened && stdfile) + quit(_fail, "Can't reset standard handle"); + + if (opened) + close(); + + if (!stdfile && NULL == file) + if (NULL == (file = std::fopen(name.c_str(), "rb"))) { + if (mode == _output) + quits(_pe, std::string("Output file not found: \"") + name + "\""); + + if (mode == _answer) + quits(_fail, std::string("Answer file not found: \"") + name + "\""); + } + + if (NULL != file) { + opened = true; + __testlib_set_binary(file); + + if (stdfile) + reader = new FileInputStreamReader(file, name); + else + reader = new BufferedFileInputStreamReader(file, name); + } else { + opened = false; + reader = NULL; + } +} + +void InStream::init(std::string fileName, TMode mode) { + opened = false; + name = fileName; + stdfile = false; + this->mode = mode; + + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + if (stream.is_open()) { + std::streampos start = stream.tellg(); + stream.seekg(0, std::ios::end); + std::streampos end = stream.tellg(); + size_t fileSize = size_t(end - start); + stream.close(); + + // You can change maxFileSize. + // Example: 'inf.maxFileSize = 256 * 1024 * 1024;'. + if (fileSize > maxFileSize) + quitf(_pe, "File size exceeds %d bytes, size is %d", int(maxFileSize), int(fileSize)); + } + + reset(); +} + +void InStream::init(std::FILE *f, TMode mode) { + opened = false; + name = "untitled"; + this->mode = mode; + + if (f == stdin) + name = "stdin", stdfile = true; + if (f == stdout) + name = "stdout", stdfile = true; + if (f == stderr) + name = "stderr", stdfile = true; + + reset(f); +} + +void InStream::skipBom() { + const std::string utf8Bom = "\xEF\xBB\xBF"; + size_t index = 0; + while (index < utf8Bom.size() && curChar() == utf8Bom[index]) { + index++; + skipChar(); + } + if (index < utf8Bom.size()) { + while (index != 0) { + unreadChar(utf8Bom[index - 1]); + index--; + } + } +} + +char InStream::curChar() { + return char(reader->curChar()); +} + +char InStream::nextChar() { + return char(reader->nextChar()); +} + +char InStream::readChar() { + return nextChar(); +} + +char InStream::readChar(char c) { + lastLine = reader->getLine(); + char found = readChar(); + if (c != found) { + if (!isEoln(found)) + quit(_pe, ("Unexpected character '" + std::string(1, found) + "', but '" + std::string(1, c) + + "' expected").c_str()); + else + quit(_pe, ("Unexpected character " + ("#" + vtos(int(found))) + ", but '" + std::string(1, c) + + "' expected").c_str()); + } + return found; +} + +char InStream::readSpace() { + return readChar(' '); +} + +void InStream::unreadChar(char c) { + reader->unreadChar(c); +} + +void InStream::skipChar() { + reader->skipChar(); +} + +void InStream::skipBlanks() { + while (isBlanks(reader->curChar())) + reader->skipChar(); +} + +std::string InStream::readWord() { + readWordTo(_tmpReadToken); + return _tmpReadToken; +} + +void InStream::readWordTo(std::string &result) { + if (!strict) + skipBlanks(); + + lastLine = reader->getLine(); + int cur = reader->nextChar(); + + if (cur == EOFC) + quit(_unexpected_eof, "Unexpected end of file - token expected"); + + if (isBlanks(cur)) + quit(_pe, "Unexpected white-space - token expected"); + + result.clear(); + + while (!(isBlanks(cur) || cur == EOFC)) { + result += char(cur); + + // You can change maxTokenLength. + // Example: 'inf.maxTokenLength = 128 * 1024 * 1024;'. + if (result.length() > maxTokenLength) + quitf(_pe, "Length of token exceeds %d, token is '%s...'", int(maxTokenLength), + __testlib_part(result).c_str()); + + cur = reader->nextChar(); + } + + reader->unreadChar(cur); + + if (result.length() == 0) + quit(_unexpected_eof, "Unexpected end of file or white-space - token expected"); +} + +std::string InStream::readToken() { + return readWord(); +} + +void InStream::readTokenTo(std::string &result) { + readWordTo(result); +} + +static std::string __testlib_part(const std::string &s) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (s[i] != '\0') + t += s[i]; + else + t += '~'; + if (t.length() <= 64) + return t; + else + return t.substr(0, 30) + "..." + t.substr(s.length() - 31, 31); +} + +#define __testlib_readMany(readMany, readOne, typeName, space) \ + if (size < 0) \ + quit(_fail, #readMany ": size should be non-negative."); \ + if (size > 100000000) \ + quit(_fail, #readMany ": size should be at most 100000000."); \ + \ + std::vector result(size); \ + readManyIteration = indexBase; \ + \ + for (int i = 0; i < size; i++) \ + { \ + result[i] = readOne; \ + readManyIteration++; \ + if (strict && space && i + 1 < size) \ + readSpace(); \ + } \ + \ + readManyIteration = NO_INDEX; \ + return result; \ + + +std::string InStream::readWord(const pattern &p, const std::string &variableName) { + readWordTo(_tmpReadToken); + if (!p.matches(_tmpReadToken)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Token \"" + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(_tmpReadToken) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Token element [index=" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token element " + variableName + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\", doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + } + } + return _tmpReadToken; +} + +std::vector +InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::vector InStream::readWords(int size, int indexBase) { + __testlib_readMany(readWords, readWord(), std::string, true); +} + +std::string InStream::readWord(const std::string &ptrn, const std::string &variableName) { + return readWord(pattern(ptrn), variableName); +} + +std::vector +InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::string InStream::readToken(const pattern &p, const std::string &variableName) { + return readWord(p, variableName); +} + +std::vector +InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readTokens, readToken(p, variablesName), std::string, true); +} + +std::vector InStream::readTokens(int size, int indexBase) { + __testlib_readMany(readTokens, readToken(), std::string, true); +} + +std::string InStream::readToken(const std::string &ptrn, const std::string &variableName) { + return readWord(ptrn, variableName); +} + +std::vector +InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readTokens, readWord(p, variablesName), std::string, true); +} + +void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) { + readWordTo(result); + if (!p.matches(result)) { + if (variableName.empty()) + quit(_wa, ("Token \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } +} + +void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, pattern(ptrn), variableName); +} + +void InStream::readTokenTo(std::string &result, const pattern &p, const std::string &variableName) { + return readWordTo(result, p, variableName); +} + +void InStream::readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, ptrn, variableName); +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(long long integer, const char *s) { + if (integer == LLONG_MIN) + return strcmp(s, "-9223372036854775808") == 0; + + if (integer == 0LL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + if (integer < 0 && s[0] != '-') + return false; + + if (integer < 0) + s++, length--, integer = -integer; + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(unsigned long long integer, const char *s) { + if (integer == ULLONG_MAX) + return strcmp(s, "18446744073709551615") == 0; + + if (integer == 0ULL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +static inline double stringToDouble(InStream &in, const char *buffer) { + double retval; + + size_t length = strlen(buffer); + + int minusCount = 0; + int plusCount = 0; + int decimalPointCount = 0; + int digitCount = 0; + int eCount = 0; + + for (size_t i = 0; i < length; i++) { + if (('0' <= buffer[i] && buffer[i] <= '9') || buffer[i] == '.' + || buffer[i] == 'e' || buffer[i] == 'E' + || buffer[i] == '-' || buffer[i] == '+') { + if ('0' <= buffer[i] && buffer[i] <= '9') + digitCount++; + if (buffer[i] == 'e' || buffer[i] == 'E') + eCount++; + if (buffer[i] == '-') + minusCount++; + if (buffer[i] == '+') + plusCount++; + if (buffer[i] == '.') + decimalPointCount++; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + // If for sure is not a number in standard notation or in e-notation. + if (digitCount == 0 || minusCount > 2 || plusCount > 2 || decimalPointCount > 1 || eCount > 1) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToDouble(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToDouble(in, buffer.c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const char *buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + if (minAfterPointDigitCount < 0) + in.quit(_fail, "stringToStrictDouble: minAfterPointDigitCount should be non-negative."); + + if (minAfterPointDigitCount > maxAfterPointDigitCount) + in.quit(_fail, + "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount."); + + double retval; + + size_t length = strlen(buffer); + + if (length == 0 || length > 1000) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[0] != '-' && (buffer[0] < '0' || buffer[0] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int pointPos = -1; + for (size_t i = 1; i + 1 < length; i++) { + if (buffer[i] == '.') { + if (pointPos > -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + pointPos = int(i); + } + if (buffer[i] != '.' && (buffer[i] < '0' || buffer[i] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + if (buffer[length - 1] < '0' || buffer[length - 1] > '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int afterDigitsCount = (pointPos == -1 ? 0 : int(length) - pointPos - 1); + if (afterDigitsCount < minAfterPointDigitCount || afterDigitsCount > maxAfterPointDigitCount) + in.quit(_pe, ("Expected strict double with number of digits after point in range [" + + vtos(minAfterPointDigitCount) + + "," + + vtos(maxAfterPointDigitCount) + + "], but \"" + __testlib_part(buffer) + "\" found").c_str() + ); + + int firstDigitPos = -1; + for (size_t i = 0; i < length; i++) + if (buffer[i] >= '0' && buffer[i] <= '9') { + firstDigitPos = int(i); + break; + } + + if (firstDigitPos > 1 || firstDigitPos == -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[firstDigitPos] == '0' && firstDigitPos + 1 < int(length) + && buffer[firstDigitPos + 1] >= '0' && buffer[firstDigitPos + 1] <= '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval) || __testlib_isInfinite(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (buffer[0] == '-' && retval >= 0) + in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const std::string& buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToStrictDouble(in, buffer.c_str(), minAfterPointDigitCount, maxAfterPointDigitCount); +} + +static inline long long stringToLongLong(InStream &in, const char *buffer) { + if (strcmp(buffer, "-9223372036854775808") == 0) + return LLONG_MIN; + + bool minus = false; + size_t length = strlen(buffer); + + if (length > 1 && buffer[0] == '-') + minus = true; + + if (length > 20) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + long long retval = 0LL; + + int zeroes = 0; + bool processingZeroes = true; + + for (int i = (minus ? 1 : 0); i < int(length); i++) { + if (buffer[i] == '0' && processingZeroes) + zeroes++; + else + processingZeroes = false; + + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (retval < 0) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if ((zeroes > 0 && (retval != 0 || minus)) || zeroes > 1) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + retval = (minus ? -retval : +retval); + + if (length < 19) + return retval; + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToLongLong(in, buffer.c_str()); +} + +static inline unsigned long long stringToUnsignedLongLong(InStream &in, const char *buffer) { + size_t length = strlen(buffer); + + if (length > 20) + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (length > 1 && buffer[0] == '0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + unsigned long long retval = 0LL; + for (int i = 0; i < int(length); i++) { + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (length < 19) + return retval; + + if (length == 20 && strcmp(buffer, "18446744073709551615") > 0) + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToUnsignedLongLong(in, buffer.c_str()); +} + +int InStream::readInteger() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int32 expected"); + + readWordTo(_tmpReadToken); + + long long value = stringToLongLong(*this, _tmpReadToken); + if (value < INT_MIN || value > INT_MAX) + quit(_pe, ("Expected int32, but \"" + __testlib_part(_tmpReadToken) + "\" found").c_str()); + + return int(value); +} + +long long InStream::readLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToLongLong(*this, _tmpReadToken); +} + +unsigned long long InStream::readUnsignedLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToUnsignedLongLong(*this, _tmpReadToken); +} + +long long InStream::readLong(long long minv, long long maxv, const std::string &variableName) { + long long result = readLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector +InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) +} + +std::vector InStream::readLongs(int size, int indexBase) { + __testlib_readMany(readLongs, readLong(), long long, true) +} + +unsigned long long +InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + unsigned long long result = readUnsignedLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, + ("Unsigned integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, ("Unsigned integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) +} + +std::vector InStream::readUnsignedLongs(int size, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) +} + +unsigned long long +InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + return readUnsignedLong(minv, maxv, variableName); +} + +int InStream::readInt() { + return readInteger(); +} + +int InStream::readInt(int minv, int maxv, const std::string &variableName) { + int result = readInt(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +int InStream::readInteger(int minv, int maxv, const std::string &variableName) { + return readInt(minv, maxv, variableName); +} + +std::vector InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readInts(int size, int indexBase) { + __testlib_readMany(readInts, readInt(), int, true) +} + +std::vector InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readIntegers(int size, int indexBase) { + __testlib_readMany(readIntegers, readInt(), int, true) +} + +double InStream::readReal() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - double expected"); + + return stringToDouble(*this, readWord()); +} + +double InStream::readDouble() { + return readReal(); +} + +double InStream::readReal(double minv, double maxv, const std::string &variableName) { + double result = readReal(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, ("Double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, + ("Double element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector +InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readReals(int size, int indexBase) { + __testlib_readMany(readReals, readReal(), double, true) +} + +double InStream::readDouble(double minv, double maxv, const std::string &variableName) { + return readReal(minv, maxv, variableName); +} + +std::vector +InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readDoubles(int size, int indexBase) { + __testlib_readMany(readDoubles, readDouble(), double, true) +} + +double InStream::readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - strict double expected"); + + double result = stringToStrictDouble(*this, readWord(), minAfterPointDigitCount, maxAfterPointDigitCount); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Strict double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, + ("Strict double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Strict double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, ("Strict double element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector InStream::readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictReals, + readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +double InStream::readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + return readStrictReal(minv, maxv, + minAfterPointDigitCount, maxAfterPointDigitCount, + variableName); +} + +std::vector InStream::readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictDoubles, + readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +bool InStream::eof() { + if (!strict && NULL == reader) + return true; + + return reader->eof(); +} + +bool InStream::seekEof() { + if (!strict && NULL == reader) + return true; + skipBlanks(); + return eof(); +} + +bool InStream::eoln() { + if (!strict && NULL == reader) + return true; + + int c = reader->nextChar(); + + if (!strict) { + if (c == EOFC) + return true; + + if (c == CR) { + c = reader->nextChar(); + + if (c != LF) { + reader->unreadChar(c); + reader->unreadChar(CR); + return false; + } else + return true; + } + + if (c == LF) + return true; + + reader->unreadChar(c); + return false; + } else { + bool returnCr = false; + +#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS) + if (c != CR) { + reader->unreadChar(c); + return false; + } else { + if (!returnCr) + returnCr = true; + c = reader->nextChar(); + } +#endif + if (c != LF) { + reader->unreadChar(c); + if (returnCr) + reader->unreadChar(CR); + return false; + } + + return true; + } +} + +void InStream::readEoln() { + lastLine = reader->getLine(); + if (!eoln()) + quit(_pe, "Expected EOLN"); +} + +void InStream::readEof() { + lastLine = reader->getLine(); + if (!eof()) + quit(_pe, "Expected EOF"); + + if (TestlibFinalizeGuard::alive && this == &inf) + testlibFinalizeGuard.readEofCount++; +} + +bool InStream::seekEoln() { + if (!strict && NULL == reader) + return true; + + int cur; + do { + cur = reader->nextChar(); + } while (cur == SPACE || cur == TAB); + + reader->unreadChar(cur); + return eoln(); +} + +void InStream::nextLine() { + readLine(); +} + +void InStream::readStringTo(std::string &result) { + if (NULL == reader) + quit(_pe, "Expected line"); + + result.clear(); + + for (;;) { + int cur = reader->curChar(); + + if (cur == LF || cur == EOFC) + break; + + if (cur == CR) { + cur = reader->nextChar(); + if (reader->curChar() == LF) { + reader->unreadChar(cur); + break; + } + } + + lastLine = reader->getLine(); + result += char(reader->nextChar()); + } + + if (strict) + readEoln(); + else + eoln(); +} + +std::string InStream::readString() { + readStringTo(_tmpReadToken); + return _tmpReadToken; +} + +std::vector InStream::readStrings(int size, int indexBase) { + __testlib_readMany(readStrings, readString(), std::string, false) +} + +void InStream::readStringTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result); + if (!p.matches(result)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Line \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Line [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Line element [index=" + vtos(readManyIteration) + "] equals to \"" + __testlib_part(result) + + "\" doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + else + quit(_wa, + ("Line element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } + } +} + +void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, pattern(ptrn), variableName); +} + +std::string InStream::readString(const pattern &p, const std::string &variableName) { + readStringTo(_tmpReadToken, p, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +std::string InStream::readString(const std::string &ptrn, const std::string &variableName) { + readStringTo(_tmpReadToken, ptrn, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +void InStream::readLineTo(std::string &result) { + readStringTo(result); +} + +std::string InStream::readLine() { + return readString(); +} + +std::vector InStream::readLines(int size, int indexBase) { + __testlib_readMany(readLines, readString(), std::string, false) +} + +void InStream::readLineTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result, p, variableName); +} + +void InStream::readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, ptrn, variableName); +} + +std::string InStream::readLine(const pattern &p, const std::string &variableName) { + return readString(p, variableName); +} + +std::vector +InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) { + return readString(ptrn, variableName); +} + +std::vector +InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void InStream::ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + this->__testlib_ensure(cond, message); + } +} + +void InStream::__testlib_ensure(bool cond, std::string message) { + if (!cond) + this->quit(_wa, message.c_str()); +} + +void InStream::close() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } + + opened = false; +} + +NORETURN void quit(TResult result, const std::string &msg) { + ouf.quit(result, msg.c_str()); +} + +NORETURN void quit(TResult result, const char *msg) { + ouf.quit(result, msg); +} + +NORETURN void __testlib_quitp(double points, const char *message) { + __testlib_points = points; + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", points)); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void __testlib_quitp(int points, const char *message) { + __testlib_points = points; + std::string stringPoints = format("%d", points); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void quitp(float points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(double points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitp(long double points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(int points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitpi(const std::string &points_info, const std::string &message = "") { + if (points_info.find(' ') != std::string::npos) + quit(_fail, "Parameter 'points_info' can't contain spaces"); + if (message.empty()) + quit(_points, ("points_info=" + points_info).c_str()); + else + quit(_points, ("points_info=" + points_info + " " + message).c_str()); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitp(F points, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quitp(points, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitf(TResult result, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quit(result, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void quitif(bool condition, TResult result, const char *format, ...) { + if (condition) { + FMT_TO_RESULT(format, format, message); + quit(result, message); + } +} + +NORETURN void __testlib_help() { + InStream::textColor(InStream::LightCyan); + std::fprintf(stderr, "TESTLIB %s, https://github.com/MikeMirzayanov/testlib/ ", VERSION); + std::fprintf(stderr, "by Mike Mirzayanov, copyright(c) 2005-2020\n"); + std::fprintf(stderr, "Checker name: \"%s\"\n", checkerName.c_str()); + InStream::textColor(InStream::LightGray); + + std::fprintf(stderr, "\n"); + std::fprintf(stderr, "Latest features: \n"); + for (size_t i = 0; i < sizeof(latestFeatures) / sizeof(char *); i++) { + std::fprintf(stderr, "*) %s\n", latestFeatures[i]); + } + std::fprintf(stderr, "\n"); + + std::fprintf(stderr, "Program must be run with the following arguments: \n"); + std::fprintf(stderr, " [--testset testset] [--group group] [ [<-appes>]]\n\n"); + + __testlib_exitCode = FAIL_EXIT_CODE; + std::exit(FAIL_EXIT_CODE); +} + +static void __testlib_ensuresPreconditions() { + // testlib assumes: sizeof(int) = 4. + __TESTLIB_STATIC_ASSERT(sizeof(int) == 4); + + // testlib assumes: INT_MAX == 2147483647. + __TESTLIB_STATIC_ASSERT(INT_MAX == 2147483647); + + // testlib assumes: sizeof(long long) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(long long) == 8); + + // testlib assumes: sizeof(double) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(double) == 8); + + // testlib assumes: no -ffast-math. + if (!__testlib_isNaN(+__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); + if (!__testlib_isNaN(-__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); +} + +std::string __testlib_testset; + +std::string getTestset() { + return __testlib_testset; +} + +std::string __testlib_group; + +std::string getGroup() { + return __testlib_group; +} + +static void __testlib_set_testset_and_group(int argc, char* argv[]) { + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + __testlib_testset = argv[++i]; + else + quit(_fail, std::string("Expected non-empty testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + __testlib_group = argv[++i]; + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } + } +} + +void registerGen(int argc, char *argv[], int randomGeneratorVersion) { + if (randomGeneratorVersion < 0 || randomGeneratorVersion > 1) + quitf(_fail, "Random generator version is expected to be 0 or 1."); + random_t::version = randomGeneratorVersion; + + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _generator; + __testlib_set_binary(stdin); + rnd.setSeed(argc, argv); + +#if __cplusplus > 199711L || defined(_MSC_VER) + prepareOpts(argc, argv); +#endif +} + +#ifdef USE_RND_AS_BEFORE_087 +void registerGen(int argc, char* argv[]) +{ + registerGen(argc, argv, 0); +} +#else +#ifdef __GNUC__ +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 4)) +__attribute__ ((deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." +" The third parameter stands for the random generator version." +" If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." +" Version 1 has been released on Spring, 2013. Use it to write new generators."))) +#else +__attribute__ ((deprecated)) +#endif +#endif +#ifdef _MSC_VER +__declspec(deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.")) +#endif +void registerGen(int argc, char *argv[]) { + std::fprintf(stderr, "Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.\n\n"); + registerGen(argc, argv, 0); +} +#endif + +void registerInteraction(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _interactor; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + tout.open(std::string(argv[3]) + "/teammessage.txt", + std::ios_base::out); + if (tout.fail() || !tout.is_open()) + quit(_fail, "Can not write to the test-output-file '" + + std::string(argv[2]) + "'"); + appesMode = false; + } + + inf.init(argv[1], _input); + + ouf.init(stdin, _output); + if (argc >= 3) + ans.init(argv[2], _answer); + else + ans.name = "unopened answer stream"; +} + +void registerValidation() { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _validator; + + __testlib_set_binary(stdin); + __testlib_set_binary(stdout); + __testlib_set_binary(stderr); + + inf.init(stdin, _input); + inf.strict = true; +} + +void registerValidation(int argc, char *argv[]) { + registerValidation(); + __testlib_set_testset_and_group(argc, argv); + + validator.initialize(); + TestlibFinalizeGuard::registered = true; + + std::string comment = "Validator must be run with the following arguments:" + " [--testset testset]" + " [--group group]" + " [--testOverviewLogFileName fileName]" + " [--testMarkupFileName fileName]" + " [--testCase testCase]" + " [--testCaseFileName fileName]" + ; + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + validator.setTestset(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + validator.setGroup(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testOverviewLogFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestOverviewLogFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testMarkupFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestMarkupFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testCase", argv[i])) { + if (i + 1 < argc) { + long long testCase = stringToLongLong(inf, argv[++i]); + if (testCase < 1 || testCase >= __TESTLIB_MAX_TEST_CASE) + quit(_fail, format("Argument testCase should be between 1 and %d, but ", __TESTLIB_MAX_TEST_CASE) + + toString(testCase) + " found"); + validator.setTestCase(int(testCase)); + } else + quit(_fail, comment); + } + if (!strcmp("--testCaseFileName", argv[i])) { + if (i + 1 < argc) { + validator.setTestCaseFileName(argv[++i]); + } else + quit(_fail, comment); + } + } +} + +void addFeature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.addFeature(feature); +} + +void feature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.feature(feature); +} + +class Checker { +private: + bool _initialized; + std::string _testset; + std::string _group; + +public: + Checker() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.group()"); + return _group; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } +} checker; + +void registerTestlibCmd(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _checker; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + + appesMode = false; + + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + appesMode = false; + } + + inf.init(argv[1], _input); + ouf.init(stdin, _output); + ans.init(argv[2], _answer); +} + +void registerTestlib(int argc, ...) { + if (argc < 3 || argc > 5) + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + + char **argv = new char *[argc + 1]; + + va_list ap; + va_start(ap, argc); + argv[0] = NULL; + for (int i = 0; i < argc; i++) { + argv[i + 1] = va_arg(ap, char*); + } + va_end(ap); + + registerTestlibCmd(argc + 1, argv); + delete[] argv; +} + +static inline void __testlib_ensure(bool cond, const std::string &msg) { + if (!cond) + quit(_fail, msg.c_str()); +} + +#ifdef __GNUC__ +__attribute__((unused)) +#endif +static inline void __testlib_ensure(bool cond, const char *msg) { + if (!cond) + quit(_fail, msg); +} + +#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) +#define ensure_ext(cond) __testlib_ensure(cond, "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"") + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +inline void ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + __testlib_ensure(cond, message); + } +} + +NORETURN static void __testlib_fail(const std::string &message) { + quitf(_fail, "%s", message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +void setName(const char *format, ...) { + FMT_TO_RESULT(format, format, name); + checkerName = name; +} + +/* + * Do not use random_shuffle, because it will produce different result + * for different C++ compilers. + * + * This implementation uses testlib random_t to produce random numbers, so + * it is stable. + */ +template +void shuffle(_RandomAccessIter __first, _RandomAccessIter __last) { + if (__first == __last) return; + for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) + std::iter_swap(__i, __first + rnd.next(int(__i - __first) + 1)); +} + + +template +#if defined(__GNUC__) && !defined(__clang__) +__attribute__ ((error("Don't use random_shuffle(), use shuffle() instead"))) +#endif +void random_shuffle(_RandomAccessIter, _RandomAccessIter) { + quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); +} + +#ifdef __GLIBC__ +# define RAND_THROW_STATEMENT throw() +#else +# define RAND_THROW_STATEMENT +#endif + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use rand(), use rnd.next() instead"))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +int rand() RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use rand(), use rnd.next() instead"); + + /* This line never runs. */ + //throw "Don't use rand(), use rnd.next() instead"; +} + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use srand(), you should use " +"'registerGen(argc, argv, 1);' to initialize generator seed " +"by hash code of the command line params. The third parameter " +"is randomGeneratorVersion (currently the latest is 1)."))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +void srand(unsigned int seed) RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use srand(), you should use " + "'registerGen(argc, argv, 1);' to initialize generator seed " + "by hash code of the command line params. The third parameter " + "is randomGeneratorVersion (currently the latest is 1) [ignored seed=%u].", seed); +} + +void startTest(int test) { + const std::string testFileName = vtos(test); + if (NULL == freopen(testFileName.c_str(), "wt", stdout)) + __testlib_fail("Unable to write file '" + testFileName + "'"); +} + +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + +inline std::string compress(const std::string &s) { + return __testlib_part(s); +} + +inline std::string englishEnding(int x) { + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separator) { + std::stringstream ss; + bool repeated = false; + for (_ForwardIterator i = first; i != last; i++) { + if (repeated) + ss << separator; + else + repeated = true; + ss << *i; + } + return ss.str(); +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last) { + return join(first, last, ' '); +} + +template +std::string join(const _Collection &collection, _Separator separator) { + return join(collection.begin(), collection.end(), separator); +} + +template +std::string join(const _Collection &collection) { + return join(collection, ' '); +} + +/** + * Splits string s by character separator returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separator returning non-empty items. + */ +std::vector tokenize(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + if (!item.empty()) + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning non-empty items. + */ +std::vector tokenize(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + + if (!item.empty()) + result.push_back(item); + + return result; +} + +NORETURN void __testlib_expectedButFound(TResult result, std::string expected, std::string found, const char *prepend) { + std::string message; + if (strlen(prepend) != 0) + message = format("%s: expected '%s', but found '%s'", + compress(prepend).c_str(), compress(expected).c_str(), compress(found).c_str()); + else + message = format("expected '%s', but found '%s'", + compress(expected).c_str(), compress(found).c_str()); + quit(result, message); +} + +NORETURN void __testlib_expectedButFound(TResult result, double expected, double found, const char *prepend) { + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, T expected, T found, const char *prependFormat = "", ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = vtos(expected); + std::string foundString = vtos(found); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, std::string expected, std::string found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, expected, found, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, double expected, double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, const char *expected, const char *found, const char *prependFormat, + ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, float expected, float found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, long double expected, long double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +struct is_iterable { + template + static char test(typename U::iterator *x); + + template + static long test(U *x); + + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct __testlib_enable_if { +}; + +template +struct __testlib_enable_if { + typedef T type; +}; + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + std::cout << t; +} + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + bool first = true; + for (typename T::const_iterator i = t.begin(); i != t.end(); i++) { + if (first) + first = false; + else + std::cout << " "; + std::cout << *i; + } +} + +template<> +typename __testlib_enable_if::value, void>::type +__testlib_print_one(const std::string &t) { + std::cout << t; +} + +template +void __println_range(A begin, B end) { + bool first = true; + for (B i = B(begin); i != end; i++) { + if (first) + first = false; + else + std::cout << " "; + __testlib_print_one(*i); + } + std::cout << std::endl; +} + +template +struct is_iterator { + static T makeT(); + + typedef void *twoptrs[2]; + + static twoptrs &test(...); + + template + static typename R::iterator_category *test(R); + + template + static void *test(R *); + + static const bool value = sizeof(test(makeT())) == sizeof(void *); +}; + +template +struct is_iterator::value>::type> { + static const bool value = false; +}; + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __println_range(a, b); +} + +template +void println(const A *a, const A *b) { + __println_range(a, b); +} + +template<> +void println(const char *a, const char *b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +void println(const T &x) { + __testlib_print_one(x); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << " "; + __testlib_print_one(g); + std::cout << std::endl; +} + +/* opts */ + +/** + * A struct for a singular testlib opt, containing the raw string value, + * and a boolean value for marking whether the opt is used. + */ +struct TestlibOpt { + std::string value; + bool used; + + TestlibOpt() : value(), used(false) {} +}; + +/** + * Get the type of opt based on the number of `-` at the beginning and the + * _validity_ of the key name. + * + * A valid key name must start with an alphabetical character. + * + * Returns: 1 if s has one `-` at the beginning, that is, "-keyName". + * 2 if s has two `-` at the beginning, that is, "--keyName". + * 0 otherwise. That is, if s has no `-` at the beginning, or has more + * than 2 at the beginning ("---keyName", "----keyName", ...), or the + * keyName is invalid (the first character is not an alphabetical + * character). + */ +size_t getOptType(char *s) { + if (!s || strlen(s) <= 1) + return 0; + + if (s[0] == '-') { + if (isalpha(s[1])) + return 1; + else if (s[1] == '-') + return isalpha(s[2]) ? 2 : 0; + } + + return 0; +} + +/** + * Parse the opt at a given index, and put it into the opts maps. + * + * An opt can has the following form: + * 1) -keyName=value or --keyName=value (ex. -n=10 --test-count=20) + * 2) -keyName value or --keyName value (ex. -n 10 --test-count 20) + * 3) -kNumval or --kNumval (ex. -n10 --t20) + * 4) -boolProperty or --boolProperty (ex. -sorted --tree-only) + * + * Only the second form consumes 2 arguments. The other consumes only 1 + * argument. + * + * In the third form, the key is a single character, and after the key is the + * value. The value _should_ be a number. + * + * In the forth form, the value is true. + * + * Params: + * - argc and argv: the number of command line arguments and the command line + * arguments themselves. + * - index: the starting index of the opts. + * - opts: the map containing the resulting opt. + * + * Returns: the number of consumed arguments to parse the opt. + * 0 if there is no arguments to parse. + * + * Algorithm details: + * TODO. Please refer to the implementation to see how the code handles the 3rd and 4th forms separately. + */ +size_t parseOpt(size_t argc, char *argv[], size_t index, std::map &opts) { + if (index >= argc) + return 0; + + size_t type = getOptType(argv[index]), inc = 1; + if (type > 0) { + std::string key(argv[index] + type), val; + size_t sep = key.find('='); + if (sep != std::string::npos) { + val = key.substr(sep + 1); + key = key.substr(0, sep); + } else { + if (index + 1 < argc && getOptType(argv[index + 1]) == 0) { + val = argv[index + 1]; + inc = 2; + } else { + if (key.length() > 1 && isdigit(key[1])) { + val = key.substr(1); + key = key.substr(0, 1); + } else { + val = "true"; + } + } + } + opts[key].value = val; + } else { + return inc; + } + + return inc; +} + +/** + * Global list containing all the arguments in the order given in the command line. + */ +std::vector __testlib_argv; + +/** + * Global dictionary containing all the parsed opts. + */ +std::map __testlib_opts; + +/** + * Whether automatic no unused opts ensurement should be done. This flag will + * be turned on when `has_opt` or `opt(key, default_value)` is called. + * + * The automatic ensurement can be suppressed when + * __testlib_ensureNoUnusedOptsSuppressed is true. + */ +bool __testlib_ensureNoUnusedOptsFlag = false; + +/** + * Suppress no unused opts automatic ensurement. Can be set to true with + * `suppressEnsureNoUnusedOpts()`. + */ +bool __testlib_ensureNoUnusedOptsSuppressed = false; + +/** + * Parse command line arguments into opts. + * The results are stored into __testlib_argv and __testlib_opts. + */ +void prepareOpts(int argc, char *argv[]) { + if (argc <= 0) + __testlib_fail("Opts: expected argc>=0 but found " + toString(argc)); + size_t n = static_cast(argc); // NOLINT(hicpp-use-auto,modernize-use-auto) + __testlib_opts = std::map(); + for (size_t index = 1; index < n; index += parseOpt(n, argv, index, __testlib_opts)); + __testlib_argv = std::vector(n); + for (size_t index = 0; index < n; index++) + __testlib_argv[index] = argv[index]; +} + +/** + * An utility function to get the argument with a given index. This function + * also print a readable message when no arguments are found. + */ +std::string __testlib_indexToArgv(int index) { + if (index < 0 || index >= int(__testlib_argv.size())) + __testlib_fail("Opts: index '" + toString(index) + "' is out of range [0," + + toString(__testlib_argv.size()) + ")"); + return __testlib_argv[size_t(index)]; +} + +/** + * An utility function to get the opt with a given key . This function + * also print a readable message when no opts are found. + */ +std::string __testlib_keyToOpts(const std::string &key) { + auto it = __testlib_opts.find(key); + if (it == __testlib_opts.end()) + __testlib_fail("Opts: unknown key '" + compress(key) + "'"); + it->second.used = true; + return it->second.value; +} + +template +T optValueToIntegral(const std::string &s, bool nonnegative); + +long double optValueToLongDouble(const std::string &s); + +std::string parseExponentialOptValue(const std::string &s) { + size_t pos = std::string::npos; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == 'e' || s[i] == 'E') { + if (pos != std::string::npos) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + pos = i; + } + if (pos == std::string::npos) + return s; + std::string e = s.substr(pos + 1); + if (!e.empty() && e[0] == '+') + e = e.substr(1); + if (e.empty()) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (e.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + int ne = optValueToIntegral(e, false); + std::string num = s.substr(0, pos); + if (num.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (!num.empty() && num[0] == '+') + num = num.substr(1); + optValueToLongDouble(num); + bool minus = false; + if (num[0] == '-') { + minus = true; + num = num.substr(1); + } + for (int i = 0; i < +ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num += '0'; + else { + if (sep + 1 == num.length()) + num[sep] = '0'; + else + std::swap(num[sep], num[sep + 1]); + } + } + for (int i = 0; i < -ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num.insert(num.begin() + int(num.length()) - 1, '.'); + else { + if (sep == 0) + num.insert(num.begin() + 1, '0'); + else + std::swap(num[sep - 1], num[sep]); + } + } + while (!num.empty() && num[0] == '0') + num = num.substr(1); + while (num.find('.') != std::string::npos && num.back() == '0') + num = num.substr(0, num.length() - 1); + if (!num.empty() && num.back() == '.') + num = num.substr(0, num.length() - 1); + if ((!num.empty() && num[0] == '.') || num.empty()) + num.insert(num.begin(), '0'); + return (minus ? "-" : "") + num; +} + +template +T optValueToIntegral(const std::string &s_, bool nonnegative) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + T value = 0; + long double about = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + if (nonnegative) + __testlib_fail("Opts: expected non-negative integer but '" + compress(s_) + "' found"); + sign = -1; + pos++; + } + for (size_t i = pos; i < s.length(); i++) { + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + value = value * 10 + s[i] - '0'; + about = about * 10 + s[i] - '0'; + } + value *= sign; + about *= sign; + if (fabsl(value - about) > 0.1) + __testlib_fail("Opts: integer overflow: expected integer but '" + compress(s_) + "' found"); + return value; +} + +long double optValueToLongDouble(const std::string &s_) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + long double value = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + sign = -1; + pos++; + } + bool period = false; + long double mul = 1.0; + for (size_t i = pos; i < s.length(); i++) { + if (s[i] == '.') { + if (period) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + else { + period = true; + continue; + } + } + if (period) + mul *= 10.0; + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + if (period) + value += (s[i] - '0') / mul; + else + value = value * 10 + s[i] - '0'; + } + value *= sign; + return value; +} + +/** + * Return true if there is an opt with a given key. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +bool has_opt(const std::string &key) { + __testlib_ensureNoUnusedOptsFlag = true; + return __testlib_opts.count(key) != 0; +} + +/* About the followings part for opt with 2 and 3 arguments. + * + * To parse the argv/opts correctly for a give type (integer, floating point or + * string), some meta programming must be done to determine the type of + * the type, and use the correct parsing function accordingly. + * + * The pseudo algorithm for determining the type of T and parse it accordingly + * is as follows: + * + * if (T is integral type) { + * if (T is unsigned) { + * parse the argv/opt as an **unsigned integer** of type T. + * } else { + * parse the argv/opt as an **signed integer** of type T. + * } else { + * if (T is floating point type) { + * parse the argv/opt as an **floating point** of type T. + * } else { + * // T should be std::string + * just the raw content of the argv/opts. + * } + * } + * + * To help with meta programming, some `opt` function with 2 or 3 arguments are + * defined. + * + * Opt with 3 arguments: T opt(true/false is_integral, true/false is_unsigned, index/key) + * + * + The first argument is for determining whether the type T is an integral + * type. That is, the result of std::is_integral() should be passed to + * this argument. When false, the type _should_ be either floating point or a + * std::string. + * + * + The second argument is for determining whether the signedness of the type + * T (if it is unsigned or signed). That is, the result of + * std::is_unsigned() should be passed to this argument. This argument can + * be ignored if the first one is false, because it only applies to integer. + * + * Opt with 2 arguments: T opt(true/false is_floating_point, index/key) + * + The first argument is for determining whether the type T is a floating + * point type. That is, the result of std::is_floating_point() should be + * passed to this argument. When false, the type _should_ be a std::string. + */ + +template +T opt(std::false_type is_floating_point, int index); + +template<> +std::string opt(std::false_type /*is_floating_point*/, int index) { + return __testlib_indexToArgv(index); +} + +template +T opt(std::true_type /*is_floating_point*/, int index) { + return T(optValueToLongDouble(__testlib_indexToArgv(index))); +} + +template +T opt(std::false_type /*is_integral*/, U /*is_unsigned*/, int index) { + return opt(std::is_floating_point(), index); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + std::string value = __testlib_indexToArgv(index); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: opt by index '" + toString(index) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed argv by a given index. + */ +template +T opt(int index) { + return opt(std::is_integral(), std::is_unsigned(), index); +} + +/** + * Return the raw string value of an argv by a given index. + */ +std::string opt(int index) { + return opt(index); +} + +/** + * Return the parsed argv by a given index. If the index is bigger than + * the number of argv, return the given default_value. + */ +template +T opt(int index, const T &default_value) { + if (index >= int(__testlib_argv.size())) { + return default_value; + } + return opt(index); +} + +/** + * Return the raw string value of an argv by a given index. If the index is + * bigger than the number of argv, return the given default_value. + */ +std::string opt(int index, const std::string &default_value) { + return opt(index, default_value); +} + +template +T opt(std::false_type is_floating_point, const std::string &key); + +template<> +std::string opt(std::false_type /*is_floating_point*/, const std::string &key) { + return __testlib_keyToOpts(key); +} + +template +T opt(std::true_type /*is_integral*/, const std::string &key) { + return T(optValueToLongDouble(__testlib_keyToOpts(key))); +} + +template +T opt(std::false_type /*is_integral*/, U, const std::string &key) { + return opt(std::is_floating_point(), key); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + if (!has_opt(key)) + return false; + std::string value = __testlib_keyToOpts(key); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: key '" + compress(key) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed opt by a given key. + */ +template +T opt(const std::string &key) { + return opt(std::is_integral(), std::is_unsigned(), key); +} + +/** + * Return the raw string value of an opt by a given key + */ +std::string opt(const std::string &key) { + return opt(key); +} + +/* Scorer started. */ + +enum TestResultVerdict { + SKIPPED, + OK, + WRONG_ANSWER, + RUNTIME_ERROR, + TIME_LIMIT_EXCEEDED, + IDLENESS_LIMIT_EXCEEDED, + MEMORY_LIMIT_EXCEEDED, + COMPILATION_ERROR, + CRASHED, + FAILED +}; + +std::string serializeVerdict(TestResultVerdict verdict) { + switch (verdict) { + case SKIPPED: return "SKIPPED"; + case OK: return "OK"; + case WRONG_ANSWER: return "WRONG_ANSWER"; + case RUNTIME_ERROR: return "RUNTIME_ERROR"; + case TIME_LIMIT_EXCEEDED: return "TIME_LIMIT_EXCEEDED"; + case IDLENESS_LIMIT_EXCEEDED: return "IDLENESS_LIMIT_EXCEEDED"; + case MEMORY_LIMIT_EXCEEDED: return "MEMORY_LIMIT_EXCEEDED"; + case COMPILATION_ERROR: return "COMPILATION_ERROR"; + case CRASHED: return "CRASHED"; + case FAILED: return "FAILED"; + } + throw "Unexpected verdict"; +} + +TestResultVerdict deserializeTestResultVerdict(std::string s) { + if (s == "SKIPPED") + return SKIPPED; + else if (s == "OK") + return OK; + else if (s == "WRONG_ANSWER") + return WRONG_ANSWER; + else if (s == "RUNTIME_ERROR") + return RUNTIME_ERROR; + else if (s == "TIME_LIMIT_EXCEEDED") + return TIME_LIMIT_EXCEEDED; + else if (s == "IDLENESS_LIMIT_EXCEEDED") + return IDLENESS_LIMIT_EXCEEDED; + else if (s == "MEMORY_LIMIT_EXCEEDED") + return MEMORY_LIMIT_EXCEEDED; + else if (s == "COMPILATION_ERROR") + return COMPILATION_ERROR; + else if (s == "CRASHED") + return CRASHED; + else if (s == "FAILED") + return FAILED; + ensuref(false, "Unexpected serialized TestResultVerdict"); + // No return actually. + return FAILED; +} + +struct TestResult { + int testIndex; + std::string testset; + std::string group; + TestResultVerdict verdict; + double points; + long long timeConsumed; + long long memoryConsumed; + std::string input; + std::string output; + std::string answer; + int exitCode; + std::string checkerComment; +}; + +std::string serializePoints(double points) { + if (std::isnan(points)) + return ""; + else { + char c[64]; + sprintf(c, "%.03lf", points); + return c; + } +} + +double deserializePoints(std::string s) { + if (s.empty()) + return std::numeric_limits::quiet_NaN(); + else { + double result; + ensuref(sscanf(s.c_str(), "%lf", &result) == 1, "Invalid serialized points"); + return result; + } +} + +std::string escapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\r') + continue; + if (s[i] == '\n') { + result += "\\n"; + continue; + } + if (s[i] == '\\' || s[i] == ';') + result += '\\'; + result += s[i]; + } + return result; +} + +std::string unescapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\' && i + 1 < s.length()) { + if (s[i + 1] == 'n') { + result += '\n'; + i++; + continue; + } else if (s[i + 1] == ';' || s[i + 1] == '\\') { + result += s[i + 1]; + i++; + continue; + } + } + result += s[i]; + } + return result; +} + +std::string serializeTestResult(TestResult tr) { + std::string result; + result += std::to_string(tr.testIndex); + result += ";"; + result += escapeTestResultString(tr.testset); + result += ";"; + result += escapeTestResultString(tr.group); + result += ";"; + result += serializeVerdict(tr.verdict); + result += ";"; + result += serializePoints(tr.points); + result += ";"; + result += std::to_string(tr.timeConsumed); + result += ";"; + result += std::to_string(tr.memoryConsumed); + result += ";"; + result += escapeTestResultString(tr.input); + result += ";"; + result += escapeTestResultString(tr.output); + result += ";"; + result += escapeTestResultString(tr.answer); + result += ";"; + result += std::to_string(tr.exitCode); + result += ";"; + result += escapeTestResultString(tr.checkerComment); + return result; +} + +TestResult deserializeTestResult(std::string s) { + std::vector items; + std::string t; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\') { + t += s[i]; + if (i + 1 < s.length()) + t += s[i + 1]; + i++; + continue; + } else { + if (s[i] == ';') { + items.push_back(t); + t = ""; + } else + t += s[i]; + } + } + items.push_back(t); + + ensuref(items.size() == 12, "Invalid TestResult serialization: expected exactly 12 items"); + + TestResult tr; + size_t pos = 0; + tr.testIndex = stoi(items[pos++]); + tr.testset = unescapeTestResultString(items[pos++]); + tr.group = unescapeTestResultString(items[pos++]); + tr.verdict = deserializeTestResultVerdict(items[pos++]); + tr.points = deserializePoints(items[pos++]); + tr.timeConsumed = stoll(items[pos++]); + tr.memoryConsumed = stoll(items[pos++]); + tr.input = unescapeTestResultString(items[pos++]); + tr.output = unescapeTestResultString(items[pos++]); + tr.answer = unescapeTestResultString(items[pos++]); + tr.exitCode = stoi(items[pos++]); + tr.checkerComment = unescapeTestResultString(items[pos++]); + + return tr; +} + +std::vector readTestResults(std::string fileName) { + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + ensuref(stream.is_open(), "Can't read test results file '%s'", fileName.c_str()); + std::vector result; + std::string line; + while (getline(stream, line)) + if (!line.empty()) + result.push_back(deserializeTestResult(line)); + stream.close(); + return result; +} + +std::function)> __testlib_scorer; + +struct TestlibScorerGuard { + ~TestlibScorerGuard() { + if (testlibMode == _scorer) { + std::vector testResults; + while (!inf.eof()) { + std::string line = inf.readLine(); + if (!line.empty()) + testResults.push_back(deserializeTestResult(line)); + } + inf.readEof(); + printf("%.3f\n", __testlib_scorer(testResults)); + } + } +} __testlib_scorer_guard; + +void registerScorer(int argc, char *argv[], std::function)> scorer) { + /* Supress unused. */ + (void)(argc), (void)(argv); + + __testlib_ensuresPreconditions(); + + testlibMode = _scorer; + __testlib_set_binary(stdin); + + inf.init(stdin, _input); + inf.strict = false; + + __testlib_scorer = scorer; +} + +/* Scorer ended. */ + +/** + * Return the parsed opt by a given key. If no opts with the given key are + * found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +template +T opt(const std::string &key, const T &default_value) { + if (!has_opt(key)) { + return default_value; + } + return opt(key); +} + +/** + * Return the raw string value of an opt by a given key. If no opts with the + * given key are found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +std::string opt(const std::string &key, const std::string &default_value) { + return opt(key, default_value); +} + +/** + * Check if all opts are used. If not, __testlib_fail is called. + * Should be used after calling all opt() function calls. + * + * This function is useful when opt() with default_value for checking typos + * in the opt's key. + */ +void ensureNoUnusedOpts() { + for (const auto &opt: __testlib_opts) { + if (!opt.second.used) { + __testlib_fail(format("Opts: unused key '%s'", compress(opt.first).c_str())); + } + } +} + +void suppressEnsureNoUnusedOpts() { + __testlib_ensureNoUnusedOptsSuppressed = true; +} + +void TestlibFinalizeGuard::autoEnsureNoUnusedOpts() { + if (__testlib_ensureNoUnusedOptsFlag && !__testlib_ensureNoUnusedOptsSuppressed) { + ensureNoUnusedOpts(); + } +} + +TestlibFinalizeGuard testlibFinalizeGuard; + +#endif +#endif diff --git a/ICPC/swerc2022_D/data.zip b/ICPC/swerc2022_D/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..0260864408463f694f9c3e4694e3a1531784d1e4 --- /dev/null +++ b/ICPC/swerc2022_D/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db4b1befecc7b130b1294a18a996a6f16a43d9e4056d74bc35b7a26e4cad8865 +size 217165 diff --git a/ICPC/swerc2022_D/init.yml b/ICPC/swerc2022_D/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a67fdab749527b2242c9a980b6416a3f9e2c3bb4 --- /dev/null +++ b/ICPC/swerc2022_D/init.yml @@ -0,0 +1,173 @@ +archive: data.zip +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 +- in: 31.in + out: 31.ans + points: 1 +- in: 32.in + out: 32.ans + points: 1 +- in: 33.in + out: 33.ans + points: 1 +- in: 34.in + out: 34.ans + points: 1 +- in: 35.in + out: 35.ans + points: 1 +- in: 36.in + out: 36.ans + points: 1 +- in: 37.in + out: 37.ans + points: 1 +- in: 38.in + out: 38.ans + points: 1 +- in: 39.in + out: 39.ans + points: 1 +- in: 40.in + out: 40.ans + points: 1 +- in: 41.in + out: 41.ans + points: 1 +- in: 42.in + out: 42.ans + points: 1 +- in: 43.in + out: 43.ans + points: 1 +- in: 44.in + out: 44.ans + points: 1 +- in: 45.in + out: 45.ans + points: 1 +- in: 46.in + out: 46.ans + points: 1 +- in: 47.in + out: 47.ans + points: 1 +- in: 48.in + out: 48.ans + points: 1 +- in: 49.in + out: 49.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 50.in + out: 50.ans + points: 1 +- in: 51.in + out: 51.ans + points: 1 +- in: 52.in + out: 52.ans + points: 1 +- in: 53.in + out: 53.ans + points: 1 +- in: 54.in + out: 54.ans + points: 1 +- in: 55.in + out: 55.ans + points: 1 +- in: 56.in + out: 56.ans + points: 1 +- in: 57.in + out: 57.ans + points: 1 +- in: 58.in + out: 58.ans + points: 1 +- in: 59.in + out: 59.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 60.in + out: 60.ans + points: 1 +- in: 61.in + out: 61.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_E/data.zip b/ICPC/swerc2022_E/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..c87064e725700a56bf51827beecf97870f5d4e52 --- /dev/null +++ b/ICPC/swerc2022_E/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d857e3af209af4002717b7c9b790154297c0653964d27cd66a8d837d4bd74d9e +size 23836 diff --git a/ICPC/swerc2022_E/init.yml b/ICPC/swerc2022_E/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7e018a0815be0d1ed18041e08677ccffd84f5d92 --- /dev/null +++ b/ICPC/swerc2022_E/init.yml @@ -0,0 +1,153 @@ +archive: data.zip +interactive: + files: + - output_validators/interactor.cpp + - output_validators/testlib.h + lang: CPP17 + type: default +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 +- in: 31.in + out: 31.ans + points: 1 +- in: 32.in + out: 32.ans + points: 1 +- in: 33.in + out: 33.ans + points: 1 +- in: 34.in + out: 34.ans + points: 1 +- in: 35.in + out: 35.ans + points: 1 +- in: 36.in + out: 36.ans + points: 1 +- in: 37.in + out: 37.ans + points: 1 +- in: 38.in + out: 38.ans + points: 1 +- in: 39.in + out: 39.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 40.in + out: 40.ans + points: 1 +- in: 41.in + out: 41.ans + points: 1 +- in: 42.in + out: 42.ans + points: 1 +- in: 43.in + out: 43.ans + points: 1 +- in: 44.in + out: 44.ans + points: 1 +- in: 45.in + out: 45.ans + points: 1 +- in: 46.in + out: 46.ans + points: 1 +- in: 47.in + out: 47.ans + points: 1 +- in: 48.in + out: 48.ans + points: 1 +- in: 49.in + out: 49.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 50.in + out: 50.ans + points: 1 +- in: 51.in + out: 51.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 +unbuffered: false diff --git a/ICPC/swerc2022_E/output_validators/interactor.cpp b/ICPC/swerc2022_E/output_validators/interactor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a0f124084e03a613b74f0e85b64b19ae825f3e55 --- /dev/null +++ b/ICPC/swerc2022_E/output_validators/interactor.cpp @@ -0,0 +1,185 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "testlib.h" +#include + +using namespace std; + +using ll = long long; + +const ll infty = 1e18; + +ll area(ll x1, ll x2, ll x3, ll y1, ll y2, ll y3) { + return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1); +} + +int find_optimal_position(int n, const vector& xx, const vector& yy, + const vector& alive) { + ll mn = infty; + int opt = -1; + int prev1 = n - 1; + while (not alive[prev1]) --prev1; + int prev2 = prev1 - 1; + while (not alive[prev2]) --prev2; + + for (int i = 0; i < n; ++i) { + if (not alive[i]) continue; + ll a = area(xx[prev2], xx[prev1], xx[i], yy[prev2], yy[prev1], yy[i]); + if (a < mn) { + mn = a; + opt = prev1; + } + prev2 = prev1; + prev1 = i; + } + return opt; +} + +int find_2nd_optimal_position(int n, const vector& xx, const vector& yy, + const vector& alive) { + ll mn1 = infty, mn2 = infty; + int opt1 = -1, opt2 = -1; + + int prev1 = n - 1; + while (not alive[prev1]) --prev1; + int prev2 = prev1 - 1; + while (not alive[prev2]) --prev2; + + for (int i = 0; i < n; ++i) { + if (not alive[i]) continue; + ll a = area(xx[prev2], xx[prev1], xx[i], yy[prev2], yy[prev1], yy[i]); + if (a < mn1) { + mn2 = mn1; + opt2 = opt1; + mn1 = a; + opt1 = prev1; + } else if (a < mn2) { + mn2 = a; + opt2 = prev1; + } + prev2 = prev1; + prev1 = i; + } + return opt2; +} + +int find_random_position(int n, const vector& alive) { + vector pos; + for (int i = 0; i < n; ++i) { + if (alive[i]) pos.push_back(i); + } + int q = pos.size(); + return pos[rnd.next(q)]; +} + +int find_position(int n, const vector& xx, const vector& yy, + const vector& alive, int strategy) { + if (strategy == 0) return find_optimal_position(n, xx, yy, alive); + if (strategy == 1) return find_2nd_optimal_position(n, xx, yy, alive); + if (strategy == 2) return find_random_position(n, alive); + return -1; +} + +ll find_area(int p, int n, const vector& xx, const vector& yy, + const vector& alive) { + int nxt = (p + 1) % n; + while (not alive[nxt]) nxt = (nxt + 1) % n; + int prv = (p + n - 1) % n; + while (not alive[prv]) prv = (prv + n - 1) % n; + return area(xx[prv], xx[p], xx[nxt], yy[prv], yy[p], yy[nxt]); +} + +int main(int argc, char* argv[]) { + setName("Greedy Interactor"); + registerInteraction(argc, argv); + + rnd.setSeed(42); + + int n = inf.readInt(); + vector xx(n), yy(n); + + cout << n << endl; + for (int i = 0; i < n; ++i) { + xx[i] = inf.readLong(); + yy[i] = inf.readLong(); + cout << xx[i] << ' ' << yy[i] << endl; + } + + int strategy = 0; // optimal + if (n == 44 or n == 45) { + strategy = 1; // second optimal + } + if (n == 78 or n == 79) { + strategy = 2; // random + } + + string he = ouf.readToken(); + tout << "< " << he << endl; + + vector alive(n, true); + + ll our_area = 0, their_area = 0; + + int cur = n; + bool our_turn; + + if (he == "Alberto") { + our_turn = false; + } else if (he == "Beatrice") { + our_turn = true; + } else { + quitf(_wa, "unrecognised player name"); + } + + while (cur > 2) { + if (our_turn) { + int p = find_position(n, xx, yy, alive, strategy); + our_area += find_area(p, n, xx, yy, alive); + + cout << p + 1 << endl; + tout << "> " << p + 1 << endl; + alive[p] = false; + } else { + int p = ouf.readInt(1, n, "chosen vertex"); + tout << "< " << p << endl; + --p; + quitif(!alive[p], _wa, "vertex already chosen"); + their_area += find_area(p, n, xx, yy, alive); + alive[p] = false; + } + + our_turn = !our_turn; + --cur; + } + + if (their_area <= our_area) { + quitf(_ok, "they win, their_area %lld <= our_area %lld. Used strategy %d", their_area, our_area, strategy); + } else { + quitf(_wa, "they lose, their_area %lld > our_area %lld. Used strategy %d", their_area, our_area, strategy); + } +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], "/dev/null", argv[2], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2022_E/output_validators/testlib.h b/ICPC/swerc2022_E/output_validators/testlib.h new file mode 100644 index 0000000000000000000000000000000000000000..69baa1f48b5d86daa58cade43c18b382abb03587 --- /dev/null +++ b/ICPC/swerc2022_E/output_validators/testlib.h @@ -0,0 +1,5893 @@ +// Modified by a script to work with DOMjudge. +// Differences with the standard testlib.h: +// - The values of some exit codes. +// - The functions registerInteraction and registerTestlibCmd. + +/* + * It is strictly recommended to include "testlib.h" before any other include + * in your code. In this case testlib overrides compiler specific "random()". + * + * If you can't compile your code and compiler outputs something about + * ambiguous call of "random_shuffle", "rand" or "srand" it means that + * you shouldn't use them. Use "shuffle", and "rnd.next()" instead of them + * because these calls produce stable result for any C++ compiler. Read + * sample generator sources for clarification. + * + * Please read the documentation for class "random_t" and use "rnd" instance in + * generators. Probably, these sample calls will be usefull for you: + * rnd.next(); rnd.next(100); rnd.next(1, 2); + * rnd.next(3.14); rnd.next("[a-z]{1,100}"). + * + * Also read about wnext() to generate off-center random distribution. + * + * See https://github.com/MikeMirzayanov/testlib/ to get latest version or bug tracker. + */ + +#ifndef _TESTLIB_H_ +#define _TESTLIB_H_ + +/* + * Copyright (c) 2005-2022 + */ + +#define VERSION "0.9.40-SNAPSHOT" + +/* + * Mike Mirzayanov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* NOTE: This file contains testlib library for C++. + * + * Check, using testlib running format: + * check.exe [ [-appes]], + * If result file is specified it will contain results. + * + * Validator, using testlib running format: + * validator.exe < input.txt, + * It will return non-zero exit code and writes message to standard output. + * + * Generator, using testlib running format: + * gen.exe [parameter-1] [parameter-2] [... paramerter-n] + * You can write generated test(s) into standard output or into the file(s). + * + * Interactor, using testlib running format: + * interactor.exe [ [ [-appes]]], + * Reads test from inf (mapped to args[1]), writes result to tout (mapped to argv[2], + * can be judged by checker later), reads program output from ouf (mapped to stdin), + * writes output to program via stdout (use cout, printf, etc). + */ + +const char *latestFeatures[] = { + "Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators", + "Added opt defaults via opt(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt()).", + "For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values", + "Added quitpi(points_info, message) function to return with _points exit code 7 and given points_info", + "rnd.partition(size, sum[, min_part=1]) returns random (unsorted) partition which is a representation of the given `sum` as a sum of `size` positive integers (or >=min_part if specified)", + "rnd.distinct(size, n) and rnd.distinct(size, from, to)", + "opt(\"some_missing_key\") returns false now", + "has_opt(key)", + "Abort validator on validator.testset()/validator.group() if registered without using command line", + "Print integer range violations in a human readable way like `violates the range [1, 10^9]`", + "Opts supported: use them like n = opt(\"n\"), in a command line you can use an exponential notation", + "Reformatted", + "Use setTestCase(i) or unsetTestCase() to support test cases (you can use it in any type of program: generator, interactor, validator or checker)", + "Fixed issue #87: readStrictDouble accepts \"-0.00\"", + "Fixed issue #83: added InStream::quitif(condition, ...)", + "Fixed issue #79: fixed missed guard against repeated header include", + "Fixed issue #80: fixed UB in case of huge quitf message", + "Fixed issue #84: added readXs(size, indexBase = 1)", + "Fixed stringstream repeated usage issue", + "Fixed compilation in g++ (for std=c++03)", + "Batch of println functions (support collections, iterator ranges)", + "Introduced rnd.perm(size, first = 0) to generate a `first`-indexed permutation", + "Allow any whitespace in readInts-like functions for non-validators", + "Ignore 4+ command line arguments ifdef EJUDGE", + "Speed up of vtos", + "Show line number in validators in case of incorrect format", + "Truncate huge checker/validator/interactor message", + "Fixed issue with readTokenTo of very long tokens, now aborts with _pe/_fail depending of a stream type", + "Introduced InStream::ensure/ensuref checking a condition, returns wa/fail depending of a stream type", + "Fixed compilation in VS 2015+", + "Introduced space-separated read functions: readWords/readTokens, multilines read functions: readStrings/readLines", + "Introduced space-separated read functions: readInts/readIntegers/readLongs/readUnsignedLongs/readDoubles/readReals/readStrictDoubles/readStrictReals", + "Introduced split/tokenize functions to separate string by given char", + "Introduced InStream::readUnsignedLong and InStream::readLong with unsigned long long paramerters", + "Supported --testOverviewLogFileName for validator: bounds hits + features", + "Fixed UB (sequence points) in random_t", + "POINTS_EXIT_CODE returned back to 7 (instead of 0)", + "Removed disable buffers for interactive problems, because it works unexpectedly in wine", + "InStream over string: constructor of InStream from base InStream to inherit policies and std::string", + "Added expectedButFound quit function, examples: expectedButFound(_wa, 10, 20), expectedButFound(_fail, ja, pa, \"[n=%d,m=%d]\", n, m)", + "Fixed incorrect interval parsing in patterns", + "Use registerGen(argc, argv, 1) to develop new generator, use registerGen(argc, argv, 0) to compile old generators (originally created for testlib under 0.8.7)", + "Introduced disableFinalizeGuard() to switch off finalization checkings", + "Use join() functions to format a range of items as a single string (separated by spaces or other separators)", + "Use -DENABLE_UNEXPECTED_EOF to enable special exit code (by default, 8) in case of unexpected eof. It is good idea to use it in interactors", + "Use -DUSE_RND_AS_BEFORE_087 to compile in compatibility mode with random behavior of versions before 0.8.7", + "Fixed bug with nan in stringToDouble", + "Fixed issue around overloads for size_t on x64", + "Added attribute 'points' to the XML output in case of result=_points", + "Exit codes can be customized via macros, e.g. -DPE_EXIT_CODE=14", + "Introduced InStream function readWordTo/readTokenTo/readStringTo/readLineTo for faster reading", + "Introduced global functions: format(), englishEnding(), upperCase(), lowerCase(), compress()", + "Manual buffer in InStreams, some IO speed improvements", + "Introduced quitif(bool, const char* pattern, ...) which delegates to quitf() in case of first argument is true", + "Introduced guard against missed quitf() in checker or readEof() in validators", + "Supported readStrictReal/readStrictDouble - to use in validators to check strictly float numbers", + "Supported registerInteraction(argc, argv)", + "Print checker message to the stderr instead of stdout", + "Supported TResult _points to output calculated score, use quitp(...) functions", + "Fixed to be compilable on Mac", + "PC_BASE_EXIT_CODE=50 in case of defined TESTSYS", + "Fixed issues 19-21, added __attribute__ format printf", + "Some bug fixes", + "ouf.readInt(1, 100) and similar calls return WA", + "Modified random_t to avoid integer overflow", + "Truncated checker output [patch by Stepan Gatilov]", + "Renamed class random -> class random_t", + "Supported name parameter for read-and-validation methods, like readInt(1, 2, \"n\")", + "Fixed bug in readDouble()", + "Improved ensuref(), fixed nextLine to work in case of EOF, added startTest()", + "Supported \"partially correct\", example: quitf(_pc(13), \"result=%d\", result)", + "Added shuffle(begin, end), use it instead of random_shuffle(begin, end)", + "Added readLine(const string& ptrn), fixed the logic of readLine() in the validation mode", + "Package extended with samples of generators and validators", + "Written the documentation for classes and public methods in testlib.h", + "Implemented random routine to support generators, use registerGen() to switch it on", + "Implemented strict mode to validate tests, use registerValidation() to switch it on", + "Now ncmp.cpp and wcmp.cpp are return WA if answer is suffix or prefix of the output", + "Added InStream::readLong() and removed InStream::readLongint()", + "Now no footer added to each report by default (use directive FOOTER to switch on)", + "Now every checker has a name, use setName(const char* format, ...) to set it", + "Now it is compatible with TTS (by Kittens Computing)", + "Added \'ensure(condition, message = \"\")\' feature, it works like assert()", + "Fixed compatibility with MS C++ 7.1", + "Added footer with exit code information", + "Added compatibility with EJUDGE (compile with EJUDGE directive)", + "Added compatibility with Contester (compile with CONTESTER directive)" +}; + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NO_VA_START_VALIDATION +#endif + +/* Overrides random() for Borland C++. */ +#define random __random_deprecated +#include +#include +#include +#include +#undef random + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +# include +#endif + +#if (_WIN32 || __WIN32__ || __WIN32 || _WIN64 || __WIN64__ || __WIN64 || WINNT || __WINNT || __WINNT__ || __CYGWIN__) +# if !defined(_MSC_VER) || _MSC_VER > 1400 +# define NOMINMAX 1 +# include +# else +# define WORD unsigned short +# include +# endif +# include +# define ON_WINDOWS +# if defined(_MSC_VER) && _MSC_VER > 1400 +# pragma warning( disable : 4127 ) +# pragma warning( disable : 4146 ) +# pragma warning( disable : 4458 ) +# endif +#else +# define WORD unsigned short +# include +#endif + +#if defined(FOR_WINDOWS) && defined(FOR_LINUX) +#error Only one target system is allowed +#endif + +#ifndef LLONG_MIN +#define LLONG_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX (18446744073709551615) +#endif + +#define LF ((char)10) +#define CR ((char)13) +#define TAB ((char)9) +#define SPACE ((char)' ') +#define EOFC (255) + +#ifndef OK_EXIT_CODE +# ifdef CONTESTER +# define OK_EXIT_CODE 42 +# else +# define OK_EXIT_CODE 42 +# endif +#endif + +#ifndef WA_EXIT_CODE +# ifdef EJUDGE +# define WA_EXIT_CODE 43 +# elif defined(CONTESTER) +# define WA_EXIT_CODE 43 +# else +# define WA_EXIT_CODE 43 +# endif +#endif + +#ifndef PE_EXIT_CODE +# ifdef EJUDGE +# define PE_EXIT_CODE 43 +# elif defined(CONTESTER) +# define PE_EXIT_CODE 43 +# else +# define PE_EXIT_CODE 43 +# endif +#endif + +#ifndef FAIL_EXIT_CODE +# ifdef EJUDGE +# define FAIL_EXIT_CODE 6 +# elif defined(CONTESTER) +# define FAIL_EXIT_CODE 0xA3 +# else +# define FAIL_EXIT_CODE 3 +# endif +#endif + +#ifndef DIRT_EXIT_CODE +# ifdef EJUDGE +# define DIRT_EXIT_CODE 43 +# else +# define DIRT_EXIT_CODE 43 +# endif +#endif + +#ifndef POINTS_EXIT_CODE +# define POINTS_EXIT_CODE 7 +#endif + +#ifndef UNEXPECTED_EOF_EXIT_CODE +# define UNEXPECTED_EOF_EXIT_CODE 43 +#endif + +#ifndef PC_BASE_EXIT_CODE +# ifdef TESTSYS +# define PC_BASE_EXIT_CODE 50 +# else +# define PC_BASE_EXIT_CODE 0 +# endif +#endif + +#ifdef __GNUC__ +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] __attribute__((unused)) +#else +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] +#endif + +#ifdef ON_WINDOWS +#define I64 "%I64d" +#define U64 "%I64u" +#else +#define I64 "%lld" +#define U64 "%llu" +#endif + +#ifdef _MSC_VER +# define NORETURN __declspec(noreturn) +#elif defined __GNUC__ +# define NORETURN __attribute__ ((noreturn)) +#else +# define NORETURN +#endif + +static char __testlib_format_buffer[16777216]; +static int __testlib_format_buffer_usage_count = 0; + +#define FMT_TO_RESULT(fmt, cstr, result) std::string result; \ + if (__testlib_format_buffer_usage_count != 0) \ + __testlib_fail("FMT_TO_RESULT::__testlib_format_buffer_usage_count != 0"); \ + __testlib_format_buffer_usage_count++; \ + va_list ap; \ + va_start(ap, fmt); \ + vsnprintf(__testlib_format_buffer, sizeof(__testlib_format_buffer), cstr, ap); \ + va_end(ap); \ + __testlib_format_buffer[sizeof(__testlib_format_buffer) - 1] = 0; \ + result = std::string(__testlib_format_buffer); \ + __testlib_format_buffer_usage_count--; \ + +const long long __TESTLIB_LONGLONG_MAX = 9223372036854775807LL; +const int __TESTLIB_MAX_TEST_CASE = 1073741823; + +int __testlib_exitCode; + +bool __testlib_hasTestCase; +int __testlib_testCase = -1; + +void setTestCase(int testCase); + +void unsetTestCase() { + __testlib_hasTestCase = false; + __testlib_testCase = -1; +} + +NORETURN static void __testlib_fail(const std::string &message); + +template +static inline T __testlib_abs(const T &x) { + return x > 0 ? x : -x; +} + +template +static inline T __testlib_min(const T &a, const T &b) { + return a < b ? a : b; +} + +template +static inline T __testlib_max(const T &a, const T &b) { + return a > b ? a : b; +} + +template +static inline T __testlib_crop(T value, T a, T b) { + return __testlib_min(__testlib_max(value, a), --b); +} + +static inline double __testlib_crop(double value, double a, double b) { + value = __testlib_min(__testlib_max(value, a), b); + if (value >= b) + value = std::nexttoward(b, a); + return value; +} + +static bool __testlib_prelimIsNaN(double r) { + volatile double ra = r; +#ifndef __BORLANDC__ + return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); +#else + return std::_isnan(ra); +#endif +} + +static std::string removeDoubleTrailingZeroes(std::string value) { + while (!value.empty() && value[value.length() - 1] == '0' && value.find('.') != std::string::npos) + value = value.substr(0, value.length() - 1); + if (!value.empty() && value[value.length() - 1] == '.') + return value + '0'; + else + return value; +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +std::string format(const char *fmt, ...) { + FMT_TO_RESULT(fmt, fmt, result); + return result; +} + +std::string format(const std::string fmt, ...) { + FMT_TO_RESULT(fmt, fmt.c_str(), result); + return result; +} + +static std::string __testlib_part(const std::string &s); + +static bool __testlib_isNaN(double r) { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); + volatile double ra = r; + long long llr1, llr2; + std::memcpy((void *) &llr1, (void *) &ra, sizeof(double)); + ra = -ra; + std::memcpy((void *) &llr2, (void *) &ra, sizeof(double)); + long long llnan = 0xFFF8000000000000LL; + return __testlib_prelimIsNaN(r) || llnan == llr1 || llnan == llr2; +} + +static double __testlib_nan() { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); +#ifndef NAN + long long llnan = 0xFFF8000000000000LL; + double nan; + std::memcpy(&nan, &llnan, sizeof(double)); + return nan; +#else + return NAN; +#endif +} + +static bool __testlib_isInfinite(double r) { + volatile double ra = r; + return (ra > 1E300 || ra < -1E300); +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline bool doubleCompare(double expected, double result, double MAX_DOUBLE_ERROR) { + MAX_DOUBLE_ERROR += 1E-15; + if (__testlib_isNaN(expected)) { + return __testlib_isNaN(result); + } else if (__testlib_isInfinite(expected)) { + if (expected > 0) { + return result > 0 && __testlib_isInfinite(result); + } else { + return result < 0 && __testlib_isInfinite(result); + } + } else if (__testlib_isNaN(result) || __testlib_isInfinite(result)) { + return false; + } else if (__testlib_abs(result - expected) <= MAX_DOUBLE_ERROR) { + return true; + } else { + double minv = __testlib_min(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + double maxv = __testlib_max(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + return result >= minv && result <= maxv; + } +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline double doubleDelta(double expected, double result) { + double absolute = __testlib_abs(result - expected); + + if (__testlib_abs(expected) > 1E-9) { + double relative = __testlib_abs(absolute / expected); + return __testlib_min(absolute, relative); + } else + return absolute; +} + +/** It does nothing on non-windows and files differ from stdin/stdout/stderr. */ +static void __testlib_set_binary(std::FILE *file) { + if (NULL != file) { +#ifdef ON_WINDOWS +# ifdef _O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(_setmode(STDIN_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdin), _O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(_setmode(STDOUT_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdout), _O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(_setmode(STDERR_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stderr), _O_BINARY)); +# endif +# elif O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(setmode(STDIN_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdin), O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(setmode(STDOUT_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdout), O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(setmode(STDERR_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stderr), O_BINARY)); +# endif +# endif +#endif + } +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +static std::string vtos(const T &t, std::true_type) { + if (t == 0) + return "0"; + else { + T n(t); + bool negative = n < 0; + std::string s; + while (n != 0) { + T digit = n % 10; + if (digit < 0) + digit = -digit; + s += char('0' + digit); + n /= 10; + } + std::reverse(s.begin(), s.end()); + return negative ? "-" + s : s; + } +} + +template +static std::string vtos(const T &t, std::false_type) { + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string vtos(const T &t) { + return vtos(t, std::is_integral()); +} + +/* signed case. */ +template +static std::string toHumanReadableString(const T &n, std::false_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else if (n_ == -1) + return "-10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +/* unsigned case. */ +template +static std::string toHumanReadableString(const T &n, std::true_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +template +static std::string toHumanReadableString(const T &n) { + return toHumanReadableString(n, std::is_unsigned()); +} +#else +template +static std::string vtos(const T& t) +{ + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string toHumanReadableString(const T &n) { + return vtos(n); +} +#endif + +template +static std::string toString(const T &t) { + return vtos(t); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +/* opts */ +void prepareOpts(int argc, char* argv[]); +#endif + +/* + * Very simple regex-like pattern. + * It used for two purposes: validation and generation. + * + * For example, pattern("[a-z]{1,5}").next(rnd) will return + * random string from lowercase latin letters with length + * from 1 to 5. It is easier to call rnd.next("[a-z]{1,5}") + * for the same effect. + * + * Another samples: + * "mike|john" will generate (match) "mike" or "john"; + * "-?[1-9][0-9]{0,3}" will generate (match) non-zero integers from -9999 to 9999; + * "id-([ac]|b{2})" will generate (match) "id-a", "id-bb", "id-c"; + * "[^0-9]*" will match sequences (empty or non-empty) without digits, you can't + * use it for generations. + * + * You can't use pattern for generation if it contains meta-symbol '*'. Also it + * is not recommended to use it for char-sets with meta-symbol '^' like [^a-z]. + * + * For matching very simple greedy algorithm is used. For example, pattern + * "[0-9]?1" will not match "1", because of greedy nature of matching. + * Alternations (meta-symbols "|") are processed with brute-force algorithm, so + * do not use many alternations in one expression. + * + * If you want to use one expression many times it is better to compile it into + * a single pattern like "pattern p("[a-z]+")". Later you can use + * "p.matches(std::string s)" or "p.next(random_t& rd)" to check matching or generate + * new string by pattern. + * + * Simpler way to read token and check it for pattern matching is "inf.readToken("[a-z]+")". + * + * All spaces are ignored in regex, unless escaped with \. For example, ouf.readLine("NO SOLUTION") + * will expect "NOSOLUTION", the correct call should be ouf.readLine("NO\\ SOLUTION") or + * ouf.readLine(R"(NO\ SOLUTION)") if you prefer raw string literals from C++11. + */ +class random_t; + +class pattern { +public: + /* Create pattern instance by string. */ + pattern(std::string s); + + /* Generate new string by pattern and given random_t. */ + std::string next(random_t &rnd) const; + + /* Checks if given string match the pattern. */ + bool matches(const std::string &s) const; + + /* Returns source string of the pattern. */ + std::string src() const; + +private: + bool matches(const std::string &s, size_t pos) const; + + std::string s; + std::vector children; + std::vector chars; + int from; + int to; +}; + +/* + * Use random_t instances to generate random values. It is preffered + * way to use randoms instead of rand() function or self-written + * randoms. + * + * Testlib defines global variable "rnd" of random_t class. + * Use registerGen(argc, argv, 1) to setup random_t seed be command + * line (to use latest random generator version). + * + * Random generates uniformly distributed values if another strategy is + * not specified explicitly. + */ +class random_t { +private: + unsigned long long seed; + static const unsigned long long multiplier; + static const unsigned long long addend; + static const unsigned long long mask; + static const int lim; + + long long nextBits(int bits) { + if (bits <= 48) { + seed = (seed * multiplier + addend) & mask; + return (long long) (seed >> (48 - bits)); + } else { + if (bits > 63) + __testlib_fail("random_t::nextBits(int bits): n must be less than 64"); + + int lowerBitCount = (random_t::version == 0 ? 31 : 32); + + long long left = (nextBits(31) << 32); + long long right = nextBits(lowerBitCount); + + return left ^ right; + } + } + +public: + static int version; + + /* New random_t with fixed seed. */ + random_t() + : seed(3905348978240129619LL) { + } + + /* Sets seed by command line. */ + void setSeed(int argc, char *argv[]) { + random_t p; + + seed = 3905348978240129619LL; + for (int i = 1; i < argc; i++) { + std::size_t le = std::strlen(argv[i]); + for (std::size_t j = 0; j < le; j++) + seed = seed * multiplier + (unsigned int) (argv[i][j]) + addend; + seed += multiplier / addend; + } + + seed = seed & mask; + } + + /* Sets seed by given value. */ + void setSeed(long long _seed) { + _seed = (_seed ^ multiplier) & mask; + seed = _seed; + } + +#ifndef __BORLANDC__ + + /* Random string value by given pattern (see pattern documentation). */ + std::string next(const std::string &ptrn) { + pattern p(ptrn); + return p.next(*this); + } + +#else + /* Random string value by given pattern (see pattern documentation). */ + std::string next(std::string ptrn) + { + pattern p(ptrn); + return p.next(*this); + } +#endif + + /* Random value in range [0, n-1]. */ + int next(int n) { + if (n <= 0) + __testlib_fail("random_t::next(int n): n must be positive"); + + if ((n & -n) == n) // n is a power of 2 + return (int) ((n * (long long) nextBits(31)) >> 31); + + const long long limit = INT_MAX / n * n; + + long long bits; + do { + bits = nextBits(31); + } while (bits >= limit); + + return int(bits % n); + } + + /* Random value in range [0, n-1]. */ + unsigned int next(unsigned int n) { + if (n >= INT_MAX) + __testlib_fail("random_t::next(unsigned int n): n must be less INT_MAX"); + return (unsigned int) next(int(n)); + } + + /* Random value in range [0, n-1]. */ + long long next(long long n) { + if (n <= 0) + __testlib_fail("random_t::next(long long n): n must be positive"); + + const long long limit = __TESTLIB_LONGLONG_MAX / n * n; + + long long bits; + do { + bits = nextBits(63); + } while (bits >= limit); + + return bits % n; + } + + /* Random value in range [0, n-1]. */ + unsigned long long next(unsigned long long n) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::next(unsigned long long n): n must be less LONGLONG_MAX"); + return (unsigned long long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + long next(long n) { + return (long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + unsigned long next(unsigned long n) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX"); + return (unsigned long) next((unsigned long long) (n)); + } + + /* Returns random value in range [from,to]. */ + int next(int from, int to) { + return int(next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + unsigned int next(unsigned int from, unsigned int to) { + return (unsigned int) (next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + long long next(long long from, long long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long long next(unsigned long long from, unsigned long long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long long from, unsigned long long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + long next(long from, long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long next(unsigned long from, unsigned long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long from, unsigned long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Random double value in range [0, 1). */ + double next() { + long long left = ((long long) (nextBits(26)) << 27); + long long right = nextBits(27); + return __testlib_crop((double) (left + right) / (double) (1LL << 53), 0.0, 1.0); + } + + /* Random double value in range [0, n). */ + double next(double n) { + if (n <= 0.0) + __testlib_fail("random_t::next(double): n should be positive"); + return __testlib_crop(n * next(), 0.0, n); + } + + /* Random double value in range [from, to). */ + double next(double from, double to) { + if (from >= to) + __testlib_fail("random_t::next(double from, double to): from should be strictly less than to"); + return next(to - from) + from; + } + + /* Returns random element from container. */ + template + typename Container::value_type any(const Container &c) { + int size = int(c.size()); + if (size <= 0) + __testlib_fail("random_t::any(const Container& c): c.size() must be positive"); + return *(c.begin() + next(size)); + } + + /* Returns random element from iterator range. */ + template + typename Iter::value_type any(const Iter &begin, const Iter &end) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length"); + return *(begin + next(size)); + } + + /* Random string value by given pattern (see pattern documentation). */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + std::string next(const char *format, ...) { + FMT_TO_RESULT(format, format, ptrn); + return next(ptrn); + } + + /* + * Weighted next. If type == 0 than it is usual "next()". + * + * If type = 1, than it returns "max(next(), next())" + * (the number of "max" functions equals to "type"). + * + * If type < 0, than "max" function replaces with "min". + */ + int wnext(int n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(int n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + int result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((int) (double(n) * p), 0, n); + } + } + + /* See wnext(int, int). It uses the same algorithms. */ + long long wnext(long long n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(long long n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + long long result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((long long) (double(n) * p), 0LL, n); + } + } + + /* Returns value in [0, n). See wnext(int, int). It uses the same algorithms. */ + double wnext(double n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(double n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + double result = next(); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next()); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next()); + + return n * result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop(n * p, 0.0, n); + } + } + + /* Returns value in [0, 1). See wnext(int, int). It uses the same algorithms. */ + double wnext(int type) { + return wnext(1.0, type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned int wnext(unsigned int n, int type) { + if (n >= INT_MAX) + __testlib_fail("random_t::wnext(unsigned int n, int type): n must be less INT_MAX"); + return (unsigned int) wnext(int(n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long long wnext(unsigned long long n, int type) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long long n, int type): n must be less LONGLONG_MAX"); + + return (unsigned long long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + long wnext(long n, int type) { + return (long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long wnext(unsigned long n, int type) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long n, int type): n must be less LONG_MAX"); + + return (unsigned long) wnext((unsigned long long) (n), type); + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(int from, int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(int from, int to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(unsigned int from, unsigned int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned int from, unsigned int to, int type): from can't not exceed to"); + return int(wnext(to - from + 1, type) + from); + } + + /* Returns weighted random value in range [from, to]. */ + long long wnext(long long from, long long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long long from, long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long long wnext(unsigned long long from, unsigned long long to, int type) { + if (from > to) + __testlib_fail( + "random_t::wnext(unsigned long long from, unsigned long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + long wnext(long from, long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long from, long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long wnext(unsigned long from, unsigned long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned long from, unsigned long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random double value in range [from, to). */ + double wnext(double from, double to, int type) { + if (from >= to) + __testlib_fail("random_t::wnext(double from, double to, int type): from should be strictly less than to"); + return wnext(to - from, type) + from; + } + + /* Returns weighted random element from container. */ + template + typename Container::value_type wany(const Container &c, int type) { + size_t size = c.size(); + if (size <= 0) + __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive"); + return *(c.begin() + wnext(size, type)); + } + + /* Returns weighted random element from iterator range. */ + template + typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail( + "random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length"); + return *(begin + wnext(size, type)); + } + + /* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/ + template + std::vector perm(T size, E first) { + if (size < 0) + __testlib_fail("random_t::perm(T size, E first = 0): size must non-negative"); + else if (size == 0) + return std::vector(); + std::vector p(size); + E current = first; + for (T i = 0; i < size; i++) + p[i] = current++; + if (size > 1) + for (T i = 1; i < size; i++) + std::swap(p[i], p[next(i + 1)]); + return p; + } + + /* Returns random permutation of the given size (values are between 0 and size-1)*/ + template + std::vector perm(T size) { + return perm(size, T(0)); + } + + /* Returns `size` unordered (unsorted) distinct numbers between `from` and `to`. */ + template + std::vector distinct(int size, T from, T to) { + std::vector result; + if (size == 0) + return result; + + if (from > to) + __testlib_fail("random_t::distinct expected from <= to"); + + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + + uint64_t n = to - from + 1; + if (uint64_t(size) > n) + __testlib_fail("random_t::distinct expected size <= to - from + 1"); + + double expected = 0.0; + for (int i = 1; i <= size; i++) + expected += double(n) / double(n - i + 1); + + if (expected < double(n)) { + std::set vals; + while (int(vals.size()) < size) { + T x = T(next(from, to)); + if (vals.insert(x).second) + result.push_back(x); + } + } else { + if (n > 1000000000) + __testlib_fail("random_t::distinct here expected to - from + 1 <= 1000000000"); + std::vector p(perm(int(n), from)); + result.insert(result.end(), p.begin(), p.begin() + size); + } + + return result; + } + + /* Returns `size` unordered (unsorted) distinct numbers between `0` and `upper`-1. */ + template + std::vector distinct(int size, T upper) { + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + if (size == 0) + return std::vector(); + + if (upper <= 0) + __testlib_fail("random_t::distinct expected upper > 0"); + if (size > upper) + __testlib_fail("random_t::distinct expected size <= upper"); + + return distinct(size, T(0), upper - 1); + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of integers not less than min_part. */ + template + std::vector partition(int size, T sum, T min_part) { + if (size < 0) + __testlib_fail("random_t::partition: size < 0"); + if (size == 0 && sum != 0) + __testlib_fail("random_t::partition: size == 0 && sum != 0"); + if (min_part * size > sum) + __testlib_fail("random_t::partition: min_part * size > sum"); + if (size == 0 && sum == 0) + return std::vector(); + + T sum_ = sum; + sum -= min_part * size; + + std::vector septums(size); + std::vector d = distinct(size - 1, T(1), T(sum + size - 1)); + for (int i = 0; i + 1 < size; i++) + septums[i + 1] = d[i]; + sort(septums.begin(), septums.end()); + + std::vector result(size); + for (int i = 0; i + 1 < size; i++) + result[i] = septums[i + 1] - septums[i] - 1; + result[size - 1] = sum + size - 1 - septums.back(); + + for (std::size_t i = 0; i < result.size(); i++) + result[i] += min_part; + + T result_sum = 0; + for (std::size_t i = 0; i < result.size(); i++) + result_sum += result[i]; + if (result_sum != sum_) + __testlib_fail("random_t::partition: partition sum is expected to be the given sum"); + + if (*std::min_element(result.begin(), result.end()) < min_part) + __testlib_fail("random_t::partition: partition min is expected to be no less than the given min_part"); + + if (int(result.size()) != size || result.size() != (size_t) size) + __testlib_fail("random_t::partition: partition size is expected to be equal to the given size"); + + return result; + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of positive integers. */ + template + std::vector partition(int size, T sum) { + return partition(size, sum, T(1)); + } +}; + +const int random_t::lim = 25; +const unsigned long long random_t::multiplier = 0x5DEECE66DLL; +const unsigned long long random_t::addend = 0xBLL; +const unsigned long long random_t::mask = (1LL << 48) - 1; +int random_t::version = -1; + +/* Pattern implementation */ +bool pattern::matches(const std::string &s) const { + return matches(s, 0); +} + +static bool __pattern_isSlash(const std::string &s, size_t pos) { + return s[pos] == '\\'; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static bool __pattern_isCommandChar(const std::string &s, size_t pos, char value) { + if (pos >= s.length()) + return false; + + int slashes = 0; + + int before = int(pos) - 1; + while (before >= 0 && s[before] == '\\') + before--, slashes++; + + return slashes % 2 == 0 && s[pos] == value; +} + +static char __pattern_getChar(const std::string &s, size_t &pos) { + if (__pattern_isSlash(s, pos)) + pos += 2; + else + pos++; + + return s[pos - 1]; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static int __pattern_greedyMatch(const std::string &s, size_t pos, const std::vector chars) { + int result = 0; + + while (pos < s.length()) { + char c = s[pos++]; + if (!std::binary_search(chars.begin(), chars.end(), c)) + break; + else + result++; + } + + return result; +} + +std::string pattern::src() const { + return s; +} + +bool pattern::matches(const std::string &s, size_t pos) const { + std::string result; + + if (to > 0) { + int size = __pattern_greedyMatch(s, pos, chars); + if (size < from) + return false; + if (size > to) + size = to; + pos += size; + } + + if (children.size() > 0) { + for (size_t child = 0; child < children.size(); child++) + if (children[child].matches(s, pos)) + return true; + return false; + } else + return pos == s.length(); +} + +std::string pattern::next(random_t &rnd) const { + std::string result; + result.reserve(20); + + if (to == INT_MAX) + __testlib_fail("pattern::next(random_t& rnd): can't process character '*' for generation"); + + if (to > 0) { + int count = rnd.next(to - from + 1) + from; + for (int i = 0; i < count; i++) + result += chars[rnd.next(int(chars.size()))]; + } + + if (children.size() > 0) { + int child = rnd.next(int(children.size())); + result += children[child].next(rnd); + } + + return result; +} + +static void __pattern_scanCounts(const std::string &s, size_t &pos, int &from, int &to) { + if (pos >= s.length()) { + from = to = 1; + return; + } + + if (__pattern_isCommandChar(s, pos, '{')) { + std::vector parts; + std::string part; + + pos++; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, '}')) { + if (__pattern_isCommandChar(s, pos, ',')) + parts.push_back(part), part = "", pos++; + else + part += __pattern_getChar(s, pos); + } + + if (part != "") + parts.push_back(part); + + if (!__pattern_isCommandChar(s, pos, '}')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (parts.size() < 1 || parts.size() > 2) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector numbers; + + for (size_t i = 0; i < parts.size(); i++) { + if (parts[i].length() == 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + int number; + if (std::sscanf(parts[i].c_str(), "%d", &number) != 1) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + numbers.push_back(number); + } + + if (numbers.size() == 1) + from = to = numbers[0]; + else + from = numbers[0], to = numbers[1]; + + if (from > to) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + } else { + if (__pattern_isCommandChar(s, pos, '?')) { + from = 0, to = 1, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '*')) { + from = 0, to = INT_MAX, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '+')) { + from = 1, to = INT_MAX, pos++; + return; + } + + from = to = 1; + } +} + +static std::vector __pattern_scanCharSet(const std::string &s, size_t &pos) { + if (pos >= s.length()) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector result; + + if (__pattern_isCommandChar(s, pos, '[')) { + pos++; + bool negative = __pattern_isCommandChar(s, pos, '^'); + if (negative) + pos++; + + char prev = 0; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, ']')) { + if (__pattern_isCommandChar(s, pos, '-') && prev != 0) { + pos++; + + if (pos + 1 == s.length() || __pattern_isCommandChar(s, pos, ']')) { + result.push_back(prev); + prev = '-'; + continue; + } + + char next = __pattern_getChar(s, pos); + if (prev > next) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + for (char c = prev; c != next; c++) + result.push_back(c); + result.push_back(next); + + prev = 0; + } else { + if (prev != 0) + result.push_back(prev); + prev = __pattern_getChar(s, pos); + } + } + + if (prev != 0) + result.push_back(prev); + + if (!__pattern_isCommandChar(s, pos, ']')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (negative) { + std::sort(result.begin(), result.end()); + std::vector actuals; + for (int code = 0; code < 255; code++) { + char c = char(code); + if (!std::binary_search(result.begin(), result.end(), c)) + actuals.push_back(c); + } + result = actuals; + } + + std::sort(result.begin(), result.end()); + } else + result.push_back(__pattern_getChar(s, pos)); + + return result; +} + +pattern::pattern(std::string s) : s(s), from(0), to(0) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (!__pattern_isCommandChar(s, i, ' ')) + t += s[i]; + s = t; + + int opened = 0; + int firstClose = -1; + std::vector seps; + + for (size_t i = 0; i < s.length(); i++) { + if (__pattern_isCommandChar(s, i, '(')) { + opened++; + continue; + } + + if (__pattern_isCommandChar(s, i, ')')) { + opened--; + if (opened == 0 && firstClose == -1) + firstClose = int(i); + continue; + } + + if (opened < 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (__pattern_isCommandChar(s, i, '|') && opened == 0) + seps.push_back(int(i)); + } + + if (opened != 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (seps.size() == 0 && firstClose + 1 == (int) s.length() + && __pattern_isCommandChar(s, 0, '(') && __pattern_isCommandChar(s, s.length() - 1, ')')) { + children.push_back(pattern(s.substr(1, s.length() - 2))); + } else { + if (seps.size() > 0) { + seps.push_back(int(s.length())); + int last = 0; + + for (size_t i = 0; i < seps.size(); i++) { + children.push_back(pattern(s.substr(last, seps[i] - last))); + last = seps[i] + 1; + } + } else { + size_t pos = 0; + chars = __pattern_scanCharSet(s, pos); + __pattern_scanCounts(s, pos, from, to); + if (pos < s.length()) + children.push_back(pattern(s.substr(pos))); + } + } +} + +/* End of pattern implementation */ + +template +inline bool isEof(C c) { + return c == EOFC; +} + +template +inline bool isEoln(C c) { + return (c == LF || c == CR); +} + +template +inline bool isBlanks(C c) { + return (c == LF || c == CR || c == SPACE || c == TAB); +} + +inline std::string trim(const std::string &s) { + if (s.empty()) + return s; + + int left = 0; + while (left < int(s.length()) && isBlanks(s[left])) + left++; + if (left >= int(s.length())) + return ""; + + int right = int(s.length()) - 1; + while (right >= 0 && isBlanks(s[right])) + right--; + if (right < 0) + return ""; + + return s.substr(left, right - left + 1); +} + +enum TMode { + _input, _output, _answer +}; + +/* Outcomes 6-15 are reserved for future use. */ +enum TResult { + _ok = 0, + _wa = 1, + _pe = 2, + _fail = 3, + _dirt = 4, + _points = 5, + _unexpected_eof = 8, + _partially = 16 +}; + +enum TTestlibMode { + _unknown, _checker, _validator, _generator, _interactor, _scorer +}; + +#define _pc(exitCode) (TResult(_partially + (exitCode))) + +/* Outcomes 6-15 are reserved for future use. */ +const std::string outcomes[] = { + "accepted", + "wrong-answer", + "presentation-error", + "fail", + "fail", +#ifndef PCMS2 + "points", +#else + "relative-scoring", +#endif + "reserved", + "reserved", + "unexpected-eof", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "partially-correct" +}; + +class InputStreamReader { +public: + virtual void setTestCase(int testCase) = 0; + + virtual std::vector getReadChars() = 0; + + virtual int curChar() = 0; + + virtual int nextChar() = 0; + + virtual void skipChar() = 0; + + virtual void unreadChar(int c) = 0; + + virtual std::string getName() = 0; + + virtual bool eof() = 0; + + virtual void close() = 0; + + virtual int getLine() = 0; + + virtual ~InputStreamReader() = 0; +}; + +InputStreamReader::~InputStreamReader() { + // No operations. +} + +class StringInputStreamReader : public InputStreamReader { +private: + std::string s; + size_t pos; + +public: + StringInputStreamReader(const std::string &content) : s(content), pos(0) { + // No operations. + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in StringInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in StringInputStreamReader"); + } + + int curChar() { + if (pos >= s.length()) + return EOFC; + else + return s[pos]; + } + + int nextChar() { + if (pos >= s.length()) { + pos++; + return EOFC; + } else + return s[pos++]; + } + + void skipChar() { + pos++; + } + + void unreadChar(int c) { + if (pos == 0) + __testlib_fail("StringInputStreamReader::unreadChar(int): pos == 0."); + pos--; + if (pos < s.length()) + s[pos] = char(c); + } + + std::string getName() { + return __testlib_part(s); + } + + int getLine() { + return -1; + } + + bool eof() { + return pos >= s.length(); + } + + void close() { + // No operations. + } +}; + +class FileInputStreamReader : public InputStreamReader { +private: + std::FILE *file; + std::string name; + int line; + std::vector undoChars; + std::vector readChars; + std::vector undoReadChars; + + inline int postprocessGetc(int getcResult) { + if (getcResult != EOF) + return getcResult; + else + return EOFC; + } + + int getc(FILE *file) { + int c; + int rc; + + if (undoChars.empty()) { + c = rc = ::getc(file); + } else { + c = undoChars.back(); + undoChars.pop_back(); + rc = undoReadChars.back(); + undoReadChars.pop_back(); + } + + if (c == LF) + line++; + + readChars.push_back(rc); + return c; + } + + int ungetc(int c/*, FILE* file*/) { + if (!readChars.empty()) { + undoReadChars.push_back(readChars.back()); + readChars.pop_back(); + } + if (c == LF) + line--; + undoChars.push_back(c); + return c; + } + +public: + FileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + // No operations. + } + + void setTestCase(int testCase) { + if (testCase < 0 || testCase > __TESTLIB_MAX_TEST_CASE) + __testlib_fail(format("testCase expected fit in [1,%d], but %d doesn't", __TESTLIB_MAX_TEST_CASE, testCase)); + readChars.push_back(testCase + 256); + } + + std::vector getReadChars() { + return readChars; + } + + int curChar() { + if (feof(file)) + return EOFC; + else { + int c = getc(file); + ungetc(c/*, file*/); + return postprocessGetc(c); + } + } + + int nextChar() { + if (feof(file)) + return EOFC; + else + return postprocessGetc(getc(file)); + } + + void skipChar() { + getc(file); + } + + void unreadChar(int c) { + ungetc(c/*, file*/); + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + if (NULL == file || feof(file)) + return true; + else { + int c = nextChar(); + if (c == EOFC || (c == EOF && feof(file))) + return true; + unreadChar(c); + return false; + } + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +class BufferedFileInputStreamReader : public InputStreamReader { +private: + static const size_t BUFFER_SIZE; + static const size_t MAX_UNREAD_COUNT; + + std::FILE *file; + std::string name; + int line; + + char *buffer; + bool *isEof; + int bufferPos; + size_t bufferSize; + + bool refill() { + if (NULL == file) + __testlib_fail("BufferedFileInputStreamReader: file == NULL (" + getName() + ")"); + + if (bufferPos >= int(bufferSize)) { + size_t readSize = fread( + buffer + MAX_UNREAD_COUNT, + 1, + BUFFER_SIZE - MAX_UNREAD_COUNT, + file + ); + + if (readSize < BUFFER_SIZE - MAX_UNREAD_COUNT + && ferror(file)) + __testlib_fail("BufferedFileInputStreamReader: unable to read (" + getName() + ")"); + + bufferSize = MAX_UNREAD_COUNT + readSize; + bufferPos = int(MAX_UNREAD_COUNT); + std::memset(isEof + MAX_UNREAD_COUNT, 0, sizeof(isEof[0]) * readSize); + + return readSize > 0; + } else + return true; + } + + char increment() { + char c; + if ((c = buffer[bufferPos++]) == LF) + line++; + return c; + } + +public: + BufferedFileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + buffer = new char[BUFFER_SIZE]; + isEof = new bool[BUFFER_SIZE]; + bufferSize = MAX_UNREAD_COUNT; + bufferPos = int(MAX_UNREAD_COUNT); + } + + ~BufferedFileInputStreamReader() { + if (NULL != buffer) { + delete[] buffer; + buffer = NULL; + } + if (NULL != isEof) { + delete[] isEof; + isEof = NULL; + } + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in BufferedFileInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in BufferedFileInputStreamReader"); + } + + int curChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : buffer[bufferPos]; + } + + int nextChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : increment(); + } + + void skipChar() { + increment(); + } + + void unreadChar(int c) { + bufferPos--; + if (bufferPos < 0) + __testlib_fail("BufferedFileInputStreamReader::unreadChar(int): bufferPos < 0"); + isEof[bufferPos] = (c == EOFC); + buffer[bufferPos] = char(c); + if (c == LF) + line--; + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + return !refill() || EOFC == curChar(); + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +const size_t BufferedFileInputStreamReader::BUFFER_SIZE = 2000000; +const size_t BufferedFileInputStreamReader::MAX_UNREAD_COUNT = BufferedFileInputStreamReader::BUFFER_SIZE / 2; + +/* + * Streams to be used for reading data in checkers or validators. + * Each read*() method moves pointer to the next character after the + * read value. + */ +struct InStream { + /* Do not use them. */ + InStream(); + + ~InStream(); + + /* Wrap std::string with InStream. */ + InStream(const InStream &baseStream, std::string content); + + InputStreamReader *reader; + int lastLine; + + std::string name; + TMode mode; + bool opened; + bool stdfile; + bool strict; + + int wordReserveSize; + std::string _tmpReadToken; + + int readManyIteration; + size_t maxFileSize; + size_t maxTokenLength; + size_t maxMessageLength; + + void init(std::string fileName, TMode mode); + + void init(std::FILE *f, TMode mode); + + void setTestCase(int testCase); + std::vector getReadChars(); + + /* Moves stream pointer to the first non-white-space character or EOF. */ + void skipBlanks(); + + /* Returns current character in the stream. Doesn't remove it from stream. */ + char curChar(); + + /* Moves stream pointer one character forward. */ + void skipChar(); + + /* Returns current character and moves pointer one character forward. */ + char nextChar(); + + /* Returns current character and moves pointer one character forward. */ + char readChar(); + + /* As "readChar()" but ensures that the result is equal to given parameter. */ + char readChar(char c); + + /* As "readChar()" but ensures that the result is equal to the space (code=32). */ + char readSpace(); + + /* Puts back the character into the stream. */ + void unreadChar(char c); + + /* Reopens stream, you should not use it. */ + void reset(std::FILE *file = NULL); + + /* Checks that current position is EOF. If not it doesn't move stream pointer. */ + bool eof(); + + /* Moves pointer to the first non-white-space character and calls "eof()". */ + bool seekEof(); + + /* + * Checks that current position contains EOLN. + * If not it doesn't move stream pointer. + * In strict mode expects "#13#10" for windows or "#10" for other platforms. + */ + bool eoln(); + + /* Moves pointer to the first non-space and non-tab character and calls "eoln()". */ + bool seekEoln(); + + /* Moves stream pointer to the first character of the next line (if exists). */ + void nextLine(); + + /* + * Reads new token. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + std::string readWord(); + + /* The same as "readWord()", it is preffered to use "readToken()". */ + std::string readToken(); + + /* The same as "readWord()", but ensures that token matches to given pattern. */ + std::string readWord(const std::string &ptrn, const std::string &variableName = ""); + + std::string readWord(const pattern &p, const std::string &variableName = ""); + + std::vector + readWords(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readWords(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readWords(int size, int indexBase = 1); + + /* The same as "readToken()", but ensures that token matches to given pattern. */ + std::string readToken(const std::string &ptrn, const std::string &variableName = ""); + + std::string readToken(const pattern &p, const std::string &variableName = ""); + + std::vector + readTokens(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readTokens(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readTokens(int size, int indexBase = 1); + + void readWordTo(std::string &result); + + void readWordTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + void readTokenTo(std::string &result); + + void readTokenTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads new long long value. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + long long readLong(); + + unsigned long long readUnsignedLong(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInteger(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInt(); + + /* As "readLong()" but ensures that value in the range [minv,maxv]. */ + long long readLong(long long minv, long long maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of long longs. */ + std::vector + readLongs(int size, long long minv, long long maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of long longs. */ + std::vector readLongs(int size, int indexBase = 1); + + unsigned long long + readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + std::vector readUnsignedLongs(int size, int indexBase = 1); + + unsigned long long readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + /* As "readInteger()" but ensures that value in the range [minv,maxv]. */ + int readInteger(int minv, int maxv, const std::string &variableName = ""); + + /* As "readInt()" but ensures that value in the range [minv,maxv]. */ + int readInt(int minv, int maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of integers. */ + std::vector + readIntegers(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readIntegers(int size, int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int indexBase = 1); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readReal(); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readDouble(); + + /* As "readReal()" but ensures that value in the range [minv,maxv]. */ + double readReal(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readReals(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readReals(int size, int indexBase = 1); + + /* As "readDouble()" but ensures that value in the range [minv,maxv]. */ + double readDouble(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readDoubles(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readDoubles(int size, int indexBase = 1); + + /* + * As "readReal()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* + * As "readDouble()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* As readLine(). */ + std::string readString(); + + /* Read many lines. */ + std::vector readStrings(int size, int indexBase = 1); + + /* See readLine(). */ + void readStringTo(std::string &result); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readStrings(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readStrings(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads line from the current position to EOLN or EOF. Moves stream pointer to + * the first character of the new line (if possible). + */ + std::string readLine(); + + /* Read many lines. */ + std::vector readLines(int size, int indexBase = 1); + + /* See readLine(). */ + void readLineTo(std::string &result); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readLines(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readLines(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* Reads EOLN or fails. Use it in validators. Calls "eoln()" method internally. */ + void readEoln(); + + /* Reads EOF or fails. Use it in validators. Calls "eof()" method internally. */ + void readEof(); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quit(TResult result, const char *msg); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quitf(TResult result, const char *msg, ...); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + void quitif(bool condition, TResult result, const char *msg, ...); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quits(TResult result, std::string msg); + + /* + * Checks condition and aborts a program if codition is false. + * Returns _wa for ouf and _fail on any other streams. + */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void ensuref(bool cond, const char *format, ...); + + void __testlib_ensure(bool cond, std::string message); + + void close(); + + const static int NO_INDEX = INT_MAX; + const static char OPEN_BRACKET = char(11); + const static char CLOSE_BRACKET = char(17); + + const static WORD LightGray = 0x07; + const static WORD LightRed = 0x0c; + const static WORD LightCyan = 0x0b; + const static WORD LightGreen = 0x0a; + const static WORD LightYellow = 0x0e; + + static void textColor(WORD color); + + static void quitscr(WORD color, const char *msg); + + static void quitscrS(WORD color, std::string msg); + + void xmlSafeWrite(std::FILE *file, const char *msg); + + /* Skips UTF-8 Byte Order Mark. */ + void skipBom(); + +private: + InStream(const InStream &); + + InStream &operator=(const InStream &); +}; + +InStream inf; +InStream ouf; +InStream ans; +bool appesMode; +std::string resultName; +std::string checkerName = "untitled checker"; +random_t rnd; +TTestlibMode testlibMode = _unknown; +double __testlib_points = std::numeric_limits::infinity(); + +struct ValidatorBoundsHit { + static const double EPS; + bool minHit; + bool maxHit; + + ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) { + }; + + ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) { + return ValidatorBoundsHit( + __testlib_max(minHit, validatorBoundsHit.minHit), + __testlib_max(maxHit, validatorBoundsHit.maxHit) + ); + } +}; + +const double ValidatorBoundsHit::EPS = 1E-12; + +class Validator { +private: + const static std::string TEST_MARKUP_HEADER; + const static std::string TEST_CASE_OPEN_TAG; + const static std::string TEST_CASE_CLOSE_TAG; + + bool _initialized; + std::string _testset; + std::string _group; + + std::string _testOverviewLogFileName; + std::string _testMarkupFileName; + int _testCase = -1; + std::string _testCaseFileName; + + std::map _boundsHitByVariableName; + std::set _features; + std::set _hitFeatures; + + bool isVariableNameBoundsAnalyzable(const std::string &variableName) { + for (size_t i = 0; i < variableName.length(); i++) + if ((variableName[i] >= '0' && variableName[i] <= '9') || variableName[i] < ' ') + return false; + return true; + } + + bool isFeatureNameAnalyzable(const std::string &featureName) { + for (size_t i = 0; i < featureName.length(); i++) + if (featureName[i] < ' ') + return false; + return true; + } + +public: + Validator() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.group()"); + return _group; + } + + std::string testOverviewLogFileName() const { + return _testOverviewLogFileName; + } + + std::string testMarkupFileName() const { + return _testMarkupFileName; + } + + int testCase() const { + return _testCase; + } + + std::string testCaseFileName() const { + return _testCaseFileName; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } + + void setTestOverviewLogFileName(const char *const testOverviewLogFileName) { + _testOverviewLogFileName = testOverviewLogFileName; + } + + void setTestMarkupFileName(const char *const testMarkupFileName) { + _testMarkupFileName = testMarkupFileName; + } + + void setTestCase(int testCase) { + _testCase = testCase; + } + + void setTestCaseFileName(const char *const testCaseFileName) { + _testCaseFileName = testCaseFileName; + } + + void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) { + if (isVariableNameBoundsAnalyzable(variableName)) { + _boundsHitByVariableName[variableName] + = boundsHit.merge(_boundsHitByVariableName[variableName]); + } + } + + std::string getBoundsHitLog() { + std::string result; + for (std::map::iterator i = _boundsHitByVariableName.begin(); + i != _boundsHitByVariableName.end(); + i++) { + result += "\"" + i->first + "\":"; + if (i->second.minHit) + result += " min-value-hit"; + if (i->second.maxHit) + result += " max-value-hit"; + result += "\n"; + } + return result; + } + + std::string getFeaturesLog() { + std::string result; + for (std::set::iterator i = _features.begin(); + i != _features.end(); + i++) { + result += "feature \"" + *i + "\":"; + if (_hitFeatures.count(*i)) + result += " hit"; + result += "\n"; + } + return result; + } + + void writeTestOverviewLog() { + if (!_testOverviewLogFileName.empty()) { + std::string fileName(_testOverviewLogFileName); + _testOverviewLogFileName = ""; + FILE *testOverviewLogFile = fopen(fileName.c_str(), "w"); + if (NULL == testOverviewLogFile) + __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")"); + fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str()); + if (fclose(testOverviewLogFile)) + __testlib_fail( + "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")"); + } + } + + void writeTestMarkup() { + if (!_testMarkupFileName.empty()) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string markup(TEST_MARKUP_HEADER); + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) { + char cc = char(c); + if (cc == '\\' || cc == '!') + markup += '\\'; + markup += cc; + } else { + markup += TEST_CASE_OPEN_TAG; + markup += toString(c - 256); + markup += TEST_CASE_CLOSE_TAG; + } + } + FILE* f; + bool standard_file = false; + if (_testMarkupFileName == "stdout") + f = stdout, standard_file = true; + else if (_testMarkupFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testMarkupFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestMarkup: can't write test markup to (" + _testMarkupFileName + ")"); + } + std::fprintf(f, "%s", markup.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestMarkup: can't close test markup file (" + _testCaseFileName + ")"); + } + } + } + + void writeTestCase() { + if (_testCase > 0) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string content, testCaseContent; + bool matchedTestCase = false; + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) + content += char(c); + else { + if (matchedTestCase) { + testCaseContent = content; + matchedTestCase = false; + } + content = ""; + int testCase = c - 256; + if (testCase == _testCase) + matchedTestCase = true; + } + } + if (matchedTestCase) + testCaseContent = content; + + if (!testCaseContent.empty()) { + FILE* f; + bool standard_file = false; + if (_testCaseFileName.empty() || _testCaseFileName == "stdout") + f = stdout, standard_file = true; + else if (_testCaseFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testCaseFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestCase: can't write test case to (" + _testCaseFileName + ")"); + } + std::fprintf(f, "%s", testCaseContent.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestCase: can't close test case file (" + _testCaseFileName + ")"); + } + } + } + } + + void addFeature(const std::string &feature) { + if (_features.count(feature)) + __testlib_fail("Feature " + feature + " registered twice."); + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + _features.insert(feature); + } + + void feature(const std::string &feature) { + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + if (!_features.count(feature)) + __testlib_fail("Feature " + feature + " didn't registered via addFeature(feature)."); + + _hitFeatures.insert(feature); + } +} validator; + +const std::string Validator::TEST_MARKUP_HEADER = "MU\xF3\x01"; +const std::string Validator::TEST_CASE_OPEN_TAG = "!c"; +const std::string Validator::TEST_CASE_CLOSE_TAG = ";"; + +struct TestlibFinalizeGuard { + static bool alive; + static bool registered; + + int quitCount, readEofCount; + + TestlibFinalizeGuard() : quitCount(0), readEofCount(0) { + // No operations. + } + + ~TestlibFinalizeGuard() { + bool _alive = alive; + alive = false; + + if (_alive) { + if (testlibMode == _checker && quitCount == 0) + __testlib_fail("Checker must end with quit or quitf call."); + + if (testlibMode == _validator && readEofCount == 0 && quitCount == 0) + __testlib_fail("Validator must end with readEof call."); + + /* opts */ + autoEnsureNoUnusedOpts(); + + if (!registered) + __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)"); + } + + if (__testlib_exitCode == 0) { + validator.writeTestOverviewLog(); + validator.writeTestMarkup(); + validator.writeTestCase(); + } + } + +private: + /* opts */ + void autoEnsureNoUnusedOpts(); +}; + +bool TestlibFinalizeGuard::alive = true; +bool TestlibFinalizeGuard::registered = false; +extern TestlibFinalizeGuard testlibFinalizeGuard; + +/* + * Call it to disable checks on finalization. + */ +void disableFinalizeGuard() { + TestlibFinalizeGuard::alive = false; +} + +/* Interactor streams. + */ +std::fstream tout; + +/* implementation + */ + +InStream::InStream() { + reader = NULL; + lastLine = -1; + opened = false; + name = ""; + mode = _input; + strict = false; + stdfile = false; + wordReserveSize = 4; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::InStream(const InStream &baseStream, std::string content) { + reader = new StringInputStreamReader(content); + lastLine = -1; + opened = true; + strict = baseStream.strict; + stdfile = false; + mode = baseStream.mode; + name = "based on " + baseStream.name; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::~InStream() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } +} + +void InStream::setTestCase(int testCase) { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::setTestCase can be used only for inf in validator-mode." + " Actually, prefer setTestCase function instead of InStream member"); + reader->setTestCase(testCase); +} + +std::vector InStream::getReadChars() { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::getReadChars can be used only for inf in validator-mode."); + return reader == NULL ? std::vector() : reader->getReadChars(); +} + +void setTestCase(int testCase) { + static bool first_run = true; + static bool zero_based = false; + + if (first_run && testCase == 0) + zero_based = true; + + if (zero_based) + testCase++; + + __testlib_hasTestCase = true; + __testlib_testCase = testCase; + + if (testlibMode == _validator) + inf.setTestCase(testCase); + + first_run = false; +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int resultExitCode(TResult r) { + if (r == _ok) + return OK_EXIT_CODE; + if (r == _wa) + return WA_EXIT_CODE; + if (r == _pe) + return PE_EXIT_CODE; + if (r == _fail) + return FAIL_EXIT_CODE; + if (r == _dirt) + return DIRT_EXIT_CODE; + if (r == _points) + return POINTS_EXIT_CODE; + if (r == _unexpected_eof) +#ifdef ENABLE_UNEXPECTED_EOF + return UNEXPECTED_EOF_EXIT_CODE; +#else + return PE_EXIT_CODE; +#endif + if (r >= _partially) + return PC_BASE_EXIT_CODE + (r - _partially); + return FAIL_EXIT_CODE; +} + +void InStream::textColor( +#if !(defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)) && defined(__GNUC__) + __attribute__((unused)) +#endif + WORD color +) { +#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400) + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, color); +#endif +#if !defined(ON_WINDOWS) && defined(__GNUC__) + if (isatty(2)) + { + switch (color) + { + case LightRed: + fprintf(stderr, "\033[1;31m"); + break; + case LightCyan: + fprintf(stderr, "\033[1;36m"); + break; + case LightGreen: + fprintf(stderr, "\033[1;32m"); + break; + case LightYellow: + fprintf(stderr, "\033[1;33m"); + break; + case LightGray: + default: + fprintf(stderr, "\033[0m"); + } + } +#endif +} + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +class exit_exception: public std::exception { +private: + int exitCode; +public: + exit_exception(int exitCode): exitCode(exitCode) {} + int getExitCode() { return exitCode; } +}; +#endif + +NORETURN void halt(int exitCode) { +#ifdef FOOTER + InStream::textColor(InStream::LightGray); + std::fprintf(stderr, "Checker: \"%s\"\n", checkerName.c_str()); + std::fprintf(stderr, "Exit code: %d\n", exitCode); + InStream::textColor(InStream::LightGray); +#endif + __testlib_exitCode = exitCode; +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT + throw exit_exception(exitCode); +#endif + std::exit(exitCode); +} + +static bool __testlib_shouldCheckDirt(TResult result) { + return result == _ok || result == _points || result >= _partially; +} + +static std::string __testlib_appendMessage(const std::string &message, const std::string &extra) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + size_t index = message.find(extra, openPos); + if (index == std::string::npos || int(index) >= closePos) { + std::string result(message); + result.insert(closePos, ", " + extra); + return result; + } + return message; + } + + return message + " " + InStream::OPEN_BRACKET + extra + InStream::CLOSE_BRACKET; +} + +static std::string __testlib_toPrintableMessage(const std::string &message) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + std::string result(message); + result[openPos] = '('; + result[closePos] = ')'; + return result; + } + + return message; +} + +NORETURN void InStream::quit(TResult result, const char *msg) { + if (TestlibFinalizeGuard::alive) + testlibFinalizeGuard.quitCount++; + + std::string message(msg); + message = trim(message); + + if (__testlib_hasTestCase) { + if (result != _ok) + message = __testlib_appendMessage(message, "test case " + vtos(__testlib_testCase)); + else { + if (__testlib_testCase == 1) + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test case"); + else + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test cases"); + } + } + + // You can change maxMessageLength. + // Example: 'inf.maxMessageLength = 1024 * 1024;'. + if (message.length() > maxMessageLength) { + std::string warn = "message length exceeds " + vtos(maxMessageLength) + + ", the message is truncated: "; + message = warn + message.substr(0, maxMessageLength - warn.length()); + } + +#ifndef ENABLE_UNEXPECTED_EOF + if (result == _unexpected_eof) + result = _pe; +#endif + + if (testlibMode == _scorer && result != _fail) + quits(_fail, "Scorer should return points only. Don't use a quit function."); + + if (mode != _output && result != _fail) { + if (mode == _input && testlibMode == _validator && lastLine != -1) + quits(_fail, __testlib_appendMessage(__testlib_appendMessage(message, name), "line " + vtos(lastLine))); + else + quits(_fail, __testlib_appendMessage(message, name)); + } + + std::FILE *resultFile; + std::string errorName; + + if (__testlib_shouldCheckDirt(result)) { + if (testlibMode != _interactor && !ouf.seekEof()) + quit(_dirt, "Extra information in the output file"); + } + + int pctype = result - _partially; + bool isPartial = false; + + switch (result) { + case _ok: + errorName = "ok "; + quitscrS(LightGreen, errorName); + break; + case _wa: + errorName = "wrong answer "; + quitscrS(LightRed, errorName); + break; + case _pe: + errorName = "wrong output format "; + quitscrS(LightRed, errorName); + break; + case _fail: + errorName = "FAIL "; + quitscrS(LightRed, errorName); + break; + case _dirt: + errorName = "wrong output format "; + quitscrS(LightCyan, errorName); + result = _pe; + break; + case _points: + errorName = "points "; + quitscrS(LightYellow, errorName); + break; + case _unexpected_eof: + errorName = "unexpected eof "; + quitscrS(LightCyan, errorName); + break; + default: + if (result >= _partially) { + errorName = format("partially correct (%d) ", pctype); + isPartial = true; + quitscrS(LightYellow, errorName); + } else + quit(_fail, "What is the code ??? "); + } + + if (resultName != "") { + resultFile = std::fopen(resultName.c_str(), "w"); + if (resultFile == NULL) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + if (appesMode) { + std::fprintf(resultFile, ""); + if (isPartial) + std::fprintf(resultFile, "", + outcomes[(int) _partially].c_str(), pctype); + else { + if (result != _points) + std::fprintf(resultFile, "", outcomes[(int) result].c_str()); + else { + if (__testlib_points == std::numeric_limits::infinity()) + quit(_fail, "Expected points, but infinity found"); + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", __testlib_points)); + std::fprintf(resultFile, "", + outcomes[(int) result].c_str(), stringPoints.c_str()); + } + } + xmlSafeWrite(resultFile, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(resultFile, "\n"); + } else + std::fprintf(resultFile, "%s", __testlib_toPrintableMessage(message).c_str()); + if (NULL == resultFile || fclose(resultFile) != 0) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + } + + quitscr(LightGray, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(stderr, "\n"); + + inf.close(); + ouf.close(); + ans.close(); + if (tout.is_open()) + tout.close(); + + textColor(LightGray); + + if (resultName != "") + std::fprintf(stderr, "See file to check exit message\n"); + + halt(resultExitCode(result)); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +NORETURN void InStream::quitf(TResult result, const char *msg, ...) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +void InStream::quitif(bool condition, TResult result, const char *msg, ...) { + if (condition) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); + } +} + +NORETURN void InStream::quits(TResult result, std::string msg) { + InStream::quit(result, msg.c_str()); +} + +void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { + size_t lmsg = strlen(msg); + for (size_t i = 0; i < lmsg; i++) { + if (msg[i] == '&') { + std::fprintf(file, "%s", "&"); + continue; + } + if (msg[i] == '<') { + std::fprintf(file, "%s", "<"); + continue; + } + if (msg[i] == '>') { + std::fprintf(file, "%s", ">"); + continue; + } + if (msg[i] == '"') { + std::fprintf(file, "%s", """); + continue; + } + if (0 <= msg[i] && msg[i] <= 31) { + std::fprintf(file, "%c", '.'); + continue; + } + std::fprintf(file, "%c", msg[i]); + } +} + +void InStream::quitscrS(WORD color, std::string msg) { + quitscr(color, msg.c_str()); +} + +void InStream::quitscr(WORD color, const char *msg) { + if (resultName == "") { + textColor(color); + std::fprintf(stderr, "%s", msg); + textColor(LightGray); + } +} + +void InStream::reset(std::FILE *file) { + if (opened && stdfile) + quit(_fail, "Can't reset standard handle"); + + if (opened) + close(); + + if (!stdfile && NULL == file) + if (NULL == (file = std::fopen(name.c_str(), "rb"))) { + if (mode == _output) + quits(_pe, std::string("Output file not found: \"") + name + "\""); + + if (mode == _answer) + quits(_fail, std::string("Answer file not found: \"") + name + "\""); + } + + if (NULL != file) { + opened = true; + __testlib_set_binary(file); + + if (stdfile) + reader = new FileInputStreamReader(file, name); + else + reader = new BufferedFileInputStreamReader(file, name); + } else { + opened = false; + reader = NULL; + } +} + +void InStream::init(std::string fileName, TMode mode) { + opened = false; + name = fileName; + stdfile = false; + this->mode = mode; + + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + if (stream.is_open()) { + std::streampos start = stream.tellg(); + stream.seekg(0, std::ios::end); + std::streampos end = stream.tellg(); + size_t fileSize = size_t(end - start); + stream.close(); + + // You can change maxFileSize. + // Example: 'inf.maxFileSize = 256 * 1024 * 1024;'. + if (fileSize > maxFileSize) + quitf(_pe, "File size exceeds %d bytes, size is %d", int(maxFileSize), int(fileSize)); + } + + reset(); +} + +void InStream::init(std::FILE *f, TMode mode) { + opened = false; + name = "untitled"; + this->mode = mode; + + if (f == stdin) + name = "stdin", stdfile = true; + if (f == stdout) + name = "stdout", stdfile = true; + if (f == stderr) + name = "stderr", stdfile = true; + + reset(f); +} + +void InStream::skipBom() { + const std::string utf8Bom = "\xEF\xBB\xBF"; + size_t index = 0; + while (index < utf8Bom.size() && curChar() == utf8Bom[index]) { + index++; + skipChar(); + } + if (index < utf8Bom.size()) { + while (index != 0) { + unreadChar(utf8Bom[index - 1]); + index--; + } + } +} + +char InStream::curChar() { + return char(reader->curChar()); +} + +char InStream::nextChar() { + return char(reader->nextChar()); +} + +char InStream::readChar() { + return nextChar(); +} + +char InStream::readChar(char c) { + lastLine = reader->getLine(); + char found = readChar(); + if (c != found) { + if (!isEoln(found)) + quit(_pe, ("Unexpected character '" + std::string(1, found) + "', but '" + std::string(1, c) + + "' expected").c_str()); + else + quit(_pe, ("Unexpected character " + ("#" + vtos(int(found))) + ", but '" + std::string(1, c) + + "' expected").c_str()); + } + return found; +} + +char InStream::readSpace() { + return readChar(' '); +} + +void InStream::unreadChar(char c) { + reader->unreadChar(c); +} + +void InStream::skipChar() { + reader->skipChar(); +} + +void InStream::skipBlanks() { + while (isBlanks(reader->curChar())) + reader->skipChar(); +} + +std::string InStream::readWord() { + readWordTo(_tmpReadToken); + return _tmpReadToken; +} + +void InStream::readWordTo(std::string &result) { + if (!strict) + skipBlanks(); + + lastLine = reader->getLine(); + int cur = reader->nextChar(); + + if (cur == EOFC) + quit(_unexpected_eof, "Unexpected end of file - token expected"); + + if (isBlanks(cur)) + quit(_pe, "Unexpected white-space - token expected"); + + result.clear(); + + while (!(isBlanks(cur) || cur == EOFC)) { + result += char(cur); + + // You can change maxTokenLength. + // Example: 'inf.maxTokenLength = 128 * 1024 * 1024;'. + if (result.length() > maxTokenLength) + quitf(_pe, "Length of token exceeds %d, token is '%s...'", int(maxTokenLength), + __testlib_part(result).c_str()); + + cur = reader->nextChar(); + } + + reader->unreadChar(cur); + + if (result.length() == 0) + quit(_unexpected_eof, "Unexpected end of file or white-space - token expected"); +} + +std::string InStream::readToken() { + return readWord(); +} + +void InStream::readTokenTo(std::string &result) { + readWordTo(result); +} + +static std::string __testlib_part(const std::string &s) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (s[i] != '\0') + t += s[i]; + else + t += '~'; + if (t.length() <= 64) + return t; + else + return t.substr(0, 30) + "..." + t.substr(s.length() - 31, 31); +} + +#define __testlib_readMany(readMany, readOne, typeName, space) \ + if (size < 0) \ + quit(_fail, #readMany ": size should be non-negative."); \ + if (size > 100000000) \ + quit(_fail, #readMany ": size should be at most 100000000."); \ + \ + std::vector result(size); \ + readManyIteration = indexBase; \ + \ + for (int i = 0; i < size; i++) \ + { \ + result[i] = readOne; \ + readManyIteration++; \ + if (strict && space && i + 1 < size) \ + readSpace(); \ + } \ + \ + readManyIteration = NO_INDEX; \ + return result; \ + + +std::string InStream::readWord(const pattern &p, const std::string &variableName) { + readWordTo(_tmpReadToken); + if (!p.matches(_tmpReadToken)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Token \"" + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(_tmpReadToken) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Token element [index=" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token element " + variableName + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\", doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + } + } + return _tmpReadToken; +} + +std::vector +InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::vector InStream::readWords(int size, int indexBase) { + __testlib_readMany(readWords, readWord(), std::string, true); +} + +std::string InStream::readWord(const std::string &ptrn, const std::string &variableName) { + return readWord(pattern(ptrn), variableName); +} + +std::vector +InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::string InStream::readToken(const pattern &p, const std::string &variableName) { + return readWord(p, variableName); +} + +std::vector +InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readTokens, readToken(p, variablesName), std::string, true); +} + +std::vector InStream::readTokens(int size, int indexBase) { + __testlib_readMany(readTokens, readToken(), std::string, true); +} + +std::string InStream::readToken(const std::string &ptrn, const std::string &variableName) { + return readWord(ptrn, variableName); +} + +std::vector +InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readTokens, readWord(p, variablesName), std::string, true); +} + +void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) { + readWordTo(result); + if (!p.matches(result)) { + if (variableName.empty()) + quit(_wa, ("Token \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } +} + +void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, pattern(ptrn), variableName); +} + +void InStream::readTokenTo(std::string &result, const pattern &p, const std::string &variableName) { + return readWordTo(result, p, variableName); +} + +void InStream::readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, ptrn, variableName); +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(long long integer, const char *s) { + if (integer == LLONG_MIN) + return strcmp(s, "-9223372036854775808") == 0; + + if (integer == 0LL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + if (integer < 0 && s[0] != '-') + return false; + + if (integer < 0) + s++, length--, integer = -integer; + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(unsigned long long integer, const char *s) { + if (integer == ULLONG_MAX) + return strcmp(s, "18446744073709551615") == 0; + + if (integer == 0ULL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +static inline double stringToDouble(InStream &in, const char *buffer) { + double retval; + + size_t length = strlen(buffer); + + int minusCount = 0; + int plusCount = 0; + int decimalPointCount = 0; + int digitCount = 0; + int eCount = 0; + + for (size_t i = 0; i < length; i++) { + if (('0' <= buffer[i] && buffer[i] <= '9') || buffer[i] == '.' + || buffer[i] == 'e' || buffer[i] == 'E' + || buffer[i] == '-' || buffer[i] == '+') { + if ('0' <= buffer[i] && buffer[i] <= '9') + digitCount++; + if (buffer[i] == 'e' || buffer[i] == 'E') + eCount++; + if (buffer[i] == '-') + minusCount++; + if (buffer[i] == '+') + plusCount++; + if (buffer[i] == '.') + decimalPointCount++; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + // If for sure is not a number in standard notation or in e-notation. + if (digitCount == 0 || minusCount > 2 || plusCount > 2 || decimalPointCount > 1 || eCount > 1) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToDouble(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToDouble(in, buffer.c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const char *buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + if (minAfterPointDigitCount < 0) + in.quit(_fail, "stringToStrictDouble: minAfterPointDigitCount should be non-negative."); + + if (minAfterPointDigitCount > maxAfterPointDigitCount) + in.quit(_fail, + "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount."); + + double retval; + + size_t length = strlen(buffer); + + if (length == 0 || length > 1000) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[0] != '-' && (buffer[0] < '0' || buffer[0] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int pointPos = -1; + for (size_t i = 1; i + 1 < length; i++) { + if (buffer[i] == '.') { + if (pointPos > -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + pointPos = int(i); + } + if (buffer[i] != '.' && (buffer[i] < '0' || buffer[i] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + if (buffer[length - 1] < '0' || buffer[length - 1] > '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int afterDigitsCount = (pointPos == -1 ? 0 : int(length) - pointPos - 1); + if (afterDigitsCount < minAfterPointDigitCount || afterDigitsCount > maxAfterPointDigitCount) + in.quit(_pe, ("Expected strict double with number of digits after point in range [" + + vtos(minAfterPointDigitCount) + + "," + + vtos(maxAfterPointDigitCount) + + "], but \"" + __testlib_part(buffer) + "\" found").c_str() + ); + + int firstDigitPos = -1; + for (size_t i = 0; i < length; i++) + if (buffer[i] >= '0' && buffer[i] <= '9') { + firstDigitPos = int(i); + break; + } + + if (firstDigitPos > 1 || firstDigitPos == -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[firstDigitPos] == '0' && firstDigitPos + 1 < int(length) + && buffer[firstDigitPos + 1] >= '0' && buffer[firstDigitPos + 1] <= '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval) || __testlib_isInfinite(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (buffer[0] == '-' && retval >= 0) + in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const std::string& buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToStrictDouble(in, buffer.c_str(), minAfterPointDigitCount, maxAfterPointDigitCount); +} + +static inline long long stringToLongLong(InStream &in, const char *buffer) { + if (strcmp(buffer, "-9223372036854775808") == 0) + return LLONG_MIN; + + bool minus = false; + size_t length = strlen(buffer); + + if (length > 1 && buffer[0] == '-') + minus = true; + + if (length > 20) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + long long retval = 0LL; + + int zeroes = 0; + bool processingZeroes = true; + + for (int i = (minus ? 1 : 0); i < int(length); i++) { + if (buffer[i] == '0' && processingZeroes) + zeroes++; + else + processingZeroes = false; + + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (retval < 0) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if ((zeroes > 0 && (retval != 0 || minus)) || zeroes > 1) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + retval = (minus ? -retval : +retval); + + if (length < 19) + return retval; + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToLongLong(in, buffer.c_str()); +} + +static inline unsigned long long stringToUnsignedLongLong(InStream &in, const char *buffer) { + size_t length = strlen(buffer); + + if (length > 20) + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (length > 1 && buffer[0] == '0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + unsigned long long retval = 0LL; + for (int i = 0; i < int(length); i++) { + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (length < 19) + return retval; + + if (length == 20 && strcmp(buffer, "18446744073709551615") > 0) + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToUnsignedLongLong(in, buffer.c_str()); +} + +int InStream::readInteger() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int32 expected"); + + readWordTo(_tmpReadToken); + + long long value = stringToLongLong(*this, _tmpReadToken); + if (value < INT_MIN || value > INT_MAX) + quit(_pe, ("Expected int32, but \"" + __testlib_part(_tmpReadToken) + "\" found").c_str()); + + return int(value); +} + +long long InStream::readLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToLongLong(*this, _tmpReadToken); +} + +unsigned long long InStream::readUnsignedLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToUnsignedLongLong(*this, _tmpReadToken); +} + +long long InStream::readLong(long long minv, long long maxv, const std::string &variableName) { + long long result = readLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector +InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) +} + +std::vector InStream::readLongs(int size, int indexBase) { + __testlib_readMany(readLongs, readLong(), long long, true) +} + +unsigned long long +InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + unsigned long long result = readUnsignedLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, + ("Unsigned integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, ("Unsigned integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) +} + +std::vector InStream::readUnsignedLongs(int size, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) +} + +unsigned long long +InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + return readUnsignedLong(minv, maxv, variableName); +} + +int InStream::readInt() { + return readInteger(); +} + +int InStream::readInt(int minv, int maxv, const std::string &variableName) { + int result = readInt(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +int InStream::readInteger(int minv, int maxv, const std::string &variableName) { + return readInt(minv, maxv, variableName); +} + +std::vector InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readInts(int size, int indexBase) { + __testlib_readMany(readInts, readInt(), int, true) +} + +std::vector InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readIntegers(int size, int indexBase) { + __testlib_readMany(readIntegers, readInt(), int, true) +} + +double InStream::readReal() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - double expected"); + + return stringToDouble(*this, readWord()); +} + +double InStream::readDouble() { + return readReal(); +} + +double InStream::readReal(double minv, double maxv, const std::string &variableName) { + double result = readReal(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, ("Double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, + ("Double element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector +InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readReals(int size, int indexBase) { + __testlib_readMany(readReals, readReal(), double, true) +} + +double InStream::readDouble(double minv, double maxv, const std::string &variableName) { + return readReal(minv, maxv, variableName); +} + +std::vector +InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readDoubles(int size, int indexBase) { + __testlib_readMany(readDoubles, readDouble(), double, true) +} + +double InStream::readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - strict double expected"); + + double result = stringToStrictDouble(*this, readWord(), minAfterPointDigitCount, maxAfterPointDigitCount); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Strict double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, + ("Strict double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Strict double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, ("Strict double element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector InStream::readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictReals, + readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +double InStream::readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + return readStrictReal(minv, maxv, + minAfterPointDigitCount, maxAfterPointDigitCount, + variableName); +} + +std::vector InStream::readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictDoubles, + readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +bool InStream::eof() { + if (!strict && NULL == reader) + return true; + + return reader->eof(); +} + +bool InStream::seekEof() { + if (!strict && NULL == reader) + return true; + skipBlanks(); + return eof(); +} + +bool InStream::eoln() { + if (!strict && NULL == reader) + return true; + + int c = reader->nextChar(); + + if (!strict) { + if (c == EOFC) + return true; + + if (c == CR) { + c = reader->nextChar(); + + if (c != LF) { + reader->unreadChar(c); + reader->unreadChar(CR); + return false; + } else + return true; + } + + if (c == LF) + return true; + + reader->unreadChar(c); + return false; + } else { + bool returnCr = false; + +#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS) + if (c != CR) { + reader->unreadChar(c); + return false; + } else { + if (!returnCr) + returnCr = true; + c = reader->nextChar(); + } +#endif + if (c != LF) { + reader->unreadChar(c); + if (returnCr) + reader->unreadChar(CR); + return false; + } + + return true; + } +} + +void InStream::readEoln() { + lastLine = reader->getLine(); + if (!eoln()) + quit(_pe, "Expected EOLN"); +} + +void InStream::readEof() { + lastLine = reader->getLine(); + if (!eof()) + quit(_pe, "Expected EOF"); + + if (TestlibFinalizeGuard::alive && this == &inf) + testlibFinalizeGuard.readEofCount++; +} + +bool InStream::seekEoln() { + if (!strict && NULL == reader) + return true; + + int cur; + do { + cur = reader->nextChar(); + } while (cur == SPACE || cur == TAB); + + reader->unreadChar(cur); + return eoln(); +} + +void InStream::nextLine() { + readLine(); +} + +void InStream::readStringTo(std::string &result) { + if (NULL == reader) + quit(_pe, "Expected line"); + + result.clear(); + + for (;;) { + int cur = reader->curChar(); + + if (cur == LF || cur == EOFC) + break; + + if (cur == CR) { + cur = reader->nextChar(); + if (reader->curChar() == LF) { + reader->unreadChar(cur); + break; + } + } + + lastLine = reader->getLine(); + result += char(reader->nextChar()); + } + + if (strict) + readEoln(); + else + eoln(); +} + +std::string InStream::readString() { + readStringTo(_tmpReadToken); + return _tmpReadToken; +} + +std::vector InStream::readStrings(int size, int indexBase) { + __testlib_readMany(readStrings, readString(), std::string, false) +} + +void InStream::readStringTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result); + if (!p.matches(result)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Line \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Line [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Line element [index=" + vtos(readManyIteration) + "] equals to \"" + __testlib_part(result) + + "\" doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + else + quit(_wa, + ("Line element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } + } +} + +void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, pattern(ptrn), variableName); +} + +std::string InStream::readString(const pattern &p, const std::string &variableName) { + readStringTo(_tmpReadToken, p, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +std::string InStream::readString(const std::string &ptrn, const std::string &variableName) { + readStringTo(_tmpReadToken, ptrn, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +void InStream::readLineTo(std::string &result) { + readStringTo(result); +} + +std::string InStream::readLine() { + return readString(); +} + +std::vector InStream::readLines(int size, int indexBase) { + __testlib_readMany(readLines, readString(), std::string, false) +} + +void InStream::readLineTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result, p, variableName); +} + +void InStream::readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, ptrn, variableName); +} + +std::string InStream::readLine(const pattern &p, const std::string &variableName) { + return readString(p, variableName); +} + +std::vector +InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) { + return readString(ptrn, variableName); +} + +std::vector +InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void InStream::ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + this->__testlib_ensure(cond, message); + } +} + +void InStream::__testlib_ensure(bool cond, std::string message) { + if (!cond) + this->quit(_wa, message.c_str()); +} + +void InStream::close() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } + + opened = false; +} + +NORETURN void quit(TResult result, const std::string &msg) { + ouf.quit(result, msg.c_str()); +} + +NORETURN void quit(TResult result, const char *msg) { + ouf.quit(result, msg); +} + +NORETURN void __testlib_quitp(double points, const char *message) { + __testlib_points = points; + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", points)); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void __testlib_quitp(int points, const char *message) { + __testlib_points = points; + std::string stringPoints = format("%d", points); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void quitp(float points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(double points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitp(long double points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(int points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitpi(const std::string &points_info, const std::string &message = "") { + if (points_info.find(' ') != std::string::npos) + quit(_fail, "Parameter 'points_info' can't contain spaces"); + if (message.empty()) + quit(_points, ("points_info=" + points_info).c_str()); + else + quit(_points, ("points_info=" + points_info + " " + message).c_str()); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitp(F points, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quitp(points, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitf(TResult result, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quit(result, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void quitif(bool condition, TResult result, const char *format, ...) { + if (condition) { + FMT_TO_RESULT(format, format, message); + quit(result, message); + } +} + +NORETURN void __testlib_help() { + InStream::textColor(InStream::LightCyan); + std::fprintf(stderr, "TESTLIB %s, https://github.com/MikeMirzayanov/testlib/ ", VERSION); + std::fprintf(stderr, "by Mike Mirzayanov, copyright(c) 2005-2020\n"); + std::fprintf(stderr, "Checker name: \"%s\"\n", checkerName.c_str()); + InStream::textColor(InStream::LightGray); + + std::fprintf(stderr, "\n"); + std::fprintf(stderr, "Latest features: \n"); + for (size_t i = 0; i < sizeof(latestFeatures) / sizeof(char *); i++) { + std::fprintf(stderr, "*) %s\n", latestFeatures[i]); + } + std::fprintf(stderr, "\n"); + + std::fprintf(stderr, "Program must be run with the following arguments: \n"); + std::fprintf(stderr, " [--testset testset] [--group group] [ [<-appes>]]\n\n"); + + __testlib_exitCode = FAIL_EXIT_CODE; + std::exit(FAIL_EXIT_CODE); +} + +static void __testlib_ensuresPreconditions() { + // testlib assumes: sizeof(int) = 4. + __TESTLIB_STATIC_ASSERT(sizeof(int) == 4); + + // testlib assumes: INT_MAX == 2147483647. + __TESTLIB_STATIC_ASSERT(INT_MAX == 2147483647); + + // testlib assumes: sizeof(long long) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(long long) == 8); + + // testlib assumes: sizeof(double) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(double) == 8); + + // testlib assumes: no -ffast-math. + if (!__testlib_isNaN(+__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); + if (!__testlib_isNaN(-__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); +} + +std::string __testlib_testset; + +std::string getTestset() { + return __testlib_testset; +} + +std::string __testlib_group; + +std::string getGroup() { + return __testlib_group; +} + +static void __testlib_set_testset_and_group(int argc, char* argv[]) { + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + __testlib_testset = argv[++i]; + else + quit(_fail, std::string("Expected non-empty testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + __testlib_group = argv[++i]; + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } + } +} + +void registerGen(int argc, char *argv[], int randomGeneratorVersion) { + if (randomGeneratorVersion < 0 || randomGeneratorVersion > 1) + quitf(_fail, "Random generator version is expected to be 0 or 1."); + random_t::version = randomGeneratorVersion; + + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _generator; + __testlib_set_binary(stdin); + rnd.setSeed(argc, argv); + +#if __cplusplus > 199711L || defined(_MSC_VER) + prepareOpts(argc, argv); +#endif +} + +#ifdef USE_RND_AS_BEFORE_087 +void registerGen(int argc, char* argv[]) +{ + registerGen(argc, argv, 0); +} +#else +#ifdef __GNUC__ +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 4)) +__attribute__ ((deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." +" The third parameter stands for the random generator version." +" If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." +" Version 1 has been released on Spring, 2013. Use it to write new generators."))) +#else +__attribute__ ((deprecated)) +#endif +#endif +#ifdef _MSC_VER +__declspec(deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.")) +#endif +void registerGen(int argc, char *argv[]) { + std::fprintf(stderr, "Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.\n\n"); + registerGen(argc, argv, 0); +} +#endif + +void registerInteraction(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _interactor; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + tout.open(std::string(argv[3]) + "/teammessage.txt", + std::ios_base::out); + if (tout.fail() || !tout.is_open()) + quit(_fail, "Can not write to the test-output-file '" + + std::string(argv[2]) + "'"); + appesMode = false; + } + + inf.init(argv[1], _input); + + ouf.init(stdin, _output); + if (argc >= 3) + ans.init(argv[2], _answer); + else + ans.name = "unopened answer stream"; +} + +void registerValidation() { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _validator; + + __testlib_set_binary(stdin); + __testlib_set_binary(stdout); + __testlib_set_binary(stderr); + + inf.init(stdin, _input); + inf.strict = true; +} + +void registerValidation(int argc, char *argv[]) { + registerValidation(); + __testlib_set_testset_and_group(argc, argv); + + validator.initialize(); + TestlibFinalizeGuard::registered = true; + + std::string comment = "Validator must be run with the following arguments:" + " [--testset testset]" + " [--group group]" + " [--testOverviewLogFileName fileName]" + " [--testMarkupFileName fileName]" + " [--testCase testCase]" + " [--testCaseFileName fileName]" + ; + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + validator.setTestset(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + validator.setGroup(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testOverviewLogFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestOverviewLogFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testMarkupFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestMarkupFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testCase", argv[i])) { + if (i + 1 < argc) { + long long testCase = stringToLongLong(inf, argv[++i]); + if (testCase < 1 || testCase >= __TESTLIB_MAX_TEST_CASE) + quit(_fail, format("Argument testCase should be between 1 and %d, but ", __TESTLIB_MAX_TEST_CASE) + + toString(testCase) + " found"); + validator.setTestCase(int(testCase)); + } else + quit(_fail, comment); + } + if (!strcmp("--testCaseFileName", argv[i])) { + if (i + 1 < argc) { + validator.setTestCaseFileName(argv[++i]); + } else + quit(_fail, comment); + } + } +} + +void addFeature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.addFeature(feature); +} + +void feature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.feature(feature); +} + +class Checker { +private: + bool _initialized; + std::string _testset; + std::string _group; + +public: + Checker() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.group()"); + return _group; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } +} checker; + +void registerTestlibCmd(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _checker; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + + appesMode = false; + + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + appesMode = false; + } + + inf.init(argv[1], _input); + ouf.init(stdin, _output); + ans.init(argv[2], _answer); +} + +void registerTestlib(int argc, ...) { + if (argc < 3 || argc > 5) + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + + char **argv = new char *[argc + 1]; + + va_list ap; + va_start(ap, argc); + argv[0] = NULL; + for (int i = 0; i < argc; i++) { + argv[i + 1] = va_arg(ap, char*); + } + va_end(ap); + + registerTestlibCmd(argc + 1, argv); + delete[] argv; +} + +static inline void __testlib_ensure(bool cond, const std::string &msg) { + if (!cond) + quit(_fail, msg.c_str()); +} + +#ifdef __GNUC__ +__attribute__((unused)) +#endif +static inline void __testlib_ensure(bool cond, const char *msg) { + if (!cond) + quit(_fail, msg); +} + +#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) +#define ensure_ext(cond) __testlib_ensure(cond, "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"") + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +inline void ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + __testlib_ensure(cond, message); + } +} + +NORETURN static void __testlib_fail(const std::string &message) { + quitf(_fail, "%s", message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +void setName(const char *format, ...) { + FMT_TO_RESULT(format, format, name); + checkerName = name; +} + +/* + * Do not use random_shuffle, because it will produce different result + * for different C++ compilers. + * + * This implementation uses testlib random_t to produce random numbers, so + * it is stable. + */ +template +void shuffle(_RandomAccessIter __first, _RandomAccessIter __last) { + if (__first == __last) return; + for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) + std::iter_swap(__i, __first + rnd.next(int(__i - __first) + 1)); +} + + +template +#if defined(__GNUC__) && !defined(__clang__) +__attribute__ ((error("Don't use random_shuffle(), use shuffle() instead"))) +#endif +void random_shuffle(_RandomAccessIter, _RandomAccessIter) { + quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); +} + +#ifdef __GLIBC__ +# define RAND_THROW_STATEMENT throw() +#else +# define RAND_THROW_STATEMENT +#endif + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use rand(), use rnd.next() instead"))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +int rand() RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use rand(), use rnd.next() instead"); + + /* This line never runs. */ + //throw "Don't use rand(), use rnd.next() instead"; +} + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use srand(), you should use " +"'registerGen(argc, argv, 1);' to initialize generator seed " +"by hash code of the command line params. The third parameter " +"is randomGeneratorVersion (currently the latest is 1)."))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +void srand(unsigned int seed) RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use srand(), you should use " + "'registerGen(argc, argv, 1);' to initialize generator seed " + "by hash code of the command line params. The third parameter " + "is randomGeneratorVersion (currently the latest is 1) [ignored seed=%u].", seed); +} + +void startTest(int test) { + const std::string testFileName = vtos(test); + if (NULL == freopen(testFileName.c_str(), "wt", stdout)) + __testlib_fail("Unable to write file '" + testFileName + "'"); +} + +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + +inline std::string compress(const std::string &s) { + return __testlib_part(s); +} + +inline std::string englishEnding(int x) { + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separator) { + std::stringstream ss; + bool repeated = false; + for (_ForwardIterator i = first; i != last; i++) { + if (repeated) + ss << separator; + else + repeated = true; + ss << *i; + } + return ss.str(); +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last) { + return join(first, last, ' '); +} + +template +std::string join(const _Collection &collection, _Separator separator) { + return join(collection.begin(), collection.end(), separator); +} + +template +std::string join(const _Collection &collection) { + return join(collection, ' '); +} + +/** + * Splits string s by character separator returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separator returning non-empty items. + */ +std::vector tokenize(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + if (!item.empty()) + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning non-empty items. + */ +std::vector tokenize(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + + if (!item.empty()) + result.push_back(item); + + return result; +} + +NORETURN void __testlib_expectedButFound(TResult result, std::string expected, std::string found, const char *prepend) { + std::string message; + if (strlen(prepend) != 0) + message = format("%s: expected '%s', but found '%s'", + compress(prepend).c_str(), compress(expected).c_str(), compress(found).c_str()); + else + message = format("expected '%s', but found '%s'", + compress(expected).c_str(), compress(found).c_str()); + quit(result, message); +} + +NORETURN void __testlib_expectedButFound(TResult result, double expected, double found, const char *prepend) { + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, T expected, T found, const char *prependFormat = "", ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = vtos(expected); + std::string foundString = vtos(found); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, std::string expected, std::string found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, expected, found, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, double expected, double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, const char *expected, const char *found, const char *prependFormat, + ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, float expected, float found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, long double expected, long double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +struct is_iterable { + template + static char test(typename U::iterator *x); + + template + static long test(U *x); + + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct __testlib_enable_if { +}; + +template +struct __testlib_enable_if { + typedef T type; +}; + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + std::cout << t; +} + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + bool first = true; + for (typename T::const_iterator i = t.begin(); i != t.end(); i++) { + if (first) + first = false; + else + std::cout << " "; + std::cout << *i; + } +} + +template<> +typename __testlib_enable_if::value, void>::type +__testlib_print_one(const std::string &t) { + std::cout << t; +} + +template +void __println_range(A begin, B end) { + bool first = true; + for (B i = B(begin); i != end; i++) { + if (first) + first = false; + else + std::cout << " "; + __testlib_print_one(*i); + } + std::cout << std::endl; +} + +template +struct is_iterator { + static T makeT(); + + typedef void *twoptrs[2]; + + static twoptrs &test(...); + + template + static typename R::iterator_category *test(R); + + template + static void *test(R *); + + static const bool value = sizeof(test(makeT())) == sizeof(void *); +}; + +template +struct is_iterator::value>::type> { + static const bool value = false; +}; + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __println_range(a, b); +} + +template +void println(const A *a, const A *b) { + __println_range(a, b); +} + +template<> +void println(const char *a, const char *b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +void println(const T &x) { + __testlib_print_one(x); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << " "; + __testlib_print_one(g); + std::cout << std::endl; +} + +/* opts */ + +/** + * A struct for a singular testlib opt, containing the raw string value, + * and a boolean value for marking whether the opt is used. + */ +struct TestlibOpt { + std::string value; + bool used; + + TestlibOpt() : value(), used(false) {} +}; + +/** + * Get the type of opt based on the number of `-` at the beginning and the + * _validity_ of the key name. + * + * A valid key name must start with an alphabetical character. + * + * Returns: 1 if s has one `-` at the beginning, that is, "-keyName". + * 2 if s has two `-` at the beginning, that is, "--keyName". + * 0 otherwise. That is, if s has no `-` at the beginning, or has more + * than 2 at the beginning ("---keyName", "----keyName", ...), or the + * keyName is invalid (the first character is not an alphabetical + * character). + */ +size_t getOptType(char *s) { + if (!s || strlen(s) <= 1) + return 0; + + if (s[0] == '-') { + if (isalpha(s[1])) + return 1; + else if (s[1] == '-') + return isalpha(s[2]) ? 2 : 0; + } + + return 0; +} + +/** + * Parse the opt at a given index, and put it into the opts maps. + * + * An opt can has the following form: + * 1) -keyName=value or --keyName=value (ex. -n=10 --test-count=20) + * 2) -keyName value or --keyName value (ex. -n 10 --test-count 20) + * 3) -kNumval or --kNumval (ex. -n10 --t20) + * 4) -boolProperty or --boolProperty (ex. -sorted --tree-only) + * + * Only the second form consumes 2 arguments. The other consumes only 1 + * argument. + * + * In the third form, the key is a single character, and after the key is the + * value. The value _should_ be a number. + * + * In the forth form, the value is true. + * + * Params: + * - argc and argv: the number of command line arguments and the command line + * arguments themselves. + * - index: the starting index of the opts. + * - opts: the map containing the resulting opt. + * + * Returns: the number of consumed arguments to parse the opt. + * 0 if there is no arguments to parse. + * + * Algorithm details: + * TODO. Please refer to the implementation to see how the code handles the 3rd and 4th forms separately. + */ +size_t parseOpt(size_t argc, char *argv[], size_t index, std::map &opts) { + if (index >= argc) + return 0; + + size_t type = getOptType(argv[index]), inc = 1; + if (type > 0) { + std::string key(argv[index] + type), val; + size_t sep = key.find('='); + if (sep != std::string::npos) { + val = key.substr(sep + 1); + key = key.substr(0, sep); + } else { + if (index + 1 < argc && getOptType(argv[index + 1]) == 0) { + val = argv[index + 1]; + inc = 2; + } else { + if (key.length() > 1 && isdigit(key[1])) { + val = key.substr(1); + key = key.substr(0, 1); + } else { + val = "true"; + } + } + } + opts[key].value = val; + } else { + return inc; + } + + return inc; +} + +/** + * Global list containing all the arguments in the order given in the command line. + */ +std::vector __testlib_argv; + +/** + * Global dictionary containing all the parsed opts. + */ +std::map __testlib_opts; + +/** + * Whether automatic no unused opts ensurement should be done. This flag will + * be turned on when `has_opt` or `opt(key, default_value)` is called. + * + * The automatic ensurement can be suppressed when + * __testlib_ensureNoUnusedOptsSuppressed is true. + */ +bool __testlib_ensureNoUnusedOptsFlag = false; + +/** + * Suppress no unused opts automatic ensurement. Can be set to true with + * `suppressEnsureNoUnusedOpts()`. + */ +bool __testlib_ensureNoUnusedOptsSuppressed = false; + +/** + * Parse command line arguments into opts. + * The results are stored into __testlib_argv and __testlib_opts. + */ +void prepareOpts(int argc, char *argv[]) { + if (argc <= 0) + __testlib_fail("Opts: expected argc>=0 but found " + toString(argc)); + size_t n = static_cast(argc); // NOLINT(hicpp-use-auto,modernize-use-auto) + __testlib_opts = std::map(); + for (size_t index = 1; index < n; index += parseOpt(n, argv, index, __testlib_opts)); + __testlib_argv = std::vector(n); + for (size_t index = 0; index < n; index++) + __testlib_argv[index] = argv[index]; +} + +/** + * An utility function to get the argument with a given index. This function + * also print a readable message when no arguments are found. + */ +std::string __testlib_indexToArgv(int index) { + if (index < 0 || index >= int(__testlib_argv.size())) + __testlib_fail("Opts: index '" + toString(index) + "' is out of range [0," + + toString(__testlib_argv.size()) + ")"); + return __testlib_argv[size_t(index)]; +} + +/** + * An utility function to get the opt with a given key . This function + * also print a readable message when no opts are found. + */ +std::string __testlib_keyToOpts(const std::string &key) { + auto it = __testlib_opts.find(key); + if (it == __testlib_opts.end()) + __testlib_fail("Opts: unknown key '" + compress(key) + "'"); + it->second.used = true; + return it->second.value; +} + +template +T optValueToIntegral(const std::string &s, bool nonnegative); + +long double optValueToLongDouble(const std::string &s); + +std::string parseExponentialOptValue(const std::string &s) { + size_t pos = std::string::npos; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == 'e' || s[i] == 'E') { + if (pos != std::string::npos) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + pos = i; + } + if (pos == std::string::npos) + return s; + std::string e = s.substr(pos + 1); + if (!e.empty() && e[0] == '+') + e = e.substr(1); + if (e.empty()) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (e.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + int ne = optValueToIntegral(e, false); + std::string num = s.substr(0, pos); + if (num.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (!num.empty() && num[0] == '+') + num = num.substr(1); + optValueToLongDouble(num); + bool minus = false; + if (num[0] == '-') { + minus = true; + num = num.substr(1); + } + for (int i = 0; i < +ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num += '0'; + else { + if (sep + 1 == num.length()) + num[sep] = '0'; + else + std::swap(num[sep], num[sep + 1]); + } + } + for (int i = 0; i < -ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num.insert(num.begin() + int(num.length()) - 1, '.'); + else { + if (sep == 0) + num.insert(num.begin() + 1, '0'); + else + std::swap(num[sep - 1], num[sep]); + } + } + while (!num.empty() && num[0] == '0') + num = num.substr(1); + while (num.find('.') != std::string::npos && num.back() == '0') + num = num.substr(0, num.length() - 1); + if (!num.empty() && num.back() == '.') + num = num.substr(0, num.length() - 1); + if ((!num.empty() && num[0] == '.') || num.empty()) + num.insert(num.begin(), '0'); + return (minus ? "-" : "") + num; +} + +template +T optValueToIntegral(const std::string &s_, bool nonnegative) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + T value = 0; + long double about = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + if (nonnegative) + __testlib_fail("Opts: expected non-negative integer but '" + compress(s_) + "' found"); + sign = -1; + pos++; + } + for (size_t i = pos; i < s.length(); i++) { + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + value = value * 10 + s[i] - '0'; + about = about * 10 + s[i] - '0'; + } + value *= sign; + about *= sign; + if (fabsl(value - about) > 0.1) + __testlib_fail("Opts: integer overflow: expected integer but '" + compress(s_) + "' found"); + return value; +} + +long double optValueToLongDouble(const std::string &s_) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + long double value = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + sign = -1; + pos++; + } + bool period = false; + long double mul = 1.0; + for (size_t i = pos; i < s.length(); i++) { + if (s[i] == '.') { + if (period) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + else { + period = true; + continue; + } + } + if (period) + mul *= 10.0; + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + if (period) + value += (s[i] - '0') / mul; + else + value = value * 10 + s[i] - '0'; + } + value *= sign; + return value; +} + +/** + * Return true if there is an opt with a given key. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +bool has_opt(const std::string &key) { + __testlib_ensureNoUnusedOptsFlag = true; + return __testlib_opts.count(key) != 0; +} + +/* About the followings part for opt with 2 and 3 arguments. + * + * To parse the argv/opts correctly for a give type (integer, floating point or + * string), some meta programming must be done to determine the type of + * the type, and use the correct parsing function accordingly. + * + * The pseudo algorithm for determining the type of T and parse it accordingly + * is as follows: + * + * if (T is integral type) { + * if (T is unsigned) { + * parse the argv/opt as an **unsigned integer** of type T. + * } else { + * parse the argv/opt as an **signed integer** of type T. + * } else { + * if (T is floating point type) { + * parse the argv/opt as an **floating point** of type T. + * } else { + * // T should be std::string + * just the raw content of the argv/opts. + * } + * } + * + * To help with meta programming, some `opt` function with 2 or 3 arguments are + * defined. + * + * Opt with 3 arguments: T opt(true/false is_integral, true/false is_unsigned, index/key) + * + * + The first argument is for determining whether the type T is an integral + * type. That is, the result of std::is_integral() should be passed to + * this argument. When false, the type _should_ be either floating point or a + * std::string. + * + * + The second argument is for determining whether the signedness of the type + * T (if it is unsigned or signed). That is, the result of + * std::is_unsigned() should be passed to this argument. This argument can + * be ignored if the first one is false, because it only applies to integer. + * + * Opt with 2 arguments: T opt(true/false is_floating_point, index/key) + * + The first argument is for determining whether the type T is a floating + * point type. That is, the result of std::is_floating_point() should be + * passed to this argument. When false, the type _should_ be a std::string. + */ + +template +T opt(std::false_type is_floating_point, int index); + +template<> +std::string opt(std::false_type /*is_floating_point*/, int index) { + return __testlib_indexToArgv(index); +} + +template +T opt(std::true_type /*is_floating_point*/, int index) { + return T(optValueToLongDouble(__testlib_indexToArgv(index))); +} + +template +T opt(std::false_type /*is_integral*/, U /*is_unsigned*/, int index) { + return opt(std::is_floating_point(), index); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + std::string value = __testlib_indexToArgv(index); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: opt by index '" + toString(index) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed argv by a given index. + */ +template +T opt(int index) { + return opt(std::is_integral(), std::is_unsigned(), index); +} + +/** + * Return the raw string value of an argv by a given index. + */ +std::string opt(int index) { + return opt(index); +} + +/** + * Return the parsed argv by a given index. If the index is bigger than + * the number of argv, return the given default_value. + */ +template +T opt(int index, const T &default_value) { + if (index >= int(__testlib_argv.size())) { + return default_value; + } + return opt(index); +} + +/** + * Return the raw string value of an argv by a given index. If the index is + * bigger than the number of argv, return the given default_value. + */ +std::string opt(int index, const std::string &default_value) { + return opt(index, default_value); +} + +template +T opt(std::false_type is_floating_point, const std::string &key); + +template<> +std::string opt(std::false_type /*is_floating_point*/, const std::string &key) { + return __testlib_keyToOpts(key); +} + +template +T opt(std::true_type /*is_integral*/, const std::string &key) { + return T(optValueToLongDouble(__testlib_keyToOpts(key))); +} + +template +T opt(std::false_type /*is_integral*/, U, const std::string &key) { + return opt(std::is_floating_point(), key); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + if (!has_opt(key)) + return false; + std::string value = __testlib_keyToOpts(key); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: key '" + compress(key) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed opt by a given key. + */ +template +T opt(const std::string &key) { + return opt(std::is_integral(), std::is_unsigned(), key); +} + +/** + * Return the raw string value of an opt by a given key + */ +std::string opt(const std::string &key) { + return opt(key); +} + +/* Scorer started. */ + +enum TestResultVerdict { + SKIPPED, + OK, + WRONG_ANSWER, + RUNTIME_ERROR, + TIME_LIMIT_EXCEEDED, + IDLENESS_LIMIT_EXCEEDED, + MEMORY_LIMIT_EXCEEDED, + COMPILATION_ERROR, + CRASHED, + FAILED +}; + +std::string serializeVerdict(TestResultVerdict verdict) { + switch (verdict) { + case SKIPPED: return "SKIPPED"; + case OK: return "OK"; + case WRONG_ANSWER: return "WRONG_ANSWER"; + case RUNTIME_ERROR: return "RUNTIME_ERROR"; + case TIME_LIMIT_EXCEEDED: return "TIME_LIMIT_EXCEEDED"; + case IDLENESS_LIMIT_EXCEEDED: return "IDLENESS_LIMIT_EXCEEDED"; + case MEMORY_LIMIT_EXCEEDED: return "MEMORY_LIMIT_EXCEEDED"; + case COMPILATION_ERROR: return "COMPILATION_ERROR"; + case CRASHED: return "CRASHED"; + case FAILED: return "FAILED"; + } + throw "Unexpected verdict"; +} + +TestResultVerdict deserializeTestResultVerdict(std::string s) { + if (s == "SKIPPED") + return SKIPPED; + else if (s == "OK") + return OK; + else if (s == "WRONG_ANSWER") + return WRONG_ANSWER; + else if (s == "RUNTIME_ERROR") + return RUNTIME_ERROR; + else if (s == "TIME_LIMIT_EXCEEDED") + return TIME_LIMIT_EXCEEDED; + else if (s == "IDLENESS_LIMIT_EXCEEDED") + return IDLENESS_LIMIT_EXCEEDED; + else if (s == "MEMORY_LIMIT_EXCEEDED") + return MEMORY_LIMIT_EXCEEDED; + else if (s == "COMPILATION_ERROR") + return COMPILATION_ERROR; + else if (s == "CRASHED") + return CRASHED; + else if (s == "FAILED") + return FAILED; + ensuref(false, "Unexpected serialized TestResultVerdict"); + // No return actually. + return FAILED; +} + +struct TestResult { + int testIndex; + std::string testset; + std::string group; + TestResultVerdict verdict; + double points; + long long timeConsumed; + long long memoryConsumed; + std::string input; + std::string output; + std::string answer; + int exitCode; + std::string checkerComment; +}; + +std::string serializePoints(double points) { + if (std::isnan(points)) + return ""; + else { + char c[64]; + sprintf(c, "%.03lf", points); + return c; + } +} + +double deserializePoints(std::string s) { + if (s.empty()) + return std::numeric_limits::quiet_NaN(); + else { + double result; + ensuref(sscanf(s.c_str(), "%lf", &result) == 1, "Invalid serialized points"); + return result; + } +} + +std::string escapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\r') + continue; + if (s[i] == '\n') { + result += "\\n"; + continue; + } + if (s[i] == '\\' || s[i] == ';') + result += '\\'; + result += s[i]; + } + return result; +} + +std::string unescapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\' && i + 1 < s.length()) { + if (s[i + 1] == 'n') { + result += '\n'; + i++; + continue; + } else if (s[i + 1] == ';' || s[i + 1] == '\\') { + result += s[i + 1]; + i++; + continue; + } + } + result += s[i]; + } + return result; +} + +std::string serializeTestResult(TestResult tr) { + std::string result; + result += std::to_string(tr.testIndex); + result += ";"; + result += escapeTestResultString(tr.testset); + result += ";"; + result += escapeTestResultString(tr.group); + result += ";"; + result += serializeVerdict(tr.verdict); + result += ";"; + result += serializePoints(tr.points); + result += ";"; + result += std::to_string(tr.timeConsumed); + result += ";"; + result += std::to_string(tr.memoryConsumed); + result += ";"; + result += escapeTestResultString(tr.input); + result += ";"; + result += escapeTestResultString(tr.output); + result += ";"; + result += escapeTestResultString(tr.answer); + result += ";"; + result += std::to_string(tr.exitCode); + result += ";"; + result += escapeTestResultString(tr.checkerComment); + return result; +} + +TestResult deserializeTestResult(std::string s) { + std::vector items; + std::string t; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\') { + t += s[i]; + if (i + 1 < s.length()) + t += s[i + 1]; + i++; + continue; + } else { + if (s[i] == ';') { + items.push_back(t); + t = ""; + } else + t += s[i]; + } + } + items.push_back(t); + + ensuref(items.size() == 12, "Invalid TestResult serialization: expected exactly 12 items"); + + TestResult tr; + size_t pos = 0; + tr.testIndex = stoi(items[pos++]); + tr.testset = unescapeTestResultString(items[pos++]); + tr.group = unescapeTestResultString(items[pos++]); + tr.verdict = deserializeTestResultVerdict(items[pos++]); + tr.points = deserializePoints(items[pos++]); + tr.timeConsumed = stoll(items[pos++]); + tr.memoryConsumed = stoll(items[pos++]); + tr.input = unescapeTestResultString(items[pos++]); + tr.output = unescapeTestResultString(items[pos++]); + tr.answer = unescapeTestResultString(items[pos++]); + tr.exitCode = stoi(items[pos++]); + tr.checkerComment = unescapeTestResultString(items[pos++]); + + return tr; +} + +std::vector readTestResults(std::string fileName) { + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + ensuref(stream.is_open(), "Can't read test results file '%s'", fileName.c_str()); + std::vector result; + std::string line; + while (getline(stream, line)) + if (!line.empty()) + result.push_back(deserializeTestResult(line)); + stream.close(); + return result; +} + +std::function)> __testlib_scorer; + +struct TestlibScorerGuard { + ~TestlibScorerGuard() { + if (testlibMode == _scorer) { + std::vector testResults; + while (!inf.eof()) { + std::string line = inf.readLine(); + if (!line.empty()) + testResults.push_back(deserializeTestResult(line)); + } + inf.readEof(); + printf("%.3f\n", __testlib_scorer(testResults)); + } + } +} __testlib_scorer_guard; + +void registerScorer(int argc, char *argv[], std::function)> scorer) { + /* Supress unused. */ + (void)(argc), (void)(argv); + + __testlib_ensuresPreconditions(); + + testlibMode = _scorer; + __testlib_set_binary(stdin); + + inf.init(stdin, _input); + inf.strict = false; + + __testlib_scorer = scorer; +} + +/* Scorer ended. */ + +/** + * Return the parsed opt by a given key. If no opts with the given key are + * found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +template +T opt(const std::string &key, const T &default_value) { + if (!has_opt(key)) { + return default_value; + } + return opt(key); +} + +/** + * Return the raw string value of an opt by a given key. If no opts with the + * given key are found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +std::string opt(const std::string &key, const std::string &default_value) { + return opt(key, default_value); +} + +/** + * Check if all opts are used. If not, __testlib_fail is called. + * Should be used after calling all opt() function calls. + * + * This function is useful when opt() with default_value for checking typos + * in the opt's key. + */ +void ensureNoUnusedOpts() { + for (const auto &opt: __testlib_opts) { + if (!opt.second.used) { + __testlib_fail(format("Opts: unused key '%s'", compress(opt.first).c_str())); + } + } +} + +void suppressEnsureNoUnusedOpts() { + __testlib_ensureNoUnusedOptsSuppressed = true; +} + +void TestlibFinalizeGuard::autoEnsureNoUnusedOpts() { + if (__testlib_ensureNoUnusedOptsFlag && !__testlib_ensureNoUnusedOptsSuppressed) { + ensureNoUnusedOpts(); + } +} + +TestlibFinalizeGuard testlibFinalizeGuard; + +#endif +#endif \ No newline at end of file diff --git a/ICPC/swerc2022_F/data.zip b/ICPC/swerc2022_F/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..11c612536ca48ca337330fc6e1cae9f0e348631f --- /dev/null +++ b/ICPC/swerc2022_F/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c001086387cf2b400bc53fdfcf66e961178b8e83b11ab11fec0458e0774925c +size 1774365 diff --git a/ICPC/swerc2022_F/init.yml b/ICPC/swerc2022_F/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..4776fe0a5f9131d0c5f8f4689d77e6449f1fcf88 --- /dev/null +++ b/ICPC/swerc2022_F/init.yml @@ -0,0 +1,17 @@ +archive: data.zip +test_cases: +- in: 2.in + out: 2.ans + points: 1 +- in: 3.in + out: 3.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 diff --git a/ICPC/swerc2022_G/data.zip b/ICPC/swerc2022_G/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..a8a0614b0a770fd862369fef051478dfa9d58bbc --- /dev/null +++ b/ICPC/swerc2022_G/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce4180e07fdc2708472dbef408756384cc1c8040439dae6226b924363b9a763b +size 9720739 diff --git a/ICPC/swerc2022_G/init.yml b/ICPC/swerc2022_G/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..15c77170b73048e75ebda41f4e23bd5a1f53b17a --- /dev/null +++ b/ICPC/swerc2022_G/init.yml @@ -0,0 +1,74 @@ +archive: data.zip +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 3.in + out: 3.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_H/data.zip b/ICPC/swerc2022_H/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..662ee05be0ae367f82b4899d206c2e088a796cdc --- /dev/null +++ b/ICPC/swerc2022_H/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:994efa28f42287e14f08364b148323ac1c4e5559576bf342c65e073c038aaaa0 +size 10439904 diff --git a/ICPC/swerc2022_H/init.yml b/ICPC/swerc2022_H/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e5b20426669a4c8e62bc9065dbe3105bbfcb3dfc --- /dev/null +++ b/ICPC/swerc2022_H/init.yml @@ -0,0 +1,68 @@ +archive: data.zip +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_I/data.zip b/ICPC/swerc2022_I/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..cf2b46b8bf88ea95ea672e8bc2f54f19e700a838 --- /dev/null +++ b/ICPC/swerc2022_I/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b2c7f9fca32b6e9533e0dc59e12ef5d938b51e2a813184b59748714e8bf5213 +size 8064 diff --git a/ICPC/swerc2022_I/init.yml b/ICPC/swerc2022_I/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7cba50be6145154ab37fd441217938d037232eb0 --- /dev/null +++ b/ICPC/swerc2022_I/init.yml @@ -0,0 +1,90 @@ +archive: data.zip +interactive: + files: + - output_validators/interactor.cpp + - output_validators/testlib.h + lang: CPP17 + type: default +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 3.in + out: 3.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 +unbuffered: false diff --git a/ICPC/swerc2022_I/output_validators/interactor.cpp b/ICPC/swerc2022_I/output_validators/interactor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de0f9d284fecb46126484b847bc16cc4324474ab --- /dev/null +++ b/ICPC/swerc2022_I/output_validators/interactor.cpp @@ -0,0 +1,123 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "testlib.h" + +#include +#include +#include +#include + +int main(int argc, char **argv) { + registerInteraction(argc, argv); + + int n = inf.readInt(); + int m = inf.readInt(); + std::vector x = inf.readInts(n); + + std::cout << n << " " << m << std::endl; + for (int i = 0; i < n - 1; ++i) std::cout << x[i] << " "; + std::cout << x[n - 1] << std::endl; + + std::string player = ouf.readWord(); + + std::vector p(n); + std::iota(p.begin(), p.end(), 0); + std::sort(p.begin(), p.end(), [&](int const& a, int const& b) { + return x[a] > x[b]; + }); + + bool win; + + if (player == "Bernardo") { // Play as Alessia + std::vector chosen(m + 1, 0); + for (int t = 0; t < n; ++t) { + int y = x[p[t]]; + int last = 0; + int min_width = m + 1; + int a = 0; + for (int i = 1; i <= m; ++i) { + if (chosen[i]) { + last = i; + } + if ((i == m || chosen[i + 1]) && i - last >= y && i - last < min_width) { + min_width = i - last; + a = last + 1; + } + } + if (a == 0) a = rnd.next(1, m - y + 1); + std::cout << y << " " << a << std::endl; + int b = ouf.readInt(a, a + y - 1); + ++chosen[b]; + } + win = true; + for (int i = 1; i <= m; ++i) { + if (chosen[i] >= 2) { + win = false; + break; + } + } + } else if (player == "Alessia") { // Play as Bernardo + int k = 0; + for (int j = 1; j < n; ++j) { + if (m / (j + 1) - x[p[j]] < m / (k + 1) - x[p[k]]) { + k = j; + } + } + std::vector chosen(m + 1, 0); + std::vector remaining(m + 1, 0); + for (int y : x) ++remaining[y]; + for (int t = 0; t < n; ++t) { + int y = ouf.readInt(1, m); + if (!remaining[y]) quitf(_wa, "Chosen an invalid y"); + --remaining[y]; + int a = ouf.readInt(1, m - y + 1); + int b = 0; + for (int i = a; i <= a + y - 1; ++i) { + if (i % x[p[k]] == 0) { + b = i; + break; + } + } + if (b == 0) b = rnd.next(a, a + y - 1); + ++chosen[b]; + std::cout << b << std::endl; + } + win = false; + for (int i = 1; i <= m; ++i) { + if (chosen[i] >= 2) { + win = true; + break; + } + } + } else quitf(_pe, "Invalid player name"); + + if (win) quitf(_wa, "Judge won the game"); + else quitf(_ok, "Contestant won the game"); + + return 0; +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], "/dev/null", argv[2], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2022_I/output_validators/testlib.h b/ICPC/swerc2022_I/output_validators/testlib.h new file mode 100644 index 0000000000000000000000000000000000000000..69baa1f48b5d86daa58cade43c18b382abb03587 --- /dev/null +++ b/ICPC/swerc2022_I/output_validators/testlib.h @@ -0,0 +1,5893 @@ +// Modified by a script to work with DOMjudge. +// Differences with the standard testlib.h: +// - The values of some exit codes. +// - The functions registerInteraction and registerTestlibCmd. + +/* + * It is strictly recommended to include "testlib.h" before any other include + * in your code. In this case testlib overrides compiler specific "random()". + * + * If you can't compile your code and compiler outputs something about + * ambiguous call of "random_shuffle", "rand" or "srand" it means that + * you shouldn't use them. Use "shuffle", and "rnd.next()" instead of them + * because these calls produce stable result for any C++ compiler. Read + * sample generator sources for clarification. + * + * Please read the documentation for class "random_t" and use "rnd" instance in + * generators. Probably, these sample calls will be usefull for you: + * rnd.next(); rnd.next(100); rnd.next(1, 2); + * rnd.next(3.14); rnd.next("[a-z]{1,100}"). + * + * Also read about wnext() to generate off-center random distribution. + * + * See https://github.com/MikeMirzayanov/testlib/ to get latest version or bug tracker. + */ + +#ifndef _TESTLIB_H_ +#define _TESTLIB_H_ + +/* + * Copyright (c) 2005-2022 + */ + +#define VERSION "0.9.40-SNAPSHOT" + +/* + * Mike Mirzayanov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* NOTE: This file contains testlib library for C++. + * + * Check, using testlib running format: + * check.exe [ [-appes]], + * If result file is specified it will contain results. + * + * Validator, using testlib running format: + * validator.exe < input.txt, + * It will return non-zero exit code and writes message to standard output. + * + * Generator, using testlib running format: + * gen.exe [parameter-1] [parameter-2] [... paramerter-n] + * You can write generated test(s) into standard output or into the file(s). + * + * Interactor, using testlib running format: + * interactor.exe [ [ [-appes]]], + * Reads test from inf (mapped to args[1]), writes result to tout (mapped to argv[2], + * can be judged by checker later), reads program output from ouf (mapped to stdin), + * writes output to program via stdout (use cout, printf, etc). + */ + +const char *latestFeatures[] = { + "Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators", + "Added opt defaults via opt(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt()).", + "For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values", + "Added quitpi(points_info, message) function to return with _points exit code 7 and given points_info", + "rnd.partition(size, sum[, min_part=1]) returns random (unsorted) partition which is a representation of the given `sum` as a sum of `size` positive integers (or >=min_part if specified)", + "rnd.distinct(size, n) and rnd.distinct(size, from, to)", + "opt(\"some_missing_key\") returns false now", + "has_opt(key)", + "Abort validator on validator.testset()/validator.group() if registered without using command line", + "Print integer range violations in a human readable way like `violates the range [1, 10^9]`", + "Opts supported: use them like n = opt(\"n\"), in a command line you can use an exponential notation", + "Reformatted", + "Use setTestCase(i) or unsetTestCase() to support test cases (you can use it in any type of program: generator, interactor, validator or checker)", + "Fixed issue #87: readStrictDouble accepts \"-0.00\"", + "Fixed issue #83: added InStream::quitif(condition, ...)", + "Fixed issue #79: fixed missed guard against repeated header include", + "Fixed issue #80: fixed UB in case of huge quitf message", + "Fixed issue #84: added readXs(size, indexBase = 1)", + "Fixed stringstream repeated usage issue", + "Fixed compilation in g++ (for std=c++03)", + "Batch of println functions (support collections, iterator ranges)", + "Introduced rnd.perm(size, first = 0) to generate a `first`-indexed permutation", + "Allow any whitespace in readInts-like functions for non-validators", + "Ignore 4+ command line arguments ifdef EJUDGE", + "Speed up of vtos", + "Show line number in validators in case of incorrect format", + "Truncate huge checker/validator/interactor message", + "Fixed issue with readTokenTo of very long tokens, now aborts with _pe/_fail depending of a stream type", + "Introduced InStream::ensure/ensuref checking a condition, returns wa/fail depending of a stream type", + "Fixed compilation in VS 2015+", + "Introduced space-separated read functions: readWords/readTokens, multilines read functions: readStrings/readLines", + "Introduced space-separated read functions: readInts/readIntegers/readLongs/readUnsignedLongs/readDoubles/readReals/readStrictDoubles/readStrictReals", + "Introduced split/tokenize functions to separate string by given char", + "Introduced InStream::readUnsignedLong and InStream::readLong with unsigned long long paramerters", + "Supported --testOverviewLogFileName for validator: bounds hits + features", + "Fixed UB (sequence points) in random_t", + "POINTS_EXIT_CODE returned back to 7 (instead of 0)", + "Removed disable buffers for interactive problems, because it works unexpectedly in wine", + "InStream over string: constructor of InStream from base InStream to inherit policies and std::string", + "Added expectedButFound quit function, examples: expectedButFound(_wa, 10, 20), expectedButFound(_fail, ja, pa, \"[n=%d,m=%d]\", n, m)", + "Fixed incorrect interval parsing in patterns", + "Use registerGen(argc, argv, 1) to develop new generator, use registerGen(argc, argv, 0) to compile old generators (originally created for testlib under 0.8.7)", + "Introduced disableFinalizeGuard() to switch off finalization checkings", + "Use join() functions to format a range of items as a single string (separated by spaces or other separators)", + "Use -DENABLE_UNEXPECTED_EOF to enable special exit code (by default, 8) in case of unexpected eof. It is good idea to use it in interactors", + "Use -DUSE_RND_AS_BEFORE_087 to compile in compatibility mode with random behavior of versions before 0.8.7", + "Fixed bug with nan in stringToDouble", + "Fixed issue around overloads for size_t on x64", + "Added attribute 'points' to the XML output in case of result=_points", + "Exit codes can be customized via macros, e.g. -DPE_EXIT_CODE=14", + "Introduced InStream function readWordTo/readTokenTo/readStringTo/readLineTo for faster reading", + "Introduced global functions: format(), englishEnding(), upperCase(), lowerCase(), compress()", + "Manual buffer in InStreams, some IO speed improvements", + "Introduced quitif(bool, const char* pattern, ...) which delegates to quitf() in case of first argument is true", + "Introduced guard against missed quitf() in checker or readEof() in validators", + "Supported readStrictReal/readStrictDouble - to use in validators to check strictly float numbers", + "Supported registerInteraction(argc, argv)", + "Print checker message to the stderr instead of stdout", + "Supported TResult _points to output calculated score, use quitp(...) functions", + "Fixed to be compilable on Mac", + "PC_BASE_EXIT_CODE=50 in case of defined TESTSYS", + "Fixed issues 19-21, added __attribute__ format printf", + "Some bug fixes", + "ouf.readInt(1, 100) and similar calls return WA", + "Modified random_t to avoid integer overflow", + "Truncated checker output [patch by Stepan Gatilov]", + "Renamed class random -> class random_t", + "Supported name parameter for read-and-validation methods, like readInt(1, 2, \"n\")", + "Fixed bug in readDouble()", + "Improved ensuref(), fixed nextLine to work in case of EOF, added startTest()", + "Supported \"partially correct\", example: quitf(_pc(13), \"result=%d\", result)", + "Added shuffle(begin, end), use it instead of random_shuffle(begin, end)", + "Added readLine(const string& ptrn), fixed the logic of readLine() in the validation mode", + "Package extended with samples of generators and validators", + "Written the documentation for classes and public methods in testlib.h", + "Implemented random routine to support generators, use registerGen() to switch it on", + "Implemented strict mode to validate tests, use registerValidation() to switch it on", + "Now ncmp.cpp and wcmp.cpp are return WA if answer is suffix or prefix of the output", + "Added InStream::readLong() and removed InStream::readLongint()", + "Now no footer added to each report by default (use directive FOOTER to switch on)", + "Now every checker has a name, use setName(const char* format, ...) to set it", + "Now it is compatible with TTS (by Kittens Computing)", + "Added \'ensure(condition, message = \"\")\' feature, it works like assert()", + "Fixed compatibility with MS C++ 7.1", + "Added footer with exit code information", + "Added compatibility with EJUDGE (compile with EJUDGE directive)", + "Added compatibility with Contester (compile with CONTESTER directive)" +}; + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NO_VA_START_VALIDATION +#endif + +/* Overrides random() for Borland C++. */ +#define random __random_deprecated +#include +#include +#include +#include +#undef random + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +# include +#endif + +#if (_WIN32 || __WIN32__ || __WIN32 || _WIN64 || __WIN64__ || __WIN64 || WINNT || __WINNT || __WINNT__ || __CYGWIN__) +# if !defined(_MSC_VER) || _MSC_VER > 1400 +# define NOMINMAX 1 +# include +# else +# define WORD unsigned short +# include +# endif +# include +# define ON_WINDOWS +# if defined(_MSC_VER) && _MSC_VER > 1400 +# pragma warning( disable : 4127 ) +# pragma warning( disable : 4146 ) +# pragma warning( disable : 4458 ) +# endif +#else +# define WORD unsigned short +# include +#endif + +#if defined(FOR_WINDOWS) && defined(FOR_LINUX) +#error Only one target system is allowed +#endif + +#ifndef LLONG_MIN +#define LLONG_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX (18446744073709551615) +#endif + +#define LF ((char)10) +#define CR ((char)13) +#define TAB ((char)9) +#define SPACE ((char)' ') +#define EOFC (255) + +#ifndef OK_EXIT_CODE +# ifdef CONTESTER +# define OK_EXIT_CODE 42 +# else +# define OK_EXIT_CODE 42 +# endif +#endif + +#ifndef WA_EXIT_CODE +# ifdef EJUDGE +# define WA_EXIT_CODE 43 +# elif defined(CONTESTER) +# define WA_EXIT_CODE 43 +# else +# define WA_EXIT_CODE 43 +# endif +#endif + +#ifndef PE_EXIT_CODE +# ifdef EJUDGE +# define PE_EXIT_CODE 43 +# elif defined(CONTESTER) +# define PE_EXIT_CODE 43 +# else +# define PE_EXIT_CODE 43 +# endif +#endif + +#ifndef FAIL_EXIT_CODE +# ifdef EJUDGE +# define FAIL_EXIT_CODE 6 +# elif defined(CONTESTER) +# define FAIL_EXIT_CODE 0xA3 +# else +# define FAIL_EXIT_CODE 3 +# endif +#endif + +#ifndef DIRT_EXIT_CODE +# ifdef EJUDGE +# define DIRT_EXIT_CODE 43 +# else +# define DIRT_EXIT_CODE 43 +# endif +#endif + +#ifndef POINTS_EXIT_CODE +# define POINTS_EXIT_CODE 7 +#endif + +#ifndef UNEXPECTED_EOF_EXIT_CODE +# define UNEXPECTED_EOF_EXIT_CODE 43 +#endif + +#ifndef PC_BASE_EXIT_CODE +# ifdef TESTSYS +# define PC_BASE_EXIT_CODE 50 +# else +# define PC_BASE_EXIT_CODE 0 +# endif +#endif + +#ifdef __GNUC__ +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] __attribute__((unused)) +#else +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] +#endif + +#ifdef ON_WINDOWS +#define I64 "%I64d" +#define U64 "%I64u" +#else +#define I64 "%lld" +#define U64 "%llu" +#endif + +#ifdef _MSC_VER +# define NORETURN __declspec(noreturn) +#elif defined __GNUC__ +# define NORETURN __attribute__ ((noreturn)) +#else +# define NORETURN +#endif + +static char __testlib_format_buffer[16777216]; +static int __testlib_format_buffer_usage_count = 0; + +#define FMT_TO_RESULT(fmt, cstr, result) std::string result; \ + if (__testlib_format_buffer_usage_count != 0) \ + __testlib_fail("FMT_TO_RESULT::__testlib_format_buffer_usage_count != 0"); \ + __testlib_format_buffer_usage_count++; \ + va_list ap; \ + va_start(ap, fmt); \ + vsnprintf(__testlib_format_buffer, sizeof(__testlib_format_buffer), cstr, ap); \ + va_end(ap); \ + __testlib_format_buffer[sizeof(__testlib_format_buffer) - 1] = 0; \ + result = std::string(__testlib_format_buffer); \ + __testlib_format_buffer_usage_count--; \ + +const long long __TESTLIB_LONGLONG_MAX = 9223372036854775807LL; +const int __TESTLIB_MAX_TEST_CASE = 1073741823; + +int __testlib_exitCode; + +bool __testlib_hasTestCase; +int __testlib_testCase = -1; + +void setTestCase(int testCase); + +void unsetTestCase() { + __testlib_hasTestCase = false; + __testlib_testCase = -1; +} + +NORETURN static void __testlib_fail(const std::string &message); + +template +static inline T __testlib_abs(const T &x) { + return x > 0 ? x : -x; +} + +template +static inline T __testlib_min(const T &a, const T &b) { + return a < b ? a : b; +} + +template +static inline T __testlib_max(const T &a, const T &b) { + return a > b ? a : b; +} + +template +static inline T __testlib_crop(T value, T a, T b) { + return __testlib_min(__testlib_max(value, a), --b); +} + +static inline double __testlib_crop(double value, double a, double b) { + value = __testlib_min(__testlib_max(value, a), b); + if (value >= b) + value = std::nexttoward(b, a); + return value; +} + +static bool __testlib_prelimIsNaN(double r) { + volatile double ra = r; +#ifndef __BORLANDC__ + return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); +#else + return std::_isnan(ra); +#endif +} + +static std::string removeDoubleTrailingZeroes(std::string value) { + while (!value.empty() && value[value.length() - 1] == '0' && value.find('.') != std::string::npos) + value = value.substr(0, value.length() - 1); + if (!value.empty() && value[value.length() - 1] == '.') + return value + '0'; + else + return value; +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +std::string format(const char *fmt, ...) { + FMT_TO_RESULT(fmt, fmt, result); + return result; +} + +std::string format(const std::string fmt, ...) { + FMT_TO_RESULT(fmt, fmt.c_str(), result); + return result; +} + +static std::string __testlib_part(const std::string &s); + +static bool __testlib_isNaN(double r) { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); + volatile double ra = r; + long long llr1, llr2; + std::memcpy((void *) &llr1, (void *) &ra, sizeof(double)); + ra = -ra; + std::memcpy((void *) &llr2, (void *) &ra, sizeof(double)); + long long llnan = 0xFFF8000000000000LL; + return __testlib_prelimIsNaN(r) || llnan == llr1 || llnan == llr2; +} + +static double __testlib_nan() { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); +#ifndef NAN + long long llnan = 0xFFF8000000000000LL; + double nan; + std::memcpy(&nan, &llnan, sizeof(double)); + return nan; +#else + return NAN; +#endif +} + +static bool __testlib_isInfinite(double r) { + volatile double ra = r; + return (ra > 1E300 || ra < -1E300); +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline bool doubleCompare(double expected, double result, double MAX_DOUBLE_ERROR) { + MAX_DOUBLE_ERROR += 1E-15; + if (__testlib_isNaN(expected)) { + return __testlib_isNaN(result); + } else if (__testlib_isInfinite(expected)) { + if (expected > 0) { + return result > 0 && __testlib_isInfinite(result); + } else { + return result < 0 && __testlib_isInfinite(result); + } + } else if (__testlib_isNaN(result) || __testlib_isInfinite(result)) { + return false; + } else if (__testlib_abs(result - expected) <= MAX_DOUBLE_ERROR) { + return true; + } else { + double minv = __testlib_min(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + double maxv = __testlib_max(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + return result >= minv && result <= maxv; + } +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline double doubleDelta(double expected, double result) { + double absolute = __testlib_abs(result - expected); + + if (__testlib_abs(expected) > 1E-9) { + double relative = __testlib_abs(absolute / expected); + return __testlib_min(absolute, relative); + } else + return absolute; +} + +/** It does nothing on non-windows and files differ from stdin/stdout/stderr. */ +static void __testlib_set_binary(std::FILE *file) { + if (NULL != file) { +#ifdef ON_WINDOWS +# ifdef _O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(_setmode(STDIN_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdin), _O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(_setmode(STDOUT_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdout), _O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(_setmode(STDERR_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stderr), _O_BINARY)); +# endif +# elif O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(setmode(STDIN_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdin), O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(setmode(STDOUT_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdout), O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(setmode(STDERR_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stderr), O_BINARY)); +# endif +# endif +#endif + } +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +static std::string vtos(const T &t, std::true_type) { + if (t == 0) + return "0"; + else { + T n(t); + bool negative = n < 0; + std::string s; + while (n != 0) { + T digit = n % 10; + if (digit < 0) + digit = -digit; + s += char('0' + digit); + n /= 10; + } + std::reverse(s.begin(), s.end()); + return negative ? "-" + s : s; + } +} + +template +static std::string vtos(const T &t, std::false_type) { + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string vtos(const T &t) { + return vtos(t, std::is_integral()); +} + +/* signed case. */ +template +static std::string toHumanReadableString(const T &n, std::false_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else if (n_ == -1) + return "-10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +/* unsigned case. */ +template +static std::string toHumanReadableString(const T &n, std::true_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +template +static std::string toHumanReadableString(const T &n) { + return toHumanReadableString(n, std::is_unsigned()); +} +#else +template +static std::string vtos(const T& t) +{ + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string toHumanReadableString(const T &n) { + return vtos(n); +} +#endif + +template +static std::string toString(const T &t) { + return vtos(t); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +/* opts */ +void prepareOpts(int argc, char* argv[]); +#endif + +/* + * Very simple regex-like pattern. + * It used for two purposes: validation and generation. + * + * For example, pattern("[a-z]{1,5}").next(rnd) will return + * random string from lowercase latin letters with length + * from 1 to 5. It is easier to call rnd.next("[a-z]{1,5}") + * for the same effect. + * + * Another samples: + * "mike|john" will generate (match) "mike" or "john"; + * "-?[1-9][0-9]{0,3}" will generate (match) non-zero integers from -9999 to 9999; + * "id-([ac]|b{2})" will generate (match) "id-a", "id-bb", "id-c"; + * "[^0-9]*" will match sequences (empty or non-empty) without digits, you can't + * use it for generations. + * + * You can't use pattern for generation if it contains meta-symbol '*'. Also it + * is not recommended to use it for char-sets with meta-symbol '^' like [^a-z]. + * + * For matching very simple greedy algorithm is used. For example, pattern + * "[0-9]?1" will not match "1", because of greedy nature of matching. + * Alternations (meta-symbols "|") are processed with brute-force algorithm, so + * do not use many alternations in one expression. + * + * If you want to use one expression many times it is better to compile it into + * a single pattern like "pattern p("[a-z]+")". Later you can use + * "p.matches(std::string s)" or "p.next(random_t& rd)" to check matching or generate + * new string by pattern. + * + * Simpler way to read token and check it for pattern matching is "inf.readToken("[a-z]+")". + * + * All spaces are ignored in regex, unless escaped with \. For example, ouf.readLine("NO SOLUTION") + * will expect "NOSOLUTION", the correct call should be ouf.readLine("NO\\ SOLUTION") or + * ouf.readLine(R"(NO\ SOLUTION)") if you prefer raw string literals from C++11. + */ +class random_t; + +class pattern { +public: + /* Create pattern instance by string. */ + pattern(std::string s); + + /* Generate new string by pattern and given random_t. */ + std::string next(random_t &rnd) const; + + /* Checks if given string match the pattern. */ + bool matches(const std::string &s) const; + + /* Returns source string of the pattern. */ + std::string src() const; + +private: + bool matches(const std::string &s, size_t pos) const; + + std::string s; + std::vector children; + std::vector chars; + int from; + int to; +}; + +/* + * Use random_t instances to generate random values. It is preffered + * way to use randoms instead of rand() function or self-written + * randoms. + * + * Testlib defines global variable "rnd" of random_t class. + * Use registerGen(argc, argv, 1) to setup random_t seed be command + * line (to use latest random generator version). + * + * Random generates uniformly distributed values if another strategy is + * not specified explicitly. + */ +class random_t { +private: + unsigned long long seed; + static const unsigned long long multiplier; + static const unsigned long long addend; + static const unsigned long long mask; + static const int lim; + + long long nextBits(int bits) { + if (bits <= 48) { + seed = (seed * multiplier + addend) & mask; + return (long long) (seed >> (48 - bits)); + } else { + if (bits > 63) + __testlib_fail("random_t::nextBits(int bits): n must be less than 64"); + + int lowerBitCount = (random_t::version == 0 ? 31 : 32); + + long long left = (nextBits(31) << 32); + long long right = nextBits(lowerBitCount); + + return left ^ right; + } + } + +public: + static int version; + + /* New random_t with fixed seed. */ + random_t() + : seed(3905348978240129619LL) { + } + + /* Sets seed by command line. */ + void setSeed(int argc, char *argv[]) { + random_t p; + + seed = 3905348978240129619LL; + for (int i = 1; i < argc; i++) { + std::size_t le = std::strlen(argv[i]); + for (std::size_t j = 0; j < le; j++) + seed = seed * multiplier + (unsigned int) (argv[i][j]) + addend; + seed += multiplier / addend; + } + + seed = seed & mask; + } + + /* Sets seed by given value. */ + void setSeed(long long _seed) { + _seed = (_seed ^ multiplier) & mask; + seed = _seed; + } + +#ifndef __BORLANDC__ + + /* Random string value by given pattern (see pattern documentation). */ + std::string next(const std::string &ptrn) { + pattern p(ptrn); + return p.next(*this); + } + +#else + /* Random string value by given pattern (see pattern documentation). */ + std::string next(std::string ptrn) + { + pattern p(ptrn); + return p.next(*this); + } +#endif + + /* Random value in range [0, n-1]. */ + int next(int n) { + if (n <= 0) + __testlib_fail("random_t::next(int n): n must be positive"); + + if ((n & -n) == n) // n is a power of 2 + return (int) ((n * (long long) nextBits(31)) >> 31); + + const long long limit = INT_MAX / n * n; + + long long bits; + do { + bits = nextBits(31); + } while (bits >= limit); + + return int(bits % n); + } + + /* Random value in range [0, n-1]. */ + unsigned int next(unsigned int n) { + if (n >= INT_MAX) + __testlib_fail("random_t::next(unsigned int n): n must be less INT_MAX"); + return (unsigned int) next(int(n)); + } + + /* Random value in range [0, n-1]. */ + long long next(long long n) { + if (n <= 0) + __testlib_fail("random_t::next(long long n): n must be positive"); + + const long long limit = __TESTLIB_LONGLONG_MAX / n * n; + + long long bits; + do { + bits = nextBits(63); + } while (bits >= limit); + + return bits % n; + } + + /* Random value in range [0, n-1]. */ + unsigned long long next(unsigned long long n) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::next(unsigned long long n): n must be less LONGLONG_MAX"); + return (unsigned long long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + long next(long n) { + return (long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + unsigned long next(unsigned long n) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX"); + return (unsigned long) next((unsigned long long) (n)); + } + + /* Returns random value in range [from,to]. */ + int next(int from, int to) { + return int(next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + unsigned int next(unsigned int from, unsigned int to) { + return (unsigned int) (next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + long long next(long long from, long long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long long next(unsigned long long from, unsigned long long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long long from, unsigned long long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + long next(long from, long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long next(unsigned long from, unsigned long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long from, unsigned long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Random double value in range [0, 1). */ + double next() { + long long left = ((long long) (nextBits(26)) << 27); + long long right = nextBits(27); + return __testlib_crop((double) (left + right) / (double) (1LL << 53), 0.0, 1.0); + } + + /* Random double value in range [0, n). */ + double next(double n) { + if (n <= 0.0) + __testlib_fail("random_t::next(double): n should be positive"); + return __testlib_crop(n * next(), 0.0, n); + } + + /* Random double value in range [from, to). */ + double next(double from, double to) { + if (from >= to) + __testlib_fail("random_t::next(double from, double to): from should be strictly less than to"); + return next(to - from) + from; + } + + /* Returns random element from container. */ + template + typename Container::value_type any(const Container &c) { + int size = int(c.size()); + if (size <= 0) + __testlib_fail("random_t::any(const Container& c): c.size() must be positive"); + return *(c.begin() + next(size)); + } + + /* Returns random element from iterator range. */ + template + typename Iter::value_type any(const Iter &begin, const Iter &end) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length"); + return *(begin + next(size)); + } + + /* Random string value by given pattern (see pattern documentation). */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + std::string next(const char *format, ...) { + FMT_TO_RESULT(format, format, ptrn); + return next(ptrn); + } + + /* + * Weighted next. If type == 0 than it is usual "next()". + * + * If type = 1, than it returns "max(next(), next())" + * (the number of "max" functions equals to "type"). + * + * If type < 0, than "max" function replaces with "min". + */ + int wnext(int n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(int n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + int result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((int) (double(n) * p), 0, n); + } + } + + /* See wnext(int, int). It uses the same algorithms. */ + long long wnext(long long n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(long long n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + long long result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((long long) (double(n) * p), 0LL, n); + } + } + + /* Returns value in [0, n). See wnext(int, int). It uses the same algorithms. */ + double wnext(double n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(double n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + double result = next(); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next()); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next()); + + return n * result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop(n * p, 0.0, n); + } + } + + /* Returns value in [0, 1). See wnext(int, int). It uses the same algorithms. */ + double wnext(int type) { + return wnext(1.0, type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned int wnext(unsigned int n, int type) { + if (n >= INT_MAX) + __testlib_fail("random_t::wnext(unsigned int n, int type): n must be less INT_MAX"); + return (unsigned int) wnext(int(n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long long wnext(unsigned long long n, int type) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long long n, int type): n must be less LONGLONG_MAX"); + + return (unsigned long long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + long wnext(long n, int type) { + return (long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long wnext(unsigned long n, int type) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long n, int type): n must be less LONG_MAX"); + + return (unsigned long) wnext((unsigned long long) (n), type); + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(int from, int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(int from, int to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(unsigned int from, unsigned int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned int from, unsigned int to, int type): from can't not exceed to"); + return int(wnext(to - from + 1, type) + from); + } + + /* Returns weighted random value in range [from, to]. */ + long long wnext(long long from, long long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long long from, long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long long wnext(unsigned long long from, unsigned long long to, int type) { + if (from > to) + __testlib_fail( + "random_t::wnext(unsigned long long from, unsigned long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + long wnext(long from, long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long from, long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long wnext(unsigned long from, unsigned long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned long from, unsigned long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random double value in range [from, to). */ + double wnext(double from, double to, int type) { + if (from >= to) + __testlib_fail("random_t::wnext(double from, double to, int type): from should be strictly less than to"); + return wnext(to - from, type) + from; + } + + /* Returns weighted random element from container. */ + template + typename Container::value_type wany(const Container &c, int type) { + size_t size = c.size(); + if (size <= 0) + __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive"); + return *(c.begin() + wnext(size, type)); + } + + /* Returns weighted random element from iterator range. */ + template + typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail( + "random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length"); + return *(begin + wnext(size, type)); + } + + /* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/ + template + std::vector perm(T size, E first) { + if (size < 0) + __testlib_fail("random_t::perm(T size, E first = 0): size must non-negative"); + else if (size == 0) + return std::vector(); + std::vector p(size); + E current = first; + for (T i = 0; i < size; i++) + p[i] = current++; + if (size > 1) + for (T i = 1; i < size; i++) + std::swap(p[i], p[next(i + 1)]); + return p; + } + + /* Returns random permutation of the given size (values are between 0 and size-1)*/ + template + std::vector perm(T size) { + return perm(size, T(0)); + } + + /* Returns `size` unordered (unsorted) distinct numbers between `from` and `to`. */ + template + std::vector distinct(int size, T from, T to) { + std::vector result; + if (size == 0) + return result; + + if (from > to) + __testlib_fail("random_t::distinct expected from <= to"); + + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + + uint64_t n = to - from + 1; + if (uint64_t(size) > n) + __testlib_fail("random_t::distinct expected size <= to - from + 1"); + + double expected = 0.0; + for (int i = 1; i <= size; i++) + expected += double(n) / double(n - i + 1); + + if (expected < double(n)) { + std::set vals; + while (int(vals.size()) < size) { + T x = T(next(from, to)); + if (vals.insert(x).second) + result.push_back(x); + } + } else { + if (n > 1000000000) + __testlib_fail("random_t::distinct here expected to - from + 1 <= 1000000000"); + std::vector p(perm(int(n), from)); + result.insert(result.end(), p.begin(), p.begin() + size); + } + + return result; + } + + /* Returns `size` unordered (unsorted) distinct numbers between `0` and `upper`-1. */ + template + std::vector distinct(int size, T upper) { + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + if (size == 0) + return std::vector(); + + if (upper <= 0) + __testlib_fail("random_t::distinct expected upper > 0"); + if (size > upper) + __testlib_fail("random_t::distinct expected size <= upper"); + + return distinct(size, T(0), upper - 1); + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of integers not less than min_part. */ + template + std::vector partition(int size, T sum, T min_part) { + if (size < 0) + __testlib_fail("random_t::partition: size < 0"); + if (size == 0 && sum != 0) + __testlib_fail("random_t::partition: size == 0 && sum != 0"); + if (min_part * size > sum) + __testlib_fail("random_t::partition: min_part * size > sum"); + if (size == 0 && sum == 0) + return std::vector(); + + T sum_ = sum; + sum -= min_part * size; + + std::vector septums(size); + std::vector d = distinct(size - 1, T(1), T(sum + size - 1)); + for (int i = 0; i + 1 < size; i++) + septums[i + 1] = d[i]; + sort(septums.begin(), septums.end()); + + std::vector result(size); + for (int i = 0; i + 1 < size; i++) + result[i] = septums[i + 1] - septums[i] - 1; + result[size - 1] = sum + size - 1 - septums.back(); + + for (std::size_t i = 0; i < result.size(); i++) + result[i] += min_part; + + T result_sum = 0; + for (std::size_t i = 0; i < result.size(); i++) + result_sum += result[i]; + if (result_sum != sum_) + __testlib_fail("random_t::partition: partition sum is expected to be the given sum"); + + if (*std::min_element(result.begin(), result.end()) < min_part) + __testlib_fail("random_t::partition: partition min is expected to be no less than the given min_part"); + + if (int(result.size()) != size || result.size() != (size_t) size) + __testlib_fail("random_t::partition: partition size is expected to be equal to the given size"); + + return result; + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of positive integers. */ + template + std::vector partition(int size, T sum) { + return partition(size, sum, T(1)); + } +}; + +const int random_t::lim = 25; +const unsigned long long random_t::multiplier = 0x5DEECE66DLL; +const unsigned long long random_t::addend = 0xBLL; +const unsigned long long random_t::mask = (1LL << 48) - 1; +int random_t::version = -1; + +/* Pattern implementation */ +bool pattern::matches(const std::string &s) const { + return matches(s, 0); +} + +static bool __pattern_isSlash(const std::string &s, size_t pos) { + return s[pos] == '\\'; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static bool __pattern_isCommandChar(const std::string &s, size_t pos, char value) { + if (pos >= s.length()) + return false; + + int slashes = 0; + + int before = int(pos) - 1; + while (before >= 0 && s[before] == '\\') + before--, slashes++; + + return slashes % 2 == 0 && s[pos] == value; +} + +static char __pattern_getChar(const std::string &s, size_t &pos) { + if (__pattern_isSlash(s, pos)) + pos += 2; + else + pos++; + + return s[pos - 1]; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static int __pattern_greedyMatch(const std::string &s, size_t pos, const std::vector chars) { + int result = 0; + + while (pos < s.length()) { + char c = s[pos++]; + if (!std::binary_search(chars.begin(), chars.end(), c)) + break; + else + result++; + } + + return result; +} + +std::string pattern::src() const { + return s; +} + +bool pattern::matches(const std::string &s, size_t pos) const { + std::string result; + + if (to > 0) { + int size = __pattern_greedyMatch(s, pos, chars); + if (size < from) + return false; + if (size > to) + size = to; + pos += size; + } + + if (children.size() > 0) { + for (size_t child = 0; child < children.size(); child++) + if (children[child].matches(s, pos)) + return true; + return false; + } else + return pos == s.length(); +} + +std::string pattern::next(random_t &rnd) const { + std::string result; + result.reserve(20); + + if (to == INT_MAX) + __testlib_fail("pattern::next(random_t& rnd): can't process character '*' for generation"); + + if (to > 0) { + int count = rnd.next(to - from + 1) + from; + for (int i = 0; i < count; i++) + result += chars[rnd.next(int(chars.size()))]; + } + + if (children.size() > 0) { + int child = rnd.next(int(children.size())); + result += children[child].next(rnd); + } + + return result; +} + +static void __pattern_scanCounts(const std::string &s, size_t &pos, int &from, int &to) { + if (pos >= s.length()) { + from = to = 1; + return; + } + + if (__pattern_isCommandChar(s, pos, '{')) { + std::vector parts; + std::string part; + + pos++; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, '}')) { + if (__pattern_isCommandChar(s, pos, ',')) + parts.push_back(part), part = "", pos++; + else + part += __pattern_getChar(s, pos); + } + + if (part != "") + parts.push_back(part); + + if (!__pattern_isCommandChar(s, pos, '}')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (parts.size() < 1 || parts.size() > 2) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector numbers; + + for (size_t i = 0; i < parts.size(); i++) { + if (parts[i].length() == 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + int number; + if (std::sscanf(parts[i].c_str(), "%d", &number) != 1) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + numbers.push_back(number); + } + + if (numbers.size() == 1) + from = to = numbers[0]; + else + from = numbers[0], to = numbers[1]; + + if (from > to) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + } else { + if (__pattern_isCommandChar(s, pos, '?')) { + from = 0, to = 1, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '*')) { + from = 0, to = INT_MAX, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '+')) { + from = 1, to = INT_MAX, pos++; + return; + } + + from = to = 1; + } +} + +static std::vector __pattern_scanCharSet(const std::string &s, size_t &pos) { + if (pos >= s.length()) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector result; + + if (__pattern_isCommandChar(s, pos, '[')) { + pos++; + bool negative = __pattern_isCommandChar(s, pos, '^'); + if (negative) + pos++; + + char prev = 0; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, ']')) { + if (__pattern_isCommandChar(s, pos, '-') && prev != 0) { + pos++; + + if (pos + 1 == s.length() || __pattern_isCommandChar(s, pos, ']')) { + result.push_back(prev); + prev = '-'; + continue; + } + + char next = __pattern_getChar(s, pos); + if (prev > next) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + for (char c = prev; c != next; c++) + result.push_back(c); + result.push_back(next); + + prev = 0; + } else { + if (prev != 0) + result.push_back(prev); + prev = __pattern_getChar(s, pos); + } + } + + if (prev != 0) + result.push_back(prev); + + if (!__pattern_isCommandChar(s, pos, ']')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (negative) { + std::sort(result.begin(), result.end()); + std::vector actuals; + for (int code = 0; code < 255; code++) { + char c = char(code); + if (!std::binary_search(result.begin(), result.end(), c)) + actuals.push_back(c); + } + result = actuals; + } + + std::sort(result.begin(), result.end()); + } else + result.push_back(__pattern_getChar(s, pos)); + + return result; +} + +pattern::pattern(std::string s) : s(s), from(0), to(0) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (!__pattern_isCommandChar(s, i, ' ')) + t += s[i]; + s = t; + + int opened = 0; + int firstClose = -1; + std::vector seps; + + for (size_t i = 0; i < s.length(); i++) { + if (__pattern_isCommandChar(s, i, '(')) { + opened++; + continue; + } + + if (__pattern_isCommandChar(s, i, ')')) { + opened--; + if (opened == 0 && firstClose == -1) + firstClose = int(i); + continue; + } + + if (opened < 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (__pattern_isCommandChar(s, i, '|') && opened == 0) + seps.push_back(int(i)); + } + + if (opened != 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (seps.size() == 0 && firstClose + 1 == (int) s.length() + && __pattern_isCommandChar(s, 0, '(') && __pattern_isCommandChar(s, s.length() - 1, ')')) { + children.push_back(pattern(s.substr(1, s.length() - 2))); + } else { + if (seps.size() > 0) { + seps.push_back(int(s.length())); + int last = 0; + + for (size_t i = 0; i < seps.size(); i++) { + children.push_back(pattern(s.substr(last, seps[i] - last))); + last = seps[i] + 1; + } + } else { + size_t pos = 0; + chars = __pattern_scanCharSet(s, pos); + __pattern_scanCounts(s, pos, from, to); + if (pos < s.length()) + children.push_back(pattern(s.substr(pos))); + } + } +} + +/* End of pattern implementation */ + +template +inline bool isEof(C c) { + return c == EOFC; +} + +template +inline bool isEoln(C c) { + return (c == LF || c == CR); +} + +template +inline bool isBlanks(C c) { + return (c == LF || c == CR || c == SPACE || c == TAB); +} + +inline std::string trim(const std::string &s) { + if (s.empty()) + return s; + + int left = 0; + while (left < int(s.length()) && isBlanks(s[left])) + left++; + if (left >= int(s.length())) + return ""; + + int right = int(s.length()) - 1; + while (right >= 0 && isBlanks(s[right])) + right--; + if (right < 0) + return ""; + + return s.substr(left, right - left + 1); +} + +enum TMode { + _input, _output, _answer +}; + +/* Outcomes 6-15 are reserved for future use. */ +enum TResult { + _ok = 0, + _wa = 1, + _pe = 2, + _fail = 3, + _dirt = 4, + _points = 5, + _unexpected_eof = 8, + _partially = 16 +}; + +enum TTestlibMode { + _unknown, _checker, _validator, _generator, _interactor, _scorer +}; + +#define _pc(exitCode) (TResult(_partially + (exitCode))) + +/* Outcomes 6-15 are reserved for future use. */ +const std::string outcomes[] = { + "accepted", + "wrong-answer", + "presentation-error", + "fail", + "fail", +#ifndef PCMS2 + "points", +#else + "relative-scoring", +#endif + "reserved", + "reserved", + "unexpected-eof", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "partially-correct" +}; + +class InputStreamReader { +public: + virtual void setTestCase(int testCase) = 0; + + virtual std::vector getReadChars() = 0; + + virtual int curChar() = 0; + + virtual int nextChar() = 0; + + virtual void skipChar() = 0; + + virtual void unreadChar(int c) = 0; + + virtual std::string getName() = 0; + + virtual bool eof() = 0; + + virtual void close() = 0; + + virtual int getLine() = 0; + + virtual ~InputStreamReader() = 0; +}; + +InputStreamReader::~InputStreamReader() { + // No operations. +} + +class StringInputStreamReader : public InputStreamReader { +private: + std::string s; + size_t pos; + +public: + StringInputStreamReader(const std::string &content) : s(content), pos(0) { + // No operations. + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in StringInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in StringInputStreamReader"); + } + + int curChar() { + if (pos >= s.length()) + return EOFC; + else + return s[pos]; + } + + int nextChar() { + if (pos >= s.length()) { + pos++; + return EOFC; + } else + return s[pos++]; + } + + void skipChar() { + pos++; + } + + void unreadChar(int c) { + if (pos == 0) + __testlib_fail("StringInputStreamReader::unreadChar(int): pos == 0."); + pos--; + if (pos < s.length()) + s[pos] = char(c); + } + + std::string getName() { + return __testlib_part(s); + } + + int getLine() { + return -1; + } + + bool eof() { + return pos >= s.length(); + } + + void close() { + // No operations. + } +}; + +class FileInputStreamReader : public InputStreamReader { +private: + std::FILE *file; + std::string name; + int line; + std::vector undoChars; + std::vector readChars; + std::vector undoReadChars; + + inline int postprocessGetc(int getcResult) { + if (getcResult != EOF) + return getcResult; + else + return EOFC; + } + + int getc(FILE *file) { + int c; + int rc; + + if (undoChars.empty()) { + c = rc = ::getc(file); + } else { + c = undoChars.back(); + undoChars.pop_back(); + rc = undoReadChars.back(); + undoReadChars.pop_back(); + } + + if (c == LF) + line++; + + readChars.push_back(rc); + return c; + } + + int ungetc(int c/*, FILE* file*/) { + if (!readChars.empty()) { + undoReadChars.push_back(readChars.back()); + readChars.pop_back(); + } + if (c == LF) + line--; + undoChars.push_back(c); + return c; + } + +public: + FileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + // No operations. + } + + void setTestCase(int testCase) { + if (testCase < 0 || testCase > __TESTLIB_MAX_TEST_CASE) + __testlib_fail(format("testCase expected fit in [1,%d], but %d doesn't", __TESTLIB_MAX_TEST_CASE, testCase)); + readChars.push_back(testCase + 256); + } + + std::vector getReadChars() { + return readChars; + } + + int curChar() { + if (feof(file)) + return EOFC; + else { + int c = getc(file); + ungetc(c/*, file*/); + return postprocessGetc(c); + } + } + + int nextChar() { + if (feof(file)) + return EOFC; + else + return postprocessGetc(getc(file)); + } + + void skipChar() { + getc(file); + } + + void unreadChar(int c) { + ungetc(c/*, file*/); + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + if (NULL == file || feof(file)) + return true; + else { + int c = nextChar(); + if (c == EOFC || (c == EOF && feof(file))) + return true; + unreadChar(c); + return false; + } + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +class BufferedFileInputStreamReader : public InputStreamReader { +private: + static const size_t BUFFER_SIZE; + static const size_t MAX_UNREAD_COUNT; + + std::FILE *file; + std::string name; + int line; + + char *buffer; + bool *isEof; + int bufferPos; + size_t bufferSize; + + bool refill() { + if (NULL == file) + __testlib_fail("BufferedFileInputStreamReader: file == NULL (" + getName() + ")"); + + if (bufferPos >= int(bufferSize)) { + size_t readSize = fread( + buffer + MAX_UNREAD_COUNT, + 1, + BUFFER_SIZE - MAX_UNREAD_COUNT, + file + ); + + if (readSize < BUFFER_SIZE - MAX_UNREAD_COUNT + && ferror(file)) + __testlib_fail("BufferedFileInputStreamReader: unable to read (" + getName() + ")"); + + bufferSize = MAX_UNREAD_COUNT + readSize; + bufferPos = int(MAX_UNREAD_COUNT); + std::memset(isEof + MAX_UNREAD_COUNT, 0, sizeof(isEof[0]) * readSize); + + return readSize > 0; + } else + return true; + } + + char increment() { + char c; + if ((c = buffer[bufferPos++]) == LF) + line++; + return c; + } + +public: + BufferedFileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + buffer = new char[BUFFER_SIZE]; + isEof = new bool[BUFFER_SIZE]; + bufferSize = MAX_UNREAD_COUNT; + bufferPos = int(MAX_UNREAD_COUNT); + } + + ~BufferedFileInputStreamReader() { + if (NULL != buffer) { + delete[] buffer; + buffer = NULL; + } + if (NULL != isEof) { + delete[] isEof; + isEof = NULL; + } + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in BufferedFileInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in BufferedFileInputStreamReader"); + } + + int curChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : buffer[bufferPos]; + } + + int nextChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : increment(); + } + + void skipChar() { + increment(); + } + + void unreadChar(int c) { + bufferPos--; + if (bufferPos < 0) + __testlib_fail("BufferedFileInputStreamReader::unreadChar(int): bufferPos < 0"); + isEof[bufferPos] = (c == EOFC); + buffer[bufferPos] = char(c); + if (c == LF) + line--; + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + return !refill() || EOFC == curChar(); + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +const size_t BufferedFileInputStreamReader::BUFFER_SIZE = 2000000; +const size_t BufferedFileInputStreamReader::MAX_UNREAD_COUNT = BufferedFileInputStreamReader::BUFFER_SIZE / 2; + +/* + * Streams to be used for reading data in checkers or validators. + * Each read*() method moves pointer to the next character after the + * read value. + */ +struct InStream { + /* Do not use them. */ + InStream(); + + ~InStream(); + + /* Wrap std::string with InStream. */ + InStream(const InStream &baseStream, std::string content); + + InputStreamReader *reader; + int lastLine; + + std::string name; + TMode mode; + bool opened; + bool stdfile; + bool strict; + + int wordReserveSize; + std::string _tmpReadToken; + + int readManyIteration; + size_t maxFileSize; + size_t maxTokenLength; + size_t maxMessageLength; + + void init(std::string fileName, TMode mode); + + void init(std::FILE *f, TMode mode); + + void setTestCase(int testCase); + std::vector getReadChars(); + + /* Moves stream pointer to the first non-white-space character or EOF. */ + void skipBlanks(); + + /* Returns current character in the stream. Doesn't remove it from stream. */ + char curChar(); + + /* Moves stream pointer one character forward. */ + void skipChar(); + + /* Returns current character and moves pointer one character forward. */ + char nextChar(); + + /* Returns current character and moves pointer one character forward. */ + char readChar(); + + /* As "readChar()" but ensures that the result is equal to given parameter. */ + char readChar(char c); + + /* As "readChar()" but ensures that the result is equal to the space (code=32). */ + char readSpace(); + + /* Puts back the character into the stream. */ + void unreadChar(char c); + + /* Reopens stream, you should not use it. */ + void reset(std::FILE *file = NULL); + + /* Checks that current position is EOF. If not it doesn't move stream pointer. */ + bool eof(); + + /* Moves pointer to the first non-white-space character and calls "eof()". */ + bool seekEof(); + + /* + * Checks that current position contains EOLN. + * If not it doesn't move stream pointer. + * In strict mode expects "#13#10" for windows or "#10" for other platforms. + */ + bool eoln(); + + /* Moves pointer to the first non-space and non-tab character and calls "eoln()". */ + bool seekEoln(); + + /* Moves stream pointer to the first character of the next line (if exists). */ + void nextLine(); + + /* + * Reads new token. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + std::string readWord(); + + /* The same as "readWord()", it is preffered to use "readToken()". */ + std::string readToken(); + + /* The same as "readWord()", but ensures that token matches to given pattern. */ + std::string readWord(const std::string &ptrn, const std::string &variableName = ""); + + std::string readWord(const pattern &p, const std::string &variableName = ""); + + std::vector + readWords(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readWords(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readWords(int size, int indexBase = 1); + + /* The same as "readToken()", but ensures that token matches to given pattern. */ + std::string readToken(const std::string &ptrn, const std::string &variableName = ""); + + std::string readToken(const pattern &p, const std::string &variableName = ""); + + std::vector + readTokens(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readTokens(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readTokens(int size, int indexBase = 1); + + void readWordTo(std::string &result); + + void readWordTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + void readTokenTo(std::string &result); + + void readTokenTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads new long long value. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + long long readLong(); + + unsigned long long readUnsignedLong(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInteger(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInt(); + + /* As "readLong()" but ensures that value in the range [minv,maxv]. */ + long long readLong(long long minv, long long maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of long longs. */ + std::vector + readLongs(int size, long long minv, long long maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of long longs. */ + std::vector readLongs(int size, int indexBase = 1); + + unsigned long long + readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + std::vector readUnsignedLongs(int size, int indexBase = 1); + + unsigned long long readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + /* As "readInteger()" but ensures that value in the range [minv,maxv]. */ + int readInteger(int minv, int maxv, const std::string &variableName = ""); + + /* As "readInt()" but ensures that value in the range [minv,maxv]. */ + int readInt(int minv, int maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of integers. */ + std::vector + readIntegers(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readIntegers(int size, int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int indexBase = 1); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readReal(); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readDouble(); + + /* As "readReal()" but ensures that value in the range [minv,maxv]. */ + double readReal(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readReals(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readReals(int size, int indexBase = 1); + + /* As "readDouble()" but ensures that value in the range [minv,maxv]. */ + double readDouble(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readDoubles(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readDoubles(int size, int indexBase = 1); + + /* + * As "readReal()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* + * As "readDouble()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* As readLine(). */ + std::string readString(); + + /* Read many lines. */ + std::vector readStrings(int size, int indexBase = 1); + + /* See readLine(). */ + void readStringTo(std::string &result); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readStrings(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readStrings(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads line from the current position to EOLN or EOF. Moves stream pointer to + * the first character of the new line (if possible). + */ + std::string readLine(); + + /* Read many lines. */ + std::vector readLines(int size, int indexBase = 1); + + /* See readLine(). */ + void readLineTo(std::string &result); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readLines(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readLines(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* Reads EOLN or fails. Use it in validators. Calls "eoln()" method internally. */ + void readEoln(); + + /* Reads EOF or fails. Use it in validators. Calls "eof()" method internally. */ + void readEof(); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quit(TResult result, const char *msg); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quitf(TResult result, const char *msg, ...); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + void quitif(bool condition, TResult result, const char *msg, ...); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quits(TResult result, std::string msg); + + /* + * Checks condition and aborts a program if codition is false. + * Returns _wa for ouf and _fail on any other streams. + */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void ensuref(bool cond, const char *format, ...); + + void __testlib_ensure(bool cond, std::string message); + + void close(); + + const static int NO_INDEX = INT_MAX; + const static char OPEN_BRACKET = char(11); + const static char CLOSE_BRACKET = char(17); + + const static WORD LightGray = 0x07; + const static WORD LightRed = 0x0c; + const static WORD LightCyan = 0x0b; + const static WORD LightGreen = 0x0a; + const static WORD LightYellow = 0x0e; + + static void textColor(WORD color); + + static void quitscr(WORD color, const char *msg); + + static void quitscrS(WORD color, std::string msg); + + void xmlSafeWrite(std::FILE *file, const char *msg); + + /* Skips UTF-8 Byte Order Mark. */ + void skipBom(); + +private: + InStream(const InStream &); + + InStream &operator=(const InStream &); +}; + +InStream inf; +InStream ouf; +InStream ans; +bool appesMode; +std::string resultName; +std::string checkerName = "untitled checker"; +random_t rnd; +TTestlibMode testlibMode = _unknown; +double __testlib_points = std::numeric_limits::infinity(); + +struct ValidatorBoundsHit { + static const double EPS; + bool minHit; + bool maxHit; + + ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) { + }; + + ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) { + return ValidatorBoundsHit( + __testlib_max(minHit, validatorBoundsHit.minHit), + __testlib_max(maxHit, validatorBoundsHit.maxHit) + ); + } +}; + +const double ValidatorBoundsHit::EPS = 1E-12; + +class Validator { +private: + const static std::string TEST_MARKUP_HEADER; + const static std::string TEST_CASE_OPEN_TAG; + const static std::string TEST_CASE_CLOSE_TAG; + + bool _initialized; + std::string _testset; + std::string _group; + + std::string _testOverviewLogFileName; + std::string _testMarkupFileName; + int _testCase = -1; + std::string _testCaseFileName; + + std::map _boundsHitByVariableName; + std::set _features; + std::set _hitFeatures; + + bool isVariableNameBoundsAnalyzable(const std::string &variableName) { + for (size_t i = 0; i < variableName.length(); i++) + if ((variableName[i] >= '0' && variableName[i] <= '9') || variableName[i] < ' ') + return false; + return true; + } + + bool isFeatureNameAnalyzable(const std::string &featureName) { + for (size_t i = 0; i < featureName.length(); i++) + if (featureName[i] < ' ') + return false; + return true; + } + +public: + Validator() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.group()"); + return _group; + } + + std::string testOverviewLogFileName() const { + return _testOverviewLogFileName; + } + + std::string testMarkupFileName() const { + return _testMarkupFileName; + } + + int testCase() const { + return _testCase; + } + + std::string testCaseFileName() const { + return _testCaseFileName; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } + + void setTestOverviewLogFileName(const char *const testOverviewLogFileName) { + _testOverviewLogFileName = testOverviewLogFileName; + } + + void setTestMarkupFileName(const char *const testMarkupFileName) { + _testMarkupFileName = testMarkupFileName; + } + + void setTestCase(int testCase) { + _testCase = testCase; + } + + void setTestCaseFileName(const char *const testCaseFileName) { + _testCaseFileName = testCaseFileName; + } + + void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) { + if (isVariableNameBoundsAnalyzable(variableName)) { + _boundsHitByVariableName[variableName] + = boundsHit.merge(_boundsHitByVariableName[variableName]); + } + } + + std::string getBoundsHitLog() { + std::string result; + for (std::map::iterator i = _boundsHitByVariableName.begin(); + i != _boundsHitByVariableName.end(); + i++) { + result += "\"" + i->first + "\":"; + if (i->second.minHit) + result += " min-value-hit"; + if (i->second.maxHit) + result += " max-value-hit"; + result += "\n"; + } + return result; + } + + std::string getFeaturesLog() { + std::string result; + for (std::set::iterator i = _features.begin(); + i != _features.end(); + i++) { + result += "feature \"" + *i + "\":"; + if (_hitFeatures.count(*i)) + result += " hit"; + result += "\n"; + } + return result; + } + + void writeTestOverviewLog() { + if (!_testOverviewLogFileName.empty()) { + std::string fileName(_testOverviewLogFileName); + _testOverviewLogFileName = ""; + FILE *testOverviewLogFile = fopen(fileName.c_str(), "w"); + if (NULL == testOverviewLogFile) + __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")"); + fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str()); + if (fclose(testOverviewLogFile)) + __testlib_fail( + "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")"); + } + } + + void writeTestMarkup() { + if (!_testMarkupFileName.empty()) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string markup(TEST_MARKUP_HEADER); + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) { + char cc = char(c); + if (cc == '\\' || cc == '!') + markup += '\\'; + markup += cc; + } else { + markup += TEST_CASE_OPEN_TAG; + markup += toString(c - 256); + markup += TEST_CASE_CLOSE_TAG; + } + } + FILE* f; + bool standard_file = false; + if (_testMarkupFileName == "stdout") + f = stdout, standard_file = true; + else if (_testMarkupFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testMarkupFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestMarkup: can't write test markup to (" + _testMarkupFileName + ")"); + } + std::fprintf(f, "%s", markup.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestMarkup: can't close test markup file (" + _testCaseFileName + ")"); + } + } + } + + void writeTestCase() { + if (_testCase > 0) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string content, testCaseContent; + bool matchedTestCase = false; + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) + content += char(c); + else { + if (matchedTestCase) { + testCaseContent = content; + matchedTestCase = false; + } + content = ""; + int testCase = c - 256; + if (testCase == _testCase) + matchedTestCase = true; + } + } + if (matchedTestCase) + testCaseContent = content; + + if (!testCaseContent.empty()) { + FILE* f; + bool standard_file = false; + if (_testCaseFileName.empty() || _testCaseFileName == "stdout") + f = stdout, standard_file = true; + else if (_testCaseFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testCaseFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestCase: can't write test case to (" + _testCaseFileName + ")"); + } + std::fprintf(f, "%s", testCaseContent.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestCase: can't close test case file (" + _testCaseFileName + ")"); + } + } + } + } + + void addFeature(const std::string &feature) { + if (_features.count(feature)) + __testlib_fail("Feature " + feature + " registered twice."); + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + _features.insert(feature); + } + + void feature(const std::string &feature) { + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + if (!_features.count(feature)) + __testlib_fail("Feature " + feature + " didn't registered via addFeature(feature)."); + + _hitFeatures.insert(feature); + } +} validator; + +const std::string Validator::TEST_MARKUP_HEADER = "MU\xF3\x01"; +const std::string Validator::TEST_CASE_OPEN_TAG = "!c"; +const std::string Validator::TEST_CASE_CLOSE_TAG = ";"; + +struct TestlibFinalizeGuard { + static bool alive; + static bool registered; + + int quitCount, readEofCount; + + TestlibFinalizeGuard() : quitCount(0), readEofCount(0) { + // No operations. + } + + ~TestlibFinalizeGuard() { + bool _alive = alive; + alive = false; + + if (_alive) { + if (testlibMode == _checker && quitCount == 0) + __testlib_fail("Checker must end with quit or quitf call."); + + if (testlibMode == _validator && readEofCount == 0 && quitCount == 0) + __testlib_fail("Validator must end with readEof call."); + + /* opts */ + autoEnsureNoUnusedOpts(); + + if (!registered) + __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)"); + } + + if (__testlib_exitCode == 0) { + validator.writeTestOverviewLog(); + validator.writeTestMarkup(); + validator.writeTestCase(); + } + } + +private: + /* opts */ + void autoEnsureNoUnusedOpts(); +}; + +bool TestlibFinalizeGuard::alive = true; +bool TestlibFinalizeGuard::registered = false; +extern TestlibFinalizeGuard testlibFinalizeGuard; + +/* + * Call it to disable checks on finalization. + */ +void disableFinalizeGuard() { + TestlibFinalizeGuard::alive = false; +} + +/* Interactor streams. + */ +std::fstream tout; + +/* implementation + */ + +InStream::InStream() { + reader = NULL; + lastLine = -1; + opened = false; + name = ""; + mode = _input; + strict = false; + stdfile = false; + wordReserveSize = 4; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::InStream(const InStream &baseStream, std::string content) { + reader = new StringInputStreamReader(content); + lastLine = -1; + opened = true; + strict = baseStream.strict; + stdfile = false; + mode = baseStream.mode; + name = "based on " + baseStream.name; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::~InStream() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } +} + +void InStream::setTestCase(int testCase) { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::setTestCase can be used only for inf in validator-mode." + " Actually, prefer setTestCase function instead of InStream member"); + reader->setTestCase(testCase); +} + +std::vector InStream::getReadChars() { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::getReadChars can be used only for inf in validator-mode."); + return reader == NULL ? std::vector() : reader->getReadChars(); +} + +void setTestCase(int testCase) { + static bool first_run = true; + static bool zero_based = false; + + if (first_run && testCase == 0) + zero_based = true; + + if (zero_based) + testCase++; + + __testlib_hasTestCase = true; + __testlib_testCase = testCase; + + if (testlibMode == _validator) + inf.setTestCase(testCase); + + first_run = false; +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int resultExitCode(TResult r) { + if (r == _ok) + return OK_EXIT_CODE; + if (r == _wa) + return WA_EXIT_CODE; + if (r == _pe) + return PE_EXIT_CODE; + if (r == _fail) + return FAIL_EXIT_CODE; + if (r == _dirt) + return DIRT_EXIT_CODE; + if (r == _points) + return POINTS_EXIT_CODE; + if (r == _unexpected_eof) +#ifdef ENABLE_UNEXPECTED_EOF + return UNEXPECTED_EOF_EXIT_CODE; +#else + return PE_EXIT_CODE; +#endif + if (r >= _partially) + return PC_BASE_EXIT_CODE + (r - _partially); + return FAIL_EXIT_CODE; +} + +void InStream::textColor( +#if !(defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)) && defined(__GNUC__) + __attribute__((unused)) +#endif + WORD color +) { +#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400) + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, color); +#endif +#if !defined(ON_WINDOWS) && defined(__GNUC__) + if (isatty(2)) + { + switch (color) + { + case LightRed: + fprintf(stderr, "\033[1;31m"); + break; + case LightCyan: + fprintf(stderr, "\033[1;36m"); + break; + case LightGreen: + fprintf(stderr, "\033[1;32m"); + break; + case LightYellow: + fprintf(stderr, "\033[1;33m"); + break; + case LightGray: + default: + fprintf(stderr, "\033[0m"); + } + } +#endif +} + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +class exit_exception: public std::exception { +private: + int exitCode; +public: + exit_exception(int exitCode): exitCode(exitCode) {} + int getExitCode() { return exitCode; } +}; +#endif + +NORETURN void halt(int exitCode) { +#ifdef FOOTER + InStream::textColor(InStream::LightGray); + std::fprintf(stderr, "Checker: \"%s\"\n", checkerName.c_str()); + std::fprintf(stderr, "Exit code: %d\n", exitCode); + InStream::textColor(InStream::LightGray); +#endif + __testlib_exitCode = exitCode; +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT + throw exit_exception(exitCode); +#endif + std::exit(exitCode); +} + +static bool __testlib_shouldCheckDirt(TResult result) { + return result == _ok || result == _points || result >= _partially; +} + +static std::string __testlib_appendMessage(const std::string &message, const std::string &extra) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + size_t index = message.find(extra, openPos); + if (index == std::string::npos || int(index) >= closePos) { + std::string result(message); + result.insert(closePos, ", " + extra); + return result; + } + return message; + } + + return message + " " + InStream::OPEN_BRACKET + extra + InStream::CLOSE_BRACKET; +} + +static std::string __testlib_toPrintableMessage(const std::string &message) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + std::string result(message); + result[openPos] = '('; + result[closePos] = ')'; + return result; + } + + return message; +} + +NORETURN void InStream::quit(TResult result, const char *msg) { + if (TestlibFinalizeGuard::alive) + testlibFinalizeGuard.quitCount++; + + std::string message(msg); + message = trim(message); + + if (__testlib_hasTestCase) { + if (result != _ok) + message = __testlib_appendMessage(message, "test case " + vtos(__testlib_testCase)); + else { + if (__testlib_testCase == 1) + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test case"); + else + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test cases"); + } + } + + // You can change maxMessageLength. + // Example: 'inf.maxMessageLength = 1024 * 1024;'. + if (message.length() > maxMessageLength) { + std::string warn = "message length exceeds " + vtos(maxMessageLength) + + ", the message is truncated: "; + message = warn + message.substr(0, maxMessageLength - warn.length()); + } + +#ifndef ENABLE_UNEXPECTED_EOF + if (result == _unexpected_eof) + result = _pe; +#endif + + if (testlibMode == _scorer && result != _fail) + quits(_fail, "Scorer should return points only. Don't use a quit function."); + + if (mode != _output && result != _fail) { + if (mode == _input && testlibMode == _validator && lastLine != -1) + quits(_fail, __testlib_appendMessage(__testlib_appendMessage(message, name), "line " + vtos(lastLine))); + else + quits(_fail, __testlib_appendMessage(message, name)); + } + + std::FILE *resultFile; + std::string errorName; + + if (__testlib_shouldCheckDirt(result)) { + if (testlibMode != _interactor && !ouf.seekEof()) + quit(_dirt, "Extra information in the output file"); + } + + int pctype = result - _partially; + bool isPartial = false; + + switch (result) { + case _ok: + errorName = "ok "; + quitscrS(LightGreen, errorName); + break; + case _wa: + errorName = "wrong answer "; + quitscrS(LightRed, errorName); + break; + case _pe: + errorName = "wrong output format "; + quitscrS(LightRed, errorName); + break; + case _fail: + errorName = "FAIL "; + quitscrS(LightRed, errorName); + break; + case _dirt: + errorName = "wrong output format "; + quitscrS(LightCyan, errorName); + result = _pe; + break; + case _points: + errorName = "points "; + quitscrS(LightYellow, errorName); + break; + case _unexpected_eof: + errorName = "unexpected eof "; + quitscrS(LightCyan, errorName); + break; + default: + if (result >= _partially) { + errorName = format("partially correct (%d) ", pctype); + isPartial = true; + quitscrS(LightYellow, errorName); + } else + quit(_fail, "What is the code ??? "); + } + + if (resultName != "") { + resultFile = std::fopen(resultName.c_str(), "w"); + if (resultFile == NULL) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + if (appesMode) { + std::fprintf(resultFile, ""); + if (isPartial) + std::fprintf(resultFile, "", + outcomes[(int) _partially].c_str(), pctype); + else { + if (result != _points) + std::fprintf(resultFile, "", outcomes[(int) result].c_str()); + else { + if (__testlib_points == std::numeric_limits::infinity()) + quit(_fail, "Expected points, but infinity found"); + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", __testlib_points)); + std::fprintf(resultFile, "", + outcomes[(int) result].c_str(), stringPoints.c_str()); + } + } + xmlSafeWrite(resultFile, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(resultFile, "\n"); + } else + std::fprintf(resultFile, "%s", __testlib_toPrintableMessage(message).c_str()); + if (NULL == resultFile || fclose(resultFile) != 0) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + } + + quitscr(LightGray, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(stderr, "\n"); + + inf.close(); + ouf.close(); + ans.close(); + if (tout.is_open()) + tout.close(); + + textColor(LightGray); + + if (resultName != "") + std::fprintf(stderr, "See file to check exit message\n"); + + halt(resultExitCode(result)); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +NORETURN void InStream::quitf(TResult result, const char *msg, ...) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +void InStream::quitif(bool condition, TResult result, const char *msg, ...) { + if (condition) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); + } +} + +NORETURN void InStream::quits(TResult result, std::string msg) { + InStream::quit(result, msg.c_str()); +} + +void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { + size_t lmsg = strlen(msg); + for (size_t i = 0; i < lmsg; i++) { + if (msg[i] == '&') { + std::fprintf(file, "%s", "&"); + continue; + } + if (msg[i] == '<') { + std::fprintf(file, "%s", "<"); + continue; + } + if (msg[i] == '>') { + std::fprintf(file, "%s", ">"); + continue; + } + if (msg[i] == '"') { + std::fprintf(file, "%s", """); + continue; + } + if (0 <= msg[i] && msg[i] <= 31) { + std::fprintf(file, "%c", '.'); + continue; + } + std::fprintf(file, "%c", msg[i]); + } +} + +void InStream::quitscrS(WORD color, std::string msg) { + quitscr(color, msg.c_str()); +} + +void InStream::quitscr(WORD color, const char *msg) { + if (resultName == "") { + textColor(color); + std::fprintf(stderr, "%s", msg); + textColor(LightGray); + } +} + +void InStream::reset(std::FILE *file) { + if (opened && stdfile) + quit(_fail, "Can't reset standard handle"); + + if (opened) + close(); + + if (!stdfile && NULL == file) + if (NULL == (file = std::fopen(name.c_str(), "rb"))) { + if (mode == _output) + quits(_pe, std::string("Output file not found: \"") + name + "\""); + + if (mode == _answer) + quits(_fail, std::string("Answer file not found: \"") + name + "\""); + } + + if (NULL != file) { + opened = true; + __testlib_set_binary(file); + + if (stdfile) + reader = new FileInputStreamReader(file, name); + else + reader = new BufferedFileInputStreamReader(file, name); + } else { + opened = false; + reader = NULL; + } +} + +void InStream::init(std::string fileName, TMode mode) { + opened = false; + name = fileName; + stdfile = false; + this->mode = mode; + + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + if (stream.is_open()) { + std::streampos start = stream.tellg(); + stream.seekg(0, std::ios::end); + std::streampos end = stream.tellg(); + size_t fileSize = size_t(end - start); + stream.close(); + + // You can change maxFileSize. + // Example: 'inf.maxFileSize = 256 * 1024 * 1024;'. + if (fileSize > maxFileSize) + quitf(_pe, "File size exceeds %d bytes, size is %d", int(maxFileSize), int(fileSize)); + } + + reset(); +} + +void InStream::init(std::FILE *f, TMode mode) { + opened = false; + name = "untitled"; + this->mode = mode; + + if (f == stdin) + name = "stdin", stdfile = true; + if (f == stdout) + name = "stdout", stdfile = true; + if (f == stderr) + name = "stderr", stdfile = true; + + reset(f); +} + +void InStream::skipBom() { + const std::string utf8Bom = "\xEF\xBB\xBF"; + size_t index = 0; + while (index < utf8Bom.size() && curChar() == utf8Bom[index]) { + index++; + skipChar(); + } + if (index < utf8Bom.size()) { + while (index != 0) { + unreadChar(utf8Bom[index - 1]); + index--; + } + } +} + +char InStream::curChar() { + return char(reader->curChar()); +} + +char InStream::nextChar() { + return char(reader->nextChar()); +} + +char InStream::readChar() { + return nextChar(); +} + +char InStream::readChar(char c) { + lastLine = reader->getLine(); + char found = readChar(); + if (c != found) { + if (!isEoln(found)) + quit(_pe, ("Unexpected character '" + std::string(1, found) + "', but '" + std::string(1, c) + + "' expected").c_str()); + else + quit(_pe, ("Unexpected character " + ("#" + vtos(int(found))) + ", but '" + std::string(1, c) + + "' expected").c_str()); + } + return found; +} + +char InStream::readSpace() { + return readChar(' '); +} + +void InStream::unreadChar(char c) { + reader->unreadChar(c); +} + +void InStream::skipChar() { + reader->skipChar(); +} + +void InStream::skipBlanks() { + while (isBlanks(reader->curChar())) + reader->skipChar(); +} + +std::string InStream::readWord() { + readWordTo(_tmpReadToken); + return _tmpReadToken; +} + +void InStream::readWordTo(std::string &result) { + if (!strict) + skipBlanks(); + + lastLine = reader->getLine(); + int cur = reader->nextChar(); + + if (cur == EOFC) + quit(_unexpected_eof, "Unexpected end of file - token expected"); + + if (isBlanks(cur)) + quit(_pe, "Unexpected white-space - token expected"); + + result.clear(); + + while (!(isBlanks(cur) || cur == EOFC)) { + result += char(cur); + + // You can change maxTokenLength. + // Example: 'inf.maxTokenLength = 128 * 1024 * 1024;'. + if (result.length() > maxTokenLength) + quitf(_pe, "Length of token exceeds %d, token is '%s...'", int(maxTokenLength), + __testlib_part(result).c_str()); + + cur = reader->nextChar(); + } + + reader->unreadChar(cur); + + if (result.length() == 0) + quit(_unexpected_eof, "Unexpected end of file or white-space - token expected"); +} + +std::string InStream::readToken() { + return readWord(); +} + +void InStream::readTokenTo(std::string &result) { + readWordTo(result); +} + +static std::string __testlib_part(const std::string &s) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (s[i] != '\0') + t += s[i]; + else + t += '~'; + if (t.length() <= 64) + return t; + else + return t.substr(0, 30) + "..." + t.substr(s.length() - 31, 31); +} + +#define __testlib_readMany(readMany, readOne, typeName, space) \ + if (size < 0) \ + quit(_fail, #readMany ": size should be non-negative."); \ + if (size > 100000000) \ + quit(_fail, #readMany ": size should be at most 100000000."); \ + \ + std::vector result(size); \ + readManyIteration = indexBase; \ + \ + for (int i = 0; i < size; i++) \ + { \ + result[i] = readOne; \ + readManyIteration++; \ + if (strict && space && i + 1 < size) \ + readSpace(); \ + } \ + \ + readManyIteration = NO_INDEX; \ + return result; \ + + +std::string InStream::readWord(const pattern &p, const std::string &variableName) { + readWordTo(_tmpReadToken); + if (!p.matches(_tmpReadToken)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Token \"" + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(_tmpReadToken) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Token element [index=" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token element " + variableName + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\", doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + } + } + return _tmpReadToken; +} + +std::vector +InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::vector InStream::readWords(int size, int indexBase) { + __testlib_readMany(readWords, readWord(), std::string, true); +} + +std::string InStream::readWord(const std::string &ptrn, const std::string &variableName) { + return readWord(pattern(ptrn), variableName); +} + +std::vector +InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::string InStream::readToken(const pattern &p, const std::string &variableName) { + return readWord(p, variableName); +} + +std::vector +InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readTokens, readToken(p, variablesName), std::string, true); +} + +std::vector InStream::readTokens(int size, int indexBase) { + __testlib_readMany(readTokens, readToken(), std::string, true); +} + +std::string InStream::readToken(const std::string &ptrn, const std::string &variableName) { + return readWord(ptrn, variableName); +} + +std::vector +InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readTokens, readWord(p, variablesName), std::string, true); +} + +void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) { + readWordTo(result); + if (!p.matches(result)) { + if (variableName.empty()) + quit(_wa, ("Token \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } +} + +void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, pattern(ptrn), variableName); +} + +void InStream::readTokenTo(std::string &result, const pattern &p, const std::string &variableName) { + return readWordTo(result, p, variableName); +} + +void InStream::readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, ptrn, variableName); +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(long long integer, const char *s) { + if (integer == LLONG_MIN) + return strcmp(s, "-9223372036854775808") == 0; + + if (integer == 0LL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + if (integer < 0 && s[0] != '-') + return false; + + if (integer < 0) + s++, length--, integer = -integer; + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(unsigned long long integer, const char *s) { + if (integer == ULLONG_MAX) + return strcmp(s, "18446744073709551615") == 0; + + if (integer == 0ULL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +static inline double stringToDouble(InStream &in, const char *buffer) { + double retval; + + size_t length = strlen(buffer); + + int minusCount = 0; + int plusCount = 0; + int decimalPointCount = 0; + int digitCount = 0; + int eCount = 0; + + for (size_t i = 0; i < length; i++) { + if (('0' <= buffer[i] && buffer[i] <= '9') || buffer[i] == '.' + || buffer[i] == 'e' || buffer[i] == 'E' + || buffer[i] == '-' || buffer[i] == '+') { + if ('0' <= buffer[i] && buffer[i] <= '9') + digitCount++; + if (buffer[i] == 'e' || buffer[i] == 'E') + eCount++; + if (buffer[i] == '-') + minusCount++; + if (buffer[i] == '+') + plusCount++; + if (buffer[i] == '.') + decimalPointCount++; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + // If for sure is not a number in standard notation or in e-notation. + if (digitCount == 0 || minusCount > 2 || plusCount > 2 || decimalPointCount > 1 || eCount > 1) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToDouble(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToDouble(in, buffer.c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const char *buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + if (minAfterPointDigitCount < 0) + in.quit(_fail, "stringToStrictDouble: minAfterPointDigitCount should be non-negative."); + + if (minAfterPointDigitCount > maxAfterPointDigitCount) + in.quit(_fail, + "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount."); + + double retval; + + size_t length = strlen(buffer); + + if (length == 0 || length > 1000) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[0] != '-' && (buffer[0] < '0' || buffer[0] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int pointPos = -1; + for (size_t i = 1; i + 1 < length; i++) { + if (buffer[i] == '.') { + if (pointPos > -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + pointPos = int(i); + } + if (buffer[i] != '.' && (buffer[i] < '0' || buffer[i] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + if (buffer[length - 1] < '0' || buffer[length - 1] > '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int afterDigitsCount = (pointPos == -1 ? 0 : int(length) - pointPos - 1); + if (afterDigitsCount < minAfterPointDigitCount || afterDigitsCount > maxAfterPointDigitCount) + in.quit(_pe, ("Expected strict double with number of digits after point in range [" + + vtos(minAfterPointDigitCount) + + "," + + vtos(maxAfterPointDigitCount) + + "], but \"" + __testlib_part(buffer) + "\" found").c_str() + ); + + int firstDigitPos = -1; + for (size_t i = 0; i < length; i++) + if (buffer[i] >= '0' && buffer[i] <= '9') { + firstDigitPos = int(i); + break; + } + + if (firstDigitPos > 1 || firstDigitPos == -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[firstDigitPos] == '0' && firstDigitPos + 1 < int(length) + && buffer[firstDigitPos + 1] >= '0' && buffer[firstDigitPos + 1] <= '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval) || __testlib_isInfinite(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (buffer[0] == '-' && retval >= 0) + in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const std::string& buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToStrictDouble(in, buffer.c_str(), minAfterPointDigitCount, maxAfterPointDigitCount); +} + +static inline long long stringToLongLong(InStream &in, const char *buffer) { + if (strcmp(buffer, "-9223372036854775808") == 0) + return LLONG_MIN; + + bool minus = false; + size_t length = strlen(buffer); + + if (length > 1 && buffer[0] == '-') + minus = true; + + if (length > 20) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + long long retval = 0LL; + + int zeroes = 0; + bool processingZeroes = true; + + for (int i = (minus ? 1 : 0); i < int(length); i++) { + if (buffer[i] == '0' && processingZeroes) + zeroes++; + else + processingZeroes = false; + + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (retval < 0) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if ((zeroes > 0 && (retval != 0 || minus)) || zeroes > 1) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + retval = (minus ? -retval : +retval); + + if (length < 19) + return retval; + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToLongLong(in, buffer.c_str()); +} + +static inline unsigned long long stringToUnsignedLongLong(InStream &in, const char *buffer) { + size_t length = strlen(buffer); + + if (length > 20) + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (length > 1 && buffer[0] == '0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + unsigned long long retval = 0LL; + for (int i = 0; i < int(length); i++) { + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (length < 19) + return retval; + + if (length == 20 && strcmp(buffer, "18446744073709551615") > 0) + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToUnsignedLongLong(in, buffer.c_str()); +} + +int InStream::readInteger() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int32 expected"); + + readWordTo(_tmpReadToken); + + long long value = stringToLongLong(*this, _tmpReadToken); + if (value < INT_MIN || value > INT_MAX) + quit(_pe, ("Expected int32, but \"" + __testlib_part(_tmpReadToken) + "\" found").c_str()); + + return int(value); +} + +long long InStream::readLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToLongLong(*this, _tmpReadToken); +} + +unsigned long long InStream::readUnsignedLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToUnsignedLongLong(*this, _tmpReadToken); +} + +long long InStream::readLong(long long minv, long long maxv, const std::string &variableName) { + long long result = readLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector +InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) +} + +std::vector InStream::readLongs(int size, int indexBase) { + __testlib_readMany(readLongs, readLong(), long long, true) +} + +unsigned long long +InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + unsigned long long result = readUnsignedLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, + ("Unsigned integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, ("Unsigned integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) +} + +std::vector InStream::readUnsignedLongs(int size, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) +} + +unsigned long long +InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + return readUnsignedLong(minv, maxv, variableName); +} + +int InStream::readInt() { + return readInteger(); +} + +int InStream::readInt(int minv, int maxv, const std::string &variableName) { + int result = readInt(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +int InStream::readInteger(int minv, int maxv, const std::string &variableName) { + return readInt(minv, maxv, variableName); +} + +std::vector InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readInts(int size, int indexBase) { + __testlib_readMany(readInts, readInt(), int, true) +} + +std::vector InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readIntegers(int size, int indexBase) { + __testlib_readMany(readIntegers, readInt(), int, true) +} + +double InStream::readReal() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - double expected"); + + return stringToDouble(*this, readWord()); +} + +double InStream::readDouble() { + return readReal(); +} + +double InStream::readReal(double minv, double maxv, const std::string &variableName) { + double result = readReal(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, ("Double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, + ("Double element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector +InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readReals(int size, int indexBase) { + __testlib_readMany(readReals, readReal(), double, true) +} + +double InStream::readDouble(double minv, double maxv, const std::string &variableName) { + return readReal(minv, maxv, variableName); +} + +std::vector +InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readDoubles(int size, int indexBase) { + __testlib_readMany(readDoubles, readDouble(), double, true) +} + +double InStream::readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - strict double expected"); + + double result = stringToStrictDouble(*this, readWord(), minAfterPointDigitCount, maxAfterPointDigitCount); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Strict double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, + ("Strict double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Strict double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, ("Strict double element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector InStream::readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictReals, + readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +double InStream::readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + return readStrictReal(minv, maxv, + minAfterPointDigitCount, maxAfterPointDigitCount, + variableName); +} + +std::vector InStream::readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictDoubles, + readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +bool InStream::eof() { + if (!strict && NULL == reader) + return true; + + return reader->eof(); +} + +bool InStream::seekEof() { + if (!strict && NULL == reader) + return true; + skipBlanks(); + return eof(); +} + +bool InStream::eoln() { + if (!strict && NULL == reader) + return true; + + int c = reader->nextChar(); + + if (!strict) { + if (c == EOFC) + return true; + + if (c == CR) { + c = reader->nextChar(); + + if (c != LF) { + reader->unreadChar(c); + reader->unreadChar(CR); + return false; + } else + return true; + } + + if (c == LF) + return true; + + reader->unreadChar(c); + return false; + } else { + bool returnCr = false; + +#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS) + if (c != CR) { + reader->unreadChar(c); + return false; + } else { + if (!returnCr) + returnCr = true; + c = reader->nextChar(); + } +#endif + if (c != LF) { + reader->unreadChar(c); + if (returnCr) + reader->unreadChar(CR); + return false; + } + + return true; + } +} + +void InStream::readEoln() { + lastLine = reader->getLine(); + if (!eoln()) + quit(_pe, "Expected EOLN"); +} + +void InStream::readEof() { + lastLine = reader->getLine(); + if (!eof()) + quit(_pe, "Expected EOF"); + + if (TestlibFinalizeGuard::alive && this == &inf) + testlibFinalizeGuard.readEofCount++; +} + +bool InStream::seekEoln() { + if (!strict && NULL == reader) + return true; + + int cur; + do { + cur = reader->nextChar(); + } while (cur == SPACE || cur == TAB); + + reader->unreadChar(cur); + return eoln(); +} + +void InStream::nextLine() { + readLine(); +} + +void InStream::readStringTo(std::string &result) { + if (NULL == reader) + quit(_pe, "Expected line"); + + result.clear(); + + for (;;) { + int cur = reader->curChar(); + + if (cur == LF || cur == EOFC) + break; + + if (cur == CR) { + cur = reader->nextChar(); + if (reader->curChar() == LF) { + reader->unreadChar(cur); + break; + } + } + + lastLine = reader->getLine(); + result += char(reader->nextChar()); + } + + if (strict) + readEoln(); + else + eoln(); +} + +std::string InStream::readString() { + readStringTo(_tmpReadToken); + return _tmpReadToken; +} + +std::vector InStream::readStrings(int size, int indexBase) { + __testlib_readMany(readStrings, readString(), std::string, false) +} + +void InStream::readStringTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result); + if (!p.matches(result)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Line \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Line [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Line element [index=" + vtos(readManyIteration) + "] equals to \"" + __testlib_part(result) + + "\" doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + else + quit(_wa, + ("Line element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } + } +} + +void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, pattern(ptrn), variableName); +} + +std::string InStream::readString(const pattern &p, const std::string &variableName) { + readStringTo(_tmpReadToken, p, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +std::string InStream::readString(const std::string &ptrn, const std::string &variableName) { + readStringTo(_tmpReadToken, ptrn, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +void InStream::readLineTo(std::string &result) { + readStringTo(result); +} + +std::string InStream::readLine() { + return readString(); +} + +std::vector InStream::readLines(int size, int indexBase) { + __testlib_readMany(readLines, readString(), std::string, false) +} + +void InStream::readLineTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result, p, variableName); +} + +void InStream::readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, ptrn, variableName); +} + +std::string InStream::readLine(const pattern &p, const std::string &variableName) { + return readString(p, variableName); +} + +std::vector +InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) { + return readString(ptrn, variableName); +} + +std::vector +InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void InStream::ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + this->__testlib_ensure(cond, message); + } +} + +void InStream::__testlib_ensure(bool cond, std::string message) { + if (!cond) + this->quit(_wa, message.c_str()); +} + +void InStream::close() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } + + opened = false; +} + +NORETURN void quit(TResult result, const std::string &msg) { + ouf.quit(result, msg.c_str()); +} + +NORETURN void quit(TResult result, const char *msg) { + ouf.quit(result, msg); +} + +NORETURN void __testlib_quitp(double points, const char *message) { + __testlib_points = points; + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", points)); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void __testlib_quitp(int points, const char *message) { + __testlib_points = points; + std::string stringPoints = format("%d", points); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void quitp(float points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(double points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitp(long double points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(int points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitpi(const std::string &points_info, const std::string &message = "") { + if (points_info.find(' ') != std::string::npos) + quit(_fail, "Parameter 'points_info' can't contain spaces"); + if (message.empty()) + quit(_points, ("points_info=" + points_info).c_str()); + else + quit(_points, ("points_info=" + points_info + " " + message).c_str()); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitp(F points, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quitp(points, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitf(TResult result, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quit(result, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void quitif(bool condition, TResult result, const char *format, ...) { + if (condition) { + FMT_TO_RESULT(format, format, message); + quit(result, message); + } +} + +NORETURN void __testlib_help() { + InStream::textColor(InStream::LightCyan); + std::fprintf(stderr, "TESTLIB %s, https://github.com/MikeMirzayanov/testlib/ ", VERSION); + std::fprintf(stderr, "by Mike Mirzayanov, copyright(c) 2005-2020\n"); + std::fprintf(stderr, "Checker name: \"%s\"\n", checkerName.c_str()); + InStream::textColor(InStream::LightGray); + + std::fprintf(stderr, "\n"); + std::fprintf(stderr, "Latest features: \n"); + for (size_t i = 0; i < sizeof(latestFeatures) / sizeof(char *); i++) { + std::fprintf(stderr, "*) %s\n", latestFeatures[i]); + } + std::fprintf(stderr, "\n"); + + std::fprintf(stderr, "Program must be run with the following arguments: \n"); + std::fprintf(stderr, " [--testset testset] [--group group] [ [<-appes>]]\n\n"); + + __testlib_exitCode = FAIL_EXIT_CODE; + std::exit(FAIL_EXIT_CODE); +} + +static void __testlib_ensuresPreconditions() { + // testlib assumes: sizeof(int) = 4. + __TESTLIB_STATIC_ASSERT(sizeof(int) == 4); + + // testlib assumes: INT_MAX == 2147483647. + __TESTLIB_STATIC_ASSERT(INT_MAX == 2147483647); + + // testlib assumes: sizeof(long long) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(long long) == 8); + + // testlib assumes: sizeof(double) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(double) == 8); + + // testlib assumes: no -ffast-math. + if (!__testlib_isNaN(+__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); + if (!__testlib_isNaN(-__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); +} + +std::string __testlib_testset; + +std::string getTestset() { + return __testlib_testset; +} + +std::string __testlib_group; + +std::string getGroup() { + return __testlib_group; +} + +static void __testlib_set_testset_and_group(int argc, char* argv[]) { + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + __testlib_testset = argv[++i]; + else + quit(_fail, std::string("Expected non-empty testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + __testlib_group = argv[++i]; + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } + } +} + +void registerGen(int argc, char *argv[], int randomGeneratorVersion) { + if (randomGeneratorVersion < 0 || randomGeneratorVersion > 1) + quitf(_fail, "Random generator version is expected to be 0 or 1."); + random_t::version = randomGeneratorVersion; + + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _generator; + __testlib_set_binary(stdin); + rnd.setSeed(argc, argv); + +#if __cplusplus > 199711L || defined(_MSC_VER) + prepareOpts(argc, argv); +#endif +} + +#ifdef USE_RND_AS_BEFORE_087 +void registerGen(int argc, char* argv[]) +{ + registerGen(argc, argv, 0); +} +#else +#ifdef __GNUC__ +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 4)) +__attribute__ ((deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." +" The third parameter stands for the random generator version." +" If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." +" Version 1 has been released on Spring, 2013. Use it to write new generators."))) +#else +__attribute__ ((deprecated)) +#endif +#endif +#ifdef _MSC_VER +__declspec(deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.")) +#endif +void registerGen(int argc, char *argv[]) { + std::fprintf(stderr, "Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.\n\n"); + registerGen(argc, argv, 0); +} +#endif + +void registerInteraction(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _interactor; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + tout.open(std::string(argv[3]) + "/teammessage.txt", + std::ios_base::out); + if (tout.fail() || !tout.is_open()) + quit(_fail, "Can not write to the test-output-file '" + + std::string(argv[2]) + "'"); + appesMode = false; + } + + inf.init(argv[1], _input); + + ouf.init(stdin, _output); + if (argc >= 3) + ans.init(argv[2], _answer); + else + ans.name = "unopened answer stream"; +} + +void registerValidation() { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _validator; + + __testlib_set_binary(stdin); + __testlib_set_binary(stdout); + __testlib_set_binary(stderr); + + inf.init(stdin, _input); + inf.strict = true; +} + +void registerValidation(int argc, char *argv[]) { + registerValidation(); + __testlib_set_testset_and_group(argc, argv); + + validator.initialize(); + TestlibFinalizeGuard::registered = true; + + std::string comment = "Validator must be run with the following arguments:" + " [--testset testset]" + " [--group group]" + " [--testOverviewLogFileName fileName]" + " [--testMarkupFileName fileName]" + " [--testCase testCase]" + " [--testCaseFileName fileName]" + ; + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + validator.setTestset(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + validator.setGroup(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testOverviewLogFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestOverviewLogFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testMarkupFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestMarkupFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testCase", argv[i])) { + if (i + 1 < argc) { + long long testCase = stringToLongLong(inf, argv[++i]); + if (testCase < 1 || testCase >= __TESTLIB_MAX_TEST_CASE) + quit(_fail, format("Argument testCase should be between 1 and %d, but ", __TESTLIB_MAX_TEST_CASE) + + toString(testCase) + " found"); + validator.setTestCase(int(testCase)); + } else + quit(_fail, comment); + } + if (!strcmp("--testCaseFileName", argv[i])) { + if (i + 1 < argc) { + validator.setTestCaseFileName(argv[++i]); + } else + quit(_fail, comment); + } + } +} + +void addFeature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.addFeature(feature); +} + +void feature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.feature(feature); +} + +class Checker { +private: + bool _initialized; + std::string _testset; + std::string _group; + +public: + Checker() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.group()"); + return _group; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } +} checker; + +void registerTestlibCmd(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _checker; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + + appesMode = false; + + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + appesMode = false; + } + + inf.init(argv[1], _input); + ouf.init(stdin, _output); + ans.init(argv[2], _answer); +} + +void registerTestlib(int argc, ...) { + if (argc < 3 || argc > 5) + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + + char **argv = new char *[argc + 1]; + + va_list ap; + va_start(ap, argc); + argv[0] = NULL; + for (int i = 0; i < argc; i++) { + argv[i + 1] = va_arg(ap, char*); + } + va_end(ap); + + registerTestlibCmd(argc + 1, argv); + delete[] argv; +} + +static inline void __testlib_ensure(bool cond, const std::string &msg) { + if (!cond) + quit(_fail, msg.c_str()); +} + +#ifdef __GNUC__ +__attribute__((unused)) +#endif +static inline void __testlib_ensure(bool cond, const char *msg) { + if (!cond) + quit(_fail, msg); +} + +#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) +#define ensure_ext(cond) __testlib_ensure(cond, "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"") + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +inline void ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + __testlib_ensure(cond, message); + } +} + +NORETURN static void __testlib_fail(const std::string &message) { + quitf(_fail, "%s", message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +void setName(const char *format, ...) { + FMT_TO_RESULT(format, format, name); + checkerName = name; +} + +/* + * Do not use random_shuffle, because it will produce different result + * for different C++ compilers. + * + * This implementation uses testlib random_t to produce random numbers, so + * it is stable. + */ +template +void shuffle(_RandomAccessIter __first, _RandomAccessIter __last) { + if (__first == __last) return; + for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) + std::iter_swap(__i, __first + rnd.next(int(__i - __first) + 1)); +} + + +template +#if defined(__GNUC__) && !defined(__clang__) +__attribute__ ((error("Don't use random_shuffle(), use shuffle() instead"))) +#endif +void random_shuffle(_RandomAccessIter, _RandomAccessIter) { + quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); +} + +#ifdef __GLIBC__ +# define RAND_THROW_STATEMENT throw() +#else +# define RAND_THROW_STATEMENT +#endif + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use rand(), use rnd.next() instead"))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +int rand() RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use rand(), use rnd.next() instead"); + + /* This line never runs. */ + //throw "Don't use rand(), use rnd.next() instead"; +} + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use srand(), you should use " +"'registerGen(argc, argv, 1);' to initialize generator seed " +"by hash code of the command line params. The third parameter " +"is randomGeneratorVersion (currently the latest is 1)."))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +void srand(unsigned int seed) RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use srand(), you should use " + "'registerGen(argc, argv, 1);' to initialize generator seed " + "by hash code of the command line params. The third parameter " + "is randomGeneratorVersion (currently the latest is 1) [ignored seed=%u].", seed); +} + +void startTest(int test) { + const std::string testFileName = vtos(test); + if (NULL == freopen(testFileName.c_str(), "wt", stdout)) + __testlib_fail("Unable to write file '" + testFileName + "'"); +} + +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + +inline std::string compress(const std::string &s) { + return __testlib_part(s); +} + +inline std::string englishEnding(int x) { + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separator) { + std::stringstream ss; + bool repeated = false; + for (_ForwardIterator i = first; i != last; i++) { + if (repeated) + ss << separator; + else + repeated = true; + ss << *i; + } + return ss.str(); +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last) { + return join(first, last, ' '); +} + +template +std::string join(const _Collection &collection, _Separator separator) { + return join(collection.begin(), collection.end(), separator); +} + +template +std::string join(const _Collection &collection) { + return join(collection, ' '); +} + +/** + * Splits string s by character separator returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separator returning non-empty items. + */ +std::vector tokenize(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + if (!item.empty()) + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning non-empty items. + */ +std::vector tokenize(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + + if (!item.empty()) + result.push_back(item); + + return result; +} + +NORETURN void __testlib_expectedButFound(TResult result, std::string expected, std::string found, const char *prepend) { + std::string message; + if (strlen(prepend) != 0) + message = format("%s: expected '%s', but found '%s'", + compress(prepend).c_str(), compress(expected).c_str(), compress(found).c_str()); + else + message = format("expected '%s', but found '%s'", + compress(expected).c_str(), compress(found).c_str()); + quit(result, message); +} + +NORETURN void __testlib_expectedButFound(TResult result, double expected, double found, const char *prepend) { + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, T expected, T found, const char *prependFormat = "", ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = vtos(expected); + std::string foundString = vtos(found); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, std::string expected, std::string found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, expected, found, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, double expected, double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, const char *expected, const char *found, const char *prependFormat, + ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, float expected, float found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, long double expected, long double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +struct is_iterable { + template + static char test(typename U::iterator *x); + + template + static long test(U *x); + + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct __testlib_enable_if { +}; + +template +struct __testlib_enable_if { + typedef T type; +}; + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + std::cout << t; +} + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + bool first = true; + for (typename T::const_iterator i = t.begin(); i != t.end(); i++) { + if (first) + first = false; + else + std::cout << " "; + std::cout << *i; + } +} + +template<> +typename __testlib_enable_if::value, void>::type +__testlib_print_one(const std::string &t) { + std::cout << t; +} + +template +void __println_range(A begin, B end) { + bool first = true; + for (B i = B(begin); i != end; i++) { + if (first) + first = false; + else + std::cout << " "; + __testlib_print_one(*i); + } + std::cout << std::endl; +} + +template +struct is_iterator { + static T makeT(); + + typedef void *twoptrs[2]; + + static twoptrs &test(...); + + template + static typename R::iterator_category *test(R); + + template + static void *test(R *); + + static const bool value = sizeof(test(makeT())) == sizeof(void *); +}; + +template +struct is_iterator::value>::type> { + static const bool value = false; +}; + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __println_range(a, b); +} + +template +void println(const A *a, const A *b) { + __println_range(a, b); +} + +template<> +void println(const char *a, const char *b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +void println(const T &x) { + __testlib_print_one(x); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << " "; + __testlib_print_one(g); + std::cout << std::endl; +} + +/* opts */ + +/** + * A struct for a singular testlib opt, containing the raw string value, + * and a boolean value for marking whether the opt is used. + */ +struct TestlibOpt { + std::string value; + bool used; + + TestlibOpt() : value(), used(false) {} +}; + +/** + * Get the type of opt based on the number of `-` at the beginning and the + * _validity_ of the key name. + * + * A valid key name must start with an alphabetical character. + * + * Returns: 1 if s has one `-` at the beginning, that is, "-keyName". + * 2 if s has two `-` at the beginning, that is, "--keyName". + * 0 otherwise. That is, if s has no `-` at the beginning, or has more + * than 2 at the beginning ("---keyName", "----keyName", ...), or the + * keyName is invalid (the first character is not an alphabetical + * character). + */ +size_t getOptType(char *s) { + if (!s || strlen(s) <= 1) + return 0; + + if (s[0] == '-') { + if (isalpha(s[1])) + return 1; + else if (s[1] == '-') + return isalpha(s[2]) ? 2 : 0; + } + + return 0; +} + +/** + * Parse the opt at a given index, and put it into the opts maps. + * + * An opt can has the following form: + * 1) -keyName=value or --keyName=value (ex. -n=10 --test-count=20) + * 2) -keyName value or --keyName value (ex. -n 10 --test-count 20) + * 3) -kNumval or --kNumval (ex. -n10 --t20) + * 4) -boolProperty or --boolProperty (ex. -sorted --tree-only) + * + * Only the second form consumes 2 arguments. The other consumes only 1 + * argument. + * + * In the third form, the key is a single character, and after the key is the + * value. The value _should_ be a number. + * + * In the forth form, the value is true. + * + * Params: + * - argc and argv: the number of command line arguments and the command line + * arguments themselves. + * - index: the starting index of the opts. + * - opts: the map containing the resulting opt. + * + * Returns: the number of consumed arguments to parse the opt. + * 0 if there is no arguments to parse. + * + * Algorithm details: + * TODO. Please refer to the implementation to see how the code handles the 3rd and 4th forms separately. + */ +size_t parseOpt(size_t argc, char *argv[], size_t index, std::map &opts) { + if (index >= argc) + return 0; + + size_t type = getOptType(argv[index]), inc = 1; + if (type > 0) { + std::string key(argv[index] + type), val; + size_t sep = key.find('='); + if (sep != std::string::npos) { + val = key.substr(sep + 1); + key = key.substr(0, sep); + } else { + if (index + 1 < argc && getOptType(argv[index + 1]) == 0) { + val = argv[index + 1]; + inc = 2; + } else { + if (key.length() > 1 && isdigit(key[1])) { + val = key.substr(1); + key = key.substr(0, 1); + } else { + val = "true"; + } + } + } + opts[key].value = val; + } else { + return inc; + } + + return inc; +} + +/** + * Global list containing all the arguments in the order given in the command line. + */ +std::vector __testlib_argv; + +/** + * Global dictionary containing all the parsed opts. + */ +std::map __testlib_opts; + +/** + * Whether automatic no unused opts ensurement should be done. This flag will + * be turned on when `has_opt` or `opt(key, default_value)` is called. + * + * The automatic ensurement can be suppressed when + * __testlib_ensureNoUnusedOptsSuppressed is true. + */ +bool __testlib_ensureNoUnusedOptsFlag = false; + +/** + * Suppress no unused opts automatic ensurement. Can be set to true with + * `suppressEnsureNoUnusedOpts()`. + */ +bool __testlib_ensureNoUnusedOptsSuppressed = false; + +/** + * Parse command line arguments into opts. + * The results are stored into __testlib_argv and __testlib_opts. + */ +void prepareOpts(int argc, char *argv[]) { + if (argc <= 0) + __testlib_fail("Opts: expected argc>=0 but found " + toString(argc)); + size_t n = static_cast(argc); // NOLINT(hicpp-use-auto,modernize-use-auto) + __testlib_opts = std::map(); + for (size_t index = 1; index < n; index += parseOpt(n, argv, index, __testlib_opts)); + __testlib_argv = std::vector(n); + for (size_t index = 0; index < n; index++) + __testlib_argv[index] = argv[index]; +} + +/** + * An utility function to get the argument with a given index. This function + * also print a readable message when no arguments are found. + */ +std::string __testlib_indexToArgv(int index) { + if (index < 0 || index >= int(__testlib_argv.size())) + __testlib_fail("Opts: index '" + toString(index) + "' is out of range [0," + + toString(__testlib_argv.size()) + ")"); + return __testlib_argv[size_t(index)]; +} + +/** + * An utility function to get the opt with a given key . This function + * also print a readable message when no opts are found. + */ +std::string __testlib_keyToOpts(const std::string &key) { + auto it = __testlib_opts.find(key); + if (it == __testlib_opts.end()) + __testlib_fail("Opts: unknown key '" + compress(key) + "'"); + it->second.used = true; + return it->second.value; +} + +template +T optValueToIntegral(const std::string &s, bool nonnegative); + +long double optValueToLongDouble(const std::string &s); + +std::string parseExponentialOptValue(const std::string &s) { + size_t pos = std::string::npos; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == 'e' || s[i] == 'E') { + if (pos != std::string::npos) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + pos = i; + } + if (pos == std::string::npos) + return s; + std::string e = s.substr(pos + 1); + if (!e.empty() && e[0] == '+') + e = e.substr(1); + if (e.empty()) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (e.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + int ne = optValueToIntegral(e, false); + std::string num = s.substr(0, pos); + if (num.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (!num.empty() && num[0] == '+') + num = num.substr(1); + optValueToLongDouble(num); + bool minus = false; + if (num[0] == '-') { + minus = true; + num = num.substr(1); + } + for (int i = 0; i < +ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num += '0'; + else { + if (sep + 1 == num.length()) + num[sep] = '0'; + else + std::swap(num[sep], num[sep + 1]); + } + } + for (int i = 0; i < -ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num.insert(num.begin() + int(num.length()) - 1, '.'); + else { + if (sep == 0) + num.insert(num.begin() + 1, '0'); + else + std::swap(num[sep - 1], num[sep]); + } + } + while (!num.empty() && num[0] == '0') + num = num.substr(1); + while (num.find('.') != std::string::npos && num.back() == '0') + num = num.substr(0, num.length() - 1); + if (!num.empty() && num.back() == '.') + num = num.substr(0, num.length() - 1); + if ((!num.empty() && num[0] == '.') || num.empty()) + num.insert(num.begin(), '0'); + return (minus ? "-" : "") + num; +} + +template +T optValueToIntegral(const std::string &s_, bool nonnegative) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + T value = 0; + long double about = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + if (nonnegative) + __testlib_fail("Opts: expected non-negative integer but '" + compress(s_) + "' found"); + sign = -1; + pos++; + } + for (size_t i = pos; i < s.length(); i++) { + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + value = value * 10 + s[i] - '0'; + about = about * 10 + s[i] - '0'; + } + value *= sign; + about *= sign; + if (fabsl(value - about) > 0.1) + __testlib_fail("Opts: integer overflow: expected integer but '" + compress(s_) + "' found"); + return value; +} + +long double optValueToLongDouble(const std::string &s_) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + long double value = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + sign = -1; + pos++; + } + bool period = false; + long double mul = 1.0; + for (size_t i = pos; i < s.length(); i++) { + if (s[i] == '.') { + if (period) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + else { + period = true; + continue; + } + } + if (period) + mul *= 10.0; + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + if (period) + value += (s[i] - '0') / mul; + else + value = value * 10 + s[i] - '0'; + } + value *= sign; + return value; +} + +/** + * Return true if there is an opt with a given key. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +bool has_opt(const std::string &key) { + __testlib_ensureNoUnusedOptsFlag = true; + return __testlib_opts.count(key) != 0; +} + +/* About the followings part for opt with 2 and 3 arguments. + * + * To parse the argv/opts correctly for a give type (integer, floating point or + * string), some meta programming must be done to determine the type of + * the type, and use the correct parsing function accordingly. + * + * The pseudo algorithm for determining the type of T and parse it accordingly + * is as follows: + * + * if (T is integral type) { + * if (T is unsigned) { + * parse the argv/opt as an **unsigned integer** of type T. + * } else { + * parse the argv/opt as an **signed integer** of type T. + * } else { + * if (T is floating point type) { + * parse the argv/opt as an **floating point** of type T. + * } else { + * // T should be std::string + * just the raw content of the argv/opts. + * } + * } + * + * To help with meta programming, some `opt` function with 2 or 3 arguments are + * defined. + * + * Opt with 3 arguments: T opt(true/false is_integral, true/false is_unsigned, index/key) + * + * + The first argument is for determining whether the type T is an integral + * type. That is, the result of std::is_integral() should be passed to + * this argument. When false, the type _should_ be either floating point or a + * std::string. + * + * + The second argument is for determining whether the signedness of the type + * T (if it is unsigned or signed). That is, the result of + * std::is_unsigned() should be passed to this argument. This argument can + * be ignored if the first one is false, because it only applies to integer. + * + * Opt with 2 arguments: T opt(true/false is_floating_point, index/key) + * + The first argument is for determining whether the type T is a floating + * point type. That is, the result of std::is_floating_point() should be + * passed to this argument. When false, the type _should_ be a std::string. + */ + +template +T opt(std::false_type is_floating_point, int index); + +template<> +std::string opt(std::false_type /*is_floating_point*/, int index) { + return __testlib_indexToArgv(index); +} + +template +T opt(std::true_type /*is_floating_point*/, int index) { + return T(optValueToLongDouble(__testlib_indexToArgv(index))); +} + +template +T opt(std::false_type /*is_integral*/, U /*is_unsigned*/, int index) { + return opt(std::is_floating_point(), index); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + std::string value = __testlib_indexToArgv(index); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: opt by index '" + toString(index) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed argv by a given index. + */ +template +T opt(int index) { + return opt(std::is_integral(), std::is_unsigned(), index); +} + +/** + * Return the raw string value of an argv by a given index. + */ +std::string opt(int index) { + return opt(index); +} + +/** + * Return the parsed argv by a given index. If the index is bigger than + * the number of argv, return the given default_value. + */ +template +T opt(int index, const T &default_value) { + if (index >= int(__testlib_argv.size())) { + return default_value; + } + return opt(index); +} + +/** + * Return the raw string value of an argv by a given index. If the index is + * bigger than the number of argv, return the given default_value. + */ +std::string opt(int index, const std::string &default_value) { + return opt(index, default_value); +} + +template +T opt(std::false_type is_floating_point, const std::string &key); + +template<> +std::string opt(std::false_type /*is_floating_point*/, const std::string &key) { + return __testlib_keyToOpts(key); +} + +template +T opt(std::true_type /*is_integral*/, const std::string &key) { + return T(optValueToLongDouble(__testlib_keyToOpts(key))); +} + +template +T opt(std::false_type /*is_integral*/, U, const std::string &key) { + return opt(std::is_floating_point(), key); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + if (!has_opt(key)) + return false; + std::string value = __testlib_keyToOpts(key); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: key '" + compress(key) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed opt by a given key. + */ +template +T opt(const std::string &key) { + return opt(std::is_integral(), std::is_unsigned(), key); +} + +/** + * Return the raw string value of an opt by a given key + */ +std::string opt(const std::string &key) { + return opt(key); +} + +/* Scorer started. */ + +enum TestResultVerdict { + SKIPPED, + OK, + WRONG_ANSWER, + RUNTIME_ERROR, + TIME_LIMIT_EXCEEDED, + IDLENESS_LIMIT_EXCEEDED, + MEMORY_LIMIT_EXCEEDED, + COMPILATION_ERROR, + CRASHED, + FAILED +}; + +std::string serializeVerdict(TestResultVerdict verdict) { + switch (verdict) { + case SKIPPED: return "SKIPPED"; + case OK: return "OK"; + case WRONG_ANSWER: return "WRONG_ANSWER"; + case RUNTIME_ERROR: return "RUNTIME_ERROR"; + case TIME_LIMIT_EXCEEDED: return "TIME_LIMIT_EXCEEDED"; + case IDLENESS_LIMIT_EXCEEDED: return "IDLENESS_LIMIT_EXCEEDED"; + case MEMORY_LIMIT_EXCEEDED: return "MEMORY_LIMIT_EXCEEDED"; + case COMPILATION_ERROR: return "COMPILATION_ERROR"; + case CRASHED: return "CRASHED"; + case FAILED: return "FAILED"; + } + throw "Unexpected verdict"; +} + +TestResultVerdict deserializeTestResultVerdict(std::string s) { + if (s == "SKIPPED") + return SKIPPED; + else if (s == "OK") + return OK; + else if (s == "WRONG_ANSWER") + return WRONG_ANSWER; + else if (s == "RUNTIME_ERROR") + return RUNTIME_ERROR; + else if (s == "TIME_LIMIT_EXCEEDED") + return TIME_LIMIT_EXCEEDED; + else if (s == "IDLENESS_LIMIT_EXCEEDED") + return IDLENESS_LIMIT_EXCEEDED; + else if (s == "MEMORY_LIMIT_EXCEEDED") + return MEMORY_LIMIT_EXCEEDED; + else if (s == "COMPILATION_ERROR") + return COMPILATION_ERROR; + else if (s == "CRASHED") + return CRASHED; + else if (s == "FAILED") + return FAILED; + ensuref(false, "Unexpected serialized TestResultVerdict"); + // No return actually. + return FAILED; +} + +struct TestResult { + int testIndex; + std::string testset; + std::string group; + TestResultVerdict verdict; + double points; + long long timeConsumed; + long long memoryConsumed; + std::string input; + std::string output; + std::string answer; + int exitCode; + std::string checkerComment; +}; + +std::string serializePoints(double points) { + if (std::isnan(points)) + return ""; + else { + char c[64]; + sprintf(c, "%.03lf", points); + return c; + } +} + +double deserializePoints(std::string s) { + if (s.empty()) + return std::numeric_limits::quiet_NaN(); + else { + double result; + ensuref(sscanf(s.c_str(), "%lf", &result) == 1, "Invalid serialized points"); + return result; + } +} + +std::string escapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\r') + continue; + if (s[i] == '\n') { + result += "\\n"; + continue; + } + if (s[i] == '\\' || s[i] == ';') + result += '\\'; + result += s[i]; + } + return result; +} + +std::string unescapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\' && i + 1 < s.length()) { + if (s[i + 1] == 'n') { + result += '\n'; + i++; + continue; + } else if (s[i + 1] == ';' || s[i + 1] == '\\') { + result += s[i + 1]; + i++; + continue; + } + } + result += s[i]; + } + return result; +} + +std::string serializeTestResult(TestResult tr) { + std::string result; + result += std::to_string(tr.testIndex); + result += ";"; + result += escapeTestResultString(tr.testset); + result += ";"; + result += escapeTestResultString(tr.group); + result += ";"; + result += serializeVerdict(tr.verdict); + result += ";"; + result += serializePoints(tr.points); + result += ";"; + result += std::to_string(tr.timeConsumed); + result += ";"; + result += std::to_string(tr.memoryConsumed); + result += ";"; + result += escapeTestResultString(tr.input); + result += ";"; + result += escapeTestResultString(tr.output); + result += ";"; + result += escapeTestResultString(tr.answer); + result += ";"; + result += std::to_string(tr.exitCode); + result += ";"; + result += escapeTestResultString(tr.checkerComment); + return result; +} + +TestResult deserializeTestResult(std::string s) { + std::vector items; + std::string t; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\') { + t += s[i]; + if (i + 1 < s.length()) + t += s[i + 1]; + i++; + continue; + } else { + if (s[i] == ';') { + items.push_back(t); + t = ""; + } else + t += s[i]; + } + } + items.push_back(t); + + ensuref(items.size() == 12, "Invalid TestResult serialization: expected exactly 12 items"); + + TestResult tr; + size_t pos = 0; + tr.testIndex = stoi(items[pos++]); + tr.testset = unescapeTestResultString(items[pos++]); + tr.group = unescapeTestResultString(items[pos++]); + tr.verdict = deserializeTestResultVerdict(items[pos++]); + tr.points = deserializePoints(items[pos++]); + tr.timeConsumed = stoll(items[pos++]); + tr.memoryConsumed = stoll(items[pos++]); + tr.input = unescapeTestResultString(items[pos++]); + tr.output = unescapeTestResultString(items[pos++]); + tr.answer = unescapeTestResultString(items[pos++]); + tr.exitCode = stoi(items[pos++]); + tr.checkerComment = unescapeTestResultString(items[pos++]); + + return tr; +} + +std::vector readTestResults(std::string fileName) { + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + ensuref(stream.is_open(), "Can't read test results file '%s'", fileName.c_str()); + std::vector result; + std::string line; + while (getline(stream, line)) + if (!line.empty()) + result.push_back(deserializeTestResult(line)); + stream.close(); + return result; +} + +std::function)> __testlib_scorer; + +struct TestlibScorerGuard { + ~TestlibScorerGuard() { + if (testlibMode == _scorer) { + std::vector testResults; + while (!inf.eof()) { + std::string line = inf.readLine(); + if (!line.empty()) + testResults.push_back(deserializeTestResult(line)); + } + inf.readEof(); + printf("%.3f\n", __testlib_scorer(testResults)); + } + } +} __testlib_scorer_guard; + +void registerScorer(int argc, char *argv[], std::function)> scorer) { + /* Supress unused. */ + (void)(argc), (void)(argv); + + __testlib_ensuresPreconditions(); + + testlibMode = _scorer; + __testlib_set_binary(stdin); + + inf.init(stdin, _input); + inf.strict = false; + + __testlib_scorer = scorer; +} + +/* Scorer ended. */ + +/** + * Return the parsed opt by a given key. If no opts with the given key are + * found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +template +T opt(const std::string &key, const T &default_value) { + if (!has_opt(key)) { + return default_value; + } + return opt(key); +} + +/** + * Return the raw string value of an opt by a given key. If no opts with the + * given key are found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +std::string opt(const std::string &key, const std::string &default_value) { + return opt(key, default_value); +} + +/** + * Check if all opts are used. If not, __testlib_fail is called. + * Should be used after calling all opt() function calls. + * + * This function is useful when opt() with default_value for checking typos + * in the opt's key. + */ +void ensureNoUnusedOpts() { + for (const auto &opt: __testlib_opts) { + if (!opt.second.used) { + __testlib_fail(format("Opts: unused key '%s'", compress(opt.first).c_str())); + } + } +} + +void suppressEnsureNoUnusedOpts() { + __testlib_ensureNoUnusedOptsSuppressed = true; +} + +void TestlibFinalizeGuard::autoEnsureNoUnusedOpts() { + if (__testlib_ensureNoUnusedOptsFlag && !__testlib_ensureNoUnusedOptsSuppressed) { + ensureNoUnusedOpts(); + } +} + +TestlibFinalizeGuard testlibFinalizeGuard; + +#endif +#endif \ No newline at end of file diff --git a/ICPC/swerc2022_J/data.zip b/ICPC/swerc2022_J/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..0e56d584b3dd6c2da71107ba4b8e62bf0af14ddb --- /dev/null +++ b/ICPC/swerc2022_J/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:082955236d3e908f9ae3b674d74bbb29afe28ba51b202816384035426b18d612 +size 70805 diff --git a/ICPC/swerc2022_J/init.yml b/ICPC/swerc2022_J/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb1355b15533e12994ac3c06123197567b0f6aae --- /dev/null +++ b/ICPC/swerc2022_J/init.yml @@ -0,0 +1,104 @@ +archive: data.zip +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 +- in: 31.in + out: 31.ans + points: 1 +- in: 32.in + out: 32.ans + points: 1 +- in: 33.in + out: 33.ans + points: 1 +- in: 34.in + out: 34.ans + points: 1 +- in: 35.in + out: 35.ans + points: 1 +- in: 36.in + out: 36.ans + points: 1 +- in: 37.in + out: 37.ans + points: 1 +- in: 38.in + out: 38.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_K/data.zip b/ICPC/swerc2022_K/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..ad87918673648d4bb1e579b080d18a17b02a17e5 --- /dev/null +++ b/ICPC/swerc2022_K/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3df858714779ce555090d27a0c0d22383106f8e526ce09712700f05b79629e81 +size 735349 diff --git a/ICPC/swerc2022_K/init.yml b/ICPC/swerc2022_K/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..10b18c346eb8aa74949d1740f020a26256e04d86 --- /dev/null +++ b/ICPC/swerc2022_K/init.yml @@ -0,0 +1,46 @@ +archive: data.zip +checker: + args: + files: + - output_validators/testlib.h + - output_validators/checker.cpp + lang: CPP17 + type: default + name: bridged +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 2.in + out: 2.ans + points: 1 +- in: 3.in + out: 3.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2022_K/output_validators/checker.cpp b/ICPC/swerc2022_K/output_validators/checker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8568a0a0e96bdc93f0b142e2eceb8a7c59f0fb96 --- /dev/null +++ b/ICPC/swerc2022_K/output_validators/checker.cpp @@ -0,0 +1,120 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "./testlib.h" +#include +#include +#include +#include +#include +using namespace std; +typedef pair pii; +typedef long long ll; +#define mp make_pair + +const int N = 55; +int n, m, k; +int ed[N * N][2]; +ll g[N]; +vector col[2 * N]; +int q[N]; +int topQ; + +void addEdges(vector edges) { + for (int e : edges) { + int v = ed[e][0], u = ed[e][1]; + g[v] |= 1LL << u; + g[u] |= 1LL << v; + } +} + +bool isConnected() { + ll used = 1; + topQ = 0; + q[topQ++] = 0; + for (int i = 0; i < topQ; i++) { + int v = q[i]; + ll mask = g[v] ^ (g[v] & used); + while(mask != 0) { + int u = __builtin_ctzll(mask); + mask ^= 1LL << u; + used ^= 1LL << u; + q[topQ++] = u; + } + } + return topQ == n; +} + +void checkTest(InStream &inf, InStream &ouf, int testId) { + setTestCase(testId); + n = inf.readInt(); + m = inf.readInt(); + for (int i = 0; i < m; i++) + for (int j = 0; j < 2; j++) { + ed[i][j] = inf.readInt(); + ed[i][j]--; + } + k = ouf.readInt(-1, m, "k"); + if (k == -1) ouf.quitf(_wa, "answer not found"); + if (k <= 1) ouf.quitf(_wa, "k is too small - %d < 2", k); + if (k > 2 * n) ouf.quitf(_wa, "k is too big - %d > 2 * %d", k, n); + for (int i = 0; i < k; i++) + col[i].clear(); + vector c = ouf.readInts(m, 1, k, "c"); + for (int i = 0; i < m; i++) { + col[c[i] - 1].push_back(i); + } + for (int i = 0; i < k; i++) { + for (int j = 0; j < n; j++) + g[j] = 0; + addEdges(col[i]); + if (isConnected()) ouf.quitf(_wa, "color %d is connected", i + 1); + } + for (int x = 0; x < k; x++) + for (int y = x + 1; y < k; y++) { + for (int j = 0; j < n; j++) + g[j] = 0; + addEdges(col[x]); + addEdges(col[y]); + if (!isConnected()) ouf.quitf(_wa, "colors %d and %d are not connected", x + 1, y + 1); + } +} + +int main(int argc, char * argv[]) +{ + registerTestlibCmd(argc, argv); + + int t = inf.readInt(); + for (int i = 1; i <= t; i++) { + checkTest(inf, ouf, i); + } + + quitf(_ok, "OK"); + + return 0; +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2022_K/output_validators/testlib.h b/ICPC/swerc2022_K/output_validators/testlib.h new file mode 100644 index 0000000000000000000000000000000000000000..7f15d596b3531af62729aee5132df3bd29d675c7 --- /dev/null +++ b/ICPC/swerc2022_K/output_validators/testlib.h @@ -0,0 +1,5893 @@ +// Modified by a script to work with DOMjudge. +// Differences with the standard testlib.h: +// - The values of some exit codes. +// - The functions registerInteraction and registerTestlibCmd. + +/* + * It is strictly recommended to include "testlib.h" before any other include + * in your code. In this case testlib overrides compiler specific "random()". + * + * If you can't compile your code and compiler outputs something about + * ambiguous call of "random_shuffle", "rand" or "srand" it means that + * you shouldn't use them. Use "shuffle", and "rnd.next()" instead of them + * because these calls produce stable result for any C++ compiler. Read + * sample generator sources for clarification. + * + * Please read the documentation for class "random_t" and use "rnd" instance in + * generators. Probably, these sample calls will be usefull for you: + * rnd.next(); rnd.next(100); rnd.next(1, 2); + * rnd.next(3.14); rnd.next("[a-z]{1,100}"). + * + * Also read about wnext() to generate off-center random distribution. + * + * See https://github.com/MikeMirzayanov/testlib/ to get latest version or bug tracker. + */ + +#ifndef _TESTLIB_H_ +#define _TESTLIB_H_ + +/* + * Copyright (c) 2005-2022 + */ + +#define VERSION "0.9.40-SNAPSHOT" + +/* + * Mike Mirzayanov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* NOTE: This file contains testlib library for C++. + * + * Check, using testlib running format: + * check.exe [ [-appes]], + * If result file is specified it will contain results. + * + * Validator, using testlib running format: + * validator.exe < input.txt, + * It will return non-zero exit code and writes message to standard output. + * + * Generator, using testlib running format: + * gen.exe [parameter-1] [parameter-2] [... paramerter-n] + * You can write generated test(s) into standard output or into the file(s). + * + * Interactor, using testlib running format: + * interactor.exe [ [ [-appes]]], + * Reads test from inf (mapped to args[1]), writes result to tout (mapped to argv[2], + * can be judged by checker later), reads program output from ouf (mapped to stdin), + * writes output to program via stdout (use cout, printf, etc). + */ + +const char *latestFeatures[] = { + "Supported '--testMarkupFileName fn' and '--testCase tc/--testCaseFileName fn' for validators", + "Added opt defaults via opt(key/index, default_val); check unused opts when using has_opt or default opt (turn off this check with suppressEnsureNoUnusedOpt()).", + "For checker added --group and --testset command line params (like for validator), use checker.group() or checker.testset() to get values", + "Added quitpi(points_info, message) function to return with _points exit code 7 and given points_info", + "rnd.partition(size, sum[, min_part=1]) returns random (unsorted) partition which is a representation of the given `sum` as a sum of `size` positive integers (or >=min_part if specified)", + "rnd.distinct(size, n) and rnd.distinct(size, from, to)", + "opt(\"some_missing_key\") returns false now", + "has_opt(key)", + "Abort validator on validator.testset()/validator.group() if registered without using command line", + "Print integer range violations in a human readable way like `violates the range [1, 10^9]`", + "Opts supported: use them like n = opt(\"n\"), in a command line you can use an exponential notation", + "Reformatted", + "Use setTestCase(i) or unsetTestCase() to support test cases (you can use it in any type of program: generator, interactor, validator or checker)", + "Fixed issue #87: readStrictDouble accepts \"-0.00\"", + "Fixed issue #83: added InStream::quitif(condition, ...)", + "Fixed issue #79: fixed missed guard against repeated header include", + "Fixed issue #80: fixed UB in case of huge quitf message", + "Fixed issue #84: added readXs(size, indexBase = 1)", + "Fixed stringstream repeated usage issue", + "Fixed compilation in g++ (for std=c++03)", + "Batch of println functions (support collections, iterator ranges)", + "Introduced rnd.perm(size, first = 0) to generate a `first`-indexed permutation", + "Allow any whitespace in readInts-like functions for non-validators", + "Ignore 4+ command line arguments ifdef EJUDGE", + "Speed up of vtos", + "Show line number in validators in case of incorrect format", + "Truncate huge checker/validator/interactor message", + "Fixed issue with readTokenTo of very long tokens, now aborts with _pe/_fail depending of a stream type", + "Introduced InStream::ensure/ensuref checking a condition, returns wa/fail depending of a stream type", + "Fixed compilation in VS 2015+", + "Introduced space-separated read functions: readWords/readTokens, multilines read functions: readStrings/readLines", + "Introduced space-separated read functions: readInts/readIntegers/readLongs/readUnsignedLongs/readDoubles/readReals/readStrictDoubles/readStrictReals", + "Introduced split/tokenize functions to separate string by given char", + "Introduced InStream::readUnsignedLong and InStream::readLong with unsigned long long paramerters", + "Supported --testOverviewLogFileName for validator: bounds hits + features", + "Fixed UB (sequence points) in random_t", + "POINTS_EXIT_CODE returned back to 7 (instead of 0)", + "Removed disable buffers for interactive problems, because it works unexpectedly in wine", + "InStream over string: constructor of InStream from base InStream to inherit policies and std::string", + "Added expectedButFound quit function, examples: expectedButFound(_wa, 10, 20), expectedButFound(_fail, ja, pa, \"[n=%d,m=%d]\", n, m)", + "Fixed incorrect interval parsing in patterns", + "Use registerGen(argc, argv, 1) to develop new generator, use registerGen(argc, argv, 0) to compile old generators (originally created for testlib under 0.8.7)", + "Introduced disableFinalizeGuard() to switch off finalization checkings", + "Use join() functions to format a range of items as a single string (separated by spaces or other separators)", + "Use -DENABLE_UNEXPECTED_EOF to enable special exit code (by default, 8) in case of unexpected eof. It is good idea to use it in interactors", + "Use -DUSE_RND_AS_BEFORE_087 to compile in compatibility mode with random behavior of versions before 0.8.7", + "Fixed bug with nan in stringToDouble", + "Fixed issue around overloads for size_t on x64", + "Added attribute 'points' to the XML output in case of result=_points", + "Exit codes can be customized via macros, e.g. -DPE_EXIT_CODE=14", + "Introduced InStream function readWordTo/readTokenTo/readStringTo/readLineTo for faster reading", + "Introduced global functions: format(), englishEnding(), upperCase(), lowerCase(), compress()", + "Manual buffer in InStreams, some IO speed improvements", + "Introduced quitif(bool, const char* pattern, ...) which delegates to quitf() in case of first argument is true", + "Introduced guard against missed quitf() in checker or readEof() in validators", + "Supported readStrictReal/readStrictDouble - to use in validators to check strictly float numbers", + "Supported registerInteraction(argc, argv)", + "Print checker message to the stderr instead of stdout", + "Supported TResult _points to output calculated score, use quitp(...) functions", + "Fixed to be compilable on Mac", + "PC_BASE_EXIT_CODE=50 in case of defined TESTSYS", + "Fixed issues 19-21, added __attribute__ format printf", + "Some bug fixes", + "ouf.readInt(1, 100) and similar calls return WA", + "Modified random_t to avoid integer overflow", + "Truncated checker output [patch by Stepan Gatilov]", + "Renamed class random -> class random_t", + "Supported name parameter for read-and-validation methods, like readInt(1, 2, \"n\")", + "Fixed bug in readDouble()", + "Improved ensuref(), fixed nextLine to work in case of EOF, added startTest()", + "Supported \"partially correct\", example: quitf(_pc(13), \"result=%d\", result)", + "Added shuffle(begin, end), use it instead of random_shuffle(begin, end)", + "Added readLine(const string& ptrn), fixed the logic of readLine() in the validation mode", + "Package extended with samples of generators and validators", + "Written the documentation for classes and public methods in testlib.h", + "Implemented random routine to support generators, use registerGen() to switch it on", + "Implemented strict mode to validate tests, use registerValidation() to switch it on", + "Now ncmp.cpp and wcmp.cpp are return WA if answer is suffix or prefix of the output", + "Added InStream::readLong() and removed InStream::readLongint()", + "Now no footer added to each report by default (use directive FOOTER to switch on)", + "Now every checker has a name, use setName(const char* format, ...) to set it", + "Now it is compatible with TTS (by Kittens Computing)", + "Added \'ensure(condition, message = \"\")\' feature, it works like assert()", + "Fixed compatibility with MS C++ 7.1", + "Added footer with exit code information", + "Added compatibility with EJUDGE (compile with EJUDGE directive)", + "Added compatibility with Contester (compile with CONTESTER directive)" +}; + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NO_VA_START_VALIDATION +#endif + +/* Overrides random() for Borland C++. */ +#define random __random_deprecated +#include +#include +#include +#include +#undef random + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +# include +#endif + +#if (_WIN32 || __WIN32__ || __WIN32 || _WIN64 || __WIN64__ || __WIN64 || WINNT || __WINNT || __WINNT__ || __CYGWIN__) +# if !defined(_MSC_VER) || _MSC_VER > 1400 +# define NOMINMAX 1 +# include +# else +# define WORD unsigned short +# include +# endif +# include +# define ON_WINDOWS +# if defined(_MSC_VER) && _MSC_VER > 1400 +# pragma warning( disable : 4127 ) +# pragma warning( disable : 4146 ) +# pragma warning( disable : 4458 ) +# endif +#else +# define WORD unsigned short +# include +#endif + +#if defined(FOR_WINDOWS) && defined(FOR_LINUX) +#error Only one target system is allowed +#endif + +#ifndef LLONG_MIN +#define LLONG_MIN (-9223372036854775807LL - 1) +#endif + +#ifndef ULLONG_MAX +#define ULLONG_MAX (18446744073709551615) +#endif + +#define LF ((char)10) +#define CR ((char)13) +#define TAB ((char)9) +#define SPACE ((char)' ') +#define EOFC (255) + +#ifndef OK_EXIT_CODE +# ifdef CONTESTER +# define OK_EXIT_CODE 42 +# else +# define OK_EXIT_CODE 42 +# endif +#endif + +#ifndef WA_EXIT_CODE +# ifdef EJUDGE +# define WA_EXIT_CODE 43 +# elif defined(CONTESTER) +# define WA_EXIT_CODE 43 +# else +# define WA_EXIT_CODE 43 +# endif +#endif + +#ifndef PE_EXIT_CODE +# ifdef EJUDGE +# define PE_EXIT_CODE 43 +# elif defined(CONTESTER) +# define PE_EXIT_CODE 43 +# else +# define PE_EXIT_CODE 43 +# endif +#endif + +#ifndef FAIL_EXIT_CODE +# ifdef EJUDGE +# define FAIL_EXIT_CODE 6 +# elif defined(CONTESTER) +# define FAIL_EXIT_CODE 0xA3 +# else +# define FAIL_EXIT_CODE 3 +# endif +#endif + +#ifndef DIRT_EXIT_CODE +# ifdef EJUDGE +# define DIRT_EXIT_CODE 43 +# else +# define DIRT_EXIT_CODE 43 +# endif +#endif + +#ifndef POINTS_EXIT_CODE +# define POINTS_EXIT_CODE 7 +#endif + +#ifndef UNEXPECTED_EOF_EXIT_CODE +# define UNEXPECTED_EOF_EXIT_CODE 43 +#endif + +#ifndef PC_BASE_EXIT_CODE +# ifdef TESTSYS +# define PC_BASE_EXIT_CODE 50 +# else +# define PC_BASE_EXIT_CODE 0 +# endif +#endif + +#ifdef __GNUC__ +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] __attribute__((unused)) +#else +# define __TESTLIB_STATIC_ASSERT(condition) typedef void* __testlib_static_assert_type[(condition) ? 1 : -1] +#endif + +#ifdef ON_WINDOWS +#define I64 "%I64d" +#define U64 "%I64u" +#else +#define I64 "%lld" +#define U64 "%llu" +#endif + +#ifdef _MSC_VER +# define NORETURN __declspec(noreturn) +#elif defined __GNUC__ +# define NORETURN __attribute__ ((noreturn)) +#else +# define NORETURN +#endif + +static char __testlib_format_buffer[16777216]; +static int __testlib_format_buffer_usage_count = 0; + +#define FMT_TO_RESULT(fmt, cstr, result) std::string result; \ + if (__testlib_format_buffer_usage_count != 0) \ + __testlib_fail("FMT_TO_RESULT::__testlib_format_buffer_usage_count != 0"); \ + __testlib_format_buffer_usage_count++; \ + va_list ap; \ + va_start(ap, fmt); \ + vsnprintf(__testlib_format_buffer, sizeof(__testlib_format_buffer), cstr, ap); \ + va_end(ap); \ + __testlib_format_buffer[sizeof(__testlib_format_buffer) - 1] = 0; \ + result = std::string(__testlib_format_buffer); \ + __testlib_format_buffer_usage_count--; \ + +const long long __TESTLIB_LONGLONG_MAX = 9223372036854775807LL; +const int __TESTLIB_MAX_TEST_CASE = 1073741823; + +int __testlib_exitCode; + +bool __testlib_hasTestCase; +int __testlib_testCase = -1; + +void setTestCase(int testCase); + +void unsetTestCase() { + __testlib_hasTestCase = false; + __testlib_testCase = -1; +} + +NORETURN static void __testlib_fail(const std::string &message); + +template +static inline T __testlib_abs(const T &x) { + return x > 0 ? x : -x; +} + +template +static inline T __testlib_min(const T &a, const T &b) { + return a < b ? a : b; +} + +template +static inline T __testlib_max(const T &a, const T &b) { + return a > b ? a : b; +} + +template +static inline T __testlib_crop(T value, T a, T b) { + return __testlib_min(__testlib_max(value, a), --b); +} + +static inline double __testlib_crop(double value, double a, double b) { + value = __testlib_min(__testlib_max(value, a), b); + if (value >= b) + value = std::nexttoward(b, a); + return value; +} + +static bool __testlib_prelimIsNaN(double r) { + volatile double ra = r; +#ifndef __BORLANDC__ + return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); +#else + return std::_isnan(ra); +#endif +} + +static std::string removeDoubleTrailingZeroes(std::string value) { + while (!value.empty() && value[value.length() - 1] == '0' && value.find('.') != std::string::npos) + value = value.substr(0, value.length() - 1); + if (!value.empty() && value[value.length() - 1] == '.') + return value + '0'; + else + return value; +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +std::string format(const char *fmt, ...) { + FMT_TO_RESULT(fmt, fmt, result); + return result; +} + +std::string format(const std::string fmt, ...) { + FMT_TO_RESULT(fmt, fmt.c_str(), result); + return result; +} + +static std::string __testlib_part(const std::string &s); + +static bool __testlib_isNaN(double r) { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); + volatile double ra = r; + long long llr1, llr2; + std::memcpy((void *) &llr1, (void *) &ra, sizeof(double)); + ra = -ra; + std::memcpy((void *) &llr2, (void *) &ra, sizeof(double)); + long long llnan = 0xFFF8000000000000LL; + return __testlib_prelimIsNaN(r) || llnan == llr1 || llnan == llr2; +} + +static double __testlib_nan() { + __TESTLIB_STATIC_ASSERT(sizeof(double) == sizeof(long long)); +#ifndef NAN + long long llnan = 0xFFF8000000000000LL; + double nan; + std::memcpy(&nan, &llnan, sizeof(double)); + return nan; +#else + return NAN; +#endif +} + +static bool __testlib_isInfinite(double r) { + volatile double ra = r; + return (ra > 1E300 || ra < -1E300); +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline bool doubleCompare(double expected, double result, double MAX_DOUBLE_ERROR) { + MAX_DOUBLE_ERROR += 1E-15; + if (__testlib_isNaN(expected)) { + return __testlib_isNaN(result); + } else if (__testlib_isInfinite(expected)) { + if (expected > 0) { + return result > 0 && __testlib_isInfinite(result); + } else { + return result < 0 && __testlib_isInfinite(result); + } + } else if (__testlib_isNaN(result) || __testlib_isInfinite(result)) { + return false; + } else if (__testlib_abs(result - expected) <= MAX_DOUBLE_ERROR) { + return true; + } else { + double minv = __testlib_min(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + double maxv = __testlib_max(expected * (1.0 - MAX_DOUBLE_ERROR), + expected * (1.0 + MAX_DOUBLE_ERROR)); + return result >= minv && result <= maxv; + } +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +inline double doubleDelta(double expected, double result) { + double absolute = __testlib_abs(result - expected); + + if (__testlib_abs(expected) > 1E-9) { + double relative = __testlib_abs(absolute / expected); + return __testlib_min(absolute, relative); + } else + return absolute; +} + +/** It does nothing on non-windows and files differ from stdin/stdout/stderr. */ +static void __testlib_set_binary(std::FILE *file) { + if (NULL != file) { +#ifdef ON_WINDOWS +# ifdef _O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(_setmode(STDIN_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdin), _O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(_setmode(STDOUT_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stdout), _O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(_setmode(STDERR_FILENO, _O_BINARY)); +# else + return void(_setmode(_fileno(stderr), _O_BINARY)); +# endif +# elif O_BINARY + if (stdin == file) +# ifdef STDIN_FILENO + return void(setmode(STDIN_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdin), O_BINARY)); +# endif + if (stdout == file) +# ifdef STDOUT_FILENO + return void(setmode(STDOUT_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stdout), O_BINARY)); +# endif + if (stderr == file) +# ifdef STDERR_FILENO + return void(setmode(STDERR_FILENO, O_BINARY)); +# else + return void(setmode(fileno(stderr), O_BINARY)); +# endif +# endif +#endif + } +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +static std::string vtos(const T &t, std::true_type) { + if (t == 0) + return "0"; + else { + T n(t); + bool negative = n < 0; + std::string s; + while (n != 0) { + T digit = n % 10; + if (digit < 0) + digit = -digit; + s += char('0' + digit); + n /= 10; + } + std::reverse(s.begin(), s.end()); + return negative ? "-" + s : s; + } +} + +template +static std::string vtos(const T &t, std::false_type) { + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string vtos(const T &t) { + return vtos(t, std::is_integral()); +} + +/* signed case. */ +template +static std::string toHumanReadableString(const T &n, std::false_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else if (n_ == -1) + return "-10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +/* unsigned case. */ +template +static std::string toHumanReadableString(const T &n, std::true_type) { + if (n == 0) + return vtos(n); + int trailingZeroCount = 0; + T n_ = n; + while (n_ % 10 == 0) + n_ /= 10, trailingZeroCount++; + if (trailingZeroCount >= 7) { + if (n_ == 1) + return "10^" + vtos(trailingZeroCount); + else + return vtos(n_) + "*10^" + vtos(trailingZeroCount); + } else + return vtos(n); +} + +template +static std::string toHumanReadableString(const T &n) { + return toHumanReadableString(n, std::is_unsigned()); +} +#else +template +static std::string vtos(const T& t) +{ + std::string s; + static std::stringstream ss; + ss.str(std::string()); + ss.clear(); + ss << t; + ss >> s; + return s; +} + +template +static std::string toHumanReadableString(const T &n) { + return vtos(n); +} +#endif + +template +static std::string toString(const T &t) { + return vtos(t); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +/* opts */ +void prepareOpts(int argc, char* argv[]); +#endif + +/* + * Very simple regex-like pattern. + * It used for two purposes: validation and generation. + * + * For example, pattern("[a-z]{1,5}").next(rnd) will return + * random string from lowercase latin letters with length + * from 1 to 5. It is easier to call rnd.next("[a-z]{1,5}") + * for the same effect. + * + * Another samples: + * "mike|john" will generate (match) "mike" or "john"; + * "-?[1-9][0-9]{0,3}" will generate (match) non-zero integers from -9999 to 9999; + * "id-([ac]|b{2})" will generate (match) "id-a", "id-bb", "id-c"; + * "[^0-9]*" will match sequences (empty or non-empty) without digits, you can't + * use it for generations. + * + * You can't use pattern for generation if it contains meta-symbol '*'. Also it + * is not recommended to use it for char-sets with meta-symbol '^' like [^a-z]. + * + * For matching very simple greedy algorithm is used. For example, pattern + * "[0-9]?1" will not match "1", because of greedy nature of matching. + * Alternations (meta-symbols "|") are processed with brute-force algorithm, so + * do not use many alternations in one expression. + * + * If you want to use one expression many times it is better to compile it into + * a single pattern like "pattern p("[a-z]+")". Later you can use + * "p.matches(std::string s)" or "p.next(random_t& rd)" to check matching or generate + * new string by pattern. + * + * Simpler way to read token and check it for pattern matching is "inf.readToken("[a-z]+")". + * + * All spaces are ignored in regex, unless escaped with \. For example, ouf.readLine("NO SOLUTION") + * will expect "NOSOLUTION", the correct call should be ouf.readLine("NO\\ SOLUTION") or + * ouf.readLine(R"(NO\ SOLUTION)") if you prefer raw string literals from C++11. + */ +class random_t; + +class pattern { +public: + /* Create pattern instance by string. */ + pattern(std::string s); + + /* Generate new string by pattern and given random_t. */ + std::string next(random_t &rnd) const; + + /* Checks if given string match the pattern. */ + bool matches(const std::string &s) const; + + /* Returns source string of the pattern. */ + std::string src() const; + +private: + bool matches(const std::string &s, size_t pos) const; + + std::string s; + std::vector children; + std::vector chars; + int from; + int to; +}; + +/* + * Use random_t instances to generate random values. It is preffered + * way to use randoms instead of rand() function or self-written + * randoms. + * + * Testlib defines global variable "rnd" of random_t class. + * Use registerGen(argc, argv, 1) to setup random_t seed be command + * line (to use latest random generator version). + * + * Random generates uniformly distributed values if another strategy is + * not specified explicitly. + */ +class random_t { +private: + unsigned long long seed; + static const unsigned long long multiplier; + static const unsigned long long addend; + static const unsigned long long mask; + static const int lim; + + long long nextBits(int bits) { + if (bits <= 48) { + seed = (seed * multiplier + addend) & mask; + return (long long) (seed >> (48 - bits)); + } else { + if (bits > 63) + __testlib_fail("random_t::nextBits(int bits): n must be less than 64"); + + int lowerBitCount = (random_t::version == 0 ? 31 : 32); + + long long left = (nextBits(31) << 32); + long long right = nextBits(lowerBitCount); + + return left ^ right; + } + } + +public: + static int version; + + /* New random_t with fixed seed. */ + random_t() + : seed(3905348978240129619LL) { + } + + /* Sets seed by command line. */ + void setSeed(int argc, char *argv[]) { + random_t p; + + seed = 3905348978240129619LL; + for (int i = 1; i < argc; i++) { + std::size_t le = std::strlen(argv[i]); + for (std::size_t j = 0; j < le; j++) + seed = seed * multiplier + (unsigned int) (argv[i][j]) + addend; + seed += multiplier / addend; + } + + seed = seed & mask; + } + + /* Sets seed by given value. */ + void setSeed(long long _seed) { + _seed = (_seed ^ multiplier) & mask; + seed = _seed; + } + +#ifndef __BORLANDC__ + + /* Random string value by given pattern (see pattern documentation). */ + std::string next(const std::string &ptrn) { + pattern p(ptrn); + return p.next(*this); + } + +#else + /* Random string value by given pattern (see pattern documentation). */ + std::string next(std::string ptrn) + { + pattern p(ptrn); + return p.next(*this); + } +#endif + + /* Random value in range [0, n-1]. */ + int next(int n) { + if (n <= 0) + __testlib_fail("random_t::next(int n): n must be positive"); + + if ((n & -n) == n) // n is a power of 2 + return (int) ((n * (long long) nextBits(31)) >> 31); + + const long long limit = INT_MAX / n * n; + + long long bits; + do { + bits = nextBits(31); + } while (bits >= limit); + + return int(bits % n); + } + + /* Random value in range [0, n-1]. */ + unsigned int next(unsigned int n) { + if (n >= INT_MAX) + __testlib_fail("random_t::next(unsigned int n): n must be less INT_MAX"); + return (unsigned int) next(int(n)); + } + + /* Random value in range [0, n-1]. */ + long long next(long long n) { + if (n <= 0) + __testlib_fail("random_t::next(long long n): n must be positive"); + + const long long limit = __TESTLIB_LONGLONG_MAX / n * n; + + long long bits; + do { + bits = nextBits(63); + } while (bits >= limit); + + return bits % n; + } + + /* Random value in range [0, n-1]. */ + unsigned long long next(unsigned long long n) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::next(unsigned long long n): n must be less LONGLONG_MAX"); + return (unsigned long long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + long next(long n) { + return (long) next((long long) (n)); + } + + /* Random value in range [0, n-1]. */ + unsigned long next(unsigned long n) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::next(unsigned long n): n must be less LONG_MAX"); + return (unsigned long) next((unsigned long long) (n)); + } + + /* Returns random value in range [from,to]. */ + int next(int from, int to) { + return int(next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + unsigned int next(unsigned int from, unsigned int to) { + return (unsigned int) (next((long long) to - from + 1) + from); + } + + /* Returns random value in range [from,to]. */ + long long next(long long from, long long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long long next(unsigned long long from, unsigned long long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long long from, unsigned long long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + long next(long from, long to) { + return next(to - from + 1) + from; + } + + /* Returns random value in range [from,to]. */ + unsigned long next(unsigned long from, unsigned long to) { + if (from > to) + __testlib_fail("random_t::next(unsigned long from, unsigned long to): from can't not exceed to"); + return next(to - from + 1) + from; + } + + /* Random double value in range [0, 1). */ + double next() { + long long left = ((long long) (nextBits(26)) << 27); + long long right = nextBits(27); + return __testlib_crop((double) (left + right) / (double) (1LL << 53), 0.0, 1.0); + } + + /* Random double value in range [0, n). */ + double next(double n) { + if (n <= 0.0) + __testlib_fail("random_t::next(double): n should be positive"); + return __testlib_crop(n * next(), 0.0, n); + } + + /* Random double value in range [from, to). */ + double next(double from, double to) { + if (from >= to) + __testlib_fail("random_t::next(double from, double to): from should be strictly less than to"); + return next(to - from) + from; + } + + /* Returns random element from container. */ + template + typename Container::value_type any(const Container &c) { + int size = int(c.size()); + if (size <= 0) + __testlib_fail("random_t::any(const Container& c): c.size() must be positive"); + return *(c.begin() + next(size)); + } + + /* Returns random element from iterator range. */ + template + typename Iter::value_type any(const Iter &begin, const Iter &end) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length"); + return *(begin + next(size)); + } + + /* Random string value by given pattern (see pattern documentation). */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + std::string next(const char *format, ...) { + FMT_TO_RESULT(format, format, ptrn); + return next(ptrn); + } + + /* + * Weighted next. If type == 0 than it is usual "next()". + * + * If type = 1, than it returns "max(next(), next())" + * (the number of "max" functions equals to "type"). + * + * If type < 0, than "max" function replaces with "min". + */ + int wnext(int n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(int n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + int result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((int) (double(n) * p), 0, n); + } + } + + /* See wnext(int, int). It uses the same algorithms. */ + long long wnext(long long n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(long long n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + long long result = next(n); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next(n)); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next(n)); + + return result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop((long long) (double(n) * p), 0LL, n); + } + } + + /* Returns value in [0, n). See wnext(int, int). It uses the same algorithms. */ + double wnext(double n, int type) { + if (n <= 0) + __testlib_fail("random_t::wnext(double n, int type): n must be positive"); + + if (abs(type) < random_t::lim) { + double result = next(); + + for (int i = 0; i < +type; i++) + result = __testlib_max(result, next()); + + for (int i = 0; i < -type; i++) + result = __testlib_min(result, next()); + + return n * result; + } else { + double p; + + if (type > 0) + p = std::pow(next() + 0.0, 1.0 / (type + 1)); + else + p = 1 - std::pow(next() + 0.0, 1.0 / (-type + 1)); + + return __testlib_crop(n * p, 0.0, n); + } + } + + /* Returns value in [0, 1). See wnext(int, int). It uses the same algorithms. */ + double wnext(int type) { + return wnext(1.0, type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned int wnext(unsigned int n, int type) { + if (n >= INT_MAX) + __testlib_fail("random_t::wnext(unsigned int n, int type): n must be less INT_MAX"); + return (unsigned int) wnext(int(n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long long wnext(unsigned long long n, int type) { + if (n >= (unsigned long long) (__TESTLIB_LONGLONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long long n, int type): n must be less LONGLONG_MAX"); + + return (unsigned long long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + long wnext(long n, int type) { + return (long) wnext((long long) (n), type); + } + + /* See wnext(int, int). It uses the same algorithms. */ + unsigned long wnext(unsigned long n, int type) { + if (n >= (unsigned long) (LONG_MAX)) + __testlib_fail("random_t::wnext(unsigned long n, int type): n must be less LONG_MAX"); + + return (unsigned long) wnext((unsigned long long) (n), type); + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(int from, int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(int from, int to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + int wnext(unsigned int from, unsigned int to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned int from, unsigned int to, int type): from can't not exceed to"); + return int(wnext(to - from + 1, type) + from); + } + + /* Returns weighted random value in range [from, to]. */ + long long wnext(long long from, long long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long long from, long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long long wnext(unsigned long long from, unsigned long long to, int type) { + if (from > to) + __testlib_fail( + "random_t::wnext(unsigned long long from, unsigned long long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + long wnext(long from, long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(long from, long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random value in range [from, to]. */ + unsigned long wnext(unsigned long from, unsigned long to, int type) { + if (from > to) + __testlib_fail("random_t::wnext(unsigned long from, unsigned long to, int type): from can't not exceed to"); + return wnext(to - from + 1, type) + from; + } + + /* Returns weighted random double value in range [from, to). */ + double wnext(double from, double to, int type) { + if (from >= to) + __testlib_fail("random_t::wnext(double from, double to, int type): from should be strictly less than to"); + return wnext(to - from, type) + from; + } + + /* Returns weighted random element from container. */ + template + typename Container::value_type wany(const Container &c, int type) { + size_t size = c.size(); + if (size <= 0) + __testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive"); + return *(c.begin() + wnext(size, type)); + } + + /* Returns weighted random element from iterator range. */ + template + typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) { + int size = int(end - begin); + if (size <= 0) + __testlib_fail( + "random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length"); + return *(begin + wnext(size, type)); + } + + /* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/ + template + std::vector perm(T size, E first) { + if (size < 0) + __testlib_fail("random_t::perm(T size, E first = 0): size must non-negative"); + else if (size == 0) + return std::vector(); + std::vector p(size); + E current = first; + for (T i = 0; i < size; i++) + p[i] = current++; + if (size > 1) + for (T i = 1; i < size; i++) + std::swap(p[i], p[next(i + 1)]); + return p; + } + + /* Returns random permutation of the given size (values are between 0 and size-1)*/ + template + std::vector perm(T size) { + return perm(size, T(0)); + } + + /* Returns `size` unordered (unsorted) distinct numbers between `from` and `to`. */ + template + std::vector distinct(int size, T from, T to) { + std::vector result; + if (size == 0) + return result; + + if (from > to) + __testlib_fail("random_t::distinct expected from <= to"); + + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + + uint64_t n = to - from + 1; + if (uint64_t(size) > n) + __testlib_fail("random_t::distinct expected size <= to - from + 1"); + + double expected = 0.0; + for (int i = 1; i <= size; i++) + expected += double(n) / double(n - i + 1); + + if (expected < double(n)) { + std::set vals; + while (int(vals.size()) < size) { + T x = T(next(from, to)); + if (vals.insert(x).second) + result.push_back(x); + } + } else { + if (n > 1000000000) + __testlib_fail("random_t::distinct here expected to - from + 1 <= 1000000000"); + std::vector p(perm(int(n), from)); + result.insert(result.end(), p.begin(), p.begin() + size); + } + + return result; + } + + /* Returns `size` unordered (unsorted) distinct numbers between `0` and `upper`-1. */ + template + std::vector distinct(int size, T upper) { + if (size < 0) + __testlib_fail("random_t::distinct expected size >= 0"); + if (size == 0) + return std::vector(); + + if (upper <= 0) + __testlib_fail("random_t::distinct expected upper > 0"); + if (size > upper) + __testlib_fail("random_t::distinct expected size <= upper"); + + return distinct(size, T(0), upper - 1); + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of integers not less than min_part. */ + template + std::vector partition(int size, T sum, T min_part) { + if (size < 0) + __testlib_fail("random_t::partition: size < 0"); + if (size == 0 && sum != 0) + __testlib_fail("random_t::partition: size == 0 && sum != 0"); + if (min_part * size > sum) + __testlib_fail("random_t::partition: min_part * size > sum"); + if (size == 0 && sum == 0) + return std::vector(); + + T sum_ = sum; + sum -= min_part * size; + + std::vector septums(size); + std::vector d = distinct(size - 1, T(1), T(sum + size - 1)); + for (int i = 0; i + 1 < size; i++) + septums[i + 1] = d[i]; + sort(septums.begin(), septums.end()); + + std::vector result(size); + for (int i = 0; i + 1 < size; i++) + result[i] = septums[i + 1] - septums[i] - 1; + result[size - 1] = sum + size - 1 - septums.back(); + + for (std::size_t i = 0; i < result.size(); i++) + result[i] += min_part; + + T result_sum = 0; + for (std::size_t i = 0; i < result.size(); i++) + result_sum += result[i]; + if (result_sum != sum_) + __testlib_fail("random_t::partition: partition sum is expected to be the given sum"); + + if (*std::min_element(result.begin(), result.end()) < min_part) + __testlib_fail("random_t::partition: partition min is expected to be no less than the given min_part"); + + if (int(result.size()) != size || result.size() != (size_t) size) + __testlib_fail("random_t::partition: partition size is expected to be equal to the given size"); + + return result; + } + + /* Returns random (unsorted) partition which is a representation of sum as a sum of positive integers. */ + template + std::vector partition(int size, T sum) { + return partition(size, sum, T(1)); + } +}; + +const int random_t::lim = 25; +const unsigned long long random_t::multiplier = 0x5DEECE66DLL; +const unsigned long long random_t::addend = 0xBLL; +const unsigned long long random_t::mask = (1LL << 48) - 1; +int random_t::version = -1; + +/* Pattern implementation */ +bool pattern::matches(const std::string &s) const { + return matches(s, 0); +} + +static bool __pattern_isSlash(const std::string &s, size_t pos) { + return s[pos] == '\\'; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static bool __pattern_isCommandChar(const std::string &s, size_t pos, char value) { + if (pos >= s.length()) + return false; + + int slashes = 0; + + int before = int(pos) - 1; + while (before >= 0 && s[before] == '\\') + before--, slashes++; + + return slashes % 2 == 0 && s[pos] == value; +} + +static char __pattern_getChar(const std::string &s, size_t &pos) { + if (__pattern_isSlash(s, pos)) + pos += 2; + else + pos++; + + return s[pos - 1]; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static int __pattern_greedyMatch(const std::string &s, size_t pos, const std::vector chars) { + int result = 0; + + while (pos < s.length()) { + char c = s[pos++]; + if (!std::binary_search(chars.begin(), chars.end(), c)) + break; + else + result++; + } + + return result; +} + +std::string pattern::src() const { + return s; +} + +bool pattern::matches(const std::string &s, size_t pos) const { + std::string result; + + if (to > 0) { + int size = __pattern_greedyMatch(s, pos, chars); + if (size < from) + return false; + if (size > to) + size = to; + pos += size; + } + + if (children.size() > 0) { + for (size_t child = 0; child < children.size(); child++) + if (children[child].matches(s, pos)) + return true; + return false; + } else + return pos == s.length(); +} + +std::string pattern::next(random_t &rnd) const { + std::string result; + result.reserve(20); + + if (to == INT_MAX) + __testlib_fail("pattern::next(random_t& rnd): can't process character '*' for generation"); + + if (to > 0) { + int count = rnd.next(to - from + 1) + from; + for (int i = 0; i < count; i++) + result += chars[rnd.next(int(chars.size()))]; + } + + if (children.size() > 0) { + int child = rnd.next(int(children.size())); + result += children[child].next(rnd); + } + + return result; +} + +static void __pattern_scanCounts(const std::string &s, size_t &pos, int &from, int &to) { + if (pos >= s.length()) { + from = to = 1; + return; + } + + if (__pattern_isCommandChar(s, pos, '{')) { + std::vector parts; + std::string part; + + pos++; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, '}')) { + if (__pattern_isCommandChar(s, pos, ',')) + parts.push_back(part), part = "", pos++; + else + part += __pattern_getChar(s, pos); + } + + if (part != "") + parts.push_back(part); + + if (!__pattern_isCommandChar(s, pos, '}')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (parts.size() < 1 || parts.size() > 2) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector numbers; + + for (size_t i = 0; i < parts.size(); i++) { + if (parts[i].length() == 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + int number; + if (std::sscanf(parts[i].c_str(), "%d", &number) != 1) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + numbers.push_back(number); + } + + if (numbers.size() == 1) + from = to = numbers[0]; + else + from = numbers[0], to = numbers[1]; + + if (from > to) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + } else { + if (__pattern_isCommandChar(s, pos, '?')) { + from = 0, to = 1, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '*')) { + from = 0, to = INT_MAX, pos++; + return; + } + + if (__pattern_isCommandChar(s, pos, '+')) { + from = 1, to = INT_MAX, pos++; + return; + } + + from = to = 1; + } +} + +static std::vector __pattern_scanCharSet(const std::string &s, size_t &pos) { + if (pos >= s.length()) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + std::vector result; + + if (__pattern_isCommandChar(s, pos, '[')) { + pos++; + bool negative = __pattern_isCommandChar(s, pos, '^'); + if (negative) + pos++; + + char prev = 0; + + while (pos < s.length() && !__pattern_isCommandChar(s, pos, ']')) { + if (__pattern_isCommandChar(s, pos, '-') && prev != 0) { + pos++; + + if (pos + 1 == s.length() || __pattern_isCommandChar(s, pos, ']')) { + result.push_back(prev); + prev = '-'; + continue; + } + + char next = __pattern_getChar(s, pos); + if (prev > next) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + for (char c = prev; c != next; c++) + result.push_back(c); + result.push_back(next); + + prev = 0; + } else { + if (prev != 0) + result.push_back(prev); + prev = __pattern_getChar(s, pos); + } + } + + if (prev != 0) + result.push_back(prev); + + if (!__pattern_isCommandChar(s, pos, ']')) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + pos++; + + if (negative) { + std::sort(result.begin(), result.end()); + std::vector actuals; + for (int code = 0; code < 255; code++) { + char c = char(code); + if (!std::binary_search(result.begin(), result.end(), c)) + actuals.push_back(c); + } + result = actuals; + } + + std::sort(result.begin(), result.end()); + } else + result.push_back(__pattern_getChar(s, pos)); + + return result; +} + +pattern::pattern(std::string s) : s(s), from(0), to(0) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (!__pattern_isCommandChar(s, i, ' ')) + t += s[i]; + s = t; + + int opened = 0; + int firstClose = -1; + std::vector seps; + + for (size_t i = 0; i < s.length(); i++) { + if (__pattern_isCommandChar(s, i, '(')) { + opened++; + continue; + } + + if (__pattern_isCommandChar(s, i, ')')) { + opened--; + if (opened == 0 && firstClose == -1) + firstClose = int(i); + continue; + } + + if (opened < 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (__pattern_isCommandChar(s, i, '|') && opened == 0) + seps.push_back(int(i)); + } + + if (opened != 0) + __testlib_fail("pattern: Illegal pattern (or part) \"" + s + "\""); + + if (seps.size() == 0 && firstClose + 1 == (int) s.length() + && __pattern_isCommandChar(s, 0, '(') && __pattern_isCommandChar(s, s.length() - 1, ')')) { + children.push_back(pattern(s.substr(1, s.length() - 2))); + } else { + if (seps.size() > 0) { + seps.push_back(int(s.length())); + int last = 0; + + for (size_t i = 0; i < seps.size(); i++) { + children.push_back(pattern(s.substr(last, seps[i] - last))); + last = seps[i] + 1; + } + } else { + size_t pos = 0; + chars = __pattern_scanCharSet(s, pos); + __pattern_scanCounts(s, pos, from, to); + if (pos < s.length()) + children.push_back(pattern(s.substr(pos))); + } + } +} + +/* End of pattern implementation */ + +template +inline bool isEof(C c) { + return c == EOFC; +} + +template +inline bool isEoln(C c) { + return (c == LF || c == CR); +} + +template +inline bool isBlanks(C c) { + return (c == LF || c == CR || c == SPACE || c == TAB); +} + +inline std::string trim(const std::string &s) { + if (s.empty()) + return s; + + int left = 0; + while (left < int(s.length()) && isBlanks(s[left])) + left++; + if (left >= int(s.length())) + return ""; + + int right = int(s.length()) - 1; + while (right >= 0 && isBlanks(s[right])) + right--; + if (right < 0) + return ""; + + return s.substr(left, right - left + 1); +} + +enum TMode { + _input, _output, _answer +}; + +/* Outcomes 6-15 are reserved for future use. */ +enum TResult { + _ok = 0, + _wa = 1, + _pe = 2, + _fail = 3, + _dirt = 4, + _points = 5, + _unexpected_eof = 8, + _partially = 16 +}; + +enum TTestlibMode { + _unknown, _checker, _validator, _generator, _interactor, _scorer +}; + +#define _pc(exitCode) (TResult(_partially + (exitCode))) + +/* Outcomes 6-15 are reserved for future use. */ +const std::string outcomes[] = { + "accepted", + "wrong-answer", + "presentation-error", + "fail", + "fail", +#ifndef PCMS2 + "points", +#else + "relative-scoring", +#endif + "reserved", + "reserved", + "unexpected-eof", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "partially-correct" +}; + +class InputStreamReader { +public: + virtual void setTestCase(int testCase) = 0; + + virtual std::vector getReadChars() = 0; + + virtual int curChar() = 0; + + virtual int nextChar() = 0; + + virtual void skipChar() = 0; + + virtual void unreadChar(int c) = 0; + + virtual std::string getName() = 0; + + virtual bool eof() = 0; + + virtual void close() = 0; + + virtual int getLine() = 0; + + virtual ~InputStreamReader() = 0; +}; + +InputStreamReader::~InputStreamReader() { + // No operations. +} + +class StringInputStreamReader : public InputStreamReader { +private: + std::string s; + size_t pos; + +public: + StringInputStreamReader(const std::string &content) : s(content), pos(0) { + // No operations. + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in StringInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in StringInputStreamReader"); + } + + int curChar() { + if (pos >= s.length()) + return EOFC; + else + return s[pos]; + } + + int nextChar() { + if (pos >= s.length()) { + pos++; + return EOFC; + } else + return s[pos++]; + } + + void skipChar() { + pos++; + } + + void unreadChar(int c) { + if (pos == 0) + __testlib_fail("StringInputStreamReader::unreadChar(int): pos == 0."); + pos--; + if (pos < s.length()) + s[pos] = char(c); + } + + std::string getName() { + return __testlib_part(s); + } + + int getLine() { + return -1; + } + + bool eof() { + return pos >= s.length(); + } + + void close() { + // No operations. + } +}; + +class FileInputStreamReader : public InputStreamReader { +private: + std::FILE *file; + std::string name; + int line; + std::vector undoChars; + std::vector readChars; + std::vector undoReadChars; + + inline int postprocessGetc(int getcResult) { + if (getcResult != EOF) + return getcResult; + else + return EOFC; + } + + int getc(FILE *file) { + int c; + int rc; + + if (undoChars.empty()) { + c = rc = ::getc(file); + } else { + c = undoChars.back(); + undoChars.pop_back(); + rc = undoReadChars.back(); + undoReadChars.pop_back(); + } + + if (c == LF) + line++; + + readChars.push_back(rc); + return c; + } + + int ungetc(int c/*, FILE* file*/) { + if (!readChars.empty()) { + undoReadChars.push_back(readChars.back()); + readChars.pop_back(); + } + if (c == LF) + line--; + undoChars.push_back(c); + return c; + } + +public: + FileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + // No operations. + } + + void setTestCase(int testCase) { + if (testCase < 0 || testCase > __TESTLIB_MAX_TEST_CASE) + __testlib_fail(format("testCase expected fit in [1,%d], but %d doesn't", __TESTLIB_MAX_TEST_CASE, testCase)); + readChars.push_back(testCase + 256); + } + + std::vector getReadChars() { + return readChars; + } + + int curChar() { + if (feof(file)) + return EOFC; + else { + int c = getc(file); + ungetc(c/*, file*/); + return postprocessGetc(c); + } + } + + int nextChar() { + if (feof(file)) + return EOFC; + else + return postprocessGetc(getc(file)); + } + + void skipChar() { + getc(file); + } + + void unreadChar(int c) { + ungetc(c/*, file*/); + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + if (NULL == file || feof(file)) + return true; + else { + int c = nextChar(); + if (c == EOFC || (c == EOF && feof(file))) + return true; + unreadChar(c); + return false; + } + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +class BufferedFileInputStreamReader : public InputStreamReader { +private: + static const size_t BUFFER_SIZE; + static const size_t MAX_UNREAD_COUNT; + + std::FILE *file; + std::string name; + int line; + + char *buffer; + bool *isEof; + int bufferPos; + size_t bufferSize; + + bool refill() { + if (NULL == file) + __testlib_fail("BufferedFileInputStreamReader: file == NULL (" + getName() + ")"); + + if (bufferPos >= int(bufferSize)) { + size_t readSize = fread( + buffer + MAX_UNREAD_COUNT, + 1, + BUFFER_SIZE - MAX_UNREAD_COUNT, + file + ); + + if (readSize < BUFFER_SIZE - MAX_UNREAD_COUNT + && ferror(file)) + __testlib_fail("BufferedFileInputStreamReader: unable to read (" + getName() + ")"); + + bufferSize = MAX_UNREAD_COUNT + readSize; + bufferPos = int(MAX_UNREAD_COUNT); + std::memset(isEof + MAX_UNREAD_COUNT, 0, sizeof(isEof[0]) * readSize); + + return readSize > 0; + } else + return true; + } + + char increment() { + char c; + if ((c = buffer[bufferPos++]) == LF) + line++; + return c; + } + +public: + BufferedFileInputStreamReader(std::FILE *file, const std::string &name) : file(file), name(name), line(1) { + buffer = new char[BUFFER_SIZE]; + isEof = new bool[BUFFER_SIZE]; + bufferSize = MAX_UNREAD_COUNT; + bufferPos = int(MAX_UNREAD_COUNT); + } + + ~BufferedFileInputStreamReader() { + if (NULL != buffer) { + delete[] buffer; + buffer = NULL; + } + if (NULL != isEof) { + delete[] isEof; + isEof = NULL; + } + } + + void setTestCase(int) { + __testlib_fail("setTestCase not implemented in BufferedFileInputStreamReader"); + } + + std::vector getReadChars() { + __testlib_fail("getReadChars not implemented in BufferedFileInputStreamReader"); + } + + int curChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : buffer[bufferPos]; + } + + int nextChar() { + if (!refill()) + return EOFC; + + return isEof[bufferPos] ? EOFC : increment(); + } + + void skipChar() { + increment(); + } + + void unreadChar(int c) { + bufferPos--; + if (bufferPos < 0) + __testlib_fail("BufferedFileInputStreamReader::unreadChar(int): bufferPos < 0"); + isEof[bufferPos] = (c == EOFC); + buffer[bufferPos] = char(c); + if (c == LF) + line--; + } + + std::string getName() { + return name; + } + + int getLine() { + return line; + } + + bool eof() { + return !refill() || EOFC == curChar(); + } + + void close() { + if (NULL != file) { + fclose(file); + file = NULL; + } + } +}; + +const size_t BufferedFileInputStreamReader::BUFFER_SIZE = 2000000; +const size_t BufferedFileInputStreamReader::MAX_UNREAD_COUNT = BufferedFileInputStreamReader::BUFFER_SIZE / 2; + +/* + * Streams to be used for reading data in checkers or validators. + * Each read*() method moves pointer to the next character after the + * read value. + */ +struct InStream { + /* Do not use them. */ + InStream(); + + ~InStream(); + + /* Wrap std::string with InStream. */ + InStream(const InStream &baseStream, std::string content); + + InputStreamReader *reader; + int lastLine; + + std::string name; + TMode mode; + bool opened; + bool stdfile; + bool strict; + + int wordReserveSize; + std::string _tmpReadToken; + + int readManyIteration; + size_t maxFileSize; + size_t maxTokenLength; + size_t maxMessageLength; + + void init(std::string fileName, TMode mode); + + void init(std::FILE *f, TMode mode); + + void setTestCase(int testCase); + std::vector getReadChars(); + + /* Moves stream pointer to the first non-white-space character or EOF. */ + void skipBlanks(); + + /* Returns current character in the stream. Doesn't remove it from stream. */ + char curChar(); + + /* Moves stream pointer one character forward. */ + void skipChar(); + + /* Returns current character and moves pointer one character forward. */ + char nextChar(); + + /* Returns current character and moves pointer one character forward. */ + char readChar(); + + /* As "readChar()" but ensures that the result is equal to given parameter. */ + char readChar(char c); + + /* As "readChar()" but ensures that the result is equal to the space (code=32). */ + char readSpace(); + + /* Puts back the character into the stream. */ + void unreadChar(char c); + + /* Reopens stream, you should not use it. */ + void reset(std::FILE *file = NULL); + + /* Checks that current position is EOF. If not it doesn't move stream pointer. */ + bool eof(); + + /* Moves pointer to the first non-white-space character and calls "eof()". */ + bool seekEof(); + + /* + * Checks that current position contains EOLN. + * If not it doesn't move stream pointer. + * In strict mode expects "#13#10" for windows or "#10" for other platforms. + */ + bool eoln(); + + /* Moves pointer to the first non-space and non-tab character and calls "eoln()". */ + bool seekEoln(); + + /* Moves stream pointer to the first character of the next line (if exists). */ + void nextLine(); + + /* + * Reads new token. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + std::string readWord(); + + /* The same as "readWord()", it is preffered to use "readToken()". */ + std::string readToken(); + + /* The same as "readWord()", but ensures that token matches to given pattern. */ + std::string readWord(const std::string &ptrn, const std::string &variableName = ""); + + std::string readWord(const pattern &p, const std::string &variableName = ""); + + std::vector + readWords(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readWords(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readWords(int size, int indexBase = 1); + + /* The same as "readToken()", but ensures that token matches to given pattern. */ + std::string readToken(const std::string &ptrn, const std::string &variableName = ""); + + std::string readToken(const pattern &p, const std::string &variableName = ""); + + std::vector + readTokens(int size, const std::string &ptrn, const std::string &variablesName = "", int indexBase = 1); + + std::vector + readTokens(int size, const pattern &p, const std::string &variablesName = "", int indexBase = 1); + + std::vector readTokens(int size, int indexBase = 1); + + void readWordTo(std::string &result); + + void readWordTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + void readTokenTo(std::string &result); + + void readTokenTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + void readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads new long long value. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + long long readLong(); + + unsigned long long readUnsignedLong(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInteger(); + + /* + * Reads new int. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + int readInt(); + + /* As "readLong()" but ensures that value in the range [minv,maxv]. */ + long long readLong(long long minv, long long maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of long longs. */ + std::vector + readLongs(int size, long long minv, long long maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of long longs. */ + std::vector readLongs(int size, int indexBase = 1); + + unsigned long long + readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + std::vector readUnsignedLongs(int size, int indexBase = 1); + + unsigned long long readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName = ""); + + std::vector + readLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string &variablesName = "", + int indexBase = 1); + + /* As "readInteger()" but ensures that value in the range [minv,maxv]. */ + int readInteger(int minv, int maxv, const std::string &variableName = ""); + + /* As "readInt()" but ensures that value in the range [minv,maxv]. */ + int readInt(int minv, int maxv, const std::string &variableName = ""); + + /* Reads space-separated sequence of integers. */ + std::vector + readIntegers(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readIntegers(int size, int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int minv, int maxv, const std::string &variablesName = "", int indexBase = 1); + + /* Reads space-separated sequence of integers. */ + std::vector readInts(int size, int indexBase = 1); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readReal(); + + /* + * Reads new double. Ignores white-spaces into the non-strict mode + * (strict mode is used in validators usually). + */ + double readDouble(); + + /* As "readReal()" but ensures that value in the range [minv,maxv]. */ + double readReal(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readReals(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readReals(int size, int indexBase = 1); + + /* As "readDouble()" but ensures that value in the range [minv,maxv]. */ + double readDouble(double minv, double maxv, const std::string &variableName = ""); + + std::vector + readDoubles(int size, double minv, double maxv, const std::string &variablesName = "", int indexBase = 1); + + std::vector readDoubles(int size, int indexBase = 1); + + /* + * As "readReal()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* + * As "readDouble()" but ensures that value in the range [minv,maxv] and + * number of digit after the decimal point is in range [minAfterPointDigitCount,maxAfterPointDigitCount] + * and number is in the form "[-]digit(s)[.digit(s)]". + */ + double readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName = ""); + + std::vector readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName = "", int indexBase = 1); + + /* As readLine(). */ + std::string readString(); + + /* Read many lines. */ + std::vector readStrings(int size, int indexBase = 1); + + /* See readLine(). */ + void readStringTo(std::string &result); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + std::string readString(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readStrings(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readStrings(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()/readString()", but ensures that line matches to the given pattern. */ + void readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* + * Reads line from the current position to EOLN or EOF. Moves stream pointer to + * the first character of the new line (if possible). + */ + std::string readLine(); + + /* Read many lines. */ + std::vector readLines(int size, int indexBase = 1); + + /* See readLine(). */ + void readLineTo(std::string &result); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + std::string readLine(const std::string &ptrn, const std::string &variableName = ""); + + /* Read many lines. */ + std::vector + readLines(int size, const pattern &p, const std::string &variableName = "", int indexBase = 1); + + /* Read many lines. */ + std::vector + readLines(int size, const std::string &ptrn, const std::string &variableName = "", int indexBase = 1); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const pattern &p, const std::string &variableName = ""); + + /* The same as "readLine()", but ensures that line matches to the given pattern. */ + void readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName = ""); + + /* Reads EOLN or fails. Use it in validators. Calls "eoln()" method internally. */ + void readEoln(); + + /* Reads EOF or fails. Use it in validators. Calls "eof()" method internally. */ + void readEof(); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quit(TResult result, const char *msg); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quitf(TResult result, const char *msg, ...); + + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + void quitif(bool condition, TResult result, const char *msg, ...); + /* + * Quit-functions aborts program with and : + * input/answer streams replace any result to FAIL. + */ + NORETURN void quits(TResult result, std::string msg); + + /* + * Checks condition and aborts a program if codition is false. + * Returns _wa for ouf and _fail on any other streams. + */ +#ifdef __GNUC__ + __attribute__ ((format (printf, 3, 4))) +#endif + void ensuref(bool cond, const char *format, ...); + + void __testlib_ensure(bool cond, std::string message); + + void close(); + + const static int NO_INDEX = INT_MAX; + const static char OPEN_BRACKET = char(11); + const static char CLOSE_BRACKET = char(17); + + const static WORD LightGray = 0x07; + const static WORD LightRed = 0x0c; + const static WORD LightCyan = 0x0b; + const static WORD LightGreen = 0x0a; + const static WORD LightYellow = 0x0e; + + static void textColor(WORD color); + + static void quitscr(WORD color, const char *msg); + + static void quitscrS(WORD color, std::string msg); + + void xmlSafeWrite(std::FILE *file, const char *msg); + + /* Skips UTF-8 Byte Order Mark. */ + void skipBom(); + +private: + InStream(const InStream &); + + InStream &operator=(const InStream &); +}; + +InStream inf; +InStream ouf; +InStream ans; +bool appesMode; +std::string resultName; +std::string checkerName = "untitled checker"; +random_t rnd; +TTestlibMode testlibMode = _unknown; +double __testlib_points = std::numeric_limits::infinity(); + +struct ValidatorBoundsHit { + static const double EPS; + bool minHit; + bool maxHit; + + ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) { + }; + + ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) { + return ValidatorBoundsHit( + __testlib_max(minHit, validatorBoundsHit.minHit), + __testlib_max(maxHit, validatorBoundsHit.maxHit) + ); + } +}; + +const double ValidatorBoundsHit::EPS = 1E-12; + +class Validator { +private: + const static std::string TEST_MARKUP_HEADER; + const static std::string TEST_CASE_OPEN_TAG; + const static std::string TEST_CASE_CLOSE_TAG; + + bool _initialized; + std::string _testset; + std::string _group; + + std::string _testOverviewLogFileName; + std::string _testMarkupFileName; + int _testCase = -1; + std::string _testCaseFileName; + + std::map _boundsHitByVariableName; + std::set _features; + std::set _hitFeatures; + + bool isVariableNameBoundsAnalyzable(const std::string &variableName) { + for (size_t i = 0; i < variableName.length(); i++) + if ((variableName[i] >= '0' && variableName[i] <= '9') || variableName[i] < ' ') + return false; + return true; + } + + bool isFeatureNameAnalyzable(const std::string &featureName) { + for (size_t i = 0; i < featureName.length(); i++) + if (featureName[i] < ' ') + return false; + return true; + } + +public: + Validator() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Validator should be initialized with registerValidation(argc, argv) instead of registerValidation() to support validator.group()"); + return _group; + } + + std::string testOverviewLogFileName() const { + return _testOverviewLogFileName; + } + + std::string testMarkupFileName() const { + return _testMarkupFileName; + } + + int testCase() const { + return _testCase; + } + + std::string testCaseFileName() const { + return _testCaseFileName; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } + + void setTestOverviewLogFileName(const char *const testOverviewLogFileName) { + _testOverviewLogFileName = testOverviewLogFileName; + } + + void setTestMarkupFileName(const char *const testMarkupFileName) { + _testMarkupFileName = testMarkupFileName; + } + + void setTestCase(int testCase) { + _testCase = testCase; + } + + void setTestCaseFileName(const char *const testCaseFileName) { + _testCaseFileName = testCaseFileName; + } + + void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) { + if (isVariableNameBoundsAnalyzable(variableName)) { + _boundsHitByVariableName[variableName] + = boundsHit.merge(_boundsHitByVariableName[variableName]); + } + } + + std::string getBoundsHitLog() { + std::string result; + for (std::map::iterator i = _boundsHitByVariableName.begin(); + i != _boundsHitByVariableName.end(); + i++) { + result += "\"" + i->first + "\":"; + if (i->second.minHit) + result += " min-value-hit"; + if (i->second.maxHit) + result += " max-value-hit"; + result += "\n"; + } + return result; + } + + std::string getFeaturesLog() { + std::string result; + for (std::set::iterator i = _features.begin(); + i != _features.end(); + i++) { + result += "feature \"" + *i + "\":"; + if (_hitFeatures.count(*i)) + result += " hit"; + result += "\n"; + } + return result; + } + + void writeTestOverviewLog() { + if (!_testOverviewLogFileName.empty()) { + std::string fileName(_testOverviewLogFileName); + _testOverviewLogFileName = ""; + FILE *testOverviewLogFile = fopen(fileName.c_str(), "w"); + if (NULL == testOverviewLogFile) + __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")"); + fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str()); + if (fclose(testOverviewLogFile)) + __testlib_fail( + "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")"); + } + } + + void writeTestMarkup() { + if (!_testMarkupFileName.empty()) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string markup(TEST_MARKUP_HEADER); + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) { + char cc = char(c); + if (cc == '\\' || cc == '!') + markup += '\\'; + markup += cc; + } else { + markup += TEST_CASE_OPEN_TAG; + markup += toString(c - 256); + markup += TEST_CASE_CLOSE_TAG; + } + } + FILE* f; + bool standard_file = false; + if (_testMarkupFileName == "stdout") + f = stdout, standard_file = true; + else if (_testMarkupFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testMarkupFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestMarkup: can't write test markup to (" + _testMarkupFileName + ")"); + } + std::fprintf(f, "%s", markup.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestMarkup: can't close test markup file (" + _testCaseFileName + ")"); + } + } + } + + void writeTestCase() { + if (_testCase > 0) { + std::vector readChars = inf.getReadChars(); + if (!readChars.empty()) { + std::string content, testCaseContent; + bool matchedTestCase = false; + for (size_t i = 0; i < readChars.size(); i++) { + int c = readChars[i]; + if (i + 1 == readChars.size() && c == -1) + continue; + if (c <= 256) + content += char(c); + else { + if (matchedTestCase) { + testCaseContent = content; + matchedTestCase = false; + } + content = ""; + int testCase = c - 256; + if (testCase == _testCase) + matchedTestCase = true; + } + } + if (matchedTestCase) + testCaseContent = content; + + if (!testCaseContent.empty()) { + FILE* f; + bool standard_file = false; + if (_testCaseFileName.empty() || _testCaseFileName == "stdout") + f = stdout, standard_file = true; + else if (_testCaseFileName == "stderr") + f = stderr, standard_file = true; + else { + f = fopen(_testCaseFileName.c_str(), "wb"); + if (NULL == f) + __testlib_fail("Validator::writeTestCase: can't write test case to (" + _testCaseFileName + ")"); + } + std::fprintf(f, "%s", testCaseContent.c_str()); + std::fflush(f); + if (!standard_file) + if (std::fclose(f)) + __testlib_fail("Validator::writeTestCase: can't close test case file (" + _testCaseFileName + ")"); + } + } + } + } + + void addFeature(const std::string &feature) { + if (_features.count(feature)) + __testlib_fail("Feature " + feature + " registered twice."); + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + _features.insert(feature); + } + + void feature(const std::string &feature) { + if (!isFeatureNameAnalyzable(feature)) + __testlib_fail("Feature name '" + feature + "' contains restricted characters."); + + if (!_features.count(feature)) + __testlib_fail("Feature " + feature + " didn't registered via addFeature(feature)."); + + _hitFeatures.insert(feature); + } +} validator; + +const std::string Validator::TEST_MARKUP_HEADER = "MU\xF3\x01"; +const std::string Validator::TEST_CASE_OPEN_TAG = "!c"; +const std::string Validator::TEST_CASE_CLOSE_TAG = ";"; + +struct TestlibFinalizeGuard { + static bool alive; + static bool registered; + + int quitCount, readEofCount; + + TestlibFinalizeGuard() : quitCount(0), readEofCount(0) { + // No operations. + } + + ~TestlibFinalizeGuard() { + bool _alive = alive; + alive = false; + + if (_alive) { + if (testlibMode == _checker && quitCount == 0) + __testlib_fail("Checker must end with quit or quitf call."); + + if (testlibMode == _validator && readEofCount == 0 && quitCount == 0) + __testlib_fail("Validator must end with readEof call."); + + /* opts */ + autoEnsureNoUnusedOpts(); + + if (!registered) + __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)"); + } + + if (__testlib_exitCode == 0) { + validator.writeTestOverviewLog(); + validator.writeTestMarkup(); + validator.writeTestCase(); + } + } + +private: + /* opts */ + void autoEnsureNoUnusedOpts(); +}; + +bool TestlibFinalizeGuard::alive = true; +bool TestlibFinalizeGuard::registered = false; +extern TestlibFinalizeGuard testlibFinalizeGuard; + +/* + * Call it to disable checks on finalization. + */ +void disableFinalizeGuard() { + TestlibFinalizeGuard::alive = false; +} + +/* Interactor streams. + */ +std::fstream tout; + +/* implementation + */ + +InStream::InStream() { + reader = NULL; + lastLine = -1; + opened = false; + name = ""; + mode = _input; + strict = false; + stdfile = false; + wordReserveSize = 4; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::InStream(const InStream &baseStream, std::string content) { + reader = new StringInputStreamReader(content); + lastLine = -1; + opened = true; + strict = baseStream.strict; + stdfile = false; + mode = baseStream.mode; + name = "based on " + baseStream.name; + readManyIteration = NO_INDEX; + maxFileSize = 128 * 1024 * 1024; // 128MB. + maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxMessageLength = 32000; +} + +InStream::~InStream() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } +} + +void InStream::setTestCase(int testCase) { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::setTestCase can be used only for inf in validator-mode." + " Actually, prefer setTestCase function instead of InStream member"); + reader->setTestCase(testCase); +} + +std::vector InStream::getReadChars() { + if (testlibMode != _validator || mode != _input || !stdfile || this != &inf) + __testlib_fail("InStream::getReadChars can be used only for inf in validator-mode."); + return reader == NULL ? std::vector() : reader->getReadChars(); +} + +void setTestCase(int testCase) { + static bool first_run = true; + static bool zero_based = false; + + if (first_run && testCase == 0) + zero_based = true; + + if (zero_based) + testCase++; + + __testlib_hasTestCase = true; + __testlib_testCase = testCase; + + if (testlibMode == _validator) + inf.setTestCase(testCase); + + first_run = false; +} + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int resultExitCode(TResult r) { + if (r == _ok) + return OK_EXIT_CODE; + if (r == _wa) + return WA_EXIT_CODE; + if (r == _pe) + return PE_EXIT_CODE; + if (r == _fail) + return FAIL_EXIT_CODE; + if (r == _dirt) + return DIRT_EXIT_CODE; + if (r == _points) + return POINTS_EXIT_CODE; + if (r == _unexpected_eof) +#ifdef ENABLE_UNEXPECTED_EOF + return UNEXPECTED_EOF_EXIT_CODE; +#else + return PE_EXIT_CODE; +#endif + if (r >= _partially) + return PC_BASE_EXIT_CODE + (r - _partially); + return FAIL_EXIT_CODE; +} + +void InStream::textColor( +#if !(defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)) && defined(__GNUC__) + __attribute__((unused)) +#endif + WORD color +) { +#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400) + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, color); +#endif +#if !defined(ON_WINDOWS) && defined(__GNUC__) + if (isatty(2)) + { + switch (color) + { + case LightRed: + fprintf(stderr, "\033[1;31m"); + break; + case LightCyan: + fprintf(stderr, "\033[1;36m"); + break; + case LightGreen: + fprintf(stderr, "\033[1;32m"); + break; + case LightYellow: + fprintf(stderr, "\033[1;33m"); + break; + case LightGray: + default: + fprintf(stderr, "\033[0m"); + } + } +#endif +} + +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT +class exit_exception: public std::exception { +private: + int exitCode; +public: + exit_exception(int exitCode): exitCode(exitCode) {} + int getExitCode() { return exitCode; } +}; +#endif + +NORETURN void halt(int exitCode) { +#ifdef FOOTER + InStream::textColor(InStream::LightGray); + std::fprintf(stderr, "Checker: \"%s\"\n", checkerName.c_str()); + std::fprintf(stderr, "Exit code: %d\n", exitCode); + InStream::textColor(InStream::LightGray); +#endif + __testlib_exitCode = exitCode; +#ifdef TESTLIB_THROW_EXIT_EXCEPTION_INSTEAD_OF_EXIT + throw exit_exception(exitCode); +#endif + std::exit(exitCode); +} + +static bool __testlib_shouldCheckDirt(TResult result) { + return result == _ok || result == _points || result >= _partially; +} + +static std::string __testlib_appendMessage(const std::string &message, const std::string &extra) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + size_t index = message.find(extra, openPos); + if (index == std::string::npos || int(index) >= closePos) { + std::string result(message); + result.insert(closePos, ", " + extra); + return result; + } + return message; + } + + return message + " " + InStream::OPEN_BRACKET + extra + InStream::CLOSE_BRACKET; +} + +static std::string __testlib_toPrintableMessage(const std::string &message) { + int openPos = -1, closePos = -1; + for (size_t i = 0; i < message.length(); i++) { + if (message[i] == InStream::OPEN_BRACKET) { + if (openPos == -1) + openPos = int(i); + else + openPos = INT_MAX; + } + if (message[i] == InStream::CLOSE_BRACKET) { + if (closePos == -1) + closePos = int(i); + else + closePos = INT_MAX; + } + } + if (openPos != -1 && openPos != INT_MAX + && closePos != -1 && closePos != INT_MAX + && openPos < closePos) { + std::string result(message); + result[openPos] = '('; + result[closePos] = ')'; + return result; + } + + return message; +} + +NORETURN void InStream::quit(TResult result, const char *msg) { + if (TestlibFinalizeGuard::alive) + testlibFinalizeGuard.quitCount++; + + std::string message(msg); + message = trim(message); + + if (__testlib_hasTestCase) { + if (result != _ok) + message = __testlib_appendMessage(message, "test case " + vtos(__testlib_testCase)); + else { + if (__testlib_testCase == 1) + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test case"); + else + message = __testlib_appendMessage(message, vtos(__testlib_testCase) + " test cases"); + } + } + + // You can change maxMessageLength. + // Example: 'inf.maxMessageLength = 1024 * 1024;'. + if (message.length() > maxMessageLength) { + std::string warn = "message length exceeds " + vtos(maxMessageLength) + + ", the message is truncated: "; + message = warn + message.substr(0, maxMessageLength - warn.length()); + } + +#ifndef ENABLE_UNEXPECTED_EOF + if (result == _unexpected_eof) + result = _pe; +#endif + + if (testlibMode == _scorer && result != _fail) + quits(_fail, "Scorer should return points only. Don't use a quit function."); + + if (mode != _output && result != _fail) { + if (mode == _input && testlibMode == _validator && lastLine != -1) + quits(_fail, __testlib_appendMessage(__testlib_appendMessage(message, name), "line " + vtos(lastLine))); + else + quits(_fail, __testlib_appendMessage(message, name)); + } + + std::FILE *resultFile; + std::string errorName; + + if (__testlib_shouldCheckDirt(result)) { + if (testlibMode != _interactor && !ouf.seekEof()) + quit(_dirt, "Extra information in the output file"); + } + + int pctype = result - _partially; + bool isPartial = false; + + switch (result) { + case _ok: + errorName = "ok "; + quitscrS(LightGreen, errorName); + break; + case _wa: + errorName = "wrong answer "; + quitscrS(LightRed, errorName); + break; + case _pe: + errorName = "wrong output format "; + quitscrS(LightRed, errorName); + break; + case _fail: + errorName = "FAIL "; + quitscrS(LightRed, errorName); + break; + case _dirt: + errorName = "wrong output format "; + quitscrS(LightCyan, errorName); + result = _pe; + break; + case _points: + errorName = "points "; + quitscrS(LightYellow, errorName); + break; + case _unexpected_eof: + errorName = "unexpected eof "; + quitscrS(LightCyan, errorName); + break; + default: + if (result >= _partially) { + errorName = format("partially correct (%d) ", pctype); + isPartial = true; + quitscrS(LightYellow, errorName); + } else + quit(_fail, "What is the code ??? "); + } + + if (resultName != "") { + resultFile = std::fopen(resultName.c_str(), "w"); + if (resultFile == NULL) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + if (appesMode) { + std::fprintf(resultFile, ""); + if (isPartial) + std::fprintf(resultFile, "", + outcomes[(int) _partially].c_str(), pctype); + else { + if (result != _points) + std::fprintf(resultFile, "", outcomes[(int) result].c_str()); + else { + if (__testlib_points == std::numeric_limits::infinity()) + quit(_fail, "Expected points, but infinity found"); + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", __testlib_points)); + std::fprintf(resultFile, "", + outcomes[(int) result].c_str(), stringPoints.c_str()); + } + } + xmlSafeWrite(resultFile, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(resultFile, "\n"); + } else + std::fprintf(resultFile, "%s", __testlib_toPrintableMessage(message).c_str()); + if (NULL == resultFile || fclose(resultFile) != 0) { + resultName = ""; + quit(_fail, "Can not write to the result file"); + } + } + + quitscr(LightGray, __testlib_toPrintableMessage(message).c_str()); + std::fprintf(stderr, "\n"); + + inf.close(); + ouf.close(); + ans.close(); + if (tout.is_open()) + tout.close(); + + textColor(LightGray); + + if (resultName != "") + std::fprintf(stderr, "See file to check exit message\n"); + + halt(resultExitCode(result)); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +NORETURN void InStream::quitf(TResult result, const char *msg, ...) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +void InStream::quitif(bool condition, TResult result, const char *msg, ...) { + if (condition) { + FMT_TO_RESULT(msg, msg, message); + InStream::quit(result, message.c_str()); + } +} + +NORETURN void InStream::quits(TResult result, std::string msg) { + InStream::quit(result, msg.c_str()); +} + +void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { + size_t lmsg = strlen(msg); + for (size_t i = 0; i < lmsg; i++) { + if (msg[i] == '&') { + std::fprintf(file, "%s", "&"); + continue; + } + if (msg[i] == '<') { + std::fprintf(file, "%s", "<"); + continue; + } + if (msg[i] == '>') { + std::fprintf(file, "%s", ">"); + continue; + } + if (msg[i] == '"') { + std::fprintf(file, "%s", """); + continue; + } + if (0 <= msg[i] && msg[i] <= 31) { + std::fprintf(file, "%c", '.'); + continue; + } + std::fprintf(file, "%c", msg[i]); + } +} + +void InStream::quitscrS(WORD color, std::string msg) { + quitscr(color, msg.c_str()); +} + +void InStream::quitscr(WORD color, const char *msg) { + if (resultName == "") { + textColor(color); + std::fprintf(stderr, "%s", msg); + textColor(LightGray); + } +} + +void InStream::reset(std::FILE *file) { + if (opened && stdfile) + quit(_fail, "Can't reset standard handle"); + + if (opened) + close(); + + if (!stdfile && NULL == file) + if (NULL == (file = std::fopen(name.c_str(), "rb"))) { + if (mode == _output) + quits(_pe, std::string("Output file not found: \"") + name + "\""); + + if (mode == _answer) + quits(_fail, std::string("Answer file not found: \"") + name + "\""); + } + + if (NULL != file) { + opened = true; + __testlib_set_binary(file); + + if (stdfile) + reader = new FileInputStreamReader(file, name); + else + reader = new BufferedFileInputStreamReader(file, name); + } else { + opened = false; + reader = NULL; + } +} + +void InStream::init(std::string fileName, TMode mode) { + opened = false; + name = fileName; + stdfile = false; + this->mode = mode; + + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + if (stream.is_open()) { + std::streampos start = stream.tellg(); + stream.seekg(0, std::ios::end); + std::streampos end = stream.tellg(); + size_t fileSize = size_t(end - start); + stream.close(); + + // You can change maxFileSize. + // Example: 'inf.maxFileSize = 256 * 1024 * 1024;'. + if (fileSize > maxFileSize) + quitf(_pe, "File size exceeds %d bytes, size is %d", int(maxFileSize), int(fileSize)); + } + + reset(); +} + +void InStream::init(std::FILE *f, TMode mode) { + opened = false; + name = "untitled"; + this->mode = mode; + + if (f == stdin) + name = "stdin", stdfile = true; + if (f == stdout) + name = "stdout", stdfile = true; + if (f == stderr) + name = "stderr", stdfile = true; + + reset(f); +} + +void InStream::skipBom() { + const std::string utf8Bom = "\xEF\xBB\xBF"; + size_t index = 0; + while (index < utf8Bom.size() && curChar() == utf8Bom[index]) { + index++; + skipChar(); + } + if (index < utf8Bom.size()) { + while (index != 0) { + unreadChar(utf8Bom[index - 1]); + index--; + } + } +} + +char InStream::curChar() { + return char(reader->curChar()); +} + +char InStream::nextChar() { + return char(reader->nextChar()); +} + +char InStream::readChar() { + return nextChar(); +} + +char InStream::readChar(char c) { + lastLine = reader->getLine(); + char found = readChar(); + if (c != found) { + if (!isEoln(found)) + quit(_pe, ("Unexpected character '" + std::string(1, found) + "', but '" + std::string(1, c) + + "' expected").c_str()); + else + quit(_pe, ("Unexpected character " + ("#" + vtos(int(found))) + ", but '" + std::string(1, c) + + "' expected").c_str()); + } + return found; +} + +char InStream::readSpace() { + return readChar(' '); +} + +void InStream::unreadChar(char c) { + reader->unreadChar(c); +} + +void InStream::skipChar() { + reader->skipChar(); +} + +void InStream::skipBlanks() { + while (isBlanks(reader->curChar())) + reader->skipChar(); +} + +std::string InStream::readWord() { + readWordTo(_tmpReadToken); + return _tmpReadToken; +} + +void InStream::readWordTo(std::string &result) { + if (!strict) + skipBlanks(); + + lastLine = reader->getLine(); + int cur = reader->nextChar(); + + if (cur == EOFC) + quit(_unexpected_eof, "Unexpected end of file - token expected"); + + if (isBlanks(cur)) + quit(_pe, "Unexpected white-space - token expected"); + + result.clear(); + + while (!(isBlanks(cur) || cur == EOFC)) { + result += char(cur); + + // You can change maxTokenLength. + // Example: 'inf.maxTokenLength = 128 * 1024 * 1024;'. + if (result.length() > maxTokenLength) + quitf(_pe, "Length of token exceeds %d, token is '%s...'", int(maxTokenLength), + __testlib_part(result).c_str()); + + cur = reader->nextChar(); + } + + reader->unreadChar(cur); + + if (result.length() == 0) + quit(_unexpected_eof, "Unexpected end of file or white-space - token expected"); +} + +std::string InStream::readToken() { + return readWord(); +} + +void InStream::readTokenTo(std::string &result) { + readWordTo(result); +} + +static std::string __testlib_part(const std::string &s) { + std::string t; + for (size_t i = 0; i < s.length(); i++) + if (s[i] != '\0') + t += s[i]; + else + t += '~'; + if (t.length() <= 64) + return t; + else + return t.substr(0, 30) + "..." + t.substr(s.length() - 31, 31); +} + +#define __testlib_readMany(readMany, readOne, typeName, space) \ + if (size < 0) \ + quit(_fail, #readMany ": size should be non-negative."); \ + if (size > 100000000) \ + quit(_fail, #readMany ": size should be at most 100000000."); \ + \ + std::vector result(size); \ + readManyIteration = indexBase; \ + \ + for (int i = 0; i < size; i++) \ + { \ + result[i] = readOne; \ + readManyIteration++; \ + if (strict && space && i + 1 < size) \ + readSpace(); \ + } \ + \ + readManyIteration = NO_INDEX; \ + return result; \ + + +std::string InStream::readWord(const pattern &p, const std::string &variableName) { + readWordTo(_tmpReadToken); + if (!p.matches(_tmpReadToken)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Token \"" + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(_tmpReadToken) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Token element [index=" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token element " + variableName + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(_tmpReadToken) + "\", doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + } + } + return _tmpReadToken; +} + +std::vector +InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::vector InStream::readWords(int size, int indexBase) { + __testlib_readMany(readWords, readWord(), std::string, true); +} + +std::string InStream::readWord(const std::string &ptrn, const std::string &variableName) { + return readWord(pattern(ptrn), variableName); +} + +std::vector +InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readWords, readWord(p, variablesName), std::string, true); +} + +std::string InStream::readToken(const pattern &p, const std::string &variableName) { + return readWord(p, variableName); +} + +std::vector +InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readTokens, readToken(p, variablesName), std::string, true); +} + +std::vector InStream::readTokens(int size, int indexBase) { + __testlib_readMany(readTokens, readToken(), std::string, true); +} + +std::string InStream::readToken(const std::string &ptrn, const std::string &variableName) { + return readWord(ptrn, variableName); +} + +std::vector +InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readTokens, readWord(p, variablesName), std::string, true); +} + +void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) { + readWordTo(result); + if (!p.matches(result)) { + if (variableName.empty()) + quit(_wa, ("Token \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } +} + +void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, pattern(ptrn), variableName); +} + +void InStream::readTokenTo(std::string &result, const pattern &p, const std::string &variableName) { + return readWordTo(result, p, variableName); +} + +void InStream::readTokenTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + return readWordTo(result, ptrn, variableName); +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(long long integer, const char *s) { + if (integer == LLONG_MIN) + return strcmp(s, "-9223372036854775808") == 0; + + if (integer == 0LL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + if (integer < 0 && s[0] != '-') + return false; + + if (integer < 0) + s++, length--, integer = -integer; + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +#ifdef __GNUC__ +__attribute__((pure)) +#endif +static inline bool equals(unsigned long long integer, const char *s) { + if (integer == ULLONG_MAX) + return strcmp(s, "18446744073709551615") == 0; + + if (integer == 0ULL) + return strcmp(s, "0") == 0; + + size_t length = strlen(s); + + if (length == 0) + return false; + + while (integer > 0) { + int digit = int(integer % 10); + + if (s[length - 1] != '0' + digit) + return false; + + length--; + integer /= 10; + } + + return length == 0; +} + +static inline double stringToDouble(InStream &in, const char *buffer) { + double retval; + + size_t length = strlen(buffer); + + int minusCount = 0; + int plusCount = 0; + int decimalPointCount = 0; + int digitCount = 0; + int eCount = 0; + + for (size_t i = 0; i < length; i++) { + if (('0' <= buffer[i] && buffer[i] <= '9') || buffer[i] == '.' + || buffer[i] == 'e' || buffer[i] == 'E' + || buffer[i] == '-' || buffer[i] == '+') { + if ('0' <= buffer[i] && buffer[i] <= '9') + digitCount++; + if (buffer[i] == 'e' || buffer[i] == 'E') + eCount++; + if (buffer[i] == '-') + minusCount++; + if (buffer[i] == '+') + plusCount++; + if (buffer[i] == '.') + decimalPointCount++; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + // If for sure is not a number in standard notation or in e-notation. + if (digitCount == 0 || minusCount > 2 || plusCount > 2 || decimalPointCount > 1 || eCount > 1) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToDouble(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToDouble(in, buffer.c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const char *buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + if (minAfterPointDigitCount < 0) + in.quit(_fail, "stringToStrictDouble: minAfterPointDigitCount should be non-negative."); + + if (minAfterPointDigitCount > maxAfterPointDigitCount) + in.quit(_fail, + "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount."); + + double retval; + + size_t length = strlen(buffer); + + if (length == 0 || length > 1000) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[0] != '-' && (buffer[0] < '0' || buffer[0] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int pointPos = -1; + for (size_t i = 1; i + 1 < length; i++) { + if (buffer[i] == '.') { + if (pointPos > -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + pointPos = int(i); + } + if (buffer[i] != '.' && (buffer[i] < '0' || buffer[i] > '9')) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + } + + if (buffer[length - 1] < '0' || buffer[length - 1] > '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + int afterDigitsCount = (pointPos == -1 ? 0 : int(length) - pointPos - 1); + if (afterDigitsCount < minAfterPointDigitCount || afterDigitsCount > maxAfterPointDigitCount) + in.quit(_pe, ("Expected strict double with number of digits after point in range [" + + vtos(minAfterPointDigitCount) + + "," + + vtos(maxAfterPointDigitCount) + + "], but \"" + __testlib_part(buffer) + "\" found").c_str() + ); + + int firstDigitPos = -1; + for (size_t i = 0; i < length; i++) + if (buffer[i] >= '0' && buffer[i] <= '9') { + firstDigitPos = int(i); + break; + } + + if (firstDigitPos > 1 || firstDigitPos == -1) + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (buffer[firstDigitPos] == '0' && firstDigitPos + 1 < int(length) + && buffer[firstDigitPos + 1] >= '0' && buffer[firstDigitPos + 1] <= '9') + in.quit(_pe, ("Expected strict double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + char *suffix = new char[length + 1]; + std::memset(suffix, 0, length + 1); + int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix); + bool empty = strlen(suffix) == 0; + delete[] suffix; + + if (scanned == 1 || (scanned == 2 && empty)) { + if (__testlib_isNaN(retval) || __testlib_isInfinite(retval)) + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (buffer[0] == '-' && retval >= 0) + in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str()); + return retval; + } else + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline double stringToStrictDouble(InStream &in, const std::string& buffer, + int minAfterPointDigitCount, int maxAfterPointDigitCount) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToStrictDouble(in, buffer.c_str(), minAfterPointDigitCount, maxAfterPointDigitCount); +} + +static inline long long stringToLongLong(InStream &in, const char *buffer) { + if (strcmp(buffer, "-9223372036854775808") == 0) + return LLONG_MIN; + + bool minus = false; + size_t length = strlen(buffer); + + if (length > 1 && buffer[0] == '-') + minus = true; + + if (length > 20) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + long long retval = 0LL; + + int zeroes = 0; + bool processingZeroes = true; + + for (int i = (minus ? 1 : 0); i < int(length); i++) { + if (buffer[i] == '0' && processingZeroes) + zeroes++; + else + processingZeroes = false; + + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (retval < 0) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if ((zeroes > 0 && (retval != 0 || minus)) || zeroes > 1) + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + retval = (minus ? -retval : +retval); + + if (length < 19) + return retval; + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToLongLong(in, buffer.c_str()); +} + +static inline unsigned long long stringToUnsignedLongLong(InStream &in, const char *buffer) { + size_t length = strlen(buffer); + + if (length > 20) + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + if (length > 1 && buffer[0] == '0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + unsigned long long retval = 0LL; + for (int i = 0; i < int(length); i++) { + if (buffer[i] < '0' || buffer[i] > '9') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str()); + retval = retval * 10 + (buffer[i] - '0'); + } + + if (length < 19) + return retval; + + if (length == 20 && strcmp(buffer, "18446744073709551615") > 0) + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); + + if (equals(retval, buffer)) + return retval; + else + in.quit(_pe, ("Expected unsigned int64, but \"" + __testlib_part(buffer) + "\" found").c_str()); +} + +static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) { + for (size_t i = 0; i < buffer.length(); i++) + if (buffer[i] == '\0') + in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found (it contains \\0)").c_str()); + return stringToUnsignedLongLong(in, buffer.c_str()); +} + +int InStream::readInteger() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int32 expected"); + + readWordTo(_tmpReadToken); + + long long value = stringToLongLong(*this, _tmpReadToken); + if (value < INT_MIN || value > INT_MAX) + quit(_pe, ("Expected int32, but \"" + __testlib_part(_tmpReadToken) + "\" found").c_str()); + + return int(value); +} + +long long InStream::readLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToLongLong(*this, _tmpReadToken); +} + +unsigned long long InStream::readUnsignedLong() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - int64 expected"); + + readWordTo(_tmpReadToken); + + return stringToUnsignedLongLong(*this, _tmpReadToken); +} + +long long InStream::readLong(long long minv, long long maxv, const std::string &variableName) { + long long result = readLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector +InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) +} + +std::vector InStream::readLongs(int size, int indexBase) { + __testlib_readMany(readLongs, readLong(), long long, true) +} + +unsigned long long +InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + unsigned long long result = readUnsignedLong(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, + ("Unsigned integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Unsigned integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, ("Unsigned integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +std::vector InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) +} + +std::vector InStream::readUnsignedLongs(int size, int indexBase) { + __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) +} + +unsigned long long +InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string &variableName) { + return readUnsignedLong(minv, maxv, variableName); +} + +int InStream::readInt() { + return readInteger(); +} + +int InStream::readInt(int minv, int maxv, const std::string &variableName) { + int result = readInt(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Integer " + vtos(result) + " violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + + "]").c_str()); + else + quit(_wa, ("Integer parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Integer element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + else + quit(_wa, + ("Integer element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + toHumanReadableString(minv) + ", " + toHumanReadableString(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result)); + + return result; +} + +int InStream::readInteger(int minv, int maxv, const std::string &variableName) { + return readInt(minv, maxv, variableName); +} + +std::vector InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readInts(int size, int indexBase) { + __testlib_readMany(readInts, readInt(), int, true) +} + +std::vector InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) +} + +std::vector InStream::readIntegers(int size, int indexBase) { + __testlib_readMany(readIntegers, readInt(), int, true) +} + +double InStream::readReal() { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - double expected"); + + return stringToDouble(*this, readWord()); +} + +double InStream::readDouble() { + return readReal(); +} + +double InStream::readReal(double minv, double maxv, const std::string &variableName) { + double result = readReal(); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, ("Double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, + ("Double element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to " + + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector +InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readReals(int size, int indexBase) { + __testlib_readMany(readReals, readReal(), double, true) +} + +double InStream::readDouble(double minv, double maxv, const std::string &variableName) { + return readReal(minv, maxv, variableName); +} + +std::vector +InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) { + __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) +} + +std::vector InStream::readDoubles(int size, int indexBase) { + __testlib_readMany(readDoubles, readDouble(), double, true) +} + +double InStream::readStrictReal(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + if (!strict && seekEof()) + quit(_unexpected_eof, "Unexpected end of file - strict double expected"); + + double result = stringToStrictDouble(*this, readWord(), minAfterPointDigitCount, maxAfterPointDigitCount); + + if (result < minv || result > maxv) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Strict double " + vtos(result) + " violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + else + quit(_wa, + ("Strict double parameter [name=" + std::string(variableName) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + } else { + if (variableName.empty()) + quit(_wa, ("Strict double element [index=" + vtos(readManyIteration) + "] equals to " + vtos(result) + + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + "]").c_str()); + else + quit(_wa, ("Strict double element " + std::string(variableName) + "[" + vtos(readManyIteration) + + "] equals to " + vtos(result) + ", violates the range [" + vtos(minv) + ", " + vtos(maxv) + + "]").c_str()); + } + } + + if (strict && !variableName.empty()) + validator.addBoundsHit(variableName, ValidatorBoundsHit( + doubleDelta(minv, result) < ValidatorBoundsHit::EPS, + doubleDelta(maxv, result) < ValidatorBoundsHit::EPS + )); + + return result; +} + +std::vector InStream::readStrictReals(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictReals, + readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +double InStream::readStrictDouble(double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variableName) { + return readStrictReal(minv, maxv, + minAfterPointDigitCount, maxAfterPointDigitCount, + variableName); +} + +std::vector InStream::readStrictDoubles(int size, double minv, double maxv, + int minAfterPointDigitCount, int maxAfterPointDigitCount, + const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrictDoubles, + readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName), + double, true) +} + +bool InStream::eof() { + if (!strict && NULL == reader) + return true; + + return reader->eof(); +} + +bool InStream::seekEof() { + if (!strict && NULL == reader) + return true; + skipBlanks(); + return eof(); +} + +bool InStream::eoln() { + if (!strict && NULL == reader) + return true; + + int c = reader->nextChar(); + + if (!strict) { + if (c == EOFC) + return true; + + if (c == CR) { + c = reader->nextChar(); + + if (c != LF) { + reader->unreadChar(c); + reader->unreadChar(CR); + return false; + } else + return true; + } + + if (c == LF) + return true; + + reader->unreadChar(c); + return false; + } else { + bool returnCr = false; + +#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS) + if (c != CR) { + reader->unreadChar(c); + return false; + } else { + if (!returnCr) + returnCr = true; + c = reader->nextChar(); + } +#endif + if (c != LF) { + reader->unreadChar(c); + if (returnCr) + reader->unreadChar(CR); + return false; + } + + return true; + } +} + +void InStream::readEoln() { + lastLine = reader->getLine(); + if (!eoln()) + quit(_pe, "Expected EOLN"); +} + +void InStream::readEof() { + lastLine = reader->getLine(); + if (!eof()) + quit(_pe, "Expected EOF"); + + if (TestlibFinalizeGuard::alive && this == &inf) + testlibFinalizeGuard.readEofCount++; +} + +bool InStream::seekEoln() { + if (!strict && NULL == reader) + return true; + + int cur; + do { + cur = reader->nextChar(); + } while (cur == SPACE || cur == TAB); + + reader->unreadChar(cur); + return eoln(); +} + +void InStream::nextLine() { + readLine(); +} + +void InStream::readStringTo(std::string &result) { + if (NULL == reader) + quit(_pe, "Expected line"); + + result.clear(); + + for (;;) { + int cur = reader->curChar(); + + if (cur == LF || cur == EOFC) + break; + + if (cur == CR) { + cur = reader->nextChar(); + if (reader->curChar() == LF) { + reader->unreadChar(cur); + break; + } + } + + lastLine = reader->getLine(); + result += char(reader->nextChar()); + } + + if (strict) + readEoln(); + else + eoln(); +} + +std::string InStream::readString() { + readStringTo(_tmpReadToken); + return _tmpReadToken; +} + +std::vector InStream::readStrings(int size, int indexBase) { + __testlib_readMany(readStrings, readString(), std::string, false) +} + +void InStream::readStringTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result); + if (!p.matches(result)) { + if (readManyIteration == NO_INDEX) { + if (variableName.empty()) + quit(_wa, ("Line \"" + __testlib_part(result) + "\" doesn't correspond to pattern \"" + p.src() + + "\"").c_str()); + else + quit(_wa, ("Line [name=" + variableName + "] equals to \"" + __testlib_part(result) + + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } else { + if (variableName.empty()) + quit(_wa, + ("Line element [index=" + vtos(readManyIteration) + "] equals to \"" + __testlib_part(result) + + "\" doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + else + quit(_wa, + ("Line element " + std::string(variableName) + "[" + vtos(readManyIteration) + "] equals to \"" + + __testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str()); + } + } +} + +void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, pattern(ptrn), variableName); +} + +std::string InStream::readString(const pattern &p, const std::string &variableName) { + readStringTo(_tmpReadToken, p, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +std::string InStream::readString(const std::string &ptrn, const std::string &variableName) { + readStringTo(_tmpReadToken, ptrn, variableName); + return _tmpReadToken; +} + +std::vector +InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readStrings, readString(p, variablesName), std::string, false) +} + +void InStream::readLineTo(std::string &result) { + readStringTo(result); +} + +std::string InStream::readLine() { + return readString(); +} + +std::vector InStream::readLines(int size, int indexBase) { + __testlib_readMany(readLines, readString(), std::string, false) +} + +void InStream::readLineTo(std::string &result, const pattern &p, const std::string &variableName) { + readStringTo(result, p, variableName); +} + +void InStream::readLineTo(std::string &result, const std::string &ptrn, const std::string &variableName) { + readStringTo(result, ptrn, variableName); +} + +std::string InStream::readLine(const pattern &p, const std::string &variableName) { + return readString(p, variableName); +} + +std::vector +InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) { + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) { + return readString(ptrn, variableName); +} + +std::vector +InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) { + pattern p(ptrn); + __testlib_readMany(readLines, readString(p, variablesName), std::string, false) +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void InStream::ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + this->__testlib_ensure(cond, message); + } +} + +void InStream::__testlib_ensure(bool cond, std::string message) { + if (!cond) + this->quit(_wa, message.c_str()); +} + +void InStream::close() { + if (NULL != reader) { + reader->close(); + delete reader; + reader = NULL; + } + + opened = false; +} + +NORETURN void quit(TResult result, const std::string &msg) { + ouf.quit(result, msg.c_str()); +} + +NORETURN void quit(TResult result, const char *msg) { + ouf.quit(result, msg); +} + +NORETURN void __testlib_quitp(double points, const char *message) { + __testlib_points = points; + std::string stringPoints = removeDoubleTrailingZeroes(format("%.10f", points)); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void __testlib_quitp(int points, const char *message) { + __testlib_points = points; + std::string stringPoints = format("%d", points); + + std::string quitMessage; + if (NULL == message || 0 == strlen(message)) + quitMessage = stringPoints; + else + quitMessage = stringPoints + " " + message; + + quit(_points, quitMessage.c_str()); +} + +NORETURN void quitp(float points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(double points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitp(long double points, const std::string &message = "") { + __testlib_quitp(double(points), message.c_str()); +} + +NORETURN void quitp(int points, const std::string &message = "") { + __testlib_quitp(points, message.c_str()); +} + +NORETURN void quitpi(const std::string &points_info, const std::string &message = "") { + if (points_info.find(' ') != std::string::npos) + quit(_fail, "Parameter 'points_info' can't contain spaces"); + if (message.empty()) + quit(_points, ("points_info=" + points_info).c_str()); + else + quit(_points, ("points_info=" + points_info + " " + message).c_str()); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitp(F points, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quitp(points, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +NORETURN void quitf(TResult result, const char *format, ...) { + FMT_TO_RESULT(format, format, message); + quit(result, message); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 3, 4))) +#endif +void quitif(bool condition, TResult result, const char *format, ...) { + if (condition) { + FMT_TO_RESULT(format, format, message); + quit(result, message); + } +} + +NORETURN void __testlib_help() { + InStream::textColor(InStream::LightCyan); + std::fprintf(stderr, "TESTLIB %s, https://github.com/MikeMirzayanov/testlib/ ", VERSION); + std::fprintf(stderr, "by Mike Mirzayanov, copyright(c) 2005-2020\n"); + std::fprintf(stderr, "Checker name: \"%s\"\n", checkerName.c_str()); + InStream::textColor(InStream::LightGray); + + std::fprintf(stderr, "\n"); + std::fprintf(stderr, "Latest features: \n"); + for (size_t i = 0; i < sizeof(latestFeatures) / sizeof(char *); i++) { + std::fprintf(stderr, "*) %s\n", latestFeatures[i]); + } + std::fprintf(stderr, "\n"); + + std::fprintf(stderr, "Program must be run with the following arguments: \n"); + std::fprintf(stderr, " [--testset testset] [--group group] [ [<-appes>]]\n\n"); + + __testlib_exitCode = FAIL_EXIT_CODE; + std::exit(FAIL_EXIT_CODE); +} + +static void __testlib_ensuresPreconditions() { + // testlib assumes: sizeof(int) = 4. + __TESTLIB_STATIC_ASSERT(sizeof(int) == 4); + + // testlib assumes: INT_MAX == 2147483647. + __TESTLIB_STATIC_ASSERT(INT_MAX == 2147483647); + + // testlib assumes: sizeof(long long) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(long long) == 8); + + // testlib assumes: sizeof(double) = 8. + __TESTLIB_STATIC_ASSERT(sizeof(double) == 8); + + // testlib assumes: no -ffast-math. + if (!__testlib_isNaN(+__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); + if (!__testlib_isNaN(-__testlib_nan())) + quit(_fail, "Function __testlib_isNaN is not working correctly: possible reason is '-ffast-math'"); +} + +std::string __testlib_testset; + +std::string getTestset() { + return __testlib_testset; +} + +std::string __testlib_group; + +std::string getGroup() { + return __testlib_group; +} + +static void __testlib_set_testset_and_group(int argc, char* argv[]) { + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + __testlib_testset = argv[++i]; + else + quit(_fail, std::string("Expected non-empty testset after --testset command line parameter")); + } else if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + __testlib_group = argv[++i]; + else + quit(_fail, std::string("Expected group after --group command line parameter")); + } + } +} + +void registerGen(int argc, char *argv[], int randomGeneratorVersion) { + if (randomGeneratorVersion < 0 || randomGeneratorVersion > 1) + quitf(_fail, "Random generator version is expected to be 0 or 1."); + random_t::version = randomGeneratorVersion; + + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _generator; + __testlib_set_binary(stdin); + rnd.setSeed(argc, argv); + +#if __cplusplus > 199711L || defined(_MSC_VER) + prepareOpts(argc, argv); +#endif +} + +#ifdef USE_RND_AS_BEFORE_087 +void registerGen(int argc, char* argv[]) +{ + registerGen(argc, argv, 0); +} +#else +#ifdef __GNUC__ +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 4)) +__attribute__ ((deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." +" The third parameter stands for the random generator version." +" If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." +" Version 1 has been released on Spring, 2013. Use it to write new generators."))) +#else +__attribute__ ((deprecated)) +#endif +#endif +#ifdef _MSC_VER +__declspec(deprecated("Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.")) +#endif +void registerGen(int argc, char *argv[]) { + std::fprintf(stderr, "Use registerGen(argc, argv, 0) or registerGen(argc, argv, 1)." + " The third parameter stands for the random generator version." + " If you are trying to compile old generator use macro -DUSE_RND_AS_BEFORE_087 or registerGen(argc, argv, 0)." + " Version 1 has been released on Spring, 2013. Use it to write new generators.\n\n"); + registerGen(argc, argv, 0); +} +#endif + +void registerInteraction(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _interactor; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + tout.open(std::string(argv[3]) + "/teammessage.txt", + std::ios_base::out); + if (tout.fail() || !tout.is_open()) + quit(_fail, "Can not write to the test-output-file '" + + std::string(argv[2]) + "'"); + appesMode = false; + } + + inf.init(argv[1], _input); + + ouf.init(stdin, _output); + if (argc >= 3) + ans.init(argv[2], _answer); + else + ans.name = "unopened answer stream"; +} + +void registerValidation() { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _validator; + + __testlib_set_binary(stdin); + __testlib_set_binary(stdout); + __testlib_set_binary(stderr); + + inf.init(stdin, _input); + inf.strict = true; +} + +void registerValidation(int argc, char *argv[]) { + registerValidation(); + __testlib_set_testset_and_group(argc, argv); + + validator.initialize(); + TestlibFinalizeGuard::registered = true; + + std::string comment = "Validator must be run with the following arguments:" + " [--testset testset]" + " [--group group]" + " [--testOverviewLogFileName fileName]" + " [--testMarkupFileName fileName]" + " [--testCase testCase]" + " [--testCaseFileName fileName]" + ; + + for (int i = 1; i < argc; i++) { + if (!strcmp("--testset", argv[i])) { + if (i + 1 < argc && strlen(argv[i + 1]) > 0) + validator.setTestset(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--group", argv[i])) { + if (i + 1 < argc) + validator.setGroup(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testOverviewLogFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestOverviewLogFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testMarkupFileName", argv[i])) { + if (i + 1 < argc) + validator.setTestMarkupFileName(argv[++i]); + else + quit(_fail, comment); + } + if (!strcmp("--testCase", argv[i])) { + if (i + 1 < argc) { + long long testCase = stringToLongLong(inf, argv[++i]); + if (testCase < 1 || testCase >= __TESTLIB_MAX_TEST_CASE) + quit(_fail, format("Argument testCase should be between 1 and %d, but ", __TESTLIB_MAX_TEST_CASE) + + toString(testCase) + " found"); + validator.setTestCase(int(testCase)); + } else + quit(_fail, comment); + } + if (!strcmp("--testCaseFileName", argv[i])) { + if (i + 1 < argc) { + validator.setTestCaseFileName(argv[++i]); + } else + quit(_fail, comment); + } + } +} + +void addFeature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.addFeature(feature); +} + +void feature(const std::string &feature) { + if (testlibMode != _validator) + quit(_fail, "Features are supported in validators only."); + validator.feature(feature); +} + +class Checker { +private: + bool _initialized; + std::string _testset; + std::string _group; + +public: + Checker() : _initialized(false), _testset("tests"), _group() { + } + + void initialize() { + _initialized = true; + } + + std::string testset() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.testset()"); + return _testset; + } + + std::string group() const { + if (!_initialized) + __testlib_fail("Checker should be initialized with registerTestlibCmd(argc, argv) instead of registerTestlibCmd() to support checker.group()"); + return _group; + } + + void setTestset(const char *const testset) { + _testset = testset; + } + + void setGroup(const char *const group) { + _group = group; + } +} checker; + +void registerTestlibCmd(int argc, char *argv[]) { + __testlib_ensuresPreconditions(); + TestlibFinalizeGuard::registered = true; + + testlibMode = _checker; + __testlib_set_binary(stdin); + + if (argc > 1 && !strcmp("--help", argv[1])) + __testlib_help(); + + appesMode = false; + + if (argc == 3) { + resultName = ""; + appesMode = false; + } + + if (argc == 4) { + resultName = std::string(argv[3]) + "/null"; + appesMode = false; + } + + inf.init(argv[1], _input); + ouf.init(stdin, _output); + ans.init(argv[2], _answer); +} + +void registerTestlib(int argc, ...) { + if (argc < 3 || argc > 5) + quit(_fail, std::string("Program must be run with the following arguments: ") + + " [ [<-appes>]]"); + + char **argv = new char *[argc + 1]; + + va_list ap; + va_start(ap, argc); + argv[0] = NULL; + for (int i = 0; i < argc; i++) { + argv[i + 1] = va_arg(ap, char*); + } + va_end(ap); + + registerTestlibCmd(argc + 1, argv); + delete[] argv; +} + +static inline void __testlib_ensure(bool cond, const std::string &msg) { + if (!cond) + quit(_fail, msg.c_str()); +} + +#ifdef __GNUC__ +__attribute__((unused)) +#endif +static inline void __testlib_ensure(bool cond, const char *msg) { + if (!cond) + quit(_fail, msg); +} + +#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") +#define STRINGIZE_DETAIL(x) #x +#define STRINGIZE(x) STRINGIZE_DETAIL(x) +#define ensure_ext(cond) __testlib_ensure(cond, "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"") + +#ifdef __GNUC__ +__attribute__ ((format (printf, 2, 3))) +#endif +inline void ensuref(bool cond, const char *format, ...) { + if (!cond) { + FMT_TO_RESULT(format, format, message); + __testlib_ensure(cond, message); + } +} + +NORETURN static void __testlib_fail(const std::string &message) { + quitf(_fail, "%s", message.c_str()); +} + +#ifdef __GNUC__ +__attribute__ ((format (printf, 1, 2))) +#endif +void setName(const char *format, ...) { + FMT_TO_RESULT(format, format, name); + checkerName = name; +} + +/* + * Do not use random_shuffle, because it will produce different result + * for different C++ compilers. + * + * This implementation uses testlib random_t to produce random numbers, so + * it is stable. + */ +template +void shuffle(_RandomAccessIter __first, _RandomAccessIter __last) { + if (__first == __last) return; + for (_RandomAccessIter __i = __first + 1; __i != __last; ++__i) + std::iter_swap(__i, __first + rnd.next(int(__i - __first) + 1)); +} + + +template +#if defined(__GNUC__) && !defined(__clang__) +__attribute__ ((error("Don't use random_shuffle(), use shuffle() instead"))) +#endif +void random_shuffle(_RandomAccessIter, _RandomAccessIter) { + quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); +} + +#ifdef __GLIBC__ +# define RAND_THROW_STATEMENT throw() +#else +# define RAND_THROW_STATEMENT +#endif + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use rand(), use rnd.next() instead"))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +int rand() RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use rand(), use rnd.next() instead"); + + /* This line never runs. */ + //throw "Don't use rand(), use rnd.next() instead"; +} + +#if defined(__GNUC__) && !defined(__clang__) + +__attribute__ ((error("Don't use srand(), you should use " +"'registerGen(argc, argv, 1);' to initialize generator seed " +"by hash code of the command line params. The third parameter " +"is randomGeneratorVersion (currently the latest is 1)."))) +#endif +#ifdef _MSC_VER +# pragma warning( disable : 4273 ) +#endif +void srand(unsigned int seed) RAND_THROW_STATEMENT +{ + quitf(_fail, "Don't use srand(), you should use " + "'registerGen(argc, argv, 1);' to initialize generator seed " + "by hash code of the command line params. The third parameter " + "is randomGeneratorVersion (currently the latest is 1) [ignored seed=%u].", seed); +} + +void startTest(int test) { + const std::string testFileName = vtos(test); + if (NULL == freopen(testFileName.c_str(), "wt", stdout)) + __testlib_fail("Unable to write file '" + testFileName + "'"); +} + +inline std::string upperCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('a' <= s[i] && s[i] <= 'z') + s[i] = char(s[i] - 'a' + 'A'); + return s; +} + +inline std::string lowerCase(std::string s) { + for (size_t i = 0; i < s.length(); i++) + if ('A' <= s[i] && s[i] <= 'Z') + s[i] = char(s[i] - 'A' + 'a'); + return s; +} + +inline std::string compress(const std::string &s) { + return __testlib_part(s); +} + +inline std::string englishEnding(int x) { + x %= 100; + if (x / 10 == 1) + return "th"; + if (x % 10 == 1) + return "st"; + if (x % 10 == 2) + return "nd"; + if (x % 10 == 3) + return "rd"; + return "th"; +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last, _Separator separator) { + std::stringstream ss; + bool repeated = false; + for (_ForwardIterator i = first; i != last; i++) { + if (repeated) + ss << separator; + else + repeated = true; + ss << *i; + } + return ss.str(); +} + +template +std::string join(_ForwardIterator first, _ForwardIterator last) { + return join(first, last, ' '); +} + +template +std::string join(const _Collection &collection, _Separator separator) { + return join(collection.begin(), collection.end(), separator); +} + +template +std::string join(const _Collection &collection) { + return join(collection, ' '); +} + +/** + * Splits string s by character separator returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning exactly k+1 items, + * where k is the number of separator occurences. + */ +std::vector split(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + result.push_back(item); + item = ""; + } else + item += s[i]; + result.push_back(item); + return result; +} + +/** + * Splits string s by character separator returning non-empty items. + */ +std::vector tokenize(const std::string &s, char separator) { + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == separator) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + if (!item.empty()) + result.push_back(item); + return result; +} + +/** + * Splits string s by character separators returning non-empty items. + */ +std::vector tokenize(const std::string &s, const std::string &separators) { + if (separators.empty()) + return std::vector(1, s); + + std::vector isSeparator(256); + for (size_t i = 0; i < separators.size(); i++) + isSeparator[(unsigned char) (separators[i])] = true; + + std::vector result; + std::string item; + for (size_t i = 0; i < s.length(); i++) + if (isSeparator[(unsigned char) (s[i])]) { + if (!item.empty()) + result.push_back(item); + item = ""; + } else + item += s[i]; + + if (!item.empty()) + result.push_back(item); + + return result; +} + +NORETURN void __testlib_expectedButFound(TResult result, std::string expected, std::string found, const char *prepend) { + std::string message; + if (strlen(prepend) != 0) + message = format("%s: expected '%s', but found '%s'", + compress(prepend).c_str(), compress(expected).c_str(), compress(found).c_str()); + else + message = format("expected '%s', but found '%s'", + compress(expected).c_str(), compress(found).c_str()); + quit(result, message); +} + +NORETURN void __testlib_expectedButFound(TResult result, double expected, double found, const char *prepend) { + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend); +} + +template +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, T expected, T found, const char *prependFormat = "", ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = vtos(expected); + std::string foundString = vtos(found); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, std::string expected, std::string found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, expected, found, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, double expected, double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); + std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); + __testlib_expectedButFound(result, expectedString, foundString, prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, const char *expected, const char *found, const char *prependFormat, + ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void expectedButFound(TResult result, float expected, float found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +template<> +#ifdef __GNUC__ +__attribute__ ((format (printf, 4, 5))) +#endif +NORETURN void +expectedButFound(TResult result, long double expected, long double found, const char *prependFormat, ...) { + FMT_TO_RESULT(prependFormat, prependFormat, prepend); + __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); +} + +#if __cplusplus > 199711L || defined(_MSC_VER) +template +struct is_iterable { + template + static char test(typename U::iterator *x); + + template + static long test(U *x); + + static const bool value = sizeof(test(0)) == 1; +}; + +template +struct __testlib_enable_if { +}; + +template +struct __testlib_enable_if { + typedef T type; +}; + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + std::cout << t; +} + +template +typename __testlib_enable_if::value, void>::type __testlib_print_one(const T &t) { + bool first = true; + for (typename T::const_iterator i = t.begin(); i != t.end(); i++) { + if (first) + first = false; + else + std::cout << " "; + std::cout << *i; + } +} + +template<> +typename __testlib_enable_if::value, void>::type +__testlib_print_one(const std::string &t) { + std::cout << t; +} + +template +void __println_range(A begin, B end) { + bool first = true; + for (B i = B(begin); i != end; i++) { + if (first) + first = false; + else + std::cout << " "; + __testlib_print_one(*i); + } + std::cout << std::endl; +} + +template +struct is_iterator { + static T makeT(); + + typedef void *twoptrs[2]; + + static twoptrs &test(...); + + template + static typename R::iterator_category *test(R); + + template + static void *test(R *); + + static const bool value = sizeof(test(makeT())) == sizeof(void *); +}; + +template +struct is_iterator::value>::type> { + static const bool value = false; +}; + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +typename __testlib_enable_if::value, void>::type println(const A &a, const B &b) { + __println_range(a, b); +} + +template +void println(const A *a, const A *b) { + __println_range(a, b); +} + +template<> +void println(const char *a, const char *b) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << std::endl; +} + +template +void println(const T &x) { + __testlib_print_one(x); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << std::endl; +} + +template +void println(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g) { + __testlib_print_one(a); + std::cout << " "; + __testlib_print_one(b); + std::cout << " "; + __testlib_print_one(c); + std::cout << " "; + __testlib_print_one(d); + std::cout << " "; + __testlib_print_one(e); + std::cout << " "; + __testlib_print_one(f); + std::cout << " "; + __testlib_print_one(g); + std::cout << std::endl; +} + +/* opts */ + +/** + * A struct for a singular testlib opt, containing the raw string value, + * and a boolean value for marking whether the opt is used. + */ +struct TestlibOpt { + std::string value; + bool used; + + TestlibOpt() : value(), used(false) {} +}; + +/** + * Get the type of opt based on the number of `-` at the beginning and the + * _validity_ of the key name. + * + * A valid key name must start with an alphabetical character. + * + * Returns: 1 if s has one `-` at the beginning, that is, "-keyName". + * 2 if s has two `-` at the beginning, that is, "--keyName". + * 0 otherwise. That is, if s has no `-` at the beginning, or has more + * than 2 at the beginning ("---keyName", "----keyName", ...), or the + * keyName is invalid (the first character is not an alphabetical + * character). + */ +size_t getOptType(char *s) { + if (!s || strlen(s) <= 1) + return 0; + + if (s[0] == '-') { + if (isalpha(s[1])) + return 1; + else if (s[1] == '-') + return isalpha(s[2]) ? 2 : 0; + } + + return 0; +} + +/** + * Parse the opt at a given index, and put it into the opts maps. + * + * An opt can has the following form: + * 1) -keyName=value or --keyName=value (ex. -n=10 --test-count=20) + * 2) -keyName value or --keyName value (ex. -n 10 --test-count 20) + * 3) -kNumval or --kNumval (ex. -n10 --t20) + * 4) -boolProperty or --boolProperty (ex. -sorted --tree-only) + * + * Only the second form consumes 2 arguments. The other consumes only 1 + * argument. + * + * In the third form, the key is a single character, and after the key is the + * value. The value _should_ be a number. + * + * In the forth form, the value is true. + * + * Params: + * - argc and argv: the number of command line arguments and the command line + * arguments themselves. + * - index: the starting index of the opts. + * - opts: the map containing the resulting opt. + * + * Returns: the number of consumed arguments to parse the opt. + * 0 if there is no arguments to parse. + * + * Algorithm details: + * TODO. Please refer to the implementation to see how the code handles the 3rd and 4th forms separately. + */ +size_t parseOpt(size_t argc, char *argv[], size_t index, std::map &opts) { + if (index >= argc) + return 0; + + size_t type = getOptType(argv[index]), inc = 1; + if (type > 0) { + std::string key(argv[index] + type), val; + size_t sep = key.find('='); + if (sep != std::string::npos) { + val = key.substr(sep + 1); + key = key.substr(0, sep); + } else { + if (index + 1 < argc && getOptType(argv[index + 1]) == 0) { + val = argv[index + 1]; + inc = 2; + } else { + if (key.length() > 1 && isdigit(key[1])) { + val = key.substr(1); + key = key.substr(0, 1); + } else { + val = "true"; + } + } + } + opts[key].value = val; + } else { + return inc; + } + + return inc; +} + +/** + * Global list containing all the arguments in the order given in the command line. + */ +std::vector __testlib_argv; + +/** + * Global dictionary containing all the parsed opts. + */ +std::map __testlib_opts; + +/** + * Whether automatic no unused opts ensurement should be done. This flag will + * be turned on when `has_opt` or `opt(key, default_value)` is called. + * + * The automatic ensurement can be suppressed when + * __testlib_ensureNoUnusedOptsSuppressed is true. + */ +bool __testlib_ensureNoUnusedOptsFlag = false; + +/** + * Suppress no unused opts automatic ensurement. Can be set to true with + * `suppressEnsureNoUnusedOpts()`. + */ +bool __testlib_ensureNoUnusedOptsSuppressed = false; + +/** + * Parse command line arguments into opts. + * The results are stored into __testlib_argv and __testlib_opts. + */ +void prepareOpts(int argc, char *argv[]) { + if (argc <= 0) + __testlib_fail("Opts: expected argc>=0 but found " + toString(argc)); + size_t n = static_cast(argc); // NOLINT(hicpp-use-auto,modernize-use-auto) + __testlib_opts = std::map(); + for (size_t index = 1; index < n; index += parseOpt(n, argv, index, __testlib_opts)); + __testlib_argv = std::vector(n); + for (size_t index = 0; index < n; index++) + __testlib_argv[index] = argv[index]; +} + +/** + * An utility function to get the argument with a given index. This function + * also print a readable message when no arguments are found. + */ +std::string __testlib_indexToArgv(int index) { + if (index < 0 || index >= int(__testlib_argv.size())) + __testlib_fail("Opts: index '" + toString(index) + "' is out of range [0," + + toString(__testlib_argv.size()) + ")"); + return __testlib_argv[size_t(index)]; +} + +/** + * An utility function to get the opt with a given key . This function + * also print a readable message when no opts are found. + */ +std::string __testlib_keyToOpts(const std::string &key) { + auto it = __testlib_opts.find(key); + if (it == __testlib_opts.end()) + __testlib_fail("Opts: unknown key '" + compress(key) + "'"); + it->second.used = true; + return it->second.value; +} + +template +T optValueToIntegral(const std::string &s, bool nonnegative); + +long double optValueToLongDouble(const std::string &s); + +std::string parseExponentialOptValue(const std::string &s) { + size_t pos = std::string::npos; + for (size_t i = 0; i < s.length(); i++) + if (s[i] == 'e' || s[i] == 'E') { + if (pos != std::string::npos) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + pos = i; + } + if (pos == std::string::npos) + return s; + std::string e = s.substr(pos + 1); + if (!e.empty() && e[0] == '+') + e = e.substr(1); + if (e.empty()) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (e.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + int ne = optValueToIntegral(e, false); + std::string num = s.substr(0, pos); + if (num.length() > 20) + __testlib_fail("Opts: expected typical exponential notation but '" + compress(s) + "' found"); + if (!num.empty() && num[0] == '+') + num = num.substr(1); + optValueToLongDouble(num); + bool minus = false; + if (num[0] == '-') { + minus = true; + num = num.substr(1); + } + for (int i = 0; i < +ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num += '0'; + else { + if (sep + 1 == num.length()) + num[sep] = '0'; + else + std::swap(num[sep], num[sep + 1]); + } + } + for (int i = 0; i < -ne; i++) { + size_t sep = num.find('.'); + if (sep == std::string::npos) + num.insert(num.begin() + int(num.length()) - 1, '.'); + else { + if (sep == 0) + num.insert(num.begin() + 1, '0'); + else + std::swap(num[sep - 1], num[sep]); + } + } + while (!num.empty() && num[0] == '0') + num = num.substr(1); + while (num.find('.') != std::string::npos && num.back() == '0') + num = num.substr(0, num.length() - 1); + if (!num.empty() && num.back() == '.') + num = num.substr(0, num.length() - 1); + if ((!num.empty() && num[0] == '.') || num.empty()) + num.insert(num.begin(), '0'); + return (minus ? "-" : "") + num; +} + +template +T optValueToIntegral(const std::string &s_, bool nonnegative) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + T value = 0; + long double about = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + if (nonnegative) + __testlib_fail("Opts: expected non-negative integer but '" + compress(s_) + "' found"); + sign = -1; + pos++; + } + for (size_t i = pos; i < s.length(); i++) { + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected integer but '" + compress(s_) + "' found"); + value = value * 10 + s[i] - '0'; + about = about * 10 + s[i] - '0'; + } + value *= sign; + about *= sign; + if (fabsl(value - about) > 0.1) + __testlib_fail("Opts: integer overflow: expected integer but '" + compress(s_) + "' found"); + return value; +} + +long double optValueToLongDouble(const std::string &s_) { + std::string s(parseExponentialOptValue(s_)); + if (s.empty()) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + long double value = 0.0; + signed char sign = +1; + size_t pos = 0; + if (s[pos] == '-') { + sign = -1; + pos++; + } + bool period = false; + long double mul = 1.0; + for (size_t i = pos; i < s.length(); i++) { + if (s[i] == '.') { + if (period) + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + else { + period = true; + continue; + } + } + if (period) + mul *= 10.0; + if (s[i] < '0' || s[i] > '9') + __testlib_fail("Opts: expected float number but '" + compress(s_) + "' found"); + if (period) + value += (s[i] - '0') / mul; + else + value = value * 10 + s[i] - '0'; + } + value *= sign; + return value; +} + +/** + * Return true if there is an opt with a given key. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +bool has_opt(const std::string &key) { + __testlib_ensureNoUnusedOptsFlag = true; + return __testlib_opts.count(key) != 0; +} + +/* About the followings part for opt with 2 and 3 arguments. + * + * To parse the argv/opts correctly for a give type (integer, floating point or + * string), some meta programming must be done to determine the type of + * the type, and use the correct parsing function accordingly. + * + * The pseudo algorithm for determining the type of T and parse it accordingly + * is as follows: + * + * if (T is integral type) { + * if (T is unsigned) { + * parse the argv/opt as an **unsigned integer** of type T. + * } else { + * parse the argv/opt as an **signed integer** of type T. + * } else { + * if (T is floating point type) { + * parse the argv/opt as an **floating point** of type T. + * } else { + * // T should be std::string + * just the raw content of the argv/opts. + * } + * } + * + * To help with meta programming, some `opt` function with 2 or 3 arguments are + * defined. + * + * Opt with 3 arguments: T opt(true/false is_integral, true/false is_unsigned, index/key) + * + * + The first argument is for determining whether the type T is an integral + * type. That is, the result of std::is_integral() should be passed to + * this argument. When false, the type _should_ be either floating point or a + * std::string. + * + * + The second argument is for determining whether the signedness of the type + * T (if it is unsigned or signed). That is, the result of + * std::is_unsigned() should be passed to this argument. This argument can + * be ignored if the first one is false, because it only applies to integer. + * + * Opt with 2 arguments: T opt(true/false is_floating_point, index/key) + * + The first argument is for determining whether the type T is a floating + * point type. That is, the result of std::is_floating_point() should be + * passed to this argument. When false, the type _should_ be a std::string. + */ + +template +T opt(std::false_type is_floating_point, int index); + +template<> +std::string opt(std::false_type /*is_floating_point*/, int index) { + return __testlib_indexToArgv(index); +} + +template +T opt(std::true_type /*is_floating_point*/, int index) { + return T(optValueToLongDouble(__testlib_indexToArgv(index))); +} + +template +T opt(std::false_type /*is_integral*/, U /*is_unsigned*/, int index) { + return opt(std::is_floating_point(), index); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + return optValueToIntegral(__testlib_indexToArgv(index), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, int index) { + std::string value = __testlib_indexToArgv(index); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: opt by index '" + toString(index) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed argv by a given index. + */ +template +T opt(int index) { + return opt(std::is_integral(), std::is_unsigned(), index); +} + +/** + * Return the raw string value of an argv by a given index. + */ +std::string opt(int index) { + return opt(index); +} + +/** + * Return the parsed argv by a given index. If the index is bigger than + * the number of argv, return the given default_value. + */ +template +T opt(int index, const T &default_value) { + if (index >= int(__testlib_argv.size())) { + return default_value; + } + return opt(index); +} + +/** + * Return the raw string value of an argv by a given index. If the index is + * bigger than the number of argv, return the given default_value. + */ +std::string opt(int index, const std::string &default_value) { + return opt(index, default_value); +} + +template +T opt(std::false_type is_floating_point, const std::string &key); + +template<> +std::string opt(std::false_type /*is_floating_point*/, const std::string &key) { + return __testlib_keyToOpts(key); +} + +template +T opt(std::true_type /*is_integral*/, const std::string &key) { + return T(optValueToLongDouble(__testlib_keyToOpts(key))); +} + +template +T opt(std::false_type /*is_integral*/, U, const std::string &key) { + return opt(std::is_floating_point(), key); +} + +template +T opt(std::true_type /*is_integral*/, std::false_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), false); +} + +template +T opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + return optValueToIntegral(__testlib_keyToOpts(key), true); +} + +template<> +bool opt(std::true_type /*is_integral*/, std::true_type /*is_unsigned*/, const std::string &key) { + if (!has_opt(key)) + return false; + std::string value = __testlib_keyToOpts(key); + if (value == "true" || value == "1") + return true; + if (value == "false" || value == "0") + return false; + __testlib_fail("Opts: key '" + compress(key) + "': expected bool true/false or 0/1 but '" + + compress(value) + "' found"); +} + +/** + * Return the parsed opt by a given key. + */ +template +T opt(const std::string &key) { + return opt(std::is_integral(), std::is_unsigned(), key); +} + +/** + * Return the raw string value of an opt by a given key + */ +std::string opt(const std::string &key) { + return opt(key); +} + +/* Scorer started. */ + +enum TestResultVerdict { + SKIPPED, + OK, + WRONG_ANSWER, + RUNTIME_ERROR, + TIME_LIMIT_EXCEEDED, + IDLENESS_LIMIT_EXCEEDED, + MEMORY_LIMIT_EXCEEDED, + COMPILATION_ERROR, + CRASHED, + FAILED +}; + +std::string serializeVerdict(TestResultVerdict verdict) { + switch (verdict) { + case SKIPPED: return "SKIPPED"; + case OK: return "OK"; + case WRONG_ANSWER: return "WRONG_ANSWER"; + case RUNTIME_ERROR: return "RUNTIME_ERROR"; + case TIME_LIMIT_EXCEEDED: return "TIME_LIMIT_EXCEEDED"; + case IDLENESS_LIMIT_EXCEEDED: return "IDLENESS_LIMIT_EXCEEDED"; + case MEMORY_LIMIT_EXCEEDED: return "MEMORY_LIMIT_EXCEEDED"; + case COMPILATION_ERROR: return "COMPILATION_ERROR"; + case CRASHED: return "CRASHED"; + case FAILED: return "FAILED"; + } + throw "Unexpected verdict"; +} + +TestResultVerdict deserializeTestResultVerdict(std::string s) { + if (s == "SKIPPED") + return SKIPPED; + else if (s == "OK") + return OK; + else if (s == "WRONG_ANSWER") + return WRONG_ANSWER; + else if (s == "RUNTIME_ERROR") + return RUNTIME_ERROR; + else if (s == "TIME_LIMIT_EXCEEDED") + return TIME_LIMIT_EXCEEDED; + else if (s == "IDLENESS_LIMIT_EXCEEDED") + return IDLENESS_LIMIT_EXCEEDED; + else if (s == "MEMORY_LIMIT_EXCEEDED") + return MEMORY_LIMIT_EXCEEDED; + else if (s == "COMPILATION_ERROR") + return COMPILATION_ERROR; + else if (s == "CRASHED") + return CRASHED; + else if (s == "FAILED") + return FAILED; + ensuref(false, "Unexpected serialized TestResultVerdict"); + // No return actually. + return FAILED; +} + +struct TestResult { + int testIndex; + std::string testset; + std::string group; + TestResultVerdict verdict; + double points; + long long timeConsumed; + long long memoryConsumed; + std::string input; + std::string output; + std::string answer; + int exitCode; + std::string checkerComment; +}; + +std::string serializePoints(double points) { + if (std::isnan(points)) + return ""; + else { + char c[64]; + sprintf(c, "%.03lf", points); + return c; + } +} + +double deserializePoints(std::string s) { + if (s.empty()) + return std::numeric_limits::quiet_NaN(); + else { + double result; + ensuref(sscanf(s.c_str(), "%lf", &result) == 1, "Invalid serialized points"); + return result; + } +} + +std::string escapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\r') + continue; + if (s[i] == '\n') { + result += "\\n"; + continue; + } + if (s[i] == '\\' || s[i] == ';') + result += '\\'; + result += s[i]; + } + return result; +} + +std::string unescapeTestResultString(std::string s) { + std::string result; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\' && i + 1 < s.length()) { + if (s[i + 1] == 'n') { + result += '\n'; + i++; + continue; + } else if (s[i + 1] == ';' || s[i + 1] == '\\') { + result += s[i + 1]; + i++; + continue; + } + } + result += s[i]; + } + return result; +} + +std::string serializeTestResult(TestResult tr) { + std::string result; + result += std::to_string(tr.testIndex); + result += ";"; + result += escapeTestResultString(tr.testset); + result += ";"; + result += escapeTestResultString(tr.group); + result += ";"; + result += serializeVerdict(tr.verdict); + result += ";"; + result += serializePoints(tr.points); + result += ";"; + result += std::to_string(tr.timeConsumed); + result += ";"; + result += std::to_string(tr.memoryConsumed); + result += ";"; + result += escapeTestResultString(tr.input); + result += ";"; + result += escapeTestResultString(tr.output); + result += ";"; + result += escapeTestResultString(tr.answer); + result += ";"; + result += std::to_string(tr.exitCode); + result += ";"; + result += escapeTestResultString(tr.checkerComment); + return result; +} + +TestResult deserializeTestResult(std::string s) { + std::vector items; + std::string t; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] == '\\') { + t += s[i]; + if (i + 1 < s.length()) + t += s[i + 1]; + i++; + continue; + } else { + if (s[i] == ';') { + items.push_back(t); + t = ""; + } else + t += s[i]; + } + } + items.push_back(t); + + ensuref(items.size() == 12, "Invalid TestResult serialization: expected exactly 12 items"); + + TestResult tr; + size_t pos = 0; + tr.testIndex = stoi(items[pos++]); + tr.testset = unescapeTestResultString(items[pos++]); + tr.group = unescapeTestResultString(items[pos++]); + tr.verdict = deserializeTestResultVerdict(items[pos++]); + tr.points = deserializePoints(items[pos++]); + tr.timeConsumed = stoll(items[pos++]); + tr.memoryConsumed = stoll(items[pos++]); + tr.input = unescapeTestResultString(items[pos++]); + tr.output = unescapeTestResultString(items[pos++]); + tr.answer = unescapeTestResultString(items[pos++]); + tr.exitCode = stoi(items[pos++]); + tr.checkerComment = unescapeTestResultString(items[pos++]); + + return tr; +} + +std::vector readTestResults(std::string fileName) { + std::ifstream stream; + stream.open(fileName.c_str(), std::ios::in); + ensuref(stream.is_open(), "Can't read test results file '%s'", fileName.c_str()); + std::vector result; + std::string line; + while (getline(stream, line)) + if (!line.empty()) + result.push_back(deserializeTestResult(line)); + stream.close(); + return result; +} + +std::function)> __testlib_scorer; + +struct TestlibScorerGuard { + ~TestlibScorerGuard() { + if (testlibMode == _scorer) { + std::vector testResults; + while (!inf.eof()) { + std::string line = inf.readLine(); + if (!line.empty()) + testResults.push_back(deserializeTestResult(line)); + } + inf.readEof(); + printf("%.3f\n", __testlib_scorer(testResults)); + } + } +} __testlib_scorer_guard; + +void registerScorer(int argc, char *argv[], std::function)> scorer) { + /* Supress unused. */ + (void)(argc), (void)(argv); + + __testlib_ensuresPreconditions(); + + testlibMode = _scorer; + __testlib_set_binary(stdin); + + inf.init(stdin, _input); + inf.strict = false; + + __testlib_scorer = scorer; +} + +/* Scorer ended. */ + +/** + * Return the parsed opt by a given key. If no opts with the given key are + * found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +template +T opt(const std::string &key, const T &default_value) { + if (!has_opt(key)) { + return default_value; + } + return opt(key); +} + +/** + * Return the raw string value of an opt by a given key. If no opts with the + * given key are found, return the given default_value. + * + * By calling this function, automatic ensurement for no unused opts will be + * done when the program is finalized. Call suppressEnsureNoUnusedOpts() to + * turn it off. + */ +std::string opt(const std::string &key, const std::string &default_value) { + return opt(key, default_value); +} + +/** + * Check if all opts are used. If not, __testlib_fail is called. + * Should be used after calling all opt() function calls. + * + * This function is useful when opt() with default_value for checking typos + * in the opt's key. + */ +void ensureNoUnusedOpts() { + for (const auto &opt: __testlib_opts) { + if (!opt.second.used) { + __testlib_fail(format("Opts: unused key '%s'", compress(opt.first).c_str())); + } + } +} + +void suppressEnsureNoUnusedOpts() { + __testlib_ensureNoUnusedOptsSuppressed = true; +} + +void TestlibFinalizeGuard::autoEnsureNoUnusedOpts() { + if (__testlib_ensureNoUnusedOptsFlag && !__testlib_ensureNoUnusedOptsSuppressed) { + ensureNoUnusedOpts(); + } +} + +TestlibFinalizeGuard testlibFinalizeGuard; + +#endif +#endif diff --git a/ICPC/swerc2022_L/data.zip b/ICPC/swerc2022_L/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..677ba2148910d47fd50a031530601290a931d58e --- /dev/null +++ b/ICPC/swerc2022_L/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd0dfba74cd2bd7fafdf9b5828bf9ebf45093c8eb1b9015f2038e0cbdb2186b4 +size 37213 diff --git a/ICPC/swerc2022_L/init.yml b/ICPC/swerc2022_L/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..37a32bb8eee95d9711911e5bb42e74a7f6efe5c0 --- /dev/null +++ b/ICPC/swerc2022_L/init.yml @@ -0,0 +1,134 @@ +archive: data.zip +test_cases: +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 +- in: 31.in + out: 31.ans + points: 1 +- in: 32.in + out: 32.ans + points: 1 +- in: 33.in + out: 33.ans + points: 1 +- in: 34.in + out: 34.ans + points: 1 +- in: 35.in + out: 35.ans + points: 1 +- in: 36.in + out: 36.ans + points: 1 +- in: 37.in + out: 37.ans + points: 1 +- in: 38.in + out: 38.ans + points: 1 +- in: 39.in + out: 39.ans + points: 1 +- in: 40.in + out: 40.ans + points: 1 +- in: 41.in + out: 41.ans + points: 1 +- in: 42.in + out: 42.ans + points: 1 +- in: 43.in + out: 43.ans + points: 1 +- in: 44.in + out: 44.ans + points: 1 +- in: 45.in + out: 45.ans + points: 1 +- in: 46.in + out: 46.ans + points: 1 +- in: 47.in + out: 47.ans + points: 1 +- in: 48.in + out: 48.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 +- in: 9.in + out: 9.ans + points: 1 diff --git a/ICPC/swerc2023_A/data.zip b/ICPC/swerc2023_A/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..15c11c5be3fca48f73c77b52ae9853c82ba15f1b --- /dev/null +++ b/ICPC/swerc2023_A/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75c5e5877aebb05b244f9041f6bc4021e2cb21444091d858137820ec272e5e65 +size 300129 diff --git a/ICPC/swerc2023_A/init.yml b/ICPC/swerc2023_A/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3f637e08878fa66196595aa3f36e0176b1347de2 --- /dev/null +++ b/ICPC/swerc2023_A/init.yml @@ -0,0 +1,69 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 diff --git a/ICPC/swerc2023_B/data.zip b/ICPC/swerc2023_B/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..2758141a6f90a73f792d34eb03a7f96d092b83d8 --- /dev/null +++ b/ICPC/swerc2023_B/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48fe1ebf130532d47fb1fd455ef922478aa1ddafc68310f5f71e7c52d26b9424 +size 42408 diff --git a/ICPC/swerc2023_B/init.yml b/ICPC/swerc2023_B/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2a423416224d676079ff1d0055863634e0300969 --- /dev/null +++ b/ICPC/swerc2023_B/init.yml @@ -0,0 +1,48 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 diff --git a/ICPC/swerc2023_C/data.zip b/ICPC/swerc2023_C/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..6bb84a628283f09584abfeadcbdb6c222cbe3561 --- /dev/null +++ b/ICPC/swerc2023_C/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c9fef46ed2ec84a28c703c743af48dd58bbdc9eef651255ee9d0163dfe15526 +size 8477 diff --git a/ICPC/swerc2023_C/init.yml b/ICPC/swerc2023_C/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..cab4f39105f52de88770b2a1deda59ed3f28cbdd --- /dev/null +++ b/ICPC/swerc2023_C/init.yml @@ -0,0 +1,67 @@ +archive: data.zip +checker: + args: + precision: 4 + name: floats +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 diff --git a/ICPC/swerc2023_D/data.zip b/ICPC/swerc2023_D/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..fad1b4654a19b16e7c81a62b490743d24be0a47a --- /dev/null +++ b/ICPC/swerc2023_D/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df36472a0ab2206b4814b10e094b085ccd300755a25ae1421ffe501026b8341b +size 2926563 diff --git a/ICPC/swerc2023_D/init.yml b/ICPC/swerc2023_D/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..81fbb4275bf016d203d7f9eeeea8b1d1adb26a63 --- /dev/null +++ b/ICPC/swerc2023_D/init.yml @@ -0,0 +1,54 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 diff --git a/ICPC/swerc2023_E/data.zip b/ICPC/swerc2023_E/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..b8f1f1a9ab893a006c284f5114e4db989d3d74b4 --- /dev/null +++ b/ICPC/swerc2023_E/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d12f4291a798fb2fba0c3e96611a346f157311f918aeb0c9247751f282176cf +size 1514898 diff --git a/ICPC/swerc2023_E/init.yml b/ICPC/swerc2023_E/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2a423416224d676079ff1d0055863634e0300969 --- /dev/null +++ b/ICPC/swerc2023_E/init.yml @@ -0,0 +1,48 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 diff --git a/ICPC/swerc2023_F/data.zip b/ICPC/swerc2023_F/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..ff9928839f4018917d925185afd0deca68e7e3c4 --- /dev/null +++ b/ICPC/swerc2023_F/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:542d0236273aa7bbee60c512aef2e21c2fab43d84dea62773cde7b0fdbabffb8 +size 4139533 diff --git a/ICPC/swerc2023_F/init.yml b/ICPC/swerc2023_F/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..879545a58b26edc00459c29c058348ef61888892 --- /dev/null +++ b/ICPC/swerc2023_F/init.yml @@ -0,0 +1,87 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 diff --git a/ICPC/swerc2023_G/data.zip b/ICPC/swerc2023_G/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..2569fe7bf42c5daddf5ec7fa14d871a90d8b26ce --- /dev/null +++ b/ICPC/swerc2023_G/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:725e7f3feaad499b3bbbf1ee22a4cc82cb20a3219bcf4f893a4013d15deb3320 +size 42250973 diff --git a/ICPC/swerc2023_G/init.yml b/ICPC/swerc2023_G/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..af6134a203a7da86757ce784301800b68db4be01 --- /dev/null +++ b/ICPC/swerc2023_G/init.yml @@ -0,0 +1,60 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 diff --git a/ICPC/swerc2023_H/data.zip b/ICPC/swerc2023_H/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..bca4c03549506ff88fee5d748490ca1afff34e24 --- /dev/null +++ b/ICPC/swerc2023_H/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acec489602a7656997844e18d1c72db4d284aa3c00cb7f1817991833619c2131 +size 789248 diff --git a/ICPC/swerc2023_H/init.yml b/ICPC/swerc2023_H/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2a423416224d676079ff1d0055863634e0300969 --- /dev/null +++ b/ICPC/swerc2023_H/init.yml @@ -0,0 +1,48 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 diff --git a/ICPC/swerc2023_I/data.zip b/ICPC/swerc2023_I/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..eeaedca1fe887fe3ccbb10648399fbcbeb718b15 --- /dev/null +++ b/ICPC/swerc2023_I/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8da8d5827cd22c60ab2ae0ef85ec1b4da9c90e61705d2e48f431d1edf96a775 +size 2870817 diff --git a/ICPC/swerc2023_I/init.yml b/ICPC/swerc2023_I/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..0a3eafe39a9fb6f9eb98ef74fb1a06a90df7d025 --- /dev/null +++ b/ICPC/swerc2023_I/init.yml @@ -0,0 +1,93 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 diff --git a/ICPC/swerc2023_J/data.zip b/ICPC/swerc2023_J/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..36bbd78c72e6943e071a3bf07b5c348a0b44b156 --- /dev/null +++ b/ICPC/swerc2023_J/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97cad70ef347ea48e1ffae204bf7fd72599462ebcb345b0ea3ad932bf2b35644 +size 7837168 diff --git a/ICPC/swerc2023_J/init.yml b/ICPC/swerc2023_J/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b915c1e85248f00a2c6693b5c23f5a9cb605ee37 --- /dev/null +++ b/ICPC/swerc2023_J/init.yml @@ -0,0 +1,126 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 +- in: 28.in + out: 28.ans + points: 1 +- in: 29.in + out: 29.ans + points: 1 +- in: 30.in + out: 30.ans + points: 1 +- in: 31.in + out: 31.ans + points: 1 +- in: 32.in + out: 32.ans + points: 1 +- in: 33.in + out: 33.ans + points: 1 +- in: 34.in + out: 34.ans + points: 1 +- in: 35.in + out: 35.ans + points: 1 +- in: 36.in + out: 36.ans + points: 1 +- in: 37.in + out: 37.ans + points: 1 +- in: 38.in + out: 38.ans + points: 1 +- in: 39.in + out: 39.ans + points: 1 +- in: 40.in + out: 40.ans + points: 1 +- in: 41.in + out: 41.ans + points: 1 diff --git a/ICPC/swerc2023_K/data.zip b/ICPC/swerc2023_K/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..1b7c9dba73d8524b49944318fa729b6118c140a0 --- /dev/null +++ b/ICPC/swerc2023_K/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:283cc72d0ce8c0b7a2f47b792c075ec8efb49ee51a3504d154bfc170464b35e4 +size 90879599 diff --git a/ICPC/swerc2023_K/init.yml b/ICPC/swerc2023_K/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f1875f48d194acda013c8ab23d9caea9666a0f67 --- /dev/null +++ b/ICPC/swerc2023_K/init.yml @@ -0,0 +1,27 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 1.in + out: 1.ans + points: 1 +- in: 2.in + out: 2.ans + points: 1 +- in: 3.in + out: 3.ans + points: 1 +- in: 4.in + out: 4.ans + points: 1 +- in: 5.in + out: 5.ans + points: 1 +- in: 6.in + out: 6.ans + points: 1 +- in: 7.in + out: 7.ans + points: 1 +- in: 8.in + out: 8.ans + points: 1 diff --git a/ICPC/swerc2023_L/data.zip b/ICPC/swerc2023_L/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..7c279b860db65a982a2baa2a680e9701f514e8d1 --- /dev/null +++ b/ICPC/swerc2023_L/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2e799a4a486cdc8d9d9aabfafa3c2a12b5c93ad2e1d23506f3afdb4cc9aead9 +size 619480 diff --git a/ICPC/swerc2023_M/data.zip b/ICPC/swerc2023_M/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..0e8a2b49146254a7936403a9022395c88056cbdf --- /dev/null +++ b/ICPC/swerc2023_M/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4803e78093c06b3ae9e72243b5ff9e196c5e8f36c2606235e6f719f8151433e6 +size 15520576 diff --git a/ICPC/swerc2023_M/init.yml b/ICPC/swerc2023_M/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..637c9daccfc09a3f2d58451c9b58934472edc309 --- /dev/null +++ b/ICPC/swerc2023_M/init.yml @@ -0,0 +1,84 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: 01.in + out: 01.ans + points: 1 +- in: 02.in + out: 02.ans + points: 1 +- in: 03.in + out: 03.ans + points: 1 +- in: 04.in + out: 04.ans + points: 1 +- in: 05.in + out: 05.ans + points: 1 +- in: 06.in + out: 06.ans + points: 1 +- in: 07.in + out: 07.ans + points: 1 +- in: 08.in + out: 08.ans + points: 1 +- in: 09.in + out: 09.ans + points: 1 +- in: 10.in + out: 10.ans + points: 1 +- in: 11.in + out: 11.ans + points: 1 +- in: 12.in + out: 12.ans + points: 1 +- in: 13.in + out: 13.ans + points: 1 +- in: 14.in + out: 14.ans + points: 1 +- in: 15.in + out: 15.ans + points: 1 +- in: 16.in + out: 16.ans + points: 1 +- in: 17.in + out: 17.ans + points: 1 +- in: 18.in + out: 18.ans + points: 1 +- in: 19.in + out: 19.ans + points: 1 +- in: 20.in + out: 20.ans + points: 1 +- in: 21.in + out: 21.ans + points: 1 +- in: 22.in + out: 22.ans + points: 1 +- in: 23.in + out: 23.ans + points: 1 +- in: 24.in + out: 24.ans + points: 1 +- in: 25.in + out: 25.ans + points: 1 +- in: 26.in + out: 26.ans + points: 1 +- in: 27.in + out: 27.ans + points: 1 diff --git a/ICPC/swerc2024_A/data.zip b/ICPC/swerc2024_A/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..9eeff1f910667cb200504c5cb3f26a84a93b3ed5 --- /dev/null +++ b/ICPC/swerc2024_A/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45c669f336da71cdeafb81d76e29af5a422cc3eab3353161f0b5996daf4832f3 +size 54168139 diff --git a/ICPC/swerc2024_A/init.yml b/ICPC/swerc2024_A/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e4c4f0039c848e7442a302a1d2c776c34a5b9b69 --- /dev/null +++ b/ICPC/swerc2024_A/init.yml @@ -0,0 +1,81 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: test_1.in + out: test_1.ans + points: 1 +- in: test_10.in + out: test_10.ans + points: 1 +- in: test_11.in + out: test_11.ans + points: 1 +- in: test_12.in + out: test_12.ans + points: 1 +- in: test_13.in + out: test_13.ans + points: 1 +- in: test_14.in + out: test_14.ans + points: 1 +- in: test_15.in + out: test_15.ans + points: 1 +- in: test_16.in + out: test_16.ans + points: 1 +- in: test_17.in + out: test_17.ans + points: 1 +- in: test_18.in + out: test_18.ans + points: 1 +- in: test_19.in + out: test_19.ans + points: 1 +- in: test_2.in + out: test_2.ans + points: 1 +- in: test_20.in + out: test_20.ans + points: 1 +- in: test_21.in + out: test_21.ans + points: 1 +- in: test_22.in + out: test_22.ans + points: 1 +- in: test_23.in + out: test_23.ans + points: 1 +- in: test_24.in + out: test_24.ans + points: 1 +- in: test_25.in + out: test_25.ans + points: 1 +- in: test_26.in + out: test_26.ans + points: 1 +- in: test_3.in + out: test_3.ans + points: 1 +- in: test_4.in + out: test_4.ans + points: 1 +- in: test_5.in + out: test_5.ans + points: 1 +- in: test_6.in + out: test_6.ans + points: 1 +- in: test_7.in + out: test_7.ans + points: 1 +- in: test_8.in + out: test_8.ans + points: 1 +- in: test_9.in + out: test_9.ans + points: 1 diff --git a/ICPC/swerc2024_B/data.zip b/ICPC/swerc2024_B/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..f6cd05d95316efb5266006fe218444b5716efea6 --- /dev/null +++ b/ICPC/swerc2024_B/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:400b071b16f9221cf62923dc766de9b179e9957f4b7c75249cadd3957a4bd6a1 +size 136158 diff --git a/ICPC/swerc2024_B/init.yml b/ICPC/swerc2024_B/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e26fb976d2ab8930252af526d5923c1d70115324 --- /dev/null +++ b/ICPC/swerc2024_B/init.yml @@ -0,0 +1,77 @@ +archive: data.zip +checker: + args: + files: + - output_validators/validator/validate.h + - output_validators/validator/validator.cpp + lang: CPP17 + type: default + name: bridged +output_limit_length: 104857600 +test_cases: +- in: cornercase01.in + out: cornercase01.ans + points: 1 +- in: cornercase02.in + out: cornercase02.ans + points: 1 +- in: cornercase03.in + out: cornercase03.ans + points: 1 +- in: cornercase04.in + out: cornercase04.ans + points: 1 +- in: cornercase05.in + out: cornercase05.ans + points: 1 +- in: large_5000_20_01.in + out: large_5000_20_01.ans + points: 1 +- in: large_5000_20_02.in + out: large_5000_20_02.ans + points: 1 +- in: largeimbalanced04.in + out: largeimbalanced04.ans + points: 1 +- in: largeimbalanced06.in + out: largeimbalanced06.ans + points: 1 +- in: largeimbalanced07.in + out: largeimbalanced07.ans + points: 1 +- in: largeimbalanced_5000_20_01.in + out: largeimbalanced_5000_20_01.ans + points: 1 +- in: largeimbalanced_5000_20_02.in + out: largeimbalanced_5000_20_02.ans + points: 1 +- in: largeimbalanced_middle_5000_20_01.in + out: largeimbalanced_middle_5000_20_01.ans + points: 1 +- in: largeimbalanced_middle_5000_20_02.in + out: largeimbalanced_middle_5000_20_02.ans + points: 1 +- in: medium01.in + out: medium01.ans + points: 1 +- in: medium02.in + out: medium02.ans + points: 1 +- in: medium03.in + out: medium03.ans + points: 1 +- in: medium04.in + out: medium04.ans + points: 1 +- in: medium05.in + out: medium05.ans + points: 1 +- in: medium06.in + out: medium06.ans + points: 1 +- in: small01.in + out: small01.ans + points: 1 +- in: small02.in + out: small02.ans + points: 1 diff --git a/ICPC/swerc2024_B/output_validators/validator/validate.h b/ICPC/swerc2024_B/output_validators/validator/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..40d868802055ef0fd4a26503e6641a4a50941d2c --- /dev/null +++ b/ICPC/swerc2024_B/output_validators/validator/validate.h @@ -0,0 +1,157 @@ +// Taken from: https://ncpc.idi.ntnu.no/ncpc2017/ncpc2017-packages.tar.bz2 +// Licence is Creative Commons BY-SA v3.0 + +/* Utility functions for writing output validators for the Kattis + * problem format. + * + * The primary functions and variables available are the following. + * In many cases, the only functions needed are "init_io", + * "wrong_answer", and "accept". + * + * - init_io(argc, argv): + * initialization + * + * - judge_in, judge_ans, author_out: + * std::istream objects for judge input file, judge answer + * file, and submission output file. + * + * - accept(): + * exit and give Accepted! + * + * - accept_with_score(double score): + * exit with Accepted and give a score (for scoring problems) + * + * - judge_message(std::string msg, ...): + * printf-style function for emitting a judge message (a + * message that gets displayed to a privileged user with access + * to secret data etc). + * + * - wrong_answer(std::string msg, ...): + * printf-style function for exitting and giving Wrong Answer, + * and emitting a judge message (which would typically explain + * the cause of the Wrong Answer) + * + * - judge_error(std::string msg, ...): + * printf-style function for exitting and giving Judge Error, + * and emitting a judge message (which would typically explain + * the cause of the Judge Error) + * + * - author_message(std::string msg, ...): + * printf-style function for emitting an author message (a + * message that gets displayed to the author of the + * submission). (Use with caution, and be careful not to let + * it leak information!) + * + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +typedef void (*feedback_function)(const std::string &, ...); + +const int EXITCODE_AC = 42; +const int EXITCODE_WA = 43; +const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt"; +const std::string FILENAME_JUDGE_MESSAGE = "null"; +const std::string FILENAME_JUDGE_ERROR = "judgeerror.txt"; +const std::string FILENAME_SCORE = "score.txt"; + +#define USAGE "%s: judge_in judge_ans feedback_dir < author_out\n" + +std::ifstream judge_in, judge_ans; +std::istream author_out(std::cin.rdbuf()); + +char *feedbackdir = NULL; + +void vreport_feedback(const std::string &category, + const std::string &msg, + va_list pvar) { + std::ostringstream fname; + if (feedbackdir) + fname << feedbackdir << '/'; + fname << category; + FILE *f = fopen(fname.str().c_str(), "a"); + assert(f); + vfprintf(f, msg.c_str(), pvar); + fclose(f); +} + +void report_feedback(const std::string &category, const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(category, msg, pvar); +} + +void author_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_AUTHOR_MESSAGE, msg, pvar); +} + +void judge_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); +} + +void wrong_answer(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); + exit(EXITCODE_WA); +} + +void judge_error(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_ERROR, msg, pvar); + assert(0); +} + +void accept() { + exit(EXITCODE_AC); +} + +void accept_with_score(double scorevalue) { + report_feedback(FILENAME_SCORE, "%.9le", scorevalue); + exit(EXITCODE_AC); +} + + +bool is_directory(const char *path) { +if(std::string(path) == std::string("/dev")) return 1; + struct stat entry; + return stat(path, &entry) == 0 && S_ISDIR(entry.st_mode); +} + +void init_io(int argc, char **argv) { + if(argc < 4) { + fprintf(stderr, USAGE, argv[0]); + judge_error("Usage: %s judgein judgeans feedbackdir [opts] < userout", argv[0]); + } + + // Set up feedbackdir first, as that allows us to produce feedback + // files for errors in the other parameters. + if (!is_directory(argv[3])) { + judge_error("%s: %s is not a directory\n", argv[0], argv[3]); + } + feedbackdir = argv[3]; + + judge_in.open(argv[1], std::ios_base::in); + if (judge_in.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[1]); + } + + judge_ans.open(argv[2], std::ios_base::in); + if (judge_ans.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[2]); + } + + author_out.rdbuf(std::cin.rdbuf()); +} \ No newline at end of file diff --git a/ICPC/swerc2024_B/output_validators/validator/validator.cpp b/ICPC/swerc2024_B/output_validators/validator/validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a7ae8f7eaba19df475751bfd7271cc1afff4d74 --- /dev/null +++ b/ICPC/swerc2024_B/output_validators/validator/validator.cpp @@ -0,0 +1,98 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +// usage: ./a.out input_file correct_output output_dir < contestants_output +// See specification there: +// http://www.problemarchive.org/wiki/index.php/Output_validator + +#include +#include +#include +#include +#include "validate.h" +#include +#include +#include +#include + +using namespace std; +int main(int argc, char **argv) { + init_io(argc, argv); + + int N; + int K; + judge_in >> N; + judge_in >> K; + vector D; + for (int i = 0; i < N; i++) { + int64_t d; + judge_in >> d; + D.push_back(d); + } + assert(N > 0); + const int64_t max_input_day = *max_element(D.begin(), D.end()); + int64_t judge_cost = 0; + for (int i = 0; i < N; i++) { + int64_t d; + judge_ans >> d; + assert(d >= D[i]); + judge_cost += (d - D[i]) * (d - D[i]); + } + int64_t author_cost = 0; + set author_days; + for (int i = 0; i < N; i++) { + int64_t d; + if (!(author_out >> d)) { + wrong_answer("Wrong answer (probably too short at index %d)\n", i); + } + if (d < 0) { + wrong_answer("Wrong answer: negative day %" PRId64 "\n", d); + } + if (d < D[i]) { + wrong_answer("Wrong answer: delivering gift too early %" PRId64 " < %" PRId64 "\n", + d, D[i]); + } + if (d > max_input_day) { + // This prevents a possible overflow when computing (d - D[i])^2 below. + wrong_answer("Wrong answer: delivering gift in day %" PRId64 " > %" PRId64 " is never optimal\n", + d, max_input_day); + } + author_days.insert(d); + author_cost += (d - D[i]) * (d - D[i]); + } + + if (author_days.size() > K) { + wrong_answer("Invalid answer: Too many different days used"); + } + + if (author_cost != judge_cost) { + wrong_answer("Invalid answer: author cost %" PRId64 " != judge cost %" PRId64 "\n", + author_cost, judge_cost); + } + accept(); +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2024_C/data.zip b/ICPC/swerc2024_C/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..6554195100db8ee02599f2d9d930a302e261645c --- /dev/null +++ b/ICPC/swerc2024_C/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f72be314556f9132d56f8c9437092abc05021f71b953611330761f5c991aa46e +size 9427 diff --git a/ICPC/swerc2024_C/init.yml b/ICPC/swerc2024_C/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9f9c34ef4c2c318c2a2e2ab972d9cf29bd870fee --- /dev/null +++ b/ICPC/swerc2024_C/init.yml @@ -0,0 +1,120 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: blocks01.in + out: blocks01.ans + points: 1 +- in: blocks02.in + out: blocks02.ans + points: 1 +- in: blocks03.in + out: blocks03.ans + points: 1 +- in: blocks04.in + out: blocks04.ans + points: 1 +- in: blocks05.in + out: blocks05.ans + points: 1 +- in: blocks06.in + out: blocks06.ans + points: 1 +- in: blocks07.in + out: blocks07.ans + points: 1 +- in: blocks08.in + out: blocks08.ans + points: 1 +- in: diff01.in + out: diff01.ans + points: 1 +- in: diff02.in + out: diff02.ans + points: 1 +- in: diff03.in + out: diff03.ans + points: 1 +- in: diff04.in + out: diff04.ans + points: 1 +- in: diff05.in + out: diff05.ans + points: 1 +- in: diff06.in + out: diff06.ans + points: 1 +- in: diff07.in + out: diff07.ans + points: 1 +- in: diff08.in + out: diff08.ans + points: 1 +- in: diff09.in + out: diff09.ans + points: 1 +- in: diff10.in + out: diff10.ans + points: 1 +- in: diff11.in + out: diff11.ans + points: 1 +- in: diff12.in + out: diff12.ans + points: 1 +- in: diff13.in + out: diff13.ans + points: 1 +- in: diff14.in + out: diff14.ans + points: 1 +- in: many_glob01.in + out: many_glob01.ans + points: 1 +- in: many_glob02.in + out: many_glob02.ans + points: 1 +- in: many_glob03.in + out: many_glob03.ans + points: 1 +- in: many_glob04.in + out: many_glob04.ans + points: 1 +- in: many_glob05.in + out: many_glob05.ans + points: 1 +- in: many_glob06.in + out: many_glob06.ans + points: 1 +- in: many_glob07.in + out: many_glob07.ans + points: 1 +- in: many_glob08.in + out: many_glob08.ans + points: 1 +- in: many_glob09.in + out: many_glob09.ans + points: 1 +- in: many_glob10.in + out: many_glob10.ans + points: 1 +- in: small01.in + out: small01.ans + points: 1 +- in: small02.in + out: small02.ans + points: 1 +- in: small03.in + out: small03.ans + points: 1 +- in: small04.in + out: small04.ans + points: 1 +- in: small05.in + out: small05.ans + points: 1 +- in: small06.in + out: small06.ans + points: 1 +- in: small07.in + out: small07.ans + points: 1 diff --git a/ICPC/swerc2024_D/data.zip b/ICPC/swerc2024_D/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..df0f1c9d95b6eb7d2c54c39a402e29502432350a --- /dev/null +++ b/ICPC/swerc2024_D/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b985cbb3eaa1fbaebed69ef28e2215ff1f8e5d8db2d60f958055f340d02e8a42 +size 2875660 diff --git a/ICPC/swerc2024_D/init.yml b/ICPC/swerc2024_D/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..13576182fc83d53fee976c55417da2556592ea22 --- /dev/null +++ b/ICPC/swerc2024_D/init.yml @@ -0,0 +1,21 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: test02.in + out: test02.ans + points: 1 +- in: test03.in + out: test03.ans + points: 1 +- in: test04.in + out: test04.ans + points: 1 +- in: test05.in + out: test05.ans + points: 1 +- in: test06.in + out: test06.ans + points: 1 +- in: test07.in + out: test07.ans + points: 1 diff --git a/ICPC/swerc2024_E/data.zip b/ICPC/swerc2024_E/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..ddf5c3981b73e17fd116b4e0aea30ce060aae35d --- /dev/null +++ b/ICPC/swerc2024_E/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:462206fde59f278b7d8dc4930853e58f305bc1ce72b599b605dc6cf685dbd8f6 +size 161911 diff --git a/ICPC/swerc2024_E/init.yml b/ICPC/swerc2024_E/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..0c487adc48fae6198f357ba1d4321a45d4b4cb08 --- /dev/null +++ b/ICPC/swerc2024_E/init.yml @@ -0,0 +1,56 @@ +archive: data.zip +checker: + args: + files: + - output_validators/pointoutpolygon_validator/validate.cpp + - output_validators/pointoutpolygon_validator/validate.h + lang: CPP17 + type: default + name: bridged +output_limit_length: 104857600 +test_cases: +- in: frame01.in + out: frame01.ans + points: 1 +- in: frame02.in + out: frame02.ans + points: 1 +- in: frame03.in + out: frame03.ans + points: 1 +- in: frame04.in + out: frame04.ans + points: 1 +- in: line01.in + out: line01.ans + points: 1 +- in: line02.in + out: line02.ans + points: 1 +- in: line03.in + out: line03.ans + points: 1 +- in: line04.in + out: line04.ans + points: 1 +- in: line05.in + out: line05.ans + points: 1 +- in: line06.in + out: line06.ans + points: 1 +- in: line07.in + out: line07.ans + points: 1 +- in: line08.in + out: line08.ans + points: 1 +- in: random01.in + out: random01.ans + points: 1 +- in: random02.in + out: random02.ans + points: 1 +- in: random03.in + out: random03.ans + points: 1 diff --git a/ICPC/swerc2024_E/output_validators/pointoutpolygon_validator/validate.cpp b/ICPC/swerc2024_E/output_validators/pointoutpolygon_validator/validate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6555d911037cf8e209e7ebfe614d75871187b017 --- /dev/null +++ b/ICPC/swerc2024_E/output_validators/pointoutpolygon_validator/validate.cpp @@ -0,0 +1,158 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validate.h" + +#include +#include +#include +#include +using namespace std; + +typedef long long ll; +typedef complex pt; + +ll dot(pt v, pt w) { return (conj(v) * w).real(); } +ll cross(pt v, pt w) { return (conj(v) * w).imag(); } +ll orient(pt a, pt b, pt c) { return cross(b-a, c-a); } + +bool inDisk(pt a, pt b, pt p) { + return dot(a - p, b - p) <= 0; +} + +bool onSegment(pt a, pt b, pt p) { + return orient(a, b, p) == 0 && inDisk(a, b, p); +} + +bool intersect(pt a, pt b, pt c, pt d) { + __int128_t oa = orient(c,d,a), ob = orient(c,d,b), + oc = orient(a,b,c), od = orient(a,b,d); + return oa * ob < 0 && oc * od < 0; +} + +ll area(vector P) { + ll area = 0; + for (size_t i = 0; i < P.size(); i++) { + area += cross(P[i], P[(i + 1) % P.size()]); + } + return abs(area); +} + +int main(int argc, char **argv) { + init_io(argc, argv); + + size_t N; + if (!(judge_in >> N)) judge_error("Invalid input"); + + vector points(N); + for (size_t i = 0; i < N; i++) { + ll x, y; + if (!(judge_in >> x >> y)) judge_error("Invalid input"); + points[i] = {x, y}; + } + + /* + Constraints: + - [x] K <= 3N + - [x] polygon is simple and non-degenerate: + - [x] no two edges intersect + - [x] each edge does not touch any other edge + - [x] each vertex is unique + - [x] the initial points are all vertices of the polygon + - [x] no integer point is located inside the polygon + - [x] all vertices coordinates are between 1 and 10^9 + */ + + size_t K; + if (!(author_out >> K)) wrong_answer("Malformed output"); + if (K < 3) wrong_answer("Too few vertices"); + if (K > 3 * N) wrong_answer("Too many vertices"); + + vector polygon(K); + for (size_t i = 0; i < K; i++) { + ll x, y; + if (!(author_out >> x >> y)) wrong_answer("Malformed output"); + polygon[i] = {x, y}; + if (!(1 <= x && x <= 1e9) || !(1 <= y && y <= 1e9)) { + wrong_answer("Vertex outside the boundary: (%lld, %lld)", x, y); + } + } + + auto comp = [](const pt& a, const pt& b) { + return pair(a.real(), a.imag()) < pair(b.real(), b.imag()); + }; + + set vertices(comp); + for (size_t i = 0; i < K; i++) { + if (!vertices.insert(polygon[i]).second) { + wrong_answer("Duplicate vertex: (%lld, %lld)", polygon[i].real(), polygon[i].imag()); + } + } + + for (size_t i = 0; i < N; i++) { + if (!vertices.count(points[i])) { + wrong_answer("Missing points: (%lld, %lld)", points[i].real(), points[i].imag()); + } + } + + for (size_t i = 0; i < K; i++) { + for (size_t j = 0; j < K; j++) { + if (i == j) continue; + if (intersect(polygon[i], polygon[(i + 1) % K], polygon[j], polygon[(j + 1) % K])) { + wrong_answer("Intersects itself"); + } + + if ((i + 1) % K == j) continue; + if (onSegment(polygon[i], polygon[(i + 1) % K], polygon[j])) { + wrong_answer("Degenerate polygon"); + } + } + } + + ll boundary = 0; + for (size_t i = 0; i < K; i++) { + pt d = polygon[i] - polygon[(i + 1) % K]; + ll dx = abs(d.real()); + ll dy = abs(d.imag()); + if (dx == 0 || dy == 0) { + boundary += dx + dy; + } else { + boundary += gcd(dx, dy); + } + } + if (boundary - area(polygon) != 2) { + wrong_answer("Integer points inside"); + } + + string trash; + if (author_out >> trash) { + wrong_answer("Malformed output"); + } + + accept(); +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + freopen(argv[2], "r", stdin); + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[3], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2024_E/output_validators/pointoutpolygon_validator/validate.h b/ICPC/swerc2024_E/output_validators/pointoutpolygon_validator/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..d7b30881fe93fc2174e773b07bb0c2d5aa9ea557 --- /dev/null +++ b/ICPC/swerc2024_E/output_validators/pointoutpolygon_validator/validate.h @@ -0,0 +1,158 @@ +// Taken from +// https://github.com/Kattis/problemtools/blob/develop/examples/guess/output_validators/guess_validator/validate.h +// (under MIT License) + +/* Utility functions for writing output validators for the Kattis + * problem format. + * + * The primary functions and variables available are the following. + * In many cases, the only functions needed are "init_io", + * "wrong_answer", and "accept". + * + * - init_io(argc, argv): + * initialization + * + * - judge_in, judge_ans, author_out: + * std::istream objects for judge input file, judge answer + * file, and submission output file. + * + * - accept(): + * exit and give Accepted! + * + * - accept_with_score(double score): + * exit with Accepted and give a score (for scoring problems) + * + * - judge_message(std::string msg, ...): + * printf-style function for emitting a judge message (a + * message that gets displayed to a privileged user with access + * to secret data etc). + * + * - wrong_answer(std::string msg, ...): + * printf-style function for exiting and giving Wrong Answer, + * and emitting a judge message (which would typically explain + * the cause of the Wrong Answer) + * + * - judge_error(std::string msg, ...): + * printf-style function for exiting and giving Judge Error, + * and emitting a judge message (which would typically explain + * the cause of the Judge Error) + * + * - author_message(std::string msg, ...): + * printf-style function for emitting an author message (a + * message that gets displayed to the author of the + * submission). (Use with caution, and be careful not to let + * it leak information!) + * + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +typedef void (*feedback_function)(const std::string &, ...); + +const int EXITCODE_AC = 42; +const int EXITCODE_WA = 43; +const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt"; +const std::string FILENAME_JUDGE_MESSAGE = "null"; +const std::string FILENAME_JUDGE_ERROR = "judgeerror.txt"; +const std::string FILENAME_SCORE = "score.txt"; + +#define USAGE "%s: judge_in judge_ans feedback_dir < author_out\n" + +std::ifstream judge_in, judge_ans; +std::istream author_out(std::cin.rdbuf()); + +char *feedbackdir = NULL; + +void vreport_feedback(const std::string &category, + const std::string &msg, + va_list pvar) { + std::ostringstream fname; + if (feedbackdir) + fname << feedbackdir << '/'; + fname << category; + FILE *f = fopen(fname.str().c_str(), "a"); + assert(f); + vfprintf(f, msg.c_str(), pvar); + fclose(f); +} + +void report_feedback(const std::string &category, const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(category, msg, pvar); +} + +void author_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_AUTHOR_MESSAGE, msg, pvar); +} + +void judge_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); +} + +void wrong_answer(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); + exit(EXITCODE_WA); +} + +void judge_error(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_ERROR, msg, pvar); + assert(0); +} + +void accept() { + exit(EXITCODE_AC); +} + +void accept_with_score(double scorevalue) { + report_feedback(FILENAME_SCORE, "%.9le", scorevalue); + exit(EXITCODE_AC); +} + + +bool is_directory(const char *path) { +if(std::string(path) == std::string("/dev")) return 1; + struct stat entry; + return stat(path, &entry) == 0 && S_ISDIR(entry.st_mode); +} + +void init_io(int argc, char **argv) { + if(argc < 4) { + fprintf(stderr, USAGE, argv[0]); + judge_error("Usage: %s judgein judgeans feedbackdir [opts] < userout", argv[0]); + } + + // Set up feedbackdir first, as that allows us to produce feedback + // files for errors in the other parameters. + if (!is_directory(argv[3])) { + judge_error("%s: %s is not a directory\n", argv[0], argv[3]); + } + feedbackdir = argv[3]; + + judge_in.open(argv[1], std::ios_base::in); + if (judge_in.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[1]); + } + + judge_ans.open(argv[2], std::ios_base::in); + if (judge_ans.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[2]); + } + + author_out.rdbuf(std::cin.rdbuf()); +} \ No newline at end of file diff --git a/ICPC/swerc2024_F/data.zip b/ICPC/swerc2024_F/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..7461de1a30022b562a1156183f32136382e36c86 --- /dev/null +++ b/ICPC/swerc2024_F/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03ec841ae73738589d8fb5d83e742c110312eb4b728a9e4528d685bcdc4286b3 +size 38779468 diff --git a/ICPC/swerc2024_F/init.yml b/ICPC/swerc2024_F/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..8adfc6c236f8d5d8740a1b8cc476254d11fa39e2 --- /dev/null +++ b/ICPC/swerc2024_F/init.yml @@ -0,0 +1,138 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: cornercase01.in + out: cornercase01.ans + points: 1 +- in: cornercase02.in + out: cornercase02.ans + points: 1 +- in: cornercase03.in + out: cornercase03.ans + points: 1 +- in: cornercase04.in + out: cornercase04.ans + points: 1 +- in: cornercase05.in + out: cornercase05.ans + points: 1 +- in: cornercase06.in + out: cornercase06.ans + points: 1 +- in: cornercase07.in + out: cornercase07.ans + points: 1 +- in: cornercase08.in + out: cornercase08.ans + points: 1 +- in: cornercase09.in + out: cornercase09.ans + points: 1 +- in: cornercase_manual_01.in + out: cornercase_manual_01.ans + points: 1 +- in: cornercase_manual_02.in + out: cornercase_manual_02.ans + points: 1 +- in: cornercase_manual_03.in + out: cornercase_manual_03.ans + points: 1 +- in: cornercase_manual_04.in + out: cornercase_manual_04.ans + points: 1 +- in: cornercase_manual_05.in + out: cornercase_manual_05.ans + points: 1 +- in: cornercase_manual_06.in + out: cornercase_manual_06.ans + points: 1 +- in: linear_medium01.in + out: linear_medium01.ans + points: 1 +- in: linear_medium02.in + out: linear_medium02.ans + points: 1 +- in: linear_medium03.in + out: linear_medium03.ans + points: 1 +- in: linear_medium04.in + out: linear_medium04.ans + points: 1 +- in: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom.in + out: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom.ans + points: 1 +- in: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom02.in + out: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom02.ans + points: 1 +- in: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom03_kmaxccsize.in + out: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom03_kmaxccsize.ans + points: 1 +- in: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom03_kmaxccsize02.in + out: linear_n50000_a1_m100000_t500000_e100_b1_longtrapsandrandom03_kmaxccsize02.ans + points: 1 +- in: linear_n50000_a1_m49990_t500000.in + out: linear_n50000_a1_m49990_t500000.ans + points: 1 +- in: linear_n50000_a1_m49990_t500000_k49990.in + out: linear_n50000_a1_m49990_t500000_k49990.ans + points: 1 +- in: linear_n50000_a1_m49990_t500000_k49990_b50000.in + out: linear_n50000_a1_m49990_t500000_k49990_b50000.ans + points: 1 +- in: linear_n50000_a1_m49990_t500000_k49991.in + out: linear_n50000_a1_m49990_t500000_k49991.ans + points: 1 +- in: linear_n50000_a1_m49990_t500000_k49991_b50000.in + out: linear_n50000_a1_m49990_t500000_k49991_b50000.ans + points: 1 +- in: linear_n50000_a50_m250_t500000_e100_k6_b10000.in + out: linear_n50000_a50_m250_t500000_e100_k6_b10000.ans + points: 1 +- in: linear_n50000_a50_m5_t500000_e100_k10_b1_longtraps.in + out: linear_n50000_a50_m5_t500000_e100_k10_b1_longtraps.ans + points: 1 +- in: linear_n50000_a50_m5_t500000_e100_k10_b1_longtraps02.in + out: linear_n50000_a50_m5_t500000_e100_k10_b1_longtraps02.ans + points: 1 +- in: linear_n50000_a50_m5_t500000_e100_k10_b1_longtraps_02.in + out: linear_n50000_a50_m5_t500000_e100_k10_b1_longtraps_02.ans + points: 1 +- in: linear_n50000_a50_m5_t500000_e100_k6_b10000.in + out: linear_n50000_a50_m5_t500000_e100_k6_b10000.ans + points: 1 +- in: linear_n50000_t500000.in + out: linear_n50000_t500000.ans + points: 1 +- in: medium01.in + out: medium01.ans + points: 1 +- in: medium02.in + out: medium02.ans + points: 1 +- in: test02.in + out: test02.ans + points: 1 +- in: test04.in + out: test04.ans + points: 1 +- in: test05.in + out: test05.ans + points: 1 +- in: traps01.in + out: traps01.ans + points: 1 +- in: traps02.in + out: traps02.ans + points: 1 +- in: traps03.in + out: traps03.ans + points: 1 +- in: traps04.in + out: traps04.ans + points: 1 +- in: zlarge02.in + out: zlarge02.ans + points: 1 +- in: zlarge03.in + out: zlarge03.ans + points: 1 diff --git a/ICPC/swerc2024_G/data.zip b/ICPC/swerc2024_G/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..d77dc9dfedab33aa33fd0ca11fcdeb76fd0c3643 --- /dev/null +++ b/ICPC/swerc2024_G/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50287aa18951731157377e6a449143409c0bdf7f375f532a126061d8c888cea9 +size 10415 diff --git a/ICPC/swerc2024_G/init.yml b/ICPC/swerc2024_G/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..cdc157477e6c9866a08f14ba2d7a96f7319784fd --- /dev/null +++ b/ICPC/swerc2024_G/init.yml @@ -0,0 +1,24 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: bigrange.in + out: bigrange.ans + points: 1 +- in: bigrange2.in + out: bigrange2.ans + points: 1 +- in: int64.in + out: int64.ans + points: 1 +- in: negative.in + out: negative.ans + points: 1 +- in: short.in + out: short.ans + points: 1 +- in: short2.in + out: short2.ans + points: 1 +- in: uncertain1.in + out: uncertain1.ans + points: 1 diff --git a/ICPC/swerc2024_H/data.zip b/ICPC/swerc2024_H/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..59757a02ca6c90bed13471001532eca1ebc68208 --- /dev/null +++ b/ICPC/swerc2024_H/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:002f5c5a8162a28091976e308feb445f8124eeadd8d377210cb910e223f9e534 +size 2788 diff --git a/ICPC/swerc2024_H/init.yml b/ICPC/swerc2024_H/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..56e92322d685ce23d4602adb2aaaae059fad822a --- /dev/null +++ b/ICPC/swerc2024_H/init.yml @@ -0,0 +1,24 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: secret01.in + out: secret01.ans + points: 1 +- in: secret02.in + out: secret02.ans + points: 1 +- in: secret03.in + out: secret03.ans + points: 1 +- in: secret04.in + out: secret04.ans + points: 1 +- in: secret05.in + out: secret05.ans + points: 1 +- in: secret06.in + out: secret06.ans + points: 1 +- in: secret07.in + out: secret07.ans + points: 1 diff --git a/ICPC/swerc2024_I/data.zip b/ICPC/swerc2024_I/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..6f8377d77b50fc7a965337ac9e231a8f884e86d4 --- /dev/null +++ b/ICPC/swerc2024_I/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c20afe7604a9cfd1083b8e82469ca270a98e22b6242061a3b17452f2966c3710 +size 10113404 diff --git a/ICPC/swerc2024_I/init.yml b/ICPC/swerc2024_I/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d5c5c360e4151b939ff331f08d42a4b88a7ca159 --- /dev/null +++ b/ICPC/swerc2024_I/init.yml @@ -0,0 +1,51 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: secret01.in + out: secret01.ans + points: 1 +- in: secret02.in + out: secret02.ans + points: 1 +- in: secret03.in + out: secret03.ans + points: 1 +- in: secret04.in + out: secret04.ans + points: 1 +- in: secret05.in + out: secret05.ans + points: 1 +- in: secret06.in + out: secret06.ans + points: 1 +- in: secret07.in + out: secret07.ans + points: 1 +- in: secret08.in + out: secret08.ans + points: 1 +- in: secret09.in + out: secret09.ans + points: 1 +- in: secret10.in + out: secret10.ans + points: 1 +- in: secret11.in + out: secret11.ans + points: 1 +- in: secret12.in + out: secret12.ans + points: 1 +- in: secret13.in + out: secret13.ans + points: 1 +- in: secret14.in + out: secret14.ans + points: 1 +- in: secret15.in + out: secret15.ans + points: 1 +- in: secret16.in + out: secret16.ans + points: 1 diff --git a/ICPC/swerc2024_J/data.zip b/ICPC/swerc2024_J/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..c56ccbac1009e5ff5f0474ff769b261a15c79510 --- /dev/null +++ b/ICPC/swerc2024_J/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2cc8eec5b654a1e63e45dcde96c75d94e65f07814d817ad32cb52c8d2461062 +size 3974 diff --git a/ICPC/swerc2024_J/init.yml b/ICPC/swerc2024_J/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..133f3ec7e4e81f27b0c3459ad82bacbcae7aad56 --- /dev/null +++ b/ICPC/swerc2024_J/init.yml @@ -0,0 +1,33 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: secret01.in + out: secret01.ans + points: 1 +- in: secret02.in + out: secret02.ans + points: 1 +- in: secret03.in + out: secret03.ans + points: 1 +- in: secret04.in + out: secret04.ans + points: 1 +- in: secret05.in + out: secret05.ans + points: 1 +- in: secret06.in + out: secret06.ans + points: 1 +- in: secret07.in + out: secret07.ans + points: 1 +- in: secret08.in + out: secret08.ans + points: 1 +- in: secret09.in + out: secret09.ans + points: 1 +- in: secret10.in + out: secret10.ans + points: 1 diff --git a/ICPC/swerc2024_K/data.zip b/ICPC/swerc2024_K/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..82153e11090466bc244f3b2ea7efd365eab1fcfb --- /dev/null +++ b/ICPC/swerc2024_K/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:217893ccc5b5837579815e547c4574f5150fe8e85644a4aadc554dc5fd6dcfc9 +size 16740 diff --git a/ICPC/swerc2024_K/init.yml b/ICPC/swerc2024_K/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3a0adc703405bbcfd6fdfb34707c43b07eeabad0 --- /dev/null +++ b/ICPC/swerc2024_K/init.yml @@ -0,0 +1,99 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: almosttangent01.in + out: almosttangent01.ans + points: 1 +- in: almosttangent02.in + out: almosttangent02.ans + points: 1 +- in: almosttangent03.in + out: almosttangent03.ans + points: 1 +- in: almosttangent04.in + out: almosttangent04.ans + points: 1 +- in: almosttangent05.in + out: almosttangent05.ans + points: 1 +- in: secret01.in + out: secret01.ans + points: 1 +- in: secret02.in + out: secret02.ans + points: 1 +- in: secret03.in + out: secret03.ans + points: 1 +- in: secret04.in + out: secret04.ans + points: 1 +- in: secret05.in + out: secret05.ans + points: 1 +- in: secret06.in + out: secret06.ans + points: 1 +- in: secret07.in + out: secret07.ans + points: 1 +- in: secret08.in + out: secret08.ans + points: 1 +- in: secret09.in + out: secret09.ans + points: 1 +- in: secret10.in + out: secret10.ans + points: 1 +- in: secret11.in + out: secret11.ans + points: 1 +- in: secret12.in + out: secret12.ans + points: 1 +- in: secret13.in + out: secret13.ans + points: 1 +- in: secret14.in + out: secret14.ans + points: 1 +- in: secret15.in + out: secret15.ans + points: 1 +- in: secret16.in + out: secret16.ans + points: 1 +- in: secret17.in + out: secret17.ans + points: 1 +- in: secret18.in + out: secret18.ans + points: 1 +- in: secret19.in + out: secret19.ans + points: 1 +- in: secret20.in + out: secret20.ans + points: 1 +- in: secret21.in + out: secret21.ans + points: 1 +- in: secret22.in + out: secret22.ans + points: 1 +- in: secret23.in + out: secret23.ans + points: 1 +- in: secret24.in + out: secret24.ans + points: 1 +- in: secret25.in + out: secret25.ans + points: 1 +- in: two_zones01.in + out: two_zones01.ans + points: 1 +- in: two_zones02.in + out: two_zones02.ans + points: 1 diff --git a/ICPC/swerc2024_L/data.zip b/ICPC/swerc2024_L/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..74eecd40c7706bcbd8b9b0e36c4b8d1b8172287e --- /dev/null +++ b/ICPC/swerc2024_L/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72efdd1fa8713ac05b214919e31f0ec792f0d836b37649a24afc4b612ffd66c6 +size 11919 diff --git a/ICPC/swerc2024_L/init.yml b/ICPC/swerc2024_L/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ee7707402cca8582880ad56ea30cd968789d380c --- /dev/null +++ b/ICPC/swerc2024_L/init.yml @@ -0,0 +1,184 @@ +archive: data.zip +interactive: + files: + - output_validators/car_validator/validate.h + - output_validators/car_validator/validate.cc + lang: CPP17 + type: default +output_limit_length: 104857600 +test_cases: +- in: test_1.in + out: test_1.ans + points: 1 +- in: test_10.in + out: test_10.ans + points: 1 +- in: test_11.in + out: test_11.ans + points: 1 +- in: test_12.in + out: test_12.ans + points: 1 +- in: test_13.in + out: test_13.ans + points: 1 +- in: test_14.in + out: test_14.ans + points: 1 +- in: test_15.in + out: test_15.ans + points: 1 +- in: test_16.in + out: test_16.ans + points: 1 +- in: test_17.in + out: test_17.ans + points: 1 +- in: test_18.in + out: test_18.ans + points: 1 +- in: test_19.in + out: test_19.ans + points: 1 +- in: test_2.in + out: test_2.ans + points: 1 +- in: test_20.in + out: test_20.ans + points: 1 +- in: test_21.in + out: test_21.ans + points: 1 +- in: test_22.in + out: test_22.ans + points: 1 +- in: test_23.in + out: test_23.ans + points: 1 +- in: test_24.in + out: test_24.ans + points: 1 +- in: test_25.in + out: test_25.ans + points: 1 +- in: test_26.in + out: test_26.ans + points: 1 +- in: test_27.in + out: test_27.ans + points: 1 +- in: test_28.in + out: test_28.ans + points: 1 +- in: test_29.in + out: test_29.ans + points: 1 +- in: test_3.in + out: test_3.ans + points: 1 +- in: test_30.in + out: test_30.ans + points: 1 +- in: test_31.in + out: test_31.ans + points: 1 +- in: test_32.in + out: test_32.ans + points: 1 +- in: test_33.in + out: test_33.ans + points: 1 +- in: test_34.in + out: test_34.ans + points: 1 +- in: test_35.in + out: test_35.ans + points: 1 +- in: test_36.in + out: test_36.ans + points: 1 +- in: test_37.in + out: test_37.ans + points: 1 +- in: test_38.in + out: test_38.ans + points: 1 +- in: test_39.in + out: test_39.ans + points: 1 +- in: test_4.in + out: test_4.ans + points: 1 +- in: test_40.in + out: test_40.ans + points: 1 +- in: test_41.in + out: test_41.ans + points: 1 +- in: test_42.in + out: test_42.ans + points: 1 +- in: test_43.in + out: test_43.ans + points: 1 +- in: test_44.in + out: test_44.ans + points: 1 +- in: test_45.in + out: test_45.ans + points: 1 +- in: test_46.in + out: test_46.ans + points: 1 +- in: test_47.in + out: test_47.ans + points: 1 +- in: test_48.in + out: test_48.ans + points: 1 +- in: test_49.in + out: test_49.ans + points: 1 +- in: test_5.in + out: test_5.ans + points: 1 +- in: test_50.in + out: test_50.ans + points: 1 +- in: test_51.in + out: test_51.ans + points: 1 +- in: test_52.in + out: test_52.ans + points: 1 +- in: test_53.in + out: test_53.ans + points: 1 +- in: test_54.in + out: test_54.ans + points: 1 +- in: test_55.in + out: test_55.ans + points: 1 +- in: test_56.in + out: test_56.ans + points: 1 +- in: test_57.in + out: test_57.ans + points: 1 +- in: test_58.in + out: test_58.ans + points: 1 +- in: test_6.in + out: test_6.ans + points: 1 +- in: test_7.in + out: test_7.ans + points: 1 +- in: test_8.in + out: test_8.ans + points: 1 +- in: test_9.in + out: test_9.ans + points: 1 +unbuffered: false diff --git a/ICPC/swerc2024_L/output_validators/car_validator/validate.cc b/ICPC/swerc2024_L/output_validators/car_validator/validate.cc new file mode 100644 index 0000000000000000000000000000000000000000..800fe78ea3cd0fa4c03317f80f37aee37db0969c --- /dev/null +++ b/ICPC/swerc2024_L/output_validators/car_validator/validate.cc @@ -0,0 +1,135 @@ + +#include +int qwerty_getcode(int code) { + return code == 42? 0: 1; +} +namespace std { + void qwerty_exit(int code){ + exit(qwerty_getcode(code)); + } +} using std::qwerty_exit; +#define exit qwerty_exit +#define main qwerty_main +#include "validate.h" +#include +#include +#include +#include +#include + +using namespace std; + +void check_case() { + string line; + /* Get test mode description from judge input file */ + assert(getline(judge_in, line)); + + int64_t x, y; + + // Should we make a version of this validator where x + // and y are actually not fixed until we gave the + // player enough information, to make sure he's using + // the best possible guesser, like in guess??? + + stringstream sstr(line); + sstr >> x >> y; + + assert(x <= 1000 * 1000); + assert(x >= -1000 * 1000); + assert(y <= 1000 * 1000); + assert(y >= -1000 * 1000); + + int orientation = 0; + int64_t playerX = 0, playerY = 0; + + for (int playerV = 1; playerV < 2 * 10 * 1000; playerV++) { + std::string command; + if (!std::getline(author_out, command)) { + wrong_answer("Command %d: couldn't read a command\n", playerV); + return; + } + + judge_message("read command %s\n", command.c_str()); + + if ((command.length() != 3) || (command[0] != '?') || (command[1] != ' ')) { + wrong_answer("Wrong command '%s'\n", command.c_str()); + return; + } + switch (command[2]) { + case 'L': + orientation += 1; + break; + case 'R': + orientation += 3; + break; + case 'F': + break; + default: + wrong_answer("Wrong command %s\n", command.c_str()); + return; + } + orientation = orientation % 4; + switch (orientation) { + case 0: + playerX += playerV; + break; + case 1: + playerY += playerV; + break; + case 2: + playerX -= playerV; + break; + case 3: + playerY -= playerV; + break; + } + + judge_message("player position is now %lld %lld\n", playerX, playerY); + + int64_t distance = llabs(playerX - x) + llabs(playerY - y); + + cout << distance << endl; + cout.flush(); + + if (distance == 0) { + return; + } + } + + wrong_answer("Reached escape velocity"); + return; +} + +int main(int argc, char **argv) { + init_io(argc, argv); + + check_case(); + + judge_message("now checking for trailing output"); + + /* Check for trailing output. */ + string trash; + if (author_out >> trash) { + wrong_answer("Trailing output\n"); + } + + judge_message("accepting"); + + /* Yay! */ + accept(); +} + +#undef main +#include +#include +#include +#include +int main(int argc, char **argv) { + namespace fs = std::filesystem; + char judge_out[] = "/dev"; + std::vector new_argv = { + argv[0], argv[1], argv[2], + judge_out, + }; + return qwerty_getcode(qwerty_main((int)new_argv.size(), new_argv.data())); +} diff --git a/ICPC/swerc2024_L/output_validators/car_validator/validate.h b/ICPC/swerc2024_L/output_validators/car_validator/validate.h new file mode 100644 index 0000000000000000000000000000000000000000..fe5da0fc3b53096956209b42f7d2723f7421d6c2 --- /dev/null +++ b/ICPC/swerc2024_L/output_validators/car_validator/validate.h @@ -0,0 +1,153 @@ +/* Utility functions for writing output validators for the Kattis + * problem format. + * + * The primary functions and variables available are the following. + * In many cases, the only functions needed are "init_io", + * "wrong_answer", and "accept". + * + * - init_io(argc, argv): + * initialization + * + * - judge_in, judge_ans, author_out: + * std::istream objects for judge input file, judge answer + * file, and submission output file. + * + * - accept(): + * exit and give Accepted! + * + * - accept_with_score(double score): + * exit with Accepted and give a score (for scoring problems) + * + * - judge_message(std::string msg, ...): + * printf-style function for emitting a judge message (a + * message that gets displayed to a privileged user with access + * to secret data etc). + * + * - wrong_answer(std::string msg, ...): + * printf-style function for exitting and giving Wrong Answer, + * and emitting a judge message (which would typically explain + * the cause of the Wrong Answer) + * + * - judge_error(std::string msg, ...): + * printf-style function for exitting and giving Judge Error, + * and emitting a judge message (which would typically explain + * the cause of the Judge Error) + * + * - author_message(std::string msg, ...): + * printf-style function for emitting an author message (a + * message that gets displayed to the author of the + * submission). (Use with caution, and be careful not to let + * it leak information!) + * + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +typedef void (*feedback_function)(const std::string &, ...); + +const int EXITCODE_AC = 42; +const int EXITCODE_WA = 43; +const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt"; +const std::string FILENAME_JUDGE_MESSAGE = "null"; +const std::string FILENAME_SCORE = "score.txt"; + +#define USAGE "%s: judge_in judge_ans feedback_dir < author_out\n" + +std::ifstream judge_in, judge_ans; +std::istream author_out(std::cin.rdbuf()); + +char *feedbackdir = NULL; + +void vreport_feedback(const std::string &category, + const std::string &msg, + va_list pvar) { + std::ostringstream fname; + if (feedbackdir) + fname << feedbackdir << '/'; + fname << category; + FILE *f = fopen(fname.str().c_str(), "a"); + assert(f); + vfprintf(f, msg.c_str(), pvar); + fclose(f); +} + +void report_feedback(const std::string &category, const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(category, msg, pvar); +} + +void author_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_AUTHOR_MESSAGE, msg, pvar); +} + +void judge_message(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); +} + +void wrong_answer(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); + exit(EXITCODE_WA); +} + +void judge_error(const std::string &msg, ...) { + va_list pvar; + va_start(pvar, msg); + vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); + assert(0); +} + +void accept() { + exit(EXITCODE_AC); +} + +void accept_with_score(double scorevalue) { + report_feedback(FILENAME_SCORE, "%.9le", scorevalue); + exit(EXITCODE_AC); +} + + +bool is_directory(const char *path) { +if(std::string(path) == std::string("/dev")) return 1; + struct stat entry; + return stat(path, &entry) == 0 && S_ISDIR(entry.st_mode); +} + +void init_io(int argc, char **argv) { + if(argc < 4) { + fprintf(stderr, USAGE, argv[0]); + judge_error("Usage: %s judgein judgeans feedbackdir [opts] < userout", argv[0]); + } + + // Set up feedbackdir first, as that allows us to produce feedback + // files for errors in the other parameters. + if (!is_directory(argv[3])) { + judge_error("%s: %s is not a directory\n", argv[0], argv[3]); + } + feedbackdir = argv[3]; + + judge_in.open(argv[1], std::ios_base::in); + if (judge_in.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[1]); + } + + judge_ans.open(argv[2], std::ios_base::in); + if (judge_ans.fail()) { + judge_error("%s: failed to open %s\n", argv[0], argv[2]); + } + + author_out.rdbuf(std::cin.rdbuf()); +} \ No newline at end of file diff --git a/ICPC/swerc2024_M/data.zip b/ICPC/swerc2024_M/data.zip new file mode 100644 index 0000000000000000000000000000000000000000..1fb75a67574a1d0b10deef53eba870c8a35a4877 --- /dev/null +++ b/ICPC/swerc2024_M/data.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d53a25b3bf427dd423122ed5ce2863e5d6bec83f45d2812209c61df035274efb +size 2267 diff --git a/ICPC/swerc2024_M/init.yml b/ICPC/swerc2024_M/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..35fe74b966f61e8531ff0e9aeae2f2767c8197d6 --- /dev/null +++ b/ICPC/swerc2024_M/init.yml @@ -0,0 +1,27 @@ +archive: data.zip +output_limit_length: 104857600 +test_cases: +- in: secret04.in + out: secret04.ans + points: 1 +- in: secret05.in + out: secret05.ans + points: 1 +- in: secret06.in + out: secret06.ans + points: 1 +- in: secret07.in + out: secret07.ans + points: 1 +- in: secret08.in + out: secret08.ans + points: 1 +- in: secret09.in + out: secret09.ans + points: 1 +- in: secret10.in + out: secret10.ans + points: 1 +- in: secret11.in + out: secret11.ans + points: 1 diff --git a/NOI/loj-2083/init.yml b/NOI/loj-2083/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7775f0956dce9a3ba38de45bc5639628bcd46162 --- /dev/null +++ b/NOI/loj-2083/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: excellent1.in + out: excellent1.out + points: 10 +- in: excellent2.in + out: excellent2.out + points: 10 +- in: excellent17.in + out: excellent17.out + points: 10 +- in: excellent7.in + out: excellent7.out + points: 10 +- in: excellent12.in + out: excellent12.out + points: 10 +- in: excellent18.in + out: excellent18.out + points: 10 +- in: excellent15.in + out: excellent15.out + points: 10 +- in: excellent8.in + out: excellent8.out + points: 10 +- in: excellent5.in + out: excellent5.out + points: 10 +- in: excellent9.in + out: excellent9.out + points: 10 +- in: excellent4.in + out: excellent4.out + points: 10 +- in: excellent13.in + out: excellent13.out + points: 10 +- in: excellent14.in + out: excellent14.out + points: 10 +- in: excellent20.in + out: excellent20.out + points: 10 +- in: excellent10.in + out: excellent10.out + points: 10 +- in: excellent6.in + out: excellent6.out + points: 10 +- in: excellent11.in + out: excellent11.out + points: 10 +- in: excellent16.in + out: excellent16.out + points: 10 +- in: excellent3.in + out: excellent3.out + points: 10 +- in: excellent19.in + out: excellent19.out + points: 10 diff --git a/NOI/loj-2083/tests.zip b/NOI/loj-2083/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..f3a33edfd6593fe06ca07fb74f35902e7eb9748c --- /dev/null +++ b/NOI/loj-2083/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e82140d47e5bea90b068130d6a86716cfe4b7147a2d70191cee4c9743b93f6d +size 332889 diff --git a/NOI/loj-2084/init.yml b/NOI/loj-2084/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5cc8e0bff6bec3d41f252af8bc0660f466b396b9 --- /dev/null +++ b/NOI/loj-2084/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: grid4.in + out: grid4.out + points: 10 +- in: grid12.in + out: grid12.out + points: 10 +- in: grid22.in + out: grid22.out + points: 10 +- in: grid8.in + out: grid8.out + points: 10 +- in: grid7.in + out: grid7.out + points: 10 +- in: grid24.in + out: grid24.out + points: 10 +- in: grid23.in + out: grid23.out + points: 10 +- in: grid21.in + out: grid21.out + points: 10 +- in: grid13.in + out: grid13.out + points: 10 +- in: grid18.in + out: grid18.out + points: 10 +- in: grid9.in + out: grid9.out + points: 10 +- in: grid19.in + out: grid19.out + points: 10 +- in: grid25.in + out: grid25.out + points: 10 +- in: grid11.in + out: grid11.out + points: 10 +- in: grid20.in + out: grid20.out + points: 10 +- in: grid10.in + out: grid10.out + points: 10 +- in: grid17.in + out: grid17.out + points: 10 +- in: grid3.in + out: grid3.out + points: 10 +- in: grid2.in + out: grid2.out + points: 10 +- in: grid14.in + out: grid14.out + points: 10 +- in: grid1.in + out: grid1.out + points: 10 +- in: grid16.in + out: grid16.out + points: 10 +- in: grid6.in + out: grid6.out + points: 10 +- in: grid15.in + out: grid15.out + points: 10 +- in: grid5.in + out: grid5.out + points: 10 diff --git a/NOI/loj-2084/tests.zip b/NOI/loj-2084/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..f6bca6912099a11f7a80a5ff1c025b1cb092ddc9 --- /dev/null +++ b/NOI/loj-2084/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:efc85f700f3ef5f6a61a8a5e604481b4234e26407729cda045801fe4b9aed0b6 +size 3670759 diff --git a/NOI/loj-2085/init.yml b/NOI/loj-2085/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5bdd28c02bef404fff48156631840419c5d51976 --- /dev/null +++ b/NOI/loj-2085/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: cyclic10.in + out: cyclic10.out + points: 10 +- in: cyclic23.in + out: cyclic23.out + points: 10 +- in: cyclic25.in + out: cyclic25.out + points: 10 +- in: cyclic3.in + out: cyclic3.out + points: 10 +- in: cyclic12.in + out: cyclic12.out + points: 10 +- in: cyclic5.in + out: cyclic5.out + points: 10 +- in: cyclic8.in + out: cyclic8.out + points: 10 +- in: cyclic19.in + out: cyclic19.out + points: 10 +- in: cyclic1.in + out: cyclic1.out + points: 10 +- in: cyclic6.in + out: cyclic6.out + points: 10 +- in: cyclic22.in + out: cyclic22.out + points: 10 +- in: cyclic9.in + out: cyclic9.out + points: 10 +- in: cyclic13.in + out: cyclic13.out + points: 10 +- in: cyclic7.in + out: cyclic7.out + points: 10 +- in: cyclic15.in + out: cyclic15.out + points: 10 +- in: cyclic20.in + out: cyclic20.out + points: 10 +- in: cyclic4.in + out: cyclic4.out + points: 10 +- in: cyclic24.in + out: cyclic24.out + points: 10 +- in: cyclic14.in + out: cyclic14.out + points: 10 +- in: cyclic17.in + out: cyclic17.out + points: 10 +- in: cyclic18.in + out: cyclic18.out + points: 10 +- in: cyclic11.in + out: cyclic11.out + points: 10 +- in: cyclic21.in + out: cyclic21.out + points: 10 +- in: cyclic16.in + out: cyclic16.out + points: 10 +- in: cyclic2.in + out: cyclic2.out + points: 10 diff --git a/NOI/loj-2085/tests.zip b/NOI/loj-2085/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..784aefb2d97b92058a0e65d0220271329e9bdbf6 --- /dev/null +++ b/NOI/loj-2085/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2989bc3db7c95dfe128f7cbc923fb86f62327b6fdffb4f5fb322cc0286dc8b8 +size 5712 diff --git a/NOI/loj-2086/init.yml b/NOI/loj-2086/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..043663f7c648948ff070f77b32dbecc4bf9c8143 --- /dev/null +++ b/NOI/loj-2086/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: interval4.in + out: interval4.out + points: 10 +- in: interval15.in + out: interval15.out + points: 10 +- in: interval17.in + out: interval17.out + points: 10 +- in: interval7.in + out: interval7.out + points: 10 +- in: interval1.in + out: interval1.out + points: 10 +- in: interval19.in + out: interval19.out + points: 10 +- in: interval5.in + out: interval5.out + points: 10 +- in: interval3.in + out: interval3.out + points: 10 +- in: interval10.in + out: interval10.out + points: 10 +- in: interval20.in + out: interval20.out + points: 10 +- in: interval8.in + out: interval8.out + points: 10 +- in: interval12.in + out: interval12.out + points: 10 +- in: interval14.in + out: interval14.out + points: 10 +- in: interval9.in + out: interval9.out + points: 10 +- in: interval11.in + out: interval11.out + points: 10 +- in: interval6.in + out: interval6.out + points: 10 +- in: interval13.in + out: interval13.out + points: 10 +- in: interval18.in + out: interval18.out + points: 10 +- in: interval2.in + out: interval2.out + points: 10 +- in: interval16.in + out: interval16.out + points: 10 diff --git a/NOI/loj-2086/tests.zip b/NOI/loj-2086/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..2a4c127e78a3a657a4461cd0ac425f99d3f7dad3 --- /dev/null +++ b/NOI/loj-2086/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16ba5c6e1cb47bae5d913a3396d39ffa489ee6dd1f3151e8850091e2fe262375 +size 30406230 diff --git a/NOI/loj-2087/init.yml b/NOI/loj-2087/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5c5d89fac98712e0bcc28d9a64b44944fda0fced --- /dev/null +++ b/NOI/loj-2087/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.ans + points: 10 +- in: 19.in + out: 19.ans + points: 10 +- in: 15.in + out: 15.ans + points: 10 +- in: 9.in + out: 9.ans + points: 10 +- in: 1.in + out: 1.ans + points: 10 +- in: 8.in + out: 8.ans + points: 10 +- in: 7.in + out: 7.ans + points: 10 +- in: 6.in + out: 6.ans + points: 10 +- in: 10.in + out: 10.ans + points: 10 +- in: 20.in + out: 20.ans + points: 10 +- in: 5.in + out: 5.ans + points: 10 +- in: 11.in + out: 11.ans + points: 10 +- in: 16.in + out: 16.ans + points: 10 +- in: 12.in + out: 12.ans + points: 10 +- in: 4.in + out: 4.ans + points: 10 +- in: 17.in + out: 17.ans + points: 10 +- in: 13.in + out: 13.ans + points: 10 +- in: 3.in + out: 3.ans + points: 10 +- in: 18.in + out: 18.ans + points: 10 +- in: 14.in + out: 14.ans + points: 10 diff --git a/NOI/loj-2087/tests.zip b/NOI/loj-2087/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..8792aaf2350f7787d82b4f4123e02f87bae9e7f8 --- /dev/null +++ b/NOI/loj-2087/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d50497d320971dc6fecfc8884820c20f51319c0c19cc6e05e9a6e8731aed1598 +size 125943 diff --git a/NOI/loj-2088/init.yml b/NOI/loj-2088/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..86b6368b51700308527cfe7507965a20de057c10 --- /dev/null +++ b/NOI/loj-2088/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.ans + points: 10 +- in: 9.in + out: 9.ans + points: 10 +- in: 1.in + out: 1.ans + points: 10 +- in: 8.in + out: 8.ans + points: 10 +- in: 7.in + out: 7.ans + points: 10 +- in: 6.in + out: 6.ans + points: 10 +- in: 10.in + out: 10.ans + points: 10 +- in: 5.in + out: 5.ans + points: 10 +- in: 4.in + out: 4.ans + points: 10 +- in: 3.in + out: 3.ans + points: 10 diff --git a/NOI/loj-2088/tests.zip b/NOI/loj-2088/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..666278618414b8c0077e7e4ba590568be13978a4 --- /dev/null +++ b/NOI/loj-2088/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb2cb30b707924c09085711f26ca32ab7f89c225076eb8766b806db21761d363 +size 23587 diff --git a/NOI/loj-2129/init.yml b/NOI/loj-2129/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..88c0d4492efa900a8a54e5d318e801ffac065ca7 --- /dev/null +++ b/NOI/loj-2129/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: prog7.in + out: prog7.out + points: 10 +- in: prog9.in + out: prog9.out + points: 10 +- in: prog2.in + out: prog2.out + points: 10 +- in: prog4.in + out: prog4.out + points: 10 +- in: prog6.in + out: prog6.out + points: 10 +- in: prog8.in + out: prog8.out + points: 10 +- in: prog1.in + out: prog1.out + points: 10 +- in: prog3.in + out: prog3.out + points: 10 +- in: prog5.in + out: prog5.out + points: 10 +- in: prog10.in + out: prog10.out + points: 10 diff --git a/NOI/loj-2129/tests.zip b/NOI/loj-2129/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..fcf0f7c26247016bdadd4b2aebf6fb4ce808899c --- /dev/null +++ b/NOI/loj-2129/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ca57d36b87584bbf0a2bb6727c70dced38c7b0be6701f576022d46fcae6a89a +size 30035654 diff --git a/NOI/loj-2130/init.yml b/NOI/loj-2130/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..1de2efa77d6ff1ca01783bb6ac1a02f14944005e --- /dev/null +++ b/NOI/loj-2130/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: manager5.in + out: manager5.out + points: 10 +- in: manager7.in + out: manager7.out + points: 10 +- in: manager17.in + out: manager17.out + points: 10 +- in: manager2.in + out: manager2.out + points: 10 +- in: manager13.in + out: manager13.out + points: 10 +- in: manager8.in + out: manager8.out + points: 10 +- in: manager9.in + out: manager9.out + points: 10 +- in: manager12.in + out: manager12.out + points: 10 +- in: manager19.in + out: manager19.out + points: 10 +- in: manager6.in + out: manager6.out + points: 10 +- in: manager10.in + out: manager10.out + points: 10 +- in: manager15.in + out: manager15.out + points: 10 +- in: manager18.in + out: manager18.out + points: 10 +- in: manager3.in + out: manager3.out + points: 10 +- in: manager1.in + out: manager1.out + points: 10 +- in: manager20.in + out: manager20.out + points: 10 +- in: manager4.in + out: manager4.out + points: 10 +- in: manager11.in + out: manager11.out + points: 10 +- in: manager14.in + out: manager14.out + points: 10 +- in: manager16.in + out: manager16.out + points: 10 diff --git a/NOI/loj-2130/tests.zip b/NOI/loj-2130/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c121089e96719e2d82c00b12c46c6fbf9b0264d5 --- /dev/null +++ b/NOI/loj-2130/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d130a2fdf93c06e3f566cd1a23abc772664496056b6b4848fac5d1535131d6b +size 41584757 diff --git a/NOI/loj-2131/init.yml b/NOI/loj-2131/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..53c669fc4d51a5a173073cb2b546c6fa94fbce70 --- /dev/null +++ b/NOI/loj-2131/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: dinner9.in + out: dinner9.out + points: 10 +- in: dinner6.in + out: dinner6.out + points: 10 +- in: dinner2.in + out: dinner2.out + points: 10 +- in: dinner10.in + out: dinner10.out + points: 10 +- in: dinner8.in + out: dinner8.out + points: 10 +- in: dinner4.in + out: dinner4.out + points: 10 +- in: dinner3.in + out: dinner3.out + points: 10 +- in: dinner7.in + out: dinner7.out + points: 10 +- in: dinner5.in + out: dinner5.out + points: 10 +- in: dinner1.in + out: dinner1.out + points: 10 diff --git a/NOI/loj-2131/tests.zip b/NOI/loj-2131/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..bccd0a44dbb99b61eb7ea5a271aa6d20db866a66 --- /dev/null +++ b/NOI/loj-2131/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f811b74161474965838539d31ca70cd8c76203d55d0289d451088edd8b7fd35 +size 2160 diff --git a/NOI/loj-2132/init.yml b/NOI/loj-2132/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a35ac78ff91c139ef20f06615d8691a8905cef2a --- /dev/null +++ b/NOI/loj-2132/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: epic16.in + out: epic16.out + points: 10 +- in: epic19.in + out: epic19.out + points: 10 +- in: epic15.in + out: epic15.out + points: 10 +- in: epic14.in + out: epic14.out + points: 10 +- in: epic2.in + out: epic2.out + points: 10 +- in: epic1.in + out: epic1.out + points: 10 +- in: epic5.in + out: epic5.out + points: 10 +- in: epic11.in + out: epic11.out + points: 10 +- in: epic13.in + out: epic13.out + points: 10 +- in: epic10.in + out: epic10.out + points: 10 +- in: epic8.in + out: epic8.out + points: 10 +- in: epic20.in + out: epic20.out + points: 10 +- in: epic17.in + out: epic17.out + points: 10 +- in: epic12.in + out: epic12.out + points: 10 +- in: epic4.in + out: epic4.out + points: 10 +- in: epic18.in + out: epic18.out + points: 10 +- in: epic3.in + out: epic3.out + points: 10 +- in: epic7.in + out: epic7.out + points: 10 +- in: epic6.in + out: epic6.out + points: 10 +- in: epic9.in + out: epic9.out + points: 10 diff --git a/NOI/loj-2132/tests.zip b/NOI/loj-2132/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..97b4ad1766ac5fed1eea7616d5e8c47507397087 --- /dev/null +++ b/NOI/loj-2132/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1c348f929c5cfed92598d9ab4291ad93ee303096d78a72aec4fd35b5aa885bb +size 11017353 diff --git a/NOI/loj-2133/init.yml b/NOI/loj-2133/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..70bd1519c2c63a1cd071a9909d6114381f94e881 --- /dev/null +++ b/NOI/loj-2133/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: savour9.in + out: savour9.out + points: 10 +- in: savour14.in + out: savour14.out + points: 10 +- in: savour6.in + out: savour6.out + points: 10 +- in: savour17.in + out: savour17.out + points: 10 +- in: savour15.in + out: savour15.out + points: 10 +- in: savour12.in + out: savour12.out + points: 10 +- in: savour16.in + out: savour16.out + points: 10 +- in: savour20.in + out: savour20.out + points: 10 +- in: savour1.in + out: savour1.out + points: 10 +- in: savour19.in + out: savour19.out + points: 10 +- in: savour8.in + out: savour8.out + points: 10 +- in: savour2.in + out: savour2.out + points: 10 +- in: savour5.in + out: savour5.out + points: 10 +- in: savour18.in + out: savour18.out + points: 10 +- in: savour7.in + out: savour7.out + points: 10 +- in: savour4.in + out: savour4.out + points: 10 +- in: savour10.in + out: savour10.out + points: 10 +- in: savour13.in + out: savour13.out + points: 10 +- in: savour11.in + out: savour11.out + points: 10 +- in: savour3.in + out: savour3.out + points: 10 diff --git a/NOI/loj-2133/tests.zip b/NOI/loj-2133/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b90945e2a70f9b4b6f306fc8cf04eec40e5e2955 --- /dev/null +++ b/NOI/loj-2133/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3190807060897f0c6d623ef598d1c41dc0c5979e548e58fc49f21354f5a15012 +size 48616373 diff --git a/NOI/loj-2134/init.yml b/NOI/loj-2134/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..8f1a0902007578149fef2963a38b7c672657c098 --- /dev/null +++ b/NOI/loj-2134/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.out + points: 10 +- in: 19.in + out: 19.out + points: 10 +- in: 15.in + out: 15.out + points: 10 +- in: 9.in + out: 9.out + points: 10 +- in: 1.in + out: 1.out + points: 10 +- in: 8.in + out: 8.out + points: 10 +- in: 7.in + out: 7.out + points: 10 +- in: 6.in + out: 6.out + points: 10 +- in: 10.in + out: 10.out + points: 10 +- in: 20.in + out: 20.out + points: 10 +- in: 5.in + out: 5.out + points: 10 +- in: 11.in + out: 11.out + points: 10 +- in: 16.in + out: 16.out + points: 10 +- in: 12.in + out: 12.out + points: 10 +- in: 4.in + out: 4.out + points: 10 +- in: 17.in + out: 17.out + points: 10 +- in: 13.in + out: 13.out + points: 10 +- in: 3.in + out: 3.out + points: 10 +- in: 18.in + out: 18.out + points: 10 +- in: 14.in + out: 14.out + points: 10 diff --git a/NOI/loj-2134/tests.zip b/NOI/loj-2134/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e5d596579980723446d44decac0549bac4c6985f --- /dev/null +++ b/NOI/loj-2134/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86e7f291e8cbe173de902176ff89bf1124c02d74e5441c7086e6e36270dd5d0b +size 6704449 diff --git a/NOI/loj-2244/init.yml b/NOI/loj-2244/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c0643a2a805c5aecc377c306203c41ad900cbe55 --- /dev/null +++ b/NOI/loj-2244/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: sleep8.in + out: sleep8.out + points: 10 +- in: sleep3.in + out: sleep3.out + points: 10 +- in: sleep2.in + out: sleep2.out + points: 10 +- in: sleep5.in + out: sleep5.out + points: 10 +- in: sleep4.in + out: sleep4.out + points: 10 +- in: sleep9.in + out: sleep9.out + points: 10 +- in: sleep10.in + out: sleep10.out + points: 10 +- in: sleep1.in + out: sleep1.out + points: 10 +- in: sleep6.in + out: sleep6.out + points: 10 +- in: sleep7.in + out: sleep7.out + points: 10 diff --git a/NOI/loj-2244/tests.zip b/NOI/loj-2244/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..12306b6936dc0c0ed2194cceab63ecf1296203b3 --- /dev/null +++ b/NOI/loj-2244/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75901daff843e8d65029930291f1ef135c8f5d02623d022bfa705fd95d32518c +size 7747668 diff --git a/NOI/loj-2245/init.yml b/NOI/loj-2245/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f3107bad7d404920c1c4a01639c1862a4cf38d83 --- /dev/null +++ b/NOI/loj-2245/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: forest11.in + out: forest11.out + points: 10 +- in: forest4.in + out: forest4.out + points: 10 +- in: forest20.in + out: forest20.out + points: 10 +- in: forest12.in + out: forest12.out + points: 10 +- in: forest16.in + out: forest16.out + points: 10 +- in: forest10.in + out: forest10.out + points: 10 +- in: forest5.in + out: forest5.out + points: 10 +- in: forest14.in + out: forest14.out + points: 10 +- in: forest6.in + out: forest6.out + points: 10 +- in: forest17.in + out: forest17.out + points: 10 +- in: forest9.in + out: forest9.out + points: 10 +- in: forest2.in + out: forest2.out + points: 10 +- in: forest18.in + out: forest18.out + points: 10 +- in: forest1.in + out: forest1.out + points: 10 +- in: forest7.in + out: forest7.out + points: 10 +- in: forest15.in + out: forest15.out + points: 10 +- in: forest19.in + out: forest19.out + points: 10 +- in: forest3.in + out: forest3.out + points: 10 +- in: forest8.in + out: forest8.out + points: 10 +- in: forest13.in + out: forest13.out + points: 10 diff --git a/NOI/loj-2245/tests.zip b/NOI/loj-2245/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ffd623ca8703757538ad45e19f7594c172bd90bf --- /dev/null +++ b/NOI/loj-2245/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:327dc1ee4cc869efb3255b0474bd15b7a42507c840000a4bda5fe70fc34f49ec +size 22388297 diff --git a/NOI/loj-2246/init.yml b/NOI/loj-2246/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b430af3ad38ec11cdcbbf6f02acc3b2fe16b8bc3 --- /dev/null +++ b/NOI/loj-2246/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: zoo7.in + out: zoo7.out + points: 10 +- in: zoo5.in + out: zoo5.out + points: 10 +- in: zoo3.in + out: zoo3.out + points: 10 +- in: zoo10.in + out: zoo10.out + points: 10 +- in: zoo1.in + out: zoo1.out + points: 10 +- in: zoo8.in + out: zoo8.out + points: 10 +- in: zoo6.in + out: zoo6.out + points: 10 +- in: zoo4.in + out: zoo4.out + points: 10 +- in: zoo2.in + out: zoo2.out + points: 10 +- in: zoo9.in + out: zoo9.out + points: 10 diff --git a/NOI/loj-2246/tests.zip b/NOI/loj-2246/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..533515f857c4bf955602f148eb70741a7b41058e --- /dev/null +++ b/NOI/loj-2246/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5ba29ec4bdd4ee3f72de7728fb8a4f4176287e05003b2b29ee0f17ed8af0a61 +size 14104663 diff --git a/NOI/loj-2247/init.yml b/NOI/loj-2247/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c0d6a0b2e99e0e7f623b70dbce5dbfe1b9b7dd39 --- /dev/null +++ b/NOI/loj-2247/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: game8.in + out: game8.ans + points: 10 +- in: game7.in + out: game7.ans + points: 10 +- in: game10.in + out: game10.ans + points: 10 +- in: game3.in + out: game3.ans + points: 10 +- in: game2.in + out: game2.ans + points: 10 +- in: game6.in + out: game6.ans + points: 10 +- in: game1.in + out: game1.ans + points: 10 +- in: game5.in + out: game5.ans + points: 10 +- in: game9.in + out: game9.ans + points: 10 +- in: game4.in + out: game4.ans + points: 10 diff --git a/NOI/loj-2247/tests.zip b/NOI/loj-2247/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..58cc237a2ead38037b1e3d1975a87221e92211ae --- /dev/null +++ b/NOI/loj-2247/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56fe06da128c4db5d7893cbe6a4e402639e50e629766f19542bac95ef94a7b37 +size 4293066 diff --git a/NOI/loj-2248/init.yml b/NOI/loj-2248/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ef37c8a2c05a4bddf7e48c674e799b14d603222c --- /dev/null +++ b/NOI/loj-2248/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: random2.in + out: random2.out + points: 10 +- in: random10.in + out: random10.out + points: 10 +- in: random6.in + out: random6.out + points: 10 +- in: random9.in + out: random9.out + points: 10 +- in: random8.in + out: random8.out + points: 10 +- in: random3.in + out: random3.out + points: 10 +- in: random4.in + out: random4.out + points: 10 +- in: random7.in + out: random7.out + points: 10 +- in: random5.in + out: random5.out + points: 10 +- in: random1.in + out: random1.out + points: 10 diff --git a/NOI/loj-2248/tests.zip b/NOI/loj-2248/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b3cdd262558a498134d3d244a1f3bece20154a88 --- /dev/null +++ b/NOI/loj-2248/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f00d7baf9c549df4fded84bc8910ea4e69a3754adf99a4b0f4e794e61a24982 +size 3206391 diff --git a/NOI/loj-2249/init.yml b/NOI/loj-2249/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..99fbd2fb0e2861b2dc3b1068b9f19ba3245fe538 --- /dev/null +++ b/NOI/loj-2249/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: ticket7.in + out: ticket7.out + points: 10 +- in: ticket10.in + out: ticket10.out + points: 10 +- in: ticket9.in + out: ticket9.out + points: 10 +- in: ticket4.in + out: ticket4.out + points: 10 +- in: ticket2.in + out: ticket2.out + points: 10 +- in: ticket6.in + out: ticket6.out + points: 10 +- in: ticket5.in + out: ticket5.out + points: 10 +- in: ticket8.in + out: ticket8.out + points: 10 +- in: ticket3.in + out: ticket3.out + points: 10 +- in: ticket1.in + out: ticket1.out + points: 10 diff --git a/NOI/loj-2249/tests.zip b/NOI/loj-2249/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..398ab59555d7ae58e950304245e5a547fc322b58 --- /dev/null +++ b/NOI/loj-2249/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d12a57d7016bc235ac2b70f2dbc9df3d55868e18e5f537e1b9e07922e720ba8 +size 87728550 diff --git a/NOI/loj-2294/init.yml b/NOI/loj-2294/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9a710f6cfb06e7062958acba0956a154236ffbac --- /dev/null +++ b/NOI/loj-2294/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: galaxy8.in + out: galaxy8.ans + points: 10 +- in: galaxy6.in + out: galaxy6.ans + points: 10 +- in: galaxy4.in + out: galaxy4.ans + points: 10 +- in: galaxy2.in + out: galaxy2.ans + points: 10 +- in: galaxy1.in + out: galaxy1.ans + points: 10 +- in: galaxy5.in + out: galaxy5.ans + points: 10 +- in: galaxy10.in + out: galaxy10.ans + points: 10 +- in: galaxy7.in + out: galaxy7.ans + points: 10 +- in: galaxy3.in + out: galaxy3.ans + points: 10 +- in: galaxy9.in + out: galaxy9.ans + points: 10 diff --git a/NOI/loj-2294/tests.zip b/NOI/loj-2294/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..9c05f2df81a9c41072ffb6c38de19f9441ecbbbf --- /dev/null +++ b/NOI/loj-2294/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca36a4d123487997c5dd6b9f3a6032f2ad2306f3e0d0465624f5609c863aa3ee +size 27432555 diff --git a/NOI/loj-2296/init.yml b/NOI/loj-2296/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..0c99aef1d2074907f3c998e6a67df4ea5fb3ec94 --- /dev/null +++ b/NOI/loj-2296/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: dragon5.in + out: dragon5.ans + points: 10 +- in: dragon10.in + out: dragon10.ans + points: 10 +- in: dragon4.in + out: dragon4.ans + points: 10 +- in: dragon6.in + out: dragon6.ans + points: 10 +- in: dragon1.in + out: dragon1.ans + points: 10 +- in: dragon2.in + out: dragon2.ans + points: 10 +- in: dragon9.in + out: dragon9.ans + points: 10 +- in: dragon7.in + out: dragon7.ans + points: 10 +- in: dragon8.in + out: dragon8.ans + points: 10 +- in: dragon3.in + out: dragon3.ans + points: 10 diff --git a/NOI/loj-2296/tests.zip b/NOI/loj-2296/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a59aae2c8a15c9a99c18bf6d818e5416d65dea4f --- /dev/null +++ b/NOI/loj-2296/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:daa3c1b6c9139c1d4e6aff006e7cb66cd39d2e19cbd425c950708d17f5f9882a +size 19616 diff --git a/NOI/loj-2297/init.yml b/NOI/loj-2297/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e5404bdce1ba8f30f4c1010d599ba84e255f846a --- /dev/null +++ b/NOI/loj-2297/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: savage1.in + out: savage1.ans + points: 10 +- in: savage3.in + out: savage3.ans + points: 10 +- in: savage6.in + out: savage6.ans + points: 10 +- in: savage2.in + out: savage2.ans + points: 10 +- in: savage7.in + out: savage7.ans + points: 10 +- in: savage10.in + out: savage10.ans + points: 10 +- in: savage9.in + out: savage9.ans + points: 10 +- in: savage8.in + out: savage8.ans + points: 10 +- in: savage5.in + out: savage5.ans + points: 10 +- in: savage4.in + out: savage4.ans + points: 10 diff --git a/NOI/loj-2297/tests.zip b/NOI/loj-2297/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..62f70d66b9d6ee2d701319bc17679d676c1bd61f --- /dev/null +++ b/NOI/loj-2297/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b488e383c5825eee67b748141fb4dc28a8a039f43ecc45b1d6ca6fd7ccb58cc +size 2963 diff --git a/NOI/loj-2299/init.yml b/NOI/loj-2299/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5fadaaaf87c9958a7badeab6dd1ed509381337a4 --- /dev/null +++ b/NOI/loj-2299/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: robot4.in + out: robot4.ans + points: 10 +- in: robot6.in + out: robot6.ans + points: 10 +- in: robot7.in + out: robot7.ans + points: 10 +- in: robot9.in + out: robot9.ans + points: 10 +- in: robot10.in + out: robot10.ans + points: 10 +- in: robot5.in + out: robot5.ans + points: 10 +- in: robot3.in + out: robot3.ans + points: 10 +- in: robot2.in + out: robot2.ans + points: 10 +- in: robot8.in + out: robot8.ans + points: 10 +- in: robot1.in + out: robot1.ans + points: 10 diff --git a/NOI/loj-2299/tests.zip b/NOI/loj-2299/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c52339456a36434e114a70211f121af276090900 --- /dev/null +++ b/NOI/loj-2299/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfb7601b49dcacd38fc7073773610c5a1d1636bb9d636eee9d00dd9c4ccd4d51 +size 38677 diff --git a/NOI/loj-2302/init.yml b/NOI/loj-2302/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..db1ab0a2f0a0aad442e2cf7d50250fa44db27a1b --- /dev/null +++ b/NOI/loj-2302/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: integer5.in + out: integer5.ans + points: 10 +- in: integer19.in + out: integer19.ans + points: 10 +- in: integer1.in + out: integer1.ans + points: 10 +- in: integer9.in + out: integer9.ans + points: 10 +- in: integer13.in + out: integer13.ans + points: 10 +- in: integer24.in + out: integer24.ans + points: 10 +- in: integer3.in + out: integer3.ans + points: 10 +- in: integer23.in + out: integer23.ans + points: 10 +- in: integer21.in + out: integer21.ans + points: 10 +- in: integer12.in + out: integer12.ans + points: 10 +- in: integer15.in + out: integer15.ans + points: 10 +- in: integer8.in + out: integer8.ans + points: 10 +- in: integer2.in + out: integer2.ans + points: 10 +- in: integer4.in + out: integer4.ans + points: 10 +- in: integer11.in + out: integer11.ans + points: 10 +- in: integer7.in + out: integer7.ans + points: 10 +- in: integer17.in + out: integer17.ans + points: 10 +- in: integer22.in + out: integer22.ans + points: 10 +- in: integer14.in + out: integer14.ans + points: 10 +- in: integer20.in + out: integer20.ans + points: 10 +- in: integer16.in + out: integer16.ans + points: 10 +- in: integer6.in + out: integer6.ans + points: 10 +- in: integer10.in + out: integer10.ans + points: 10 +- in: integer18.in + out: integer18.ans + points: 10 +- in: integer25.in + out: integer25.ans + points: 10 diff --git a/NOI/loj-2302/tests.zip b/NOI/loj-2302/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..58be2ff493c982369b22c5d4dc49124fd7b951ac --- /dev/null +++ b/NOI/loj-2302/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eea8e2659052f7537fd2092bd996ff4963680d52be1ba149566da5b92ccec95a +size 139669173 diff --git a/NOI/loj-2303/init.yml b/NOI/loj-2303/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a78b634a9e1c08023087971173523844431aeab5 --- /dev/null +++ b/NOI/loj-2303/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: queue19.in + out: queue19.ans + points: 10 +- in: queue14.in + out: queue14.ans + points: 10 +- in: queue18.in + out: queue18.ans + points: 10 +- in: queue16.in + out: queue16.ans + points: 10 +- in: queue2.in + out: queue2.ans + points: 10 +- in: queue5.in + out: queue5.ans + points: 10 +- in: queue17.in + out: queue17.ans + points: 10 +- in: queue4.in + out: queue4.ans + points: 10 +- in: queue20.in + out: queue20.ans + points: 10 +- in: queue8.in + out: queue8.ans + points: 10 +- in: queue13.in + out: queue13.ans + points: 10 +- in: queue12.in + out: queue12.ans + points: 10 +- in: queue6.in + out: queue6.ans + points: 10 +- in: queue22.in + out: queue22.ans + points: 10 +- in: queue9.in + out: queue9.ans + points: 10 +- in: queue1.in + out: queue1.ans + points: 10 +- in: queue11.in + out: queue11.ans + points: 10 +- in: queue23.in + out: queue23.ans + points: 10 +- in: queue15.in + out: queue15.ans + points: 10 +- in: queue24.in + out: queue24.ans + points: 10 +- in: queue10.in + out: queue10.ans + points: 10 +- in: queue3.in + out: queue3.ans + points: 10 +- in: queue21.in + out: queue21.ans + points: 10 +- in: queue25.in + out: queue25.ans + points: 10 +- in: queue7.in + out: queue7.ans + points: 10 diff --git a/NOI/loj-2303/tests.zip b/NOI/loj-2303/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c48013946c6c850fb885064cbe7e2b767ba00e12 --- /dev/null +++ b/NOI/loj-2303/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab769464366bdb7429460ebeaff1d2b83570a815ac500702f01b27d972afcead +size 107104999 diff --git a/NOI/loj-2304/init.yml b/NOI/loj-2304/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2df1e2df99bc6968ff47752fa8a37cfa1f741cee --- /dev/null +++ b/NOI/loj-2304/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: pool13.in + out: pool13.ans + points: 10 +- in: pool7.in + out: pool7.ans + points: 10 +- in: pool3.in + out: pool3.ans + points: 10 +- in: pool6.in + out: pool6.ans + points: 10 +- in: pool16.in + out: pool16.ans + points: 10 +- in: pool10.in + out: pool10.ans + points: 10 +- in: pool15.in + out: pool15.ans + points: 10 +- in: pool17.in + out: pool17.ans + points: 10 +- in: pool11.in + out: pool11.ans + points: 10 +- in: pool12.in + out: pool12.ans + points: 10 +- in: pool2.in + out: pool2.ans + points: 10 +- in: pool9.in + out: pool9.ans + points: 10 +- in: pool5.in + out: pool5.ans + points: 10 +- in: pool18.in + out: pool18.ans + points: 10 +- in: pool1.in + out: pool1.ans + points: 10 +- in: pool14.in + out: pool14.ans + points: 10 +- in: pool19.in + out: pool19.ans + points: 10 +- in: pool20.in + out: pool20.ans + points: 10 +- in: pool8.in + out: pool8.ans + points: 10 +- in: pool4.in + out: pool4.ans + points: 10 diff --git a/NOI/loj-2304/tests.zip b/NOI/loj-2304/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..712dfb952b676fa4504a8a84cd05ba10f14e758e --- /dev/null +++ b/NOI/loj-2304/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11f1be420ca7a00ffa087de4e45599fa7d4f93ca6ddcf99e103fca2baba26b9e +size 4553 diff --git a/NOI/loj-2305/init.yml b/NOI/loj-2305/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb56df818978330edac57bfb52bee6766ee0fe67 --- /dev/null +++ b/NOI/loj-2305/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: game13.in + out: game13.ans + points: 10 +- in: game8.in + out: game8.ans + points: 10 +- in: game7.in + out: game7.ans + points: 10 +- in: game12.in + out: game12.ans + points: 10 +- in: game19.in + out: game19.ans + points: 10 +- in: game10.in + out: game10.ans + points: 10 +- in: game11.in + out: game11.ans + points: 10 +- in: game16.in + out: game16.ans + points: 10 +- in: game14.in + out: game14.ans + points: 10 +- in: game17.in + out: game17.ans + points: 10 +- in: game3.in + out: game3.ans + points: 10 +- in: game2.in + out: game2.ans + points: 10 +- in: game18.in + out: game18.ans + points: 10 +- in: game6.in + out: game6.ans + points: 10 +- in: game1.in + out: game1.ans + points: 10 +- in: game15.in + out: game15.ans + points: 10 +- in: game20.in + out: game20.ans + points: 10 +- in: game5.in + out: game5.ans + points: 10 +- in: game9.in + out: game9.ans + points: 10 +- in: game4.in + out: game4.ans + points: 10 diff --git a/NOI/loj-2305/tests.zip b/NOI/loj-2305/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b557fe345283b5b0a5d668c535ade4acbb1fa92b --- /dev/null +++ b/NOI/loj-2305/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a586639ee2ab2d367299282f0ebddcfb675eff2670444629579cf51e722177e2 +size 4474832 diff --git a/NOI/loj-2306/init.yml b/NOI/loj-2306/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..543c7047fa18f66e24a080c40dc66726e2e98647 --- /dev/null +++ b/NOI/loj-2306/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: vegetables9.in + out: vegetables9.ans + points: 10 +- in: vegetables7.in + out: vegetables7.ans + points: 10 +- in: vegetables5.in + out: vegetables5.ans + points: 10 +- in: vegetables25.in + out: vegetables25.ans + points: 10 +- in: vegetables15.in + out: vegetables15.ans + points: 10 +- in: vegetables13.in + out: vegetables13.ans + points: 10 +- in: vegetables2.in + out: vegetables2.ans + points: 10 +- in: vegetables11.in + out: vegetables11.ans + points: 10 +- in: vegetables16.in + out: vegetables16.ans + points: 10 +- in: vegetables14.in + out: vegetables14.ans + points: 10 +- in: vegetables4.in + out: vegetables4.ans + points: 10 +- in: vegetables12.in + out: vegetables12.ans + points: 10 +- in: vegetables22.in + out: vegetables22.ans + points: 10 +- in: vegetables10.in + out: vegetables10.ans + points: 10 +- in: vegetables20.in + out: vegetables20.ans + points: 10 +- in: vegetables8.in + out: vegetables8.ans + points: 10 +- in: vegetables18.in + out: vegetables18.ans + points: 10 +- in: vegetables23.in + out: vegetables23.ans + points: 10 +- in: vegetables21.in + out: vegetables21.ans + points: 10 +- in: vegetables1.in + out: vegetables1.ans + points: 10 +- in: vegetables17.in + out: vegetables17.ans + points: 10 +- in: vegetables19.in + out: vegetables19.ans + points: 10 +- in: vegetables3.in + out: vegetables3.ans + points: 10 +- in: vegetables6.in + out: vegetables6.ans + points: 10 +- in: vegetables24.in + out: vegetables24.ans + points: 10 diff --git a/NOI/loj-2306/tests.zip b/NOI/loj-2306/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..960be7b5392eb0b8fddac28efcd5b49489348c4d --- /dev/null +++ b/NOI/loj-2306/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e3c43d741df81bc341036a5f3df58b1b13ea136c6ff226c6732d6bd33c16a26 +size 22068265 diff --git a/NOI/loj-2307/init.yml b/NOI/loj-2307/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..fe903d3fa13882a8532fdee249b00542218c7232 --- /dev/null +++ b/NOI/loj-2307/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: phantom9.in + out: phantom9.ans + points: 10 +- in: phantom3.in + out: phantom3.ans + points: 10 +- in: phantom6.in + out: phantom6.ans + points: 10 +- in: phantom8.in + out: phantom8.ans + points: 10 +- in: phantom14.in + out: phantom14.ans + points: 10 +- in: phantom1.in + out: phantom1.ans + points: 10 +- in: phantom17.in + out: phantom17.ans + points: 10 +- in: phantom16.in + out: phantom16.ans + points: 10 +- in: phantom2.in + out: phantom2.ans + points: 10 +- in: phantom10.in + out: phantom10.ans + points: 10 +- in: phantom5.in + out: phantom5.ans + points: 10 +- in: phantom4.in + out: phantom4.ans + points: 10 +- in: phantom7.in + out: phantom7.ans + points: 10 +- in: phantom18.in + out: phantom18.ans + points: 10 +- in: phantom19.in + out: phantom19.ans + points: 10 +- in: phantom13.in + out: phantom13.ans + points: 10 +- in: phantom12.in + out: phantom12.ans + points: 10 +- in: phantom15.in + out: phantom15.ans + points: 10 +- in: phantom11.in + out: phantom11.ans + points: 10 +- in: phantom20.in + out: phantom20.ans + points: 10 diff --git a/NOI/loj-2307/tests.zip b/NOI/loj-2307/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..7156c9f8a195205b539ed15a3d566123f4fd0575 --- /dev/null +++ b/NOI/loj-2307/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32ccd6f381e00fe4aafe461db2371fab470a56d447b30eb57838694ea3aded0c +size 118980935 diff --git a/NOI/loj-2314/init.yml b/NOI/loj-2314/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f51e9b1cad7a791118ee7838d2c1159f5e48124f --- /dev/null +++ b/NOI/loj-2314/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: math19.in + out: math19.ans + points: 10 +- in: math15.in + out: math15.ans + points: 10 +- in: math7.in + out: math7.ans + points: 10 +- in: math17.in + out: math17.ans + points: 10 +- in: math3.in + out: math3.ans + points: 10 +- in: math2.in + out: math2.ans + points: 10 +- in: math14.in + out: math14.ans + points: 10 +- in: math20.in + out: math20.ans + points: 10 +- in: math6.in + out: math6.ans + points: 10 +- in: math5.in + out: math5.ans + points: 10 +- in: math11.in + out: math11.ans + points: 10 +- in: math10.in + out: math10.ans + points: 10 +- in: math12.in + out: math12.ans + points: 10 +- in: math9.in + out: math9.ans + points: 10 +- in: math1.in + out: math1.ans + points: 10 +- in: math8.in + out: math8.ans + points: 10 +- in: math13.in + out: math13.ans + points: 10 +- in: math16.in + out: math16.ans + points: 10 +- in: math18.in + out: math18.ans + points: 10 +- in: math4.in + out: math4.ans + points: 10 diff --git a/NOI/loj-2314/tests.zip b/NOI/loj-2314/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..3afcfbd7275ee2c21d0aad0d2988cc2d0e305c67 --- /dev/null +++ b/NOI/loj-2314/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58a91e31b69739b48c824dca79de8331b13f75025231fbb84567e6677d5a24bd +size 10036 diff --git a/NOI/loj-2315/init.yml b/NOI/loj-2315/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..1560278d52f2d9873a1b4bcdf7de515beafeba5c --- /dev/null +++ b/NOI/loj-2315/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: complexity10.in + out: complexity10.ans + points: 10 +- in: complexity7.in + out: complexity7.ans + points: 10 +- in: complexity9.in + out: complexity9.ans + points: 10 +- in: complexity3.in + out: complexity3.ans + points: 10 +- in: complexity4.in + out: complexity4.ans + points: 10 +- in: complexity1.in + out: complexity1.ans + points: 10 +- in: complexity2.in + out: complexity2.ans + points: 10 +- in: complexity5.in + out: complexity5.ans + points: 10 +- in: complexity8.in + out: complexity8.ans + points: 10 +- in: complexity6.in + out: complexity6.ans + points: 10 diff --git a/NOI/loj-2315/tests.zip b/NOI/loj-2315/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..aba62f4fa9b60a2b9f3125f48ed50187422cb18e --- /dev/null +++ b/NOI/loj-2315/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0bfe57c99cad232f808483000a6b25a8bc75346d91812ce0482918b82e4c7f50 +size 11927 diff --git a/NOI/loj-2316/init.yml b/NOI/loj-2316/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..274fb22140b9dc94ded7019b4d80e0a6aad1ff2c --- /dev/null +++ b/NOI/loj-2316/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: park1.in + out: park1.ans + points: 10 +- in: park7.in + out: park7.ans + points: 10 +- in: park5.in + out: park5.ans + points: 10 +- in: park6.in + out: park6.ans + points: 10 +- in: park4.in + out: park4.ans + points: 10 +- in: park9.in + out: park9.ans + points: 10 +- in: park2.in + out: park2.ans + points: 10 +- in: park10.in + out: park10.ans + points: 10 +- in: park3.in + out: park3.ans + points: 10 +- in: park8.in + out: park8.ans + points: 10 diff --git a/NOI/loj-2316/tests.zip b/NOI/loj-2316/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a7963e22aeccec43d336388108e54618f7f6f9f5 --- /dev/null +++ b/NOI/loj-2316/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b76d8b33c134d314022e2e44f87aaf2c6954a1acc6f814abd1a441622c44fa17 +size 35633341 diff --git a/NOI/loj-2317/init.yml b/NOI/loj-2317/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d5bdb6adb8de3d754dc710204b274a4a524e7031 --- /dev/null +++ b/NOI/loj-2317/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: cheese2.in + out: cheese2.ans + points: 10 +- in: cheese5.in + out: cheese5.ans + points: 10 +- in: cheese3.in + out: cheese3.ans + points: 10 +- in: cheese10.in + out: cheese10.ans + points: 10 +- in: cheese1.in + out: cheese1.ans + points: 10 +- in: cheese6.in + out: cheese6.ans + points: 10 +- in: cheese7.in + out: cheese7.ans + points: 10 +- in: cheese8.in + out: cheese8.ans + points: 10 +- in: cheese9.in + out: cheese9.ans + points: 10 +- in: cheese4.in + out: cheese4.ans + points: 10 diff --git a/NOI/loj-2317/tests.zip b/NOI/loj-2317/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..fe3c8bc0bccce4f37e1a71124372d2710b460cfb --- /dev/null +++ b/NOI/loj-2317/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2805a8448b03387d85f18567575e63f7ea884d49b47405f6665a46bf8826cff8 +size 1881302 diff --git a/NOI/loj-2318/init.yml b/NOI/loj-2318/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..14fe4f6a8ef1edbe9dbefc76e1c26a0e893308ce --- /dev/null +++ b/NOI/loj-2318/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: treasure12.in + out: treasure12.ans + points: 10 +- in: treasure10.in + out: treasure10.ans + points: 10 +- in: treasure11.in + out: treasure11.ans + points: 10 +- in: treasure2.in + out: treasure2.ans + points: 10 +- in: treasure18.in + out: treasure18.ans + points: 10 +- in: treasure15.in + out: treasure15.ans + points: 10 +- in: treasure16.in + out: treasure16.ans + points: 10 +- in: treasure19.in + out: treasure19.ans + points: 10 +- in: treasure9.in + out: treasure9.ans + points: 10 +- in: treasure1.in + out: treasure1.ans + points: 10 +- in: treasure20.in + out: treasure20.ans + points: 10 +- in: treasure4.in + out: treasure4.ans + points: 10 +- in: treasure7.in + out: treasure7.ans + points: 10 +- in: treasure14.in + out: treasure14.ans + points: 10 +- in: treasure6.in + out: treasure6.ans + points: 10 +- in: treasure8.in + out: treasure8.ans + points: 10 +- in: treasure13.in + out: treasure13.ans + points: 10 +- in: treasure17.in + out: treasure17.ans + points: 10 +- in: treasure5.in + out: treasure5.ans + points: 10 +- in: treasure3.in + out: treasure3.ans + points: 10 diff --git a/NOI/loj-2318/tests.zip b/NOI/loj-2318/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c9f204098f5f955ff609e65fa17f1c9fcb684adb --- /dev/null +++ b/NOI/loj-2318/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1c8a6426e59bc53502870fc8679d7b66731015517ae8f9d94dbfa4a5c25e27a +size 65902 diff --git a/NOI/loj-2319/init.yml b/NOI/loj-2319/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e7f6d7bb9775baf538d23c53b4e68886c1d84fd9 --- /dev/null +++ b/NOI/loj-2319/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: phalanx10.in + out: phalanx10.ans + points: 10 +- in: phalanx4.in + out: phalanx4.ans + points: 10 +- in: phalanx19.in + out: phalanx19.ans + points: 10 +- in: phalanx6.in + out: phalanx6.ans + points: 10 +- in: phalanx3.in + out: phalanx3.ans + points: 10 +- in: phalanx14.in + out: phalanx14.ans + points: 10 +- in: phalanx20.in + out: phalanx20.ans + points: 10 +- in: phalanx5.in + out: phalanx5.ans + points: 10 +- in: phalanx8.in + out: phalanx8.ans + points: 10 +- in: phalanx7.in + out: phalanx7.ans + points: 10 +- in: phalanx18.in + out: phalanx18.ans + points: 10 +- in: phalanx2.in + out: phalanx2.ans + points: 10 +- in: phalanx11.in + out: phalanx11.ans + points: 10 +- in: phalanx1.in + out: phalanx1.ans + points: 10 +- in: phalanx17.in + out: phalanx17.ans + points: 10 +- in: phalanx9.in + out: phalanx9.ans + points: 10 +- in: phalanx13.in + out: phalanx13.ans + points: 10 +- in: phalanx12.in + out: phalanx12.ans + points: 10 +- in: phalanx16.in + out: phalanx16.ans + points: 10 +- in: phalanx15.in + out: phalanx15.ans + points: 10 diff --git a/NOI/loj-2319/tests.zip b/NOI/loj-2319/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..03151a42f679383014e225b952678f8d4af6155e --- /dev/null +++ b/NOI/loj-2319/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7496a698378a84790386c3301f78dde907ce0fcd9a15b574443614407b377213 +size 39565744 diff --git a/NOI/loj-2352/init.yml b/NOI/loj-2352/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9a6f996b44f2ed9aef320bd2fe4175b70e90c697 --- /dev/null +++ b/NOI/loj-2352/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: network10.in + out: network10.ans + points: 10 +- in: network2.in + out: network2.ans + points: 10 +- in: network4.in + out: network4.ans + points: 10 +- in: network1.in + out: network1.ans + points: 10 +- in: network8.in + out: network8.ans + points: 10 +- in: network9.in + out: network9.ans + points: 10 +- in: network3.in + out: network3.ans + points: 10 +- in: network7.in + out: network7.ans + points: 10 +- in: network6.in + out: network6.ans + points: 10 +- in: network5.in + out: network5.ans + points: 10 diff --git a/NOI/loj-2352/tests.zip b/NOI/loj-2352/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..75fc33080124a9b9ae4dbb2ce6db7d9ef6ac8f5d --- /dev/null +++ b/NOI/loj-2352/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b14eb47e96d748380bfca28dff05f4ff5c9a0a36254a145ab83285e90bd416d5 +size 64629 diff --git a/NOI/loj-2353/init.yml b/NOI/loj-2353/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a6b4a6e23a964752a4d9b9fefd523dbf1e24d790 --- /dev/null +++ b/NOI/loj-2353/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: cash5.in + out: cash5.ans + points: 10 +- in: cash10.in + out: cash10.ans + points: 10 +- in: cash3.in + out: cash3.ans + points: 10 +- in: cash1.in + out: cash1.ans + points: 10 +- in: cash8.in + out: cash8.ans + points: 10 +- in: cash6.in + out: cash6.ans + points: 10 +- in: cash4.in + out: cash4.ans + points: 10 +- in: cash9.in + out: cash9.ans + points: 10 +- in: cash7.in + out: cash7.ans + points: 10 +- in: cash2.in + out: cash2.ans + points: 10 diff --git a/NOI/loj-2353/tests.zip b/NOI/loj-2353/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ba5de65bc14ddbadc422d9616859a0e74546605e --- /dev/null +++ b/NOI/loj-2353/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d1988fb5856f3350d5a309ecb6cf58f0be647c418762c923c906fbf81478133 +size 18393886 diff --git a/NOI/loj-2354/init.yml b/NOI/loj-2354/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3b470b5391862abbf2f63f8ad3f4434f20c226c7 --- /dev/null +++ b/NOI/loj-2354/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: surround9.in + out: surround9.ans + points: 10 +- in: surround3.in + out: surround3.ans + points: 10 +- in: surround2.in + out: surround2.ans + points: 10 +- in: surround1.in + out: surround1.ans + points: 10 +- in: surround5.in + out: surround5.ans + points: 10 +- in: surround4.in + out: surround4.ans + points: 10 +- in: surround7.in + out: surround7.ans + points: 10 +- in: surround8.in + out: surround8.ans + points: 10 +- in: surround10.in + out: surround10.ans + points: 10 +- in: surround6.in + out: surround6.ans + points: 10 diff --git a/NOI/loj-2354/tests.zip b/NOI/loj-2354/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e36361fe6b013a7a4efac04430246f41b7b9ebd7 --- /dev/null +++ b/NOI/loj-2354/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a803fc7a60d68f68e77c3409f49a382edfec80b0f3bdb81aa18a59d9f0847ee9 +size 474985 diff --git a/NOI/loj-2355/init.yml b/NOI/loj-2355/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c2aeee995ecb2c272e4c9b07dcd8e4a34acee479 --- /dev/null +++ b/NOI/loj-2355/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: necklace3.in + out: necklace3.ans + points: 10 +- in: necklace5.in + out: necklace5.ans + points: 10 +- in: necklace8.in + out: necklace8.ans + points: 10 +- in: necklace7.in + out: necklace7.ans + points: 10 +- in: necklace2.in + out: necklace2.ans + points: 10 +- in: necklace6.in + out: necklace6.ans + points: 10 +- in: necklace9.in + out: necklace9.ans + points: 10 +- in: necklace4.in + out: necklace4.ans + points: 10 +- in: necklace1.in + out: necklace1.ans + points: 10 +- in: necklace10.in + out: necklace10.ans + points: 10 diff --git a/NOI/loj-2355/tests.zip b/NOI/loj-2355/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ad8fa92013b75271957b9195b5ec028f6c170b3a --- /dev/null +++ b/NOI/loj-2355/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9de64d8b8e6865a360084742e91d30ce6c50cb59962019c27c87a159423036a5 +size 23519184 diff --git a/NOI/loj-2356/init.yml b/NOI/loj-2356/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c608cb352e8f9995e9606effaa8219e42f13de94 --- /dev/null +++ b/NOI/loj-2356/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: count9.in + out: count9.ans + points: 10 +- in: count5.in + out: count5.ans + points: 10 +- in: count2.in + out: count2.ans + points: 10 +- in: count8.in + out: count8.ans + points: 10 +- in: count1.in + out: count1.ans + points: 10 +- in: count4.in + out: count4.ans + points: 10 +- in: count10.in + out: count10.ans + points: 10 +- in: count6.in + out: count6.ans + points: 10 +- in: count7.in + out: count7.ans + points: 10 +- in: count3.in + out: count3.ans + points: 10 diff --git a/NOI/loj-2356/tests.zip b/NOI/loj-2356/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..38e24ba83e5fd9b40ee13ebd54ebf3adcbfd1b4d --- /dev/null +++ b/NOI/loj-2356/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20653ed85d816b4a6467d63a6cdfbebe400812c75f6f072f57f66c5edf1986ae +size 2055 diff --git a/NOI/loj-2357/init.yml b/NOI/loj-2357/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9502c22186e75d3b61a772e2b878825243ece771 --- /dev/null +++ b/NOI/loj-2357/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: catch7.in + out: catch7.ans + points: 10 +- in: catch9.in + out: catch9.ans + points: 10 +- in: catch8.in + out: catch8.ans + points: 10 +- in: catch1.in + out: catch1.ans + points: 10 +- in: catch2.in + out: catch2.ans + points: 10 +- in: catch3.in + out: catch3.ans + points: 10 +- in: catch5.in + out: catch5.ans + points: 10 +- in: catch6.in + out: catch6.ans + points: 10 +- in: catch4.in + out: catch4.ans + points: 10 +- in: catch10.in + out: catch10.ans + points: 10 diff --git a/NOI/loj-2357/tests.zip b/NOI/loj-2357/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..96b8bcd9b4c1e6490c4472591a6929ca730cf3dd --- /dev/null +++ b/NOI/loj-2357/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b995399521b1250d845527a7e63fa29a2fbb7c0d05aee4331d362e1d61e47fc0 +size 157749 diff --git a/NOI/loj-2358/init.yml b/NOI/loj-2358/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a5fc5512014d8fe5cea4ff16c1e43d5682e7f50b --- /dev/null +++ b/NOI/loj-2358/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: toy17.in + out: toy17.ans + points: 10 +- in: toy7.in + out: toy7.ans + points: 10 +- in: toy19.in + out: toy19.ans + points: 10 +- in: toy12.in + out: toy12.ans + points: 10 +- in: toy5.in + out: toy5.ans + points: 10 +- in: toy18.in + out: toy18.ans + points: 10 +- in: toy14.in + out: toy14.ans + points: 10 +- in: toy9.in + out: toy9.ans + points: 10 +- in: toy3.in + out: toy3.ans + points: 10 +- in: toy20.in + out: toy20.ans + points: 10 +- in: toy13.in + out: toy13.ans + points: 10 +- in: toy1.in + out: toy1.ans + points: 10 +- in: toy15.in + out: toy15.ans + points: 10 +- in: toy6.in + out: toy6.ans + points: 10 +- in: toy10.in + out: toy10.ans + points: 10 +- in: toy4.in + out: toy4.ans + points: 10 +- in: toy16.in + out: toy16.ans + points: 10 +- in: toy8.in + out: toy8.ans + points: 10 +- in: toy2.in + out: toy2.ans + points: 10 +- in: toy11.in + out: toy11.ans + points: 10 diff --git a/NOI/loj-2358/tests.zip b/NOI/loj-2358/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..876c6b8a79ba94c5d60119978c80168cc35da744 --- /dev/null +++ b/NOI/loj-2358/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0830097c9e7a6191683a68c92bff3ccd2683a13dc68901dcaf729d3f66b025c +size 7071198 diff --git a/NOI/loj-2359/init.yml b/NOI/loj-2359/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..90186a4472331dc36c4a8ba761cc45048719f72f --- /dev/null +++ b/NOI/loj-2359/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: running1.in + out: running1.ans + points: 10 +- in: running20.in + out: running20.ans + points: 10 +- in: running11.in + out: running11.ans + points: 10 +- in: running17.in + out: running17.ans + points: 10 +- in: running19.in + out: running19.ans + points: 10 +- in: running13.in + out: running13.ans + points: 10 +- in: running16.in + out: running16.ans + points: 10 +- in: running5.in + out: running5.ans + points: 10 +- in: running15.in + out: running15.ans + points: 10 +- in: running18.in + out: running18.ans + points: 10 +- in: running12.in + out: running12.ans + points: 10 +- in: running2.in + out: running2.ans + points: 10 +- in: running8.in + out: running8.ans + points: 10 +- in: running7.in + out: running7.ans + points: 10 +- in: running9.in + out: running9.ans + points: 10 +- in: running6.in + out: running6.ans + points: 10 +- in: running3.in + out: running3.ans + points: 10 +- in: running14.in + out: running14.ans + points: 10 +- in: running4.in + out: running4.ans + points: 10 +- in: running10.in + out: running10.ans + points: 10 diff --git a/NOI/loj-2359/tests.zip b/NOI/loj-2359/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..57c8dfc12546331e7183291574702dc9a5f0a077 --- /dev/null +++ b/NOI/loj-2359/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7eb4565e74929ad63b6159837ebf94ffa00711518143e2e063f9e210a9e8f95 +size 52888717 diff --git a/NOI/loj-2360/init.yml b/NOI/loj-2360/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd6f2ddd871e518f7fce1812c6361337bc2d194e --- /dev/null +++ b/NOI/loj-2360/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: classroom24.in + out: classroom24.ans + points: 10 +- in: classroom2.in + out: classroom2.ans + points: 10 +- in: classroom5.in + out: classroom5.ans + points: 10 +- in: classroom15.in + out: classroom15.ans + points: 10 +- in: classroom25.in + out: classroom25.ans + points: 10 +- in: classroom16.in + out: classroom16.ans + points: 10 +- in: classroom19.in + out: classroom19.ans + points: 10 +- in: classroom13.in + out: classroom13.ans + points: 10 +- in: classroom8.in + out: classroom8.ans + points: 10 +- in: classroom12.in + out: classroom12.ans + points: 10 +- in: classroom23.in + out: classroom23.ans + points: 10 +- in: classroom14.in + out: classroom14.ans + points: 10 +- in: classroom9.in + out: classroom9.ans + points: 10 +- in: classroom6.in + out: classroom6.ans + points: 10 +- in: classroom1.in + out: classroom1.ans + points: 10 +- in: classroom22.in + out: classroom22.ans + points: 10 +- in: classroom17.in + out: classroom17.ans + points: 10 +- in: classroom18.in + out: classroom18.ans + points: 10 +- in: classroom4.in + out: classroom4.ans + points: 10 +- in: classroom3.in + out: classroom3.ans + points: 10 +- in: classroom10.in + out: classroom10.ans + points: 10 +- in: classroom20.in + out: classroom20.ans + points: 10 +- in: classroom7.in + out: classroom7.ans + points: 10 +- in: classroom11.in + out: classroom11.ans + points: 10 +- in: classroom21.in + out: classroom21.ans + points: 10 diff --git a/NOI/loj-2360/tests.zip b/NOI/loj-2360/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b1e0a42134fe5b06e264265577dcf333a56fbf8d --- /dev/null +++ b/NOI/loj-2360/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a4a6626b5115dd656a6374fc283019946d8aaf4c2131e80f291f02b9b175e20 +size 3564939 diff --git a/NOI/loj-2361/init.yml b/NOI/loj-2361/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f17a8e9986ac2eca6364950991c510bc8dd89698 --- /dev/null +++ b/NOI/loj-2361/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: problem7.in + out: problem7.ans + points: 10 +- in: problem14.in + out: problem14.ans + points: 10 +- in: problem16.in + out: problem16.ans + points: 10 +- in: problem4.in + out: problem4.ans + points: 10 +- in: problem15.in + out: problem15.ans + points: 10 +- in: problem8.in + out: problem8.ans + points: 10 +- in: problem17.in + out: problem17.ans + points: 10 +- in: problem10.in + out: problem10.ans + points: 10 +- in: problem3.in + out: problem3.ans + points: 10 +- in: problem12.in + out: problem12.ans + points: 10 +- in: problem18.in + out: problem18.ans + points: 10 +- in: problem1.in + out: problem1.ans + points: 10 +- in: problem13.in + out: problem13.ans + points: 10 +- in: problem20.in + out: problem20.ans + points: 10 +- in: problem5.in + out: problem5.ans + points: 10 +- in: problem19.in + out: problem19.ans + points: 10 +- in: problem2.in + out: problem2.ans + points: 10 +- in: problem6.in + out: problem6.ans + points: 10 +- in: problem11.in + out: problem11.ans + points: 10 +- in: problem9.in + out: problem9.ans + points: 10 diff --git a/NOI/loj-2361/tests.zip b/NOI/loj-2361/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..6d29ca0ee355304048005d9bd8761cfd10ab3185 --- /dev/null +++ b/NOI/loj-2361/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d6ddf06c8a1e95643023473454dc13358eb7d3467b45ac613a4a5dc93226946 +size 669897 diff --git a/NOI/loj-2362/init.yml b/NOI/loj-2362/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ef6e38458c88d84aa05615731d6f82c8853237ba --- /dev/null +++ b/NOI/loj-2362/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: earthworm17.in + out: earthworm17.ans + points: 10 +- in: earthworm18.in + out: earthworm18.ans + points: 10 +- in: earthworm8.in + out: earthworm8.ans + points: 10 +- in: earthworm1.in + out: earthworm1.ans + points: 10 +- in: earthworm5.in + out: earthworm5.ans + points: 10 +- in: earthworm20.in + out: earthworm20.ans + points: 10 +- in: earthworm11.in + out: earthworm11.ans + points: 10 +- in: earthworm6.in + out: earthworm6.ans + points: 10 +- in: earthworm7.in + out: earthworm7.ans + points: 10 +- in: earthworm9.in + out: earthworm9.ans + points: 10 +- in: earthworm4.in + out: earthworm4.ans + points: 10 +- in: earthworm15.in + out: earthworm15.ans + points: 10 +- in: earthworm14.in + out: earthworm14.ans + points: 10 +- in: earthworm12.in + out: earthworm12.ans + points: 10 +- in: earthworm3.in + out: earthworm3.ans + points: 10 +- in: earthworm2.in + out: earthworm2.ans + points: 10 +- in: earthworm13.in + out: earthworm13.ans + points: 10 +- in: earthworm19.in + out: earthworm19.ans + points: 10 +- in: earthworm10.in + out: earthworm10.ans + points: 10 +- in: earthworm16.in + out: earthworm16.ans + points: 10 diff --git a/NOI/loj-2362/tests.zip b/NOI/loj-2362/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..bf2bec05f93701b8b7d0a6c9b0105268c63076ad --- /dev/null +++ b/NOI/loj-2362/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55093b0695e1698a6e5678ffa724b5030e1a02237922ce1e16166620d32a1dc3 +size 28797828 diff --git a/NOI/loj-2363/init.yml b/NOI/loj-2363/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ae4e09bba62f1a4f60864094fcdf5a48e37763c4 --- /dev/null +++ b/NOI/loj-2363/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: angrybirds14.in + out: angrybirds14.ans + points: 10 +- in: angrybirds19.in + out: angrybirds19.ans + points: 10 +- in: angrybirds5.in + out: angrybirds5.ans + points: 10 +- in: angrybirds16.in + out: angrybirds16.ans + points: 10 +- in: angrybirds10.in + out: angrybirds10.ans + points: 10 +- in: angrybirds8.in + out: angrybirds8.ans + points: 10 +- in: angrybirds4.in + out: angrybirds4.ans + points: 10 +- in: angrybirds2.in + out: angrybirds2.ans + points: 10 +- in: angrybirds6.in + out: angrybirds6.ans + points: 10 +- in: angrybirds18.in + out: angrybirds18.ans + points: 10 +- in: angrybirds9.in + out: angrybirds9.ans + points: 10 +- in: angrybirds17.in + out: angrybirds17.ans + points: 10 +- in: angrybirds11.in + out: angrybirds11.ans + points: 10 +- in: angrybirds13.in + out: angrybirds13.ans + points: 10 +- in: angrybirds12.in + out: angrybirds12.ans + points: 10 +- in: angrybirds3.in + out: angrybirds3.ans + points: 10 +- in: angrybirds15.in + out: angrybirds15.ans + points: 10 +- in: angrybirds7.in + out: angrybirds7.ans + points: 10 +- in: angrybirds1.in + out: angrybirds1.ans + points: 10 +- in: angrybirds20.in + out: angrybirds20.ans + points: 10 diff --git a/NOI/loj-2363/tests.zip b/NOI/loj-2363/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..acd89053057a46093402054bd49c4fab38de1562 --- /dev/null +++ b/NOI/loj-2363/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54c338839673877d26545681b753c87f984c33cb266e7ccdab84b153c0de14fa +size 33087 diff --git a/NOI/loj-2415/init.yml b/NOI/loj-2415/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..29d93406579ee01bc39401a9509e3055d6c6624d --- /dev/null +++ b/NOI/loj-2415/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: message9.in + out: message9.ans + points: 10 +- in: message7.in + out: message7.ans + points: 10 +- in: message1.in + out: message1.ans + points: 10 +- in: message5.in + out: message5.ans + points: 10 +- in: message6.in + out: message6.ans + points: 10 +- in: message4.in + out: message4.ans + points: 10 +- in: message3.in + out: message3.ans + points: 10 +- in: message2.in + out: message2.ans + points: 10 +- in: message10.in + out: message10.ans + points: 10 +- in: message8.in + out: message8.ans + points: 10 diff --git a/NOI/loj-2415/tests.zip b/NOI/loj-2415/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..47c76c8edb885f020246831b16ebfd795692f9a6 --- /dev/null +++ b/NOI/loj-2415/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f6fe5922957e5ff4a956d66f9f49f36112c2d187b658d968203af843d74de4e +size 31583 diff --git a/NOI/loj-2416/init.yml b/NOI/loj-2416/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a7df35300d957f364036a91e1dd011b5e795199e --- /dev/null +++ b/NOI/loj-2416/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: twostack5.in + out: twostack5.ans + points: 10 +- in: twostack8.in + out: twostack8.ans + points: 10 +- in: twostack2.in + out: twostack2.ans + points: 10 +- in: twostack3.in + out: twostack3.ans + points: 10 +- in: twostack7.in + out: twostack7.ans + points: 10 +- in: twostack6.in + out: twostack6.ans + points: 10 +- in: twostack1.in + out: twostack1.ans + points: 10 +- in: twostack4.in + out: twostack4.ans + points: 10 +- in: twostack9.in + out: twostack9.ans + points: 10 +- in: twostack10.in + out: twostack10.ans + points: 10 diff --git a/NOI/loj-2416/tests.zip b/NOI/loj-2416/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..da44be2e91a211e1cb8424fc908edc83dcb2e294 --- /dev/null +++ b/NOI/loj-2416/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3eb5c75f1c044d359199c4ac63b4df04cdbf476a7608521c92935495ef589529 +size 22110 diff --git a/NOI/loj-2420/init.yml b/NOI/loj-2420/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..4ca8705c685cc3b52bffd429948a4cba83a7c67e --- /dev/null +++ b/NOI/loj-2420/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: magic9.in + out: magic9.ans + points: 10 +- in: magic4.in + out: magic4.ans + points: 10 +- in: magic6.in + out: magic6.ans + points: 10 +- in: magic3.in + out: magic3.ans + points: 10 +- in: magic7.in + out: magic7.ans + points: 10 +- in: magic2.in + out: magic2.ans + points: 10 +- in: magic5.in + out: magic5.ans + points: 10 +- in: magic8.in + out: magic8.ans + points: 10 +- in: magic10.in + out: magic10.ans + points: 10 +- in: magic1.in + out: magic1.ans + points: 10 diff --git a/NOI/loj-2420/tests.zip b/NOI/loj-2420/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..58a210c53a8bc032f833ff7a107f4ab7d21b0ee2 --- /dev/null +++ b/NOI/loj-2420/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:029ccc40d4386748ab5c20838c0097fdd4c67f954cdb139f8ec5f18d74154f51 +size 25477 diff --git a/NOI/loj-2421/init.yml b/NOI/loj-2421/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..29d93406579ee01bc39401a9509e3055d6c6624d --- /dev/null +++ b/NOI/loj-2421/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: message9.in + out: message9.ans + points: 10 +- in: message7.in + out: message7.ans + points: 10 +- in: message1.in + out: message1.ans + points: 10 +- in: message5.in + out: message5.ans + points: 10 +- in: message6.in + out: message6.ans + points: 10 +- in: message4.in + out: message4.ans + points: 10 +- in: message3.in + out: message3.ans + points: 10 +- in: message2.in + out: message2.ans + points: 10 +- in: message10.in + out: message10.ans + points: 10 +- in: message8.in + out: message8.ans + points: 10 diff --git a/NOI/loj-2421/tests.zip b/NOI/loj-2421/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a544880e7f06d36274a3028ac97205cb18fe3497 --- /dev/null +++ b/NOI/loj-2421/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1554f3e80c2cefae8fa0d87017ca4c701d99ec1ca9421af16d3ddf7961292fe +size 2240452 diff --git a/NOI/loj-2422/init.yml b/NOI/loj-2422/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ce545de81391a79ac48a92cfa5696ba96957faf --- /dev/null +++ b/NOI/loj-2422/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: landlords15.in + out: landlords15.ans + points: 10 +- in: landlords12.in + out: landlords12.ans + points: 10 +- in: landlords9.in + out: landlords9.ans + points: 10 +- in: landlords17.in + out: landlords17.ans + points: 10 +- in: landlords19.in + out: landlords19.ans + points: 10 +- in: landlords13.in + out: landlords13.ans + points: 10 +- in: landlords4.in + out: landlords4.ans + points: 10 +- in: landlords18.in + out: landlords18.ans + points: 10 +- in: landlords10.in + out: landlords10.ans + points: 10 +- in: landlords7.in + out: landlords7.ans + points: 10 +- in: landlords6.in + out: landlords6.ans + points: 10 +- in: landlords2.in + out: landlords2.ans + points: 10 +- in: landlords8.in + out: landlords8.ans + points: 10 +- in: landlords5.in + out: landlords5.ans + points: 10 +- in: landlords20.in + out: landlords20.ans + points: 10 +- in: landlords11.in + out: landlords11.ans + points: 10 +- in: landlords14.in + out: landlords14.ans + points: 10 +- in: landlords16.in + out: landlords16.ans + points: 10 +- in: landlords3.in + out: landlords3.ans + points: 10 +- in: landlords1.in + out: landlords1.ans + points: 10 diff --git a/NOI/loj-2422/tests.zip b/NOI/loj-2422/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..1e1e454d28d336098e388180296a7f4724ef6988 --- /dev/null +++ b/NOI/loj-2422/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4be7c2987ea8ac416f34d6241ceb3166e9821981de3b186867ffed3d12894d0f +size 53489 diff --git a/NOI/loj-2423/init.yml b/NOI/loj-2423/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6004dd9f8d03d18ebe486d398525a930b7c4a771 --- /dev/null +++ b/NOI/loj-2423/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: stone8.in + out: stone8.ans + points: 10 +- in: stone2.in + out: stone2.ans + points: 10 +- in: stone5.in + out: stone5.ans + points: 10 +- in: stone4.in + out: stone4.ans + points: 10 +- in: stone3.in + out: stone3.ans + points: 10 +- in: stone6.in + out: stone6.ans + points: 10 +- in: stone7.in + out: stone7.ans + points: 10 +- in: stone1.in + out: stone1.ans + points: 10 +- in: stone9.in + out: stone9.ans + points: 10 +- in: stone10.in + out: stone10.ans + points: 10 diff --git a/NOI/loj-2423/tests.zip b/NOI/loj-2423/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c314d46c1e26c68a4d8f750a3ef89b858ca4d6f1 --- /dev/null +++ b/NOI/loj-2423/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:640557a8a73155d9f6b93b7902fd4da916a50e72c33475fff9390f24921fadfe +size 1454443 diff --git a/NOI/loj-2424/init.yml b/NOI/loj-2424/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2ec0743fa86f2d4cacf17d62185d3baee6dad7da --- /dev/null +++ b/NOI/loj-2424/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: substring7.in + out: substring7.ans + points: 10 +- in: substring1.in + out: substring1.ans + points: 10 +- in: substring6.in + out: substring6.ans + points: 10 +- in: substring2.in + out: substring2.ans + points: 10 +- in: substring4.in + out: substring4.ans + points: 10 +- in: substring10.in + out: substring10.ans + points: 10 +- in: substring5.in + out: substring5.ans + points: 10 +- in: substring8.in + out: substring8.ans + points: 10 +- in: substring9.in + out: substring9.ans + points: 10 +- in: substring3.in + out: substring3.ans + points: 10 diff --git a/NOI/loj-2424/tests.zip b/NOI/loj-2424/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..3aa71760e65278111bf47b3f3a40dce21b7dfd59 --- /dev/null +++ b/NOI/loj-2424/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91dfa646e5697b0234d891db3b3ddb06d306e56085255bc32019e41ce4888888 +size 8826 diff --git a/NOI/loj-2425/init.yml b/NOI/loj-2425/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..70db35d89d12a53957281991882b33722be10136 --- /dev/null +++ b/NOI/loj-2425/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: transport19.in + out: transport19.ans + points: 10 +- in: transport11.in + out: transport11.ans + points: 10 +- in: transport15.in + out: transport15.ans + points: 10 +- in: transport4.in + out: transport4.ans + points: 10 +- in: transport20.in + out: transport20.ans + points: 10 +- in: transport16.in + out: transport16.ans + points: 10 +- in: transport13.in + out: transport13.ans + points: 10 +- in: transport7.in + out: transport7.ans + points: 10 +- in: transport5.in + out: transport5.ans + points: 10 +- in: transport2.in + out: transport2.ans + points: 10 +- in: transport10.in + out: transport10.ans + points: 10 +- in: transport12.in + out: transport12.ans + points: 10 +- in: transport14.in + out: transport14.ans + points: 10 +- in: transport1.in + out: transport1.ans + points: 10 +- in: transport6.in + out: transport6.ans + points: 10 +- in: transport3.in + out: transport3.ans + points: 10 +- in: transport9.in + out: transport9.ans + points: 10 +- in: transport8.in + out: transport8.ans + points: 10 +- in: transport17.in + out: transport17.ans + points: 10 +- in: transport18.in + out: transport18.ans + points: 10 diff --git a/NOI/loj-2425/tests.zip b/NOI/loj-2425/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..076964a7322da26a97e8617bf6bda407e5e1ef85 --- /dev/null +++ b/NOI/loj-2425/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1546e95feafc422b72042b4a8ea9d61cad8e4f04cc2e94cd37afaf6bce100cf +size 29848777 diff --git a/NOI/loj-2442/init.yml b/NOI/loj-2442/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ba57d97dd05fe85e4e110dd043a929bd90ed5b2b --- /dev/null +++ b/NOI/loj-2442/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: rabbit2.in + out: rabbit2.ans + points: 10 +- in: rabbit11.in + out: rabbit11.ans + points: 10 +- in: rabbit16.in + out: rabbit16.ans + points: 10 +- in: rabbit14.in + out: rabbit14.ans + points: 10 +- in: rabbit3.in + out: rabbit3.ans + points: 10 +- in: rabbit18.in + out: rabbit18.ans + points: 10 +- in: rabbit4.in + out: rabbit4.ans + points: 10 +- in: rabbit8.in + out: rabbit8.ans + points: 10 +- in: rabbit17.in + out: rabbit17.ans + points: 10 +- in: rabbit15.in + out: rabbit15.ans + points: 10 +- in: rabbit5.in + out: rabbit5.ans + points: 10 +- in: rabbit9.in + out: rabbit9.ans + points: 10 +- in: rabbit6.in + out: rabbit6.ans + points: 10 +- in: rabbit10.in + out: rabbit10.ans + points: 10 +- in: rabbit12.in + out: rabbit12.ans + points: 10 +- in: rabbit7.in + out: rabbit7.ans + points: 10 +- in: rabbit19.in + out: rabbit19.ans + points: 10 +- in: rabbit20.in + out: rabbit20.ans + points: 10 +- in: rabbit13.in + out: rabbit13.ans + points: 10 +- in: rabbit1.in + out: rabbit1.ans + points: 10 diff --git a/NOI/loj-2442/tests.zip b/NOI/loj-2442/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..44a76e4c81dedef415fb9a0ba67692cdfa39d050 --- /dev/null +++ b/NOI/loj-2442/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8cf0b6d65b7d2108c47d44a78aeb2c147eef927fb5d47dab47c48fb05e7deccf +size 4360 diff --git a/NOI/loj-2443/init.yml b/NOI/loj-2443/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..72a2129f58ca2ad2d0283208ea6c330ce5b6559b --- /dev/null +++ b/NOI/loj-2443/init.yml @@ -0,0 +1,29 @@ +archive: tests.zip +test_cases: +- in: car3.in + out: car3.ans + points: 10 +- in: car1.in + out: car1.ans + points: 10 +- in: car8.in + out: car8.ans + points: 10 +- in: car6.in + out: car6.ans + points: 10 +- in: car10.in + out: car10.ans + points: 10 +- in: car4.in + out: car4.ans + points: 10 +- in: car2.in + out: car2.ans + points: 10 +- in: car9.in + out: car9.ans + points: 10 +- in: car5.in + out: car5.ans + points: 10 diff --git a/NOI/loj-2443/tests.zip b/NOI/loj-2443/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..3ce74113bf9f65dfa7962cc9ef7e259c8ab8af97 --- /dev/null +++ b/NOI/loj-2443/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c726ca0047519932b95fc8eb6375a7d62595958d7445cf7a7a6307b4e356e057 +size 92539 diff --git a/NOI/loj-2444/init.yml b/NOI/loj-2444/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2bcb4e66874f8bb1f292acd2a91528c4400dd091 --- /dev/null +++ b/NOI/loj-2444/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: type3.in + out: type3.ans + points: 10 +- in: type7.in + out: type7.ans + points: 10 +- in: type2.in + out: type2.ans + points: 10 +- in: type9.in + out: type9.ans + points: 10 +- in: type4.in + out: type4.ans + points: 10 +- in: type8.in + out: type8.ans + points: 10 +- in: type6.in + out: type6.ans + points: 10 +- in: type1.in + out: type1.ans + points: 10 +- in: type5.in + out: type5.ans + points: 10 +- in: type10.in + out: type10.ans + points: 10 diff --git a/NOI/loj-2444/tests.zip b/NOI/loj-2444/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..4dc8d5f54e743cf736b222b94a74ac5bb43ad0cd --- /dev/null +++ b/NOI/loj-2444/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e2b12de0d6d3ac8b54ca6d2bb317f45811375c0fdf286cae9967236291c7cbf +size 6816725 diff --git a/NOI/loj-2445/init.yml b/NOI/loj-2445/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6dfddd91b1b838267adbd56dbc7bd77f81e59968 --- /dev/null +++ b/NOI/loj-2445/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: road1.in + out: road1.ans + points: 10 +- in: road10.in + out: road10.ans + points: 10 +- in: road14.in + out: road14.ans + points: 10 +- in: road5.in + out: road5.ans + points: 10 +- in: road17.in + out: road17.ans + points: 10 +- in: road19.in + out: road19.ans + points: 10 +- in: road3.in + out: road3.ans + points: 10 +- in: road13.in + out: road13.ans + points: 10 +- in: road7.in + out: road7.ans + points: 10 +- in: road15.in + out: road15.ans + points: 10 +- in: road12.in + out: road12.ans + points: 10 +- in: road2.in + out: road2.ans + points: 10 +- in: road11.in + out: road11.ans + points: 10 +- in: road20.in + out: road20.ans + points: 10 +- in: road9.in + out: road9.ans + points: 10 +- in: road18.in + out: road18.ans + points: 10 +- in: road4.in + out: road4.ans + points: 10 +- in: road8.in + out: road8.ans + points: 10 +- in: road6.in + out: road6.ans + points: 10 +- in: road16.in + out: road16.ans + points: 10 diff --git a/NOI/loj-2445/tests.zip b/NOI/loj-2445/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..fcfef9e0d8abb87453651b29105ba95b4c00ceac --- /dev/null +++ b/NOI/loj-2445/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea24135bfbeab7627fa982c487ca6b2e71455eee4870eb16632973cfdbba1a08 +size 109073968 diff --git a/NOI/loj-2446/init.yml b/NOI/loj-2446/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d92ccb5c90aa31d4c97413a19ca3418b32dd07e0 --- /dev/null +++ b/NOI/loj-2446/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: show9.in + out: show9.ans + points: 10 +- in: show3.in + out: show3.ans + points: 10 +- in: show4.in + out: show4.ans + points: 10 +- in: show7.in + out: show7.ans + points: 10 +- in: show2.in + out: show2.ans + points: 10 +- in: show6.in + out: show6.ans + points: 10 +- in: show10.in + out: show10.ans + points: 10 +- in: show1.in + out: show1.ans + points: 10 +- in: show5.in + out: show5.ans + points: 10 +- in: show8.in + out: show8.ans + points: 10 diff --git a/NOI/loj-2446/tests.zip b/NOI/loj-2446/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..8e20654d785094c99da170daf247b09a0dfd1e99 --- /dev/null +++ b/NOI/loj-2446/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a62b2d3c9023b44c3dbfe9c180f2dbbcfb6711c23795d8c7d22cad61fe89658d +size 26370 diff --git a/NOI/loj-2447/init.yml b/NOI/loj-2447/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb56df818978330edac57bfb52bee6766ee0fe67 --- /dev/null +++ b/NOI/loj-2447/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: game13.in + out: game13.ans + points: 10 +- in: game8.in + out: game8.ans + points: 10 +- in: game7.in + out: game7.ans + points: 10 +- in: game12.in + out: game12.ans + points: 10 +- in: game19.in + out: game19.ans + points: 10 +- in: game10.in + out: game10.ans + points: 10 +- in: game11.in + out: game11.ans + points: 10 +- in: game16.in + out: game16.ans + points: 10 +- in: game14.in + out: game14.ans + points: 10 +- in: game17.in + out: game17.ans + points: 10 +- in: game3.in + out: game3.ans + points: 10 +- in: game2.in + out: game2.ans + points: 10 +- in: game18.in + out: game18.ans + points: 10 +- in: game6.in + out: game6.ans + points: 10 +- in: game1.in + out: game1.ans + points: 10 +- in: game15.in + out: game15.ans + points: 10 +- in: game20.in + out: game20.ans + points: 10 +- in: game5.in + out: game5.ans + points: 10 +- in: game9.in + out: game9.ans + points: 10 +- in: game4.in + out: game4.ans + points: 10 diff --git a/NOI/loj-2447/tests.zip b/NOI/loj-2447/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..26d89dc519d36f1fb93fa20612deee3d64ece18a --- /dev/null +++ b/NOI/loj-2447/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38f356282badea7a6dd6a9b9c456c5a362e27910edf50edeb9a2959e6c471d84 +size 29856 diff --git a/NOI/loj-2498/init.yml b/NOI/loj-2498/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c8acd1e323bcb20ed797bcb1944e92f7c6aa5e0f --- /dev/null +++ b/NOI/loj-2498/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: rps5.in + out: rps5.ans + points: 10 +- in: rps10.in + out: rps10.ans + points: 10 +- in: rps3.in + out: rps3.ans + points: 10 +- in: rps1.in + out: rps1.ans + points: 10 +- in: rps8.in + out: rps8.ans + points: 10 +- in: rps6.in + out: rps6.ans + points: 10 +- in: rps4.in + out: rps4.ans + points: 10 +- in: rps2.in + out: rps2.ans + points: 10 +- in: rps9.in + out: rps9.ans + points: 10 +- in: rps7.in + out: rps7.ans + points: 10 diff --git a/NOI/loj-2498/tests.zip b/NOI/loj-2498/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..371dce9fefc9b201acba184a0dfe2021cc550002 --- /dev/null +++ b/NOI/loj-2498/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de5030e07751d91328b742cf33886714e8232b94870b9c9935e88c5a29d6e365 +size 3536 diff --git a/NOI/loj-2499/init.yml b/NOI/loj-2499/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..baf7a40f46b0a9d4a161efe68247133955461395 --- /dev/null +++ b/NOI/loj-2499/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: link6.in + out: link6.ans + points: 10 +- in: link1.in + out: link1.ans + points: 10 +- in: link2.in + out: link2.ans + points: 10 +- in: link9.in + out: link9.ans + points: 10 +- in: link4.in + out: link4.ans + points: 10 +- in: link5.in + out: link5.ans + points: 10 +- in: link10.in + out: link10.ans + points: 10 +- in: link7.in + out: link7.ans + points: 10 +- in: link8.in + out: link8.ans + points: 10 +- in: link3.in + out: link3.ans + points: 10 diff --git a/NOI/loj-2499/tests.zip b/NOI/loj-2499/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..63688080aab8badb5daecdb3e32d735e5904643f --- /dev/null +++ b/NOI/loj-2499/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b859dc28a7e01fb4adf61667b7521bcdf087202624770fefd1f585f01d0ceb01 +size 8672866 diff --git a/NOI/loj-2500/init.yml b/NOI/loj-2500/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..78c9240d5d715c1d7d5a606cece3fb3d15059f29 --- /dev/null +++ b/NOI/loj-2500/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: bird3.in + out: bird3.ans + points: 10 +- in: bird12.in + out: bird12.ans + points: 10 +- in: bird20.in + out: bird20.ans + points: 10 +- in: bird10.in + out: bird10.ans + points: 10 +- in: bird5.in + out: bird5.ans + points: 10 +- in: bird9.in + out: bird9.ans + points: 10 +- in: bird19.in + out: bird19.ans + points: 10 +- in: bird7.in + out: bird7.ans + points: 10 +- in: bird11.in + out: bird11.ans + points: 10 +- in: bird14.in + out: bird14.ans + points: 10 +- in: bird16.in + out: bird16.ans + points: 10 +- in: bird2.in + out: bird2.ans + points: 10 +- in: bird6.in + out: bird6.ans + points: 10 +- in: bird18.in + out: bird18.ans + points: 10 +- in: bird17.in + out: bird17.ans + points: 10 +- in: bird15.in + out: bird15.ans + points: 10 +- in: bird1.in + out: bird1.ans + points: 10 +- in: bird4.in + out: bird4.ans + points: 10 +- in: bird8.in + out: bird8.ans + points: 10 +- in: bird13.in + out: bird13.ans + points: 10 diff --git a/NOI/loj-2500/tests.zip b/NOI/loj-2500/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..f9aefff2e4962b734e7483b3b593c27fe408d191 --- /dev/null +++ b/NOI/loj-2500/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1358110e731a933921269fd564397b1cd2c110c84ddb6a31d354dee42a4b86b6 +size 320370 diff --git a/NOI/loj-2501/init.yml b/NOI/loj-2501/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c1b663ee7b3abbc0adecb93942c08aeca9ba404a --- /dev/null +++ b/NOI/loj-2501/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: wireless6.in + out: wireless6.ans + points: 10 +- in: wireless9.in + out: wireless9.ans + points: 10 +- in: wireless10.in + out: wireless10.ans + points: 10 +- in: wireless7.in + out: wireless7.ans + points: 10 +- in: wireless5.in + out: wireless5.ans + points: 10 +- in: wireless3.in + out: wireless3.ans + points: 10 +- in: wireless8.in + out: wireless8.ans + points: 10 +- in: wireless4.in + out: wireless4.ans + points: 10 +- in: wireless2.in + out: wireless2.ans + points: 10 +- in: wireless1.in + out: wireless1.ans + points: 10 diff --git a/NOI/loj-2501/tests.zip b/NOI/loj-2501/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..0056ed29899fc52c40a795f239b09c4ee59d3384 --- /dev/null +++ b/NOI/loj-2501/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64f954adb4ca50a94ad759b0b8596032c62567f819252a4654694e1b5584d985 +size 3884 diff --git a/NOI/loj-2502/init.yml b/NOI/loj-2502/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..8337caf54b46f701d74d966a5ef107ba08bcb17f --- /dev/null +++ b/NOI/loj-2502/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: road1.in + out: road1.ans + points: 10 +- in: road10.in + out: road10.ans + points: 10 +- in: road5.in + out: road5.ans + points: 10 +- in: road3.in + out: road3.ans + points: 10 +- in: road7.in + out: road7.ans + points: 10 +- in: road2.in + out: road2.ans + points: 10 +- in: road9.in + out: road9.ans + points: 10 +- in: road4.in + out: road4.ans + points: 10 +- in: road8.in + out: road8.ans + points: 10 +- in: road6.in + out: road6.ans + points: 10 diff --git a/NOI/loj-2502/tests.zip b/NOI/loj-2502/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..1868030ed6cd7abb22c2227032ad9978ffa7b34d --- /dev/null +++ b/NOI/loj-2502/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fec8430a2f083129efca3a6832e428ca32f2f02a73e84931a67fdef7f8013c5 +size 2660401 diff --git a/NOI/loj-2503/init.yml b/NOI/loj-2503/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..35aa32be9c2793b3123011fda16868e69dcdae6f --- /dev/null +++ b/NOI/loj-2503/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: equation4.in + out: equation4.ans + points: 10 +- in: equation6.in + out: equation6.ans + points: 10 +- in: equation10.in + out: equation10.ans + points: 10 +- in: equation7.in + out: equation7.ans + points: 10 +- in: equation3.in + out: equation3.ans + points: 10 +- in: equation1.in + out: equation1.ans + points: 10 +- in: equation5.in + out: equation5.ans + points: 10 +- in: equation8.in + out: equation8.ans + points: 10 +- in: equation9.in + out: equation9.ans + points: 10 +- in: equation2.in + out: equation2.ans + points: 10 diff --git a/NOI/loj-2503/tests.zip b/NOI/loj-2503/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..0d08d15848f15aa787f70a13a3138a6423e49678 --- /dev/null +++ b/NOI/loj-2503/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d4e06d6695fe91d4c02339c6267a256b6604d2e903cb78f3d126521f6e0e83b +size 4124714 diff --git a/NOI/loj-2588/init.yml b/NOI/loj-2588/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a5027c104bf506e0f72d4f187c36f89284b22d57 --- /dev/null +++ b/NOI/loj-2588/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: spy5.in + out: spy5.out + points: 10 +- in: spy8.in + out: spy8.out + points: 10 +- in: spy2.in + out: spy2.out + points: 10 +- in: spy6.in + out: spy6.out + points: 10 +- in: spy4.in + out: spy4.out + points: 10 +- in: spy9.in + out: spy9.out + points: 10 +- in: spy10.in + out: spy10.out + points: 10 +- in: spy3.in + out: spy3.out + points: 10 +- in: spy7.in + out: spy7.out + points: 10 +- in: spy1.in + out: spy1.out + points: 10 diff --git a/NOI/loj-2588/tests.zip b/NOI/loj-2588/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..78bb5d81ed8444dfe66c3e002d31e1d49349ee3e --- /dev/null +++ b/NOI/loj-2588/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:590d12b05ebe4308158680e2aa1e8684a62cb24acfc5b6d6d1890706def812f0 +size 3460 diff --git a/NOI/loj-2589/init.yml b/NOI/loj-2589/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e37182022b624becd148ee47cfc8d8b551ff4c82 --- /dev/null +++ b/NOI/loj-2589/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: son9.in + out: son9.out + points: 10 +- in: son10.in + out: son10.out + points: 10 +- in: son7.in + out: son7.out + points: 10 +- in: son5.in + out: son5.out + points: 10 +- in: son3.in + out: son3.out + points: 10 +- in: son1.in + out: son1.out + points: 10 +- in: son8.in + out: son8.out + points: 10 +- in: son6.in + out: son6.out + points: 10 +- in: son4.in + out: son4.out + points: 10 +- in: son2.in + out: son2.out + points: 10 diff --git a/NOI/loj-2589/tests.zip b/NOI/loj-2589/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ab2e0514ce012b40dbe590be4a2322e627553732 --- /dev/null +++ b/NOI/loj-2589/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bcea981983db6e759574592ab745c456f39ce22eab6b2a70e861e64403142f22 +size 145267 diff --git a/NOI/loj-2590/init.yml b/NOI/loj-2590/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9c651629341e79dc753833ce5fd29183d430567a --- /dev/null +++ b/NOI/loj-2590/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: trade4.in + out: trade4.out + points: 10 +- in: trade3.in + out: trade3.out + points: 10 +- in: trade10.in + out: trade10.out + points: 10 +- in: trade8.in + out: trade8.out + points: 10 +- in: trade2.in + out: trade2.out + points: 10 +- in: trade9.in + out: trade9.out + points: 10 +- in: trade6.in + out: trade6.out + points: 10 +- in: trade7.in + out: trade7.out + points: 10 +- in: trade1.in + out: trade1.out + points: 10 +- in: trade5.in + out: trade5.out + points: 10 diff --git a/NOI/loj-2590/tests.zip b/NOI/loj-2590/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..4ed5f4839839b65d0e78e8c02dff2a37287bd2eb --- /dev/null +++ b/NOI/loj-2590/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3fd284349f3542987f93e351d1b7508d3a37cfdcd1b7b1bdf04148929893fb55 +size 6889932 diff --git a/NOI/loj-2591/init.yml b/NOI/loj-2591/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c06b3a5ce4d1a4cd03a34491aafd26e05e0ff360 --- /dev/null +++ b/NOI/loj-2591/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: sudoku2.in + out: sudoku2.out + points: 10 +- in: sudoku6.in + out: sudoku6.out + points: 10 +- in: sudoku16.in + out: sudoku16.out + points: 10 +- in: sudoku13.in + out: sudoku13.out + points: 10 +- in: sudoku12.in + out: sudoku12.out + points: 10 +- in: sudoku17.in + out: sudoku17.out + points: 10 +- in: sudoku7.in + out: sudoku7.out + points: 10 +- in: sudoku1.in + out: sudoku1.out + points: 10 +- in: sudoku14.in + out: sudoku14.out + points: 10 +- in: sudoku15.in + out: sudoku15.out + points: 10 +- in: sudoku4.in + out: sudoku4.out + points: 10 +- in: sudoku9.in + out: sudoku9.out + points: 10 +- in: sudoku10.in + out: sudoku10.out + points: 10 +- in: sudoku19.in + out: sudoku19.out + points: 10 +- in: sudoku3.in + out: sudoku3.out + points: 10 +- in: sudoku8.in + out: sudoku8.out + points: 10 +- in: sudoku20.in + out: sudoku20.out + points: 10 +- in: sudoku5.in + out: sudoku5.out + points: 10 +- in: sudoku18.in + out: sudoku18.out + points: 10 +- in: sudoku11.in + out: sudoku11.out + points: 10 diff --git a/NOI/loj-2591/tests.zip b/NOI/loj-2591/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..407cb8baccd25dd3dbd526f5a158bd0f96752e2f --- /dev/null +++ b/NOI/loj-2591/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36176d9b6ffee3015bcec6ebaf7c0e33a0a7aee800be90a335fe3098d5bcfcb1 +size 45296 diff --git a/NOI/loj-2592/init.yml b/NOI/loj-2592/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..fb831e3089cdd7f4e6d84e541c1a33b99756ff3e --- /dev/null +++ b/NOI/loj-2592/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: translate8.in + out: translate8.ans + points: 10 +- in: translate7.in + out: translate7.ans + points: 10 +- in: translate6.in + out: translate6.ans + points: 10 +- in: translate3.in + out: translate3.ans + points: 10 +- in: translate9.in + out: translate9.ans + points: 10 +- in: translate10.in + out: translate10.ans + points: 10 +- in: translate1.in + out: translate1.ans + points: 10 +- in: translate2.in + out: translate2.ans + points: 10 +- in: translate5.in + out: translate5.ans + points: 10 +- in: translate4.in + out: translate4.ans + points: 10 diff --git a/NOI/loj-2592/tests.zip b/NOI/loj-2592/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b103970bc321840d09826a27eab208cd4ba9418d --- /dev/null +++ b/NOI/loj-2592/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bbac842fa85bad1cc5a937e1ff16fa54654157f98ce7412101dec3baa450582c +size 13671 diff --git a/NOI/loj-2593/init.yml b/NOI/loj-2593/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..fbbeaba87351257a8a57e004cf2acaab73309014 --- /dev/null +++ b/NOI/loj-2593/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: tortoise4.in + out: tortoise4.ans + points: 10 +- in: tortoise2.in + out: tortoise2.ans + points: 10 +- in: tortoise7.in + out: tortoise7.ans + points: 10 +- in: tortoise5.in + out: tortoise5.ans + points: 10 +- in: tortoise10.in + out: tortoise10.ans + points: 10 +- in: tortoise9.in + out: tortoise9.ans + points: 10 +- in: tortoise3.in + out: tortoise3.ans + points: 10 +- in: tortoise1.in + out: tortoise1.ans + points: 10 +- in: tortoise6.in + out: tortoise6.ans + points: 10 +- in: tortoise8.in + out: tortoise8.ans + points: 10 diff --git a/NOI/loj-2593/tests.zip b/NOI/loj-2593/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..401df218571c73a7e07b5c2208050fe8ab76f997 --- /dev/null +++ b/NOI/loj-2593/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a68a6798168c7970f4c072bcc82c3e6b3713d36670882db81dffc7270eab142 +size 9497 diff --git a/NOI/loj-2594/init.yml b/NOI/loj-2594/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3f1a9e0a24890781156784cb1fc74c1b839dcfbf --- /dev/null +++ b/NOI/loj-2594/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: prison2.in + out: prison2.ans + points: 10 +- in: prison7.in + out: prison7.ans + points: 10 +- in: prison5.in + out: prison5.ans + points: 10 +- in: prison1.in + out: prison1.ans + points: 10 +- in: prison8.in + out: prison8.ans + points: 10 +- in: prison3.in + out: prison3.ans + points: 10 +- in: prison4.in + out: prison4.ans + points: 10 +- in: prison9.in + out: prison9.ans + points: 10 +- in: prison10.in + out: prison10.ans + points: 10 +- in: prison6.in + out: prison6.ans + points: 10 diff --git a/NOI/loj-2594/tests.zip b/NOI/loj-2594/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..da0f71879db3544c9028b36f9b2784e53a97518b --- /dev/null +++ b/NOI/loj-2594/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af9822c70ad817a2e37255f9e50737b2bd18a4d9c07db5c52be919e242b55c77 +size 4863143 diff --git a/NOI/loj-2595/init.yml b/NOI/loj-2595/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3a1310b82d5493199543e2441e075b4c6e0a39d6 --- /dev/null +++ b/NOI/loj-2595/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: flow10.in + out: flow10.ans + points: 10 +- in: flow2.in + out: flow2.ans + points: 10 +- in: flow5.in + out: flow5.ans + points: 10 +- in: flow8.in + out: flow8.ans + points: 10 +- in: flow6.in + out: flow6.ans + points: 10 +- in: flow9.in + out: flow9.ans + points: 10 +- in: flow3.in + out: flow3.ans + points: 10 +- in: flow1.in + out: flow1.ans + points: 10 +- in: flow4.in + out: flow4.ans + points: 10 +- in: flow7.in + out: flow7.ans + points: 10 diff --git a/NOI/loj-2595/tests.zip b/NOI/loj-2595/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..6a256fdeab4561d2fafa260a5d1e3498229524eb --- /dev/null +++ b/NOI/loj-2595/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de760b9d6f3cce11e64dc3b8c493ffb0362cba7cd49376192d570f37453337d9 +size 2954505 diff --git a/NOI/loj-2596/init.yml b/NOI/loj-2596/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..fb07320b8281181d2285a7d5d81cc726fa06e747 --- /dev/null +++ b/NOI/loj-2596/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: carpet6.in + out: carpet6.ans + points: 10 +- in: carpet1.in + out: carpet1.ans + points: 10 +- in: carpet8.in + out: carpet8.ans + points: 10 +- in: carpet10.in + out: carpet10.ans + points: 10 +- in: carpet3.in + out: carpet3.ans + points: 10 +- in: carpet5.in + out: carpet5.ans + points: 10 +- in: carpet9.in + out: carpet9.ans + points: 10 +- in: carpet7.in + out: carpet7.ans + points: 10 +- in: carpet2.in + out: carpet2.ans + points: 10 +- in: carpet4.in + out: carpet4.ans + points: 10 diff --git a/NOI/loj-2596/tests.zip b/NOI/loj-2596/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c8caf8405285e1e13028ea673d59e3a9ed3791d9 --- /dev/null +++ b/NOI/loj-2596/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81d69c4bbc86e8eaa6ba059d3f708f12b752e926e8ef0fe2bc8d933c4faa503c +size 762500 diff --git a/NOI/loj-2597/init.yml b/NOI/loj-2597/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ff6ead58fe24589e51b9d08e7388b76147e425c0 --- /dev/null +++ b/NOI/loj-2597/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: hotel6.in + out: hotel6.ans + points: 10 +- in: hotel11.in + out: hotel11.ans + points: 10 +- in: hotel15.in + out: hotel15.ans + points: 10 +- in: hotel19.in + out: hotel19.ans + points: 10 +- in: hotel20.in + out: hotel20.ans + points: 10 +- in: hotel9.in + out: hotel9.ans + points: 10 +- in: hotel5.in + out: hotel5.ans + points: 10 +- in: hotel3.in + out: hotel3.ans + points: 10 +- in: hotel2.in + out: hotel2.ans + points: 10 +- in: hotel16.in + out: hotel16.ans + points: 10 +- in: hotel10.in + out: hotel10.ans + points: 10 +- in: hotel18.in + out: hotel18.ans + points: 10 +- in: hotel1.in + out: hotel1.ans + points: 10 +- in: hotel17.in + out: hotel17.ans + points: 10 +- in: hotel4.in + out: hotel4.ans + points: 10 +- in: hotel12.in + out: hotel12.ans + points: 10 +- in: hotel7.in + out: hotel7.ans + points: 10 +- in: hotel13.in + out: hotel13.ans + points: 10 +- in: hotel14.in + out: hotel14.ans + points: 10 +- in: hotel8.in + out: hotel8.ans + points: 10 diff --git a/NOI/loj-2597/tests.zip b/NOI/loj-2597/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..7491f629d21a9b3c7c2a0efc8c32e9a9374abb2e --- /dev/null +++ b/NOI/loj-2597/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c95e21313ccbad58d19e32e5b7ee36d39201510cb0f478d724cdbcd0ee9281a6 +size 41589066 diff --git a/NOI/loj-2598/init.yml b/NOI/loj-2598/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9f8a7d5ece3225ddb740c8417300d0e0f9265f0c --- /dev/null +++ b/NOI/loj-2598/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: mayan1.in + out: mayan1.ans + points: 10 +- in: mayan9.in + out: mayan9.ans + points: 10 +- in: mayan5.in + out: mayan5.ans + points: 10 +- in: mayan6.in + out: mayan6.ans + points: 10 +- in: mayan7.in + out: mayan7.ans + points: 10 +- in: mayan4.in + out: mayan4.ans + points: 10 +- in: mayan2.in + out: mayan2.ans + points: 10 +- in: mayan8.in + out: mayan8.ans + points: 10 +- in: mayan10.in + out: mayan10.ans + points: 10 +- in: mayan3.in + out: mayan3.ans + points: 10 diff --git a/NOI/loj-2598/tests.zip b/NOI/loj-2598/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a5f87cfe567d4a3f01e4cae4422057b52e6aae83 --- /dev/null +++ b/NOI/loj-2598/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb6f0bfce916c3cafabe1afb698c911d38bd8d951f9cec6244167e55f115218b +size 64570 diff --git a/NOI/loj-2599/init.yml b/NOI/loj-2599/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..30ab54c63c8efeb577e6bd2212df0f8b45fda4eb --- /dev/null +++ b/NOI/loj-2599/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: factor10.in + out: factor10.ans + points: 10 +- in: factor7.in + out: factor7.ans + points: 10 +- in: factor5.in + out: factor5.ans + points: 10 +- in: factor4.in + out: factor4.ans + points: 10 +- in: factor2.in + out: factor2.ans + points: 10 +- in: factor8.in + out: factor8.ans + points: 10 +- in: factor3.in + out: factor3.ans + points: 10 +- in: factor1.in + out: factor1.ans + points: 10 +- in: factor9.in + out: factor9.ans + points: 10 +- in: factor6.in + out: factor6.ans + points: 10 diff --git a/NOI/loj-2599/tests.zip b/NOI/loj-2599/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c23f648a0897e7ddfd84cabc78753881b1f98d9a --- /dev/null +++ b/NOI/loj-2599/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f762abf34c6c7917805b5d5b4cb7757126bd6332a060f11a8e2de96c6380fdd6 +size 2184 diff --git a/NOI/loj-2600/init.yml b/NOI/loj-2600/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d00ac07dcf8d838591e4e0caa1169719fa7ae0f8 --- /dev/null +++ b/NOI/loj-2600/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: qc1.in + out: qc1.ans + points: 10 +- in: qc2.in + out: qc2.ans + points: 10 +- in: qc12.in + out: qc12.ans + points: 10 +- in: qc19.in + out: qc19.ans + points: 10 +- in: qc9.in + out: qc9.ans + points: 10 +- in: qc10.in + out: qc10.ans + points: 10 +- in: qc17.in + out: qc17.ans + points: 10 +- in: qc20.in + out: qc20.ans + points: 10 +- in: qc6.in + out: qc6.ans + points: 10 +- in: qc15.in + out: qc15.ans + points: 10 +- in: qc3.in + out: qc3.ans + points: 10 +- in: qc13.in + out: qc13.ans + points: 10 +- in: qc11.in + out: qc11.ans + points: 10 +- in: qc18.in + out: qc18.ans + points: 10 +- in: qc7.in + out: qc7.ans + points: 10 +- in: qc8.in + out: qc8.ans + points: 10 +- in: qc16.in + out: qc16.ans + points: 10 +- in: qc4.in + out: qc4.ans + points: 10 +- in: qc5.in + out: qc5.ans + points: 10 +- in: qc14.in + out: qc14.ans + points: 10 diff --git a/NOI/loj-2600/tests.zip b/NOI/loj-2600/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..66e6337b86cf491a8e9315989abf6e37961b6505 --- /dev/null +++ b/NOI/loj-2600/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4de5b2408cfd129da9fa0f9fb6d9898cdbd2f7274d7f8627d22c4dd6898b003d +size 14581965 diff --git a/NOI/loj-2601/init.yml b/NOI/loj-2601/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..26e522c4f23639bf9f0cebf72b29ba3bbb7cff52 --- /dev/null +++ b/NOI/loj-2601/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: bus25.in + out: bus25.ans + points: 10 +- in: bus16.in + out: bus16.ans + points: 10 +- in: bus1.in + out: bus1.ans + points: 10 +- in: bus12.in + out: bus12.ans + points: 10 +- in: bus8.in + out: bus8.ans + points: 10 +- in: bus20.in + out: bus20.ans + points: 10 +- in: bus21.in + out: bus21.ans + points: 10 +- in: bus22.in + out: bus22.ans + points: 10 +- in: bus6.in + out: bus6.ans + points: 10 +- in: bus17.in + out: bus17.ans + points: 10 +- in: bus23.in + out: bus23.ans + points: 10 +- in: bus24.in + out: bus24.ans + points: 10 +- in: bus4.in + out: bus4.ans + points: 10 +- in: bus13.in + out: bus13.ans + points: 10 +- in: bus10.in + out: bus10.ans + points: 10 +- in: bus19.in + out: bus19.ans + points: 10 +- in: bus2.in + out: bus2.ans + points: 10 +- in: bus9.in + out: bus9.ans + points: 10 +- in: bus18.in + out: bus18.ans + points: 10 +- in: bus15.in + out: bus15.ans + points: 10 +- in: bus7.in + out: bus7.ans + points: 10 +- in: bus14.in + out: bus14.ans + points: 10 +- in: bus11.in + out: bus11.ans + points: 10 +- in: bus5.in + out: bus5.ans + points: 10 +- in: bus3.in + out: bus3.ans + points: 10 diff --git a/NOI/loj-2601/tests.zip b/NOI/loj-2601/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b0c687f1df78f9c9e4b38fd99ad5c43545db003c --- /dev/null +++ b/NOI/loj-2601/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d52f23bd3772603699f7cb33ea099a2a2dddd33ed36584905d8fbafa0c0a52c5 +size 7932839 diff --git a/NOI/loj-2602/init.yml b/NOI/loj-2602/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..16d4779120052910a07d71fc9372511bff11b247 --- /dev/null +++ b/NOI/loj-2602/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: vigenere1.in + out: vigenere1.ans + points: 10 +- in: vigenere9.in + out: vigenere9.ans + points: 10 +- in: vigenere4.in + out: vigenere4.ans + points: 10 +- in: vigenere8.in + out: vigenere8.ans + points: 10 +- in: vigenere2.in + out: vigenere2.ans + points: 10 +- in: vigenere3.in + out: vigenere3.ans + points: 10 +- in: vigenere6.in + out: vigenere6.ans + points: 10 +- in: vigenere7.in + out: vigenere7.ans + points: 10 +- in: vigenere10.in + out: vigenere10.ans + points: 10 +- in: vigenere5.in + out: vigenere5.ans + points: 10 diff --git a/NOI/loj-2602/tests.zip b/NOI/loj-2602/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..75c35d598b59473876a0748ad012d013c7b48a1a --- /dev/null +++ b/NOI/loj-2602/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e827feda3f329081c14458932012bfd1fabd0a04ff9d2d874d52e17f7dc4393a +size 13101 diff --git a/NOI/loj-2603/init.yml b/NOI/loj-2603/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c0d6a0b2e99e0e7f623b70dbce5dbfe1b9b7dd39 --- /dev/null +++ b/NOI/loj-2603/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: game8.in + out: game8.ans + points: 10 +- in: game7.in + out: game7.ans + points: 10 +- in: game10.in + out: game10.ans + points: 10 +- in: game3.in + out: game3.ans + points: 10 +- in: game2.in + out: game2.ans + points: 10 +- in: game6.in + out: game6.ans + points: 10 +- in: game1.in + out: game1.ans + points: 10 +- in: game5.in + out: game5.ans + points: 10 +- in: game9.in + out: game9.ans + points: 10 +- in: game4.in + out: game4.ans + points: 10 diff --git a/NOI/loj-2603/tests.zip b/NOI/loj-2603/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..69303aef42b3a96070ac99a9cbf6d6748d94129e --- /dev/null +++ b/NOI/loj-2603/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6cc6df368f2c1b12f76fc4ceeeeb7ac020c208afd6fddee31c49bd4383d3d600 +size 626455 diff --git a/NOI/loj-2604/init.yml b/NOI/loj-2604/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a832607f6e8a01c442d9676a45cd27f0ba8c8838 --- /dev/null +++ b/NOI/loj-2604/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: drive5.in + out: drive5.ans + points: 10 +- in: drive6.in + out: drive6.ans + points: 10 +- in: drive14.in + out: drive14.ans + points: 10 +- in: drive19.in + out: drive19.ans + points: 10 +- in: drive2.in + out: drive2.ans + points: 10 +- in: drive8.in + out: drive8.ans + points: 10 +- in: drive16.in + out: drive16.ans + points: 10 +- in: drive4.in + out: drive4.ans + points: 10 +- in: drive20.in + out: drive20.ans + points: 10 +- in: drive10.in + out: drive10.ans + points: 10 +- in: drive3.in + out: drive3.ans + points: 10 +- in: drive1.in + out: drive1.ans + points: 10 +- in: drive18.in + out: drive18.ans + points: 10 +- in: drive17.in + out: drive17.ans + points: 10 +- in: drive9.in + out: drive9.ans + points: 10 +- in: drive12.in + out: drive12.ans + points: 10 +- in: drive11.in + out: drive11.ans + points: 10 +- in: drive15.in + out: drive15.ans + points: 10 +- in: drive13.in + out: drive13.ans + points: 10 +- in: drive7.in + out: drive7.ans + points: 10 diff --git a/NOI/loj-2604/tests.zip b/NOI/loj-2604/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..5ed9b26759ed943931ba7e4d659a16403345f33e --- /dev/null +++ b/NOI/loj-2604/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a7252bab8cbd4b164bf5cc271d207fbb6a7d2d19097f9513b90f39b996e330f +size 18997431 diff --git a/NOI/loj-2605/init.yml b/NOI/loj-2605/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b01908fef619d1f336af5c27562c764f4ae13e5a --- /dev/null +++ b/NOI/loj-2605/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: mod7.in + out: mod7.ans + points: 10 +- in: mod5.in + out: mod5.ans + points: 10 +- in: mod3.in + out: mod3.ans + points: 10 +- in: mod1.in + out: mod1.ans + points: 10 +- in: mod10.in + out: mod10.ans + points: 10 +- in: mod8.in + out: mod8.ans + points: 10 +- in: mod6.in + out: mod6.ans + points: 10 +- in: mod4.in + out: mod4.ans + points: 10 +- in: mod2.in + out: mod2.ans + points: 10 +- in: mod9.in + out: mod9.ans + points: 10 diff --git a/NOI/loj-2605/tests.zip b/NOI/loj-2605/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..cc6912d0bb06cef3c4398372408cb7d9b046bee6 --- /dev/null +++ b/NOI/loj-2605/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f475d0aa98f91fa886462e4c0e232c0906380630c4a5bb359adf8e05ac1babbc +size 2063 diff --git a/NOI/loj-2606/init.yml b/NOI/loj-2606/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..82642a43cecf1fdca3e90c50ce67f97d300156b4 --- /dev/null +++ b/NOI/loj-2606/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: classroom2.in + out: classroom2.ans + points: 10 +- in: classroom5.in + out: classroom5.ans + points: 10 +- in: classroom15.in + out: classroom15.ans + points: 10 +- in: classroom16.in + out: classroom16.ans + points: 10 +- in: classroom19.in + out: classroom19.ans + points: 10 +- in: classroom13.in + out: classroom13.ans + points: 10 +- in: classroom8.in + out: classroom8.ans + points: 10 +- in: classroom12.in + out: classroom12.ans + points: 10 +- in: classroom14.in + out: classroom14.ans + points: 10 +- in: classroom9.in + out: classroom9.ans + points: 10 +- in: classroom6.in + out: classroom6.ans + points: 10 +- in: classroom1.in + out: classroom1.ans + points: 10 +- in: classroom17.in + out: classroom17.ans + points: 10 +- in: classroom18.in + out: classroom18.ans + points: 10 +- in: classroom4.in + out: classroom4.ans + points: 10 +- in: classroom3.in + out: classroom3.ans + points: 10 +- in: classroom10.in + out: classroom10.ans + points: 10 +- in: classroom20.in + out: classroom20.ans + points: 10 +- in: classroom7.in + out: classroom7.ans + points: 10 +- in: classroom11.in + out: classroom11.ans + points: 10 diff --git a/NOI/loj-2606/tests.zip b/NOI/loj-2606/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ac0928c356b7ba82d98a2a6793788d019b5f6228 --- /dev/null +++ b/NOI/loj-2606/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:000d5244cdbb3c4f126d4e721e7d987e222cb11dd23ab3de6570d55d3d99e8cc +size 76062598 diff --git a/NOI/loj-2607/init.yml b/NOI/loj-2607/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3fc7b68d47c22b5566b84e1385b2b57de439b414 --- /dev/null +++ b/NOI/loj-2607/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: blockade19.in + out: blockade19.ans + points: 10 +- in: blockade4.in + out: blockade4.ans + points: 10 +- in: blockade15.in + out: blockade15.ans + points: 10 +- in: blockade14.in + out: blockade14.ans + points: 10 +- in: blockade6.in + out: blockade6.ans + points: 10 +- in: blockade13.in + out: blockade13.ans + points: 10 +- in: blockade7.in + out: blockade7.ans + points: 10 +- in: blockade9.in + out: blockade9.ans + points: 10 +- in: blockade1.in + out: blockade1.ans + points: 10 +- in: blockade10.in + out: blockade10.ans + points: 10 +- in: blockade20.in + out: blockade20.ans + points: 10 +- in: blockade17.in + out: blockade17.ans + points: 10 +- in: blockade18.in + out: blockade18.ans + points: 10 +- in: blockade12.in + out: blockade12.ans + points: 10 +- in: blockade16.in + out: blockade16.ans + points: 10 +- in: blockade5.in + out: blockade5.ans + points: 10 +- in: blockade8.in + out: blockade8.ans + points: 10 +- in: blockade2.in + out: blockade2.ans + points: 10 +- in: blockade3.in + out: blockade3.ans + points: 10 +- in: blockade11.in + out: blockade11.ans + points: 10 diff --git a/NOI/loj-2607/tests.zip b/NOI/loj-2607/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..8885303327e4f27bc24e14fda53183fdfedb16db --- /dev/null +++ b/NOI/loj-2607/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06743316f3faa181067f6cacb34b271a1eb6da465c98f344d4f70dd4396397b2 +size 40934993 diff --git a/NOI/loj-2608/init.yml b/NOI/loj-2608/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a3d93761b0e2e0c1e197d70d34afac34fb58071d --- /dev/null +++ b/NOI/loj-2608/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: circle10.in + out: circle10.ans + points: 10 +- in: circle2.in + out: circle2.ans + points: 10 +- in: circle3.in + out: circle3.ans + points: 10 +- in: circle8.in + out: circle8.ans + points: 10 +- in: circle7.in + out: circle7.ans + points: 10 +- in: circle9.in + out: circle9.ans + points: 10 +- in: circle5.in + out: circle5.ans + points: 10 +- in: circle6.in + out: circle6.ans + points: 10 +- in: circle1.in + out: circle1.ans + points: 10 +- in: circle4.in + out: circle4.ans + points: 10 diff --git a/NOI/loj-2608/tests.zip b/NOI/loj-2608/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..66783c79fb0c94767a62205588fdda4a5ac54b53 --- /dev/null +++ b/NOI/loj-2608/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63d30d4dcd631cfe8326c5a8dd5769e9521c7293314ae5a56ede50c75d3b8583 +size 3767 diff --git a/NOI/loj-2609/init.yml b/NOI/loj-2609/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..29674e343d1359422f4d0470cd103af6c95f9c46 --- /dev/null +++ b/NOI/loj-2609/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: match2.in + out: match2.ans + points: 10 +- in: match6.in + out: match6.ans + points: 10 +- in: match4.in + out: match4.ans + points: 10 +- in: match8.in + out: match8.ans + points: 10 +- in: match10.in + out: match10.ans + points: 10 +- in: match7.in + out: match7.ans + points: 10 +- in: match9.in + out: match9.ans + points: 10 +- in: match5.in + out: match5.ans + points: 10 +- in: match3.in + out: match3.ans + points: 10 +- in: match1.in + out: match1.ans + points: 10 diff --git a/NOI/loj-2609/tests.zip b/NOI/loj-2609/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..659beaaaf0aec1da8881ac1c972712baea03022b --- /dev/null +++ b/NOI/loj-2609/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12a65d63af0da4da249d8bc0069367e13e5e0f45900d05fe33b5344f21d60afb +size 2133777 diff --git a/NOI/loj-2610/init.yml b/NOI/loj-2610/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..810a033363beb3ec96fae89643e82dc1ac38bfa3 --- /dev/null +++ b/NOI/loj-2610/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: truck5.in + out: truck5.ans + points: 10 +- in: truck6.in + out: truck6.ans + points: 10 +- in: truck9.in + out: truck9.ans + points: 10 +- in: truck8.in + out: truck8.ans + points: 10 +- in: truck2.in + out: truck2.ans + points: 10 +- in: truck14.in + out: truck14.ans + points: 10 +- in: truck15.in + out: truck15.ans + points: 10 +- in: truck19.in + out: truck19.ans + points: 10 +- in: truck3.in + out: truck3.ans + points: 10 +- in: truck13.in + out: truck13.ans + points: 10 +- in: truck16.in + out: truck16.ans + points: 10 +- in: truck10.in + out: truck10.ans + points: 10 +- in: truck18.in + out: truck18.ans + points: 10 +- in: truck1.in + out: truck1.ans + points: 10 +- in: truck7.in + out: truck7.ans + points: 10 +- in: truck4.in + out: truck4.ans + points: 10 +- in: truck17.in + out: truck17.ans + points: 10 +- in: truck20.in + out: truck20.ans + points: 10 +- in: truck12.in + out: truck12.ans + points: 10 +- in: truck11.in + out: truck11.ans + points: 10 diff --git a/NOI/loj-2610/tests.zip b/NOI/loj-2610/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e23866236ea39360075ef6e801ebd46f37439fac --- /dev/null +++ b/NOI/loj-2610/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43bafec325d7547666ca6eb6a93d2a8b09c6d5f738498631140d147040c88578 +size 13060206 diff --git a/NOI/loj-2611/init.yml b/NOI/loj-2611/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..c81a9305462a33a9156182f575a99e81e2bc703b --- /dev/null +++ b/NOI/loj-2611/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: block5.in + out: block5.ans + points: 10 +- in: block9.in + out: block9.ans + points: 10 +- in: block4.in + out: block4.ans + points: 10 +- in: block3.in + out: block3.ans + points: 10 +- in: block7.in + out: block7.ans + points: 10 +- in: block6.in + out: block6.ans + points: 10 +- in: block1.in + out: block1.ans + points: 10 +- in: block10.in + out: block10.ans + points: 10 +- in: block2.in + out: block2.ans + points: 10 +- in: block8.in + out: block8.ans + points: 10 diff --git a/NOI/loj-2611/tests.zip b/NOI/loj-2611/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..d03c5057b744d477eceed42ace4e4e8bf40ab40d --- /dev/null +++ b/NOI/loj-2611/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b055681b4a362b71ee5690f7ec8506117da09d6c0a7c0779f11939ee42f45c4 +size 781332 diff --git a/NOI/loj-2612/init.yml b/NOI/loj-2612/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b4b4bcf67bca7bd4095209e65f578f646b665776 --- /dev/null +++ b/NOI/loj-2612/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: flower18.in + out: flower18.ans + points: 10 +- in: flower12.in + out: flower12.ans + points: 10 +- in: flower6.in + out: flower6.ans + points: 10 +- in: flower3.in + out: flower3.ans + points: 10 +- in: flower11.in + out: flower11.ans + points: 10 +- in: flower4.in + out: flower4.ans + points: 10 +- in: flower5.in + out: flower5.ans + points: 10 +- in: flower20.in + out: flower20.ans + points: 10 +- in: flower17.in + out: flower17.ans + points: 10 +- in: flower19.in + out: flower19.ans + points: 10 +- in: flower16.in + out: flower16.ans + points: 10 +- in: flower2.in + out: flower2.ans + points: 10 +- in: flower1.in + out: flower1.ans + points: 10 +- in: flower7.in + out: flower7.ans + points: 10 +- in: flower8.in + out: flower8.ans + points: 10 +- in: flower9.in + out: flower9.ans + points: 10 +- in: flower14.in + out: flower14.ans + points: 10 +- in: flower15.in + out: flower15.ans + points: 10 +- in: flower13.in + out: flower13.ans + points: 10 +- in: flower10.in + out: flower10.ans + points: 10 diff --git a/NOI/loj-2612/tests.zip b/NOI/loj-2612/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c4335f5821df81daab525616aa47c83737e006ea --- /dev/null +++ b/NOI/loj-2612/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a5654687fe3e6b6f25cd1acf5987ab974b42e1b6b5cf8182d5363bba68e35c8 +size 50977947 diff --git a/NOI/loj-2613/init.yml b/NOI/loj-2613/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..8351285f66b47fbc037043ccb204317d0d851832 --- /dev/null +++ b/NOI/loj-2613/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: puzzle20.in + out: puzzle20.ans + points: 10 +- in: puzzle14.in + out: puzzle14.ans + points: 10 +- in: puzzle18.in + out: puzzle18.ans + points: 10 +- in: puzzle2.in + out: puzzle2.ans + points: 10 +- in: puzzle7.in + out: puzzle7.ans + points: 10 +- in: puzzle8.in + out: puzzle8.ans + points: 10 +- in: puzzle1.in + out: puzzle1.ans + points: 10 +- in: puzzle10.in + out: puzzle10.ans + points: 10 +- in: puzzle12.in + out: puzzle12.ans + points: 10 +- in: puzzle17.in + out: puzzle17.ans + points: 10 +- in: puzzle9.in + out: puzzle9.ans + points: 10 +- in: puzzle4.in + out: puzzle4.ans + points: 10 +- in: puzzle13.in + out: puzzle13.ans + points: 10 +- in: puzzle3.in + out: puzzle3.ans + points: 10 +- in: puzzle19.in + out: puzzle19.ans + points: 10 +- in: puzzle5.in + out: puzzle5.ans + points: 10 +- in: puzzle15.in + out: puzzle15.ans + points: 10 +- in: puzzle16.in + out: puzzle16.ans + points: 10 +- in: puzzle11.in + out: puzzle11.ans + points: 10 +- in: puzzle6.in + out: puzzle6.ans + points: 10 diff --git a/NOI/loj-2613/tests.zip b/NOI/loj-2613/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ceac15cd2dd6fcf876121897349859ce7538f533 --- /dev/null +++ b/NOI/loj-2613/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f28e6c856bf866a69d1155e0567ba789b609c779c7ac6ee846ce3a76552c429b +size 98307 diff --git a/NOI/loj-2664/init.yml b/NOI/loj-2664/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5dba931f6726a996e4c7278c559d53aa64d803a5 --- /dev/null +++ b/NOI/loj-2664/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: meow20.in + out: meow20.ans + points: 10 +- in: meow15.in + out: meow15.ans + points: 10 +- in: meow19.in + out: meow19.ans + points: 10 +- in: meow13.in + out: meow13.ans + points: 10 +- in: meow8.in + out: meow8.ans + points: 10 +- in: meow6.in + out: meow6.ans + points: 10 +- in: meow3.in + out: meow3.ans + points: 10 +- in: meow1.in + out: meow1.ans + points: 10 +- in: meow17.in + out: meow17.ans + points: 10 +- in: meow16.in + out: meow16.ans + points: 10 +- in: meow12.in + out: meow12.ans + points: 10 +- in: meow9.in + out: meow9.ans + points: 10 +- in: meow4.in + out: meow4.ans + points: 10 +- in: meow11.in + out: meow11.ans + points: 10 +- in: meow18.in + out: meow18.ans + points: 10 +- in: meow14.in + out: meow14.ans + points: 10 +- in: meow7.in + out: meow7.ans + points: 10 +- in: meow5.in + out: meow5.ans + points: 10 +- in: meow10.in + out: meow10.ans + points: 10 +- in: meow2.in + out: meow2.ans + points: 10 diff --git a/NOI/loj-2664/tests.zip b/NOI/loj-2664/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..372f82ac83cf528acd0ac3bc997564fb3d007ad3 --- /dev/null +++ b/NOI/loj-2664/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d873844212e46e06646b23e36ecc1fee7e660972162d6d4ad16ff60b23e8429f +size 30702078 diff --git a/NOI/loj-2665/init.yml b/NOI/loj-2665/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..4078bdefd4800190766e8a6fa56ecd2407a63c3a --- /dev/null +++ b/NOI/loj-2665/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: count15.in + out: count15.ans + points: 10 +- in: count9.in + out: count9.ans + points: 10 +- in: count19.in + out: count19.ans + points: 10 +- in: count14.in + out: count14.ans + points: 10 +- in: count16.in + out: count16.ans + points: 10 +- in: count5.in + out: count5.ans + points: 10 +- in: count17.in + out: count17.ans + points: 10 +- in: count12.in + out: count12.ans + points: 10 +- in: count2.in + out: count2.ans + points: 10 +- in: count13.in + out: count13.ans + points: 10 +- in: count20.in + out: count20.ans + points: 10 +- in: count8.in + out: count8.ans + points: 10 +- in: count11.in + out: count11.ans + points: 10 +- in: count18.in + out: count18.ans + points: 10 +- in: count1.in + out: count1.ans + points: 10 +- in: count4.in + out: count4.ans + points: 10 +- in: count10.in + out: count10.ans + points: 10 +- in: count6.in + out: count6.ans + points: 10 +- in: count7.in + out: count7.ans + points: 10 +- in: count3.in + out: count3.ans + points: 10 diff --git a/NOI/loj-2665/tests.zip b/NOI/loj-2665/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..f225fa4acc2886429312c2f17886ab1efc513194 --- /dev/null +++ b/NOI/loj-2665/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8889d66ecf8776fd13ba63983586d7d2bfbe885a295a3d5ad9a129f7f0eb9d96 +size 4450282 diff --git a/NOI/loj-2666/init.yml b/NOI/loj-2666/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..88159b3296197744d080c56d4a5d41679d990771 --- /dev/null +++ b/NOI/loj-2666/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: train1.in + out: train1.ans + points: 10 +- in: train10.in + out: train10.ans + points: 10 +- in: train9.in + out: train9.ans + points: 10 +- in: train5.in + out: train5.ans + points: 10 +- in: train8.in + out: train8.ans + points: 10 +- in: train7.in + out: train7.ans + points: 10 +- in: train2.in + out: train2.ans + points: 10 +- in: train6.in + out: train6.ans + points: 10 +- in: train3.in + out: train3.ans + points: 10 +- in: train4.in + out: train4.ans + points: 10 diff --git a/NOI/loj-2666/tests.zip b/NOI/loj-2666/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..af62367f7d292eca82e7372c4ee400aee3c1f0a9 --- /dev/null +++ b/NOI/loj-2666/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90cc11b0966129ee022a0338d2a64f3ab83f737c38febe4ed6dd15cd4af6f085 +size 2341430 diff --git a/NOI/loj-2667/init.yml b/NOI/loj-2667/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..274dcece46c98930f6a22bc5439815bf8f0690e0 --- /dev/null +++ b/NOI/loj-2667/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: matrix5.in + out: matrix5.out + points: 10 +- in: matrix8.in + out: matrix8.out + points: 10 +- in: matrix10.in + out: matrix10.out + points: 10 +- in: matrix6.in + out: matrix6.out + points: 10 +- in: matrix14.in + out: matrix14.out + points: 10 +- in: matrix20.in + out: matrix20.out + points: 10 +- in: matrix15.in + out: matrix15.out + points: 10 +- in: matrix18.in + out: matrix18.out + points: 10 +- in: matrix17.in + out: matrix17.out + points: 10 +- in: matrix16.in + out: matrix16.out + points: 10 +- in: matrix4.in + out: matrix4.out + points: 10 +- in: matrix2.in + out: matrix2.out + points: 10 +- in: matrix7.in + out: matrix7.out + points: 10 +- in: matrix9.in + out: matrix9.out + points: 10 +- in: matrix1.in + out: matrix1.out + points: 10 +- in: matrix19.in + out: matrix19.out + points: 10 +- in: matrix12.in + out: matrix12.out + points: 10 +- in: matrix13.in + out: matrix13.out + points: 10 +- in: matrix3.in + out: matrix3.out + points: 10 +- in: matrix11.in + out: matrix11.out + points: 10 diff --git a/NOI/loj-2667/tests.zip b/NOI/loj-2667/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a52042b8cd094e756a55c2fadec3afa93e10a1cf --- /dev/null +++ b/NOI/loj-2667/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0fe40accb891cd69869082f3a7720293eca49ca955155f679c1ed2712634ae6a +size 8093015 diff --git a/NOI/loj-2668/init.yml b/NOI/loj-2668/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..1583e6689cd4c6a21edc32822b11fc6a97825710 --- /dev/null +++ b/NOI/loj-2668/init.yml @@ -0,0 +1,65 @@ +archive: tests.zip +test_cases: +- in: penman3.in + out: penman3.out + points: 10 +- in: penman11.in + out: penman11.out + points: 10 +- in: penman6.in + out: penman6.out + points: 10 +- in: penman8.in + out: penman8.out + points: 10 +- in: penman12.in + out: penman12.out + points: 10 +- in: penman15.in + out: penman15.out + points: 10 +- in: penman20.in + out: penman20.out + points: 10 +- in: penman13.in + out: penman13.out + points: 10 +- in: penman7.in + out: penman7.out + points: 10 +- in: penman14.in + out: penman14.out + points: 10 +- in: penman1.in + out: penman1.out + points: 10 +- in: penman10.in + out: penman10.out + points: 10 +- in: penman4.in + out: penman4.out + points: 10 +- in: penman0.in + out: penman0.out + points: 10 +- in: penman16.in + out: penman16.out + points: 10 +- in: penman18.in + out: penman18.out + points: 10 +- in: penman19.in + out: penman19.out + points: 10 +- in: penman17.in + out: penman17.out + points: 10 +- in: penman5.in + out: penman5.out + points: 10 +- in: penman2.in + out: penman2.out + points: 10 +- in: penman9.in + out: penman9.out + points: 10 diff --git a/NOI/loj-2668/tests.zip b/NOI/loj-2668/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..7a9fb1a22a14d0f9223717b67c02a9c724f1bd6d --- /dev/null +++ b/NOI/loj-2668/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0c2d298ce928fdf0da4b675a075c26f24cbec32052ba9384d881e8551950701 +size 1905378 diff --git a/NOI/loj-2669/init.yml b/NOI/loj-2669/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7ee79feaaf8381a90368a97258a166bab9e36e09 --- /dev/null +++ b/NOI/loj-2669/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: foodshop6.in + out: foodshop6.ans + points: 10 +- in: foodshop1.in + out: foodshop1.ans + points: 10 +- in: foodshop3.in + out: foodshop3.ans + points: 10 +- in: foodshop7.in + out: foodshop7.ans + points: 10 +- in: foodshop2.in + out: foodshop2.ans + points: 10 +- in: foodshop11.in + out: foodshop11.ans + points: 10 +- in: foodshop15.in + out: foodshop15.ans + points: 10 +- in: foodshop4.in + out: foodshop4.ans + points: 10 +- in: foodshop14.in + out: foodshop14.ans + points: 10 +- in: foodshop8.in + out: foodshop8.ans + points: 10 +- in: foodshop16.in + out: foodshop16.ans + points: 10 +- in: foodshop10.in + out: foodshop10.ans + points: 10 +- in: foodshop19.in + out: foodshop19.ans + points: 10 +- in: foodshop20.in + out: foodshop20.ans + points: 10 +- in: foodshop18.in + out: foodshop18.ans + points: 10 +- in: foodshop13.in + out: foodshop13.ans + points: 10 +- in: foodshop5.in + out: foodshop5.ans + points: 10 +- in: foodshop12.in + out: foodshop12.ans + points: 10 +- in: foodshop17.in + out: foodshop17.ans + points: 10 +- in: foodshop9.in + out: foodshop9.ans + points: 10 diff --git a/NOI/loj-2669/tests.zip b/NOI/loj-2669/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..893ee09ec22bd1791d5ae2891e19c8d55446915f --- /dev/null +++ b/NOI/loj-2669/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfc151cf1fad23129b71ad09ed2cf99a6545caa0118e685160476cfd4b9485b6 +size 13954881 diff --git a/NOI/loj-2670/init.yml b/NOI/loj-2670/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..81467401173a01203ca3504cbacbbefc07077531 --- /dev/null +++ b/NOI/loj-2670/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: random2.in + out: random2.ans + points: 10 +- in: random17.in + out: random17.ans + points: 10 +- in: random10.in + out: random10.ans + points: 10 +- in: random6.in + out: random6.ans + points: 10 +- in: random15.in + out: random15.ans + points: 10 +- in: random9.in + out: random9.ans + points: 10 +- in: random8.in + out: random8.ans + points: 10 +- in: random3.in + out: random3.ans + points: 10 +- in: random4.in + out: random4.ans + points: 10 +- in: random19.in + out: random19.ans + points: 10 +- in: random16.in + out: random16.ans + points: 10 +- in: random11.in + out: random11.ans + points: 10 +- in: random20.in + out: random20.ans + points: 10 +- in: random13.in + out: random13.ans + points: 10 +- in: random7.in + out: random7.ans + points: 10 +- in: random5.in + out: random5.ans + points: 10 +- in: random1.in + out: random1.ans + points: 10 +- in: random14.in + out: random14.ans + points: 10 +- in: random18.in + out: random18.ans + points: 10 +- in: random12.in + out: random12.ans + points: 10 diff --git a/NOI/loj-2670/tests.zip b/NOI/loj-2670/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..725de3bb9cf83d3bd000e0eca73628702a5f54d8 --- /dev/null +++ b/NOI/loj-2670/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5c75d5fc5f168ab8e2b2006a20e6017b02af76097c39e9c0a8c0bde1746aa18 +size 5038 diff --git a/NOI/loj-2671/init.yml b/NOI/loj-2671/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..768d3ee1fc0ec5b8b4a281391bc88ec93ed3b189 --- /dev/null +++ b/NOI/loj-2671/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: bicycling12.in + out: bicycling12.ans + points: 10 +- in: bicycling14.in + out: bicycling14.ans + points: 10 +- in: bicycling3.in + out: bicycling3.ans + points: 10 +- in: bicycling7.in + out: bicycling7.ans + points: 10 +- in: bicycling16.in + out: bicycling16.ans + points: 10 +- in: bicycling17.in + out: bicycling17.ans + points: 10 +- in: bicycling5.in + out: bicycling5.ans + points: 10 +- in: bicycling11.in + out: bicycling11.ans + points: 10 +- in: bicycling15.in + out: bicycling15.ans + points: 10 +- in: bicycling4.in + out: bicycling4.ans + points: 10 +- in: bicycling9.in + out: bicycling9.ans + points: 10 +- in: bicycling19.in + out: bicycling19.ans + points: 10 +- in: bicycling13.in + out: bicycling13.ans + points: 10 +- in: bicycling20.in + out: bicycling20.ans + points: 10 +- in: bicycling8.in + out: bicycling8.ans + points: 10 +- in: bicycling2.in + out: bicycling2.ans + points: 10 +- in: bicycling6.in + out: bicycling6.ans + points: 10 +- in: bicycling10.in + out: bicycling10.ans + points: 10 +- in: bicycling1.in + out: bicycling1.ans + points: 10 +- in: bicycling18.in + out: bicycling18.ans + points: 10 diff --git a/NOI/loj-2671/tests.zip b/NOI/loj-2671/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..9bcbf7f47dd3c8865435794e2933c62cf5589ba2 --- /dev/null +++ b/NOI/loj-2671/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0474e6e6b2170dee63140c912fedae4b460c93508f193ccb51fbe679ca020f9 +size 757491 diff --git a/NOI/loj-2672/init.yml b/NOI/loj-2672/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..13093826637d084761a41a2eddf0d3461b9d26ac --- /dev/null +++ b/NOI/loj-2672/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: chess6.in + out: chess6.ans + points: 10 +- in: chess8.in + out: chess8.ans + points: 10 +- in: chess9.in + out: chess9.ans + points: 10 +- in: chess1.in + out: chess1.ans + points: 10 +- in: chess3.in + out: chess3.ans + points: 10 +- in: chess2.in + out: chess2.ans + points: 10 +- in: chess4.in + out: chess4.ans + points: 10 +- in: chess5.in + out: chess5.ans + points: 10 +- in: chess7.in + out: chess7.ans + points: 10 +- in: chess10.in + out: chess10.ans + points: 10 diff --git a/NOI/loj-2672/tests.zip b/NOI/loj-2672/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..d0a871e2a2ce4f6226ab8b08f31d4d6a5e5707c0 --- /dev/null +++ b/NOI/loj-2672/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd14364904f5a4541bc79f3a8449956c379e69c40b48d9ac7423b32f0b681b39 +size 101780440 diff --git a/NOI/loj-2673/init.yml b/NOI/loj-2673/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..274fb22140b9dc94ded7019b4d80e0a6aad1ff2c --- /dev/null +++ b/NOI/loj-2673/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: park1.in + out: park1.ans + points: 10 +- in: park7.in + out: park7.ans + points: 10 +- in: park5.in + out: park5.ans + points: 10 +- in: park6.in + out: park6.ans + points: 10 +- in: park4.in + out: park4.ans + points: 10 +- in: park9.in + out: park9.ans + points: 10 +- in: park2.in + out: park2.ans + points: 10 +- in: park10.in + out: park10.ans + points: 10 +- in: park3.in + out: park3.ans + points: 10 +- in: park8.in + out: park8.ans + points: 10 diff --git a/NOI/loj-2673/tests.zip b/NOI/loj-2673/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..bf9c111bdfd6b1cf63f69ecf91dabf472a544312 --- /dev/null +++ b/NOI/loj-2673/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e4df9988377ae84fc94d860516aa8050356c05efcfee130185f0c3e75e6b7ce +size 6136510 diff --git a/NOI/loj-2674/init.yml b/NOI/loj-2674/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..e0810b9dd09551e3fbaa9e3a580f12b2e5f17560 --- /dev/null +++ b/NOI/loj-2674/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: delicacy3.in + out: delicacy3.out + points: 10 +- in: delicacy9.in + out: delicacy9.out + points: 10 +- in: delicacy2.in + out: delicacy2.out + points: 10 +- in: delicacy8.in + out: delicacy8.out + points: 10 +- in: delicacy5.in + out: delicacy5.out + points: 10 +- in: delicacy1.in + out: delicacy1.out + points: 10 +- in: delicacy7.in + out: delicacy7.out + points: 10 +- in: delicacy10.in + out: delicacy10.out + points: 10 +- in: delicacy4.in + out: delicacy4.out + points: 10 +- in: delicacy6.in + out: delicacy6.out + points: 10 diff --git a/NOI/loj-2674/tests.zip b/NOI/loj-2674/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..26cc3ff79de36fa642db213ccb6e9fdacc6abf5a --- /dev/null +++ b/NOI/loj-2674/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e60288bd03b4d03f775c4613de164ef343e6cd0b7d3273a3f4e2e530fbb4674 +size 61131 diff --git a/NOI/loj-2675/init.yml b/NOI/loj-2675/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5485401bfdca7b94b154a10078cfb236dec4cf6b --- /dev/null +++ b/NOI/loj-2675/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: tritown8.in + out: tritown8.ans + points: 10 +- in: tritown2.in + out: tritown2.ans + points: 10 +- in: tritown6.in + out: tritown6.ans + points: 10 +- in: tritown5.in + out: tritown5.ans + points: 10 +- in: tritown10.in + out: tritown10.ans + points: 10 +- in: tritown9.in + out: tritown9.ans + points: 10 +- in: tritown4.in + out: tritown4.ans + points: 10 +- in: tritown1.in + out: tritown1.ans + points: 10 +- in: tritown3.in + out: tritown3.ans + points: 10 +- in: tritown7.in + out: tritown7.ans + points: 10 diff --git a/NOI/loj-2675/tests.zip b/NOI/loj-2675/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..f5129c1e215ca7cd064920c332284152c9d81914 --- /dev/null +++ b/NOI/loj-2675/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:750d50e5cb8b98604aecfad471df31a069c208844f6bb40ab3229b4c3d54da5d +size 116148 diff --git a/NOI/loj-2718/init.yml b/NOI/loj-2718/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..af66cd7250989e4c090a34dab6fd96ba116fef2c --- /dev/null +++ b/NOI/loj-2718/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: return5.in + out: return5.ans + points: 10 +- in: return1.in + out: return1.ans + points: 10 +- in: return8.in + out: return8.ans + points: 10 +- in: return19.in + out: return19.ans + points: 10 +- in: return15.in + out: return15.ans + points: 10 +- in: return18.in + out: return18.ans + points: 10 +- in: return14.in + out: return14.ans + points: 10 +- in: return17.in + out: return17.ans + points: 10 +- in: return2.in + out: return2.ans + points: 10 +- in: return20.in + out: return20.ans + points: 10 +- in: return7.in + out: return7.ans + points: 10 +- in: return9.in + out: return9.ans + points: 10 +- in: return6.in + out: return6.ans + points: 10 +- in: return16.in + out: return16.ans + points: 10 +- in: return4.in + out: return4.ans + points: 10 +- in: return12.in + out: return12.ans + points: 10 +- in: return10.in + out: return10.ans + points: 10 +- in: return3.in + out: return3.ans + points: 10 +- in: return13.in + out: return13.ans + points: 10 +- in: return11.in + out: return11.ans + points: 10 diff --git a/NOI/loj-2718/tests.zip b/NOI/loj-2718/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..34cce7bc55d243d017ecb0f4d4b84df2303d3f91 --- /dev/null +++ b/NOI/loj-2718/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a03deb652de5b54e8ebd85920fdd6620b9a1a81344de1dc08a756fd00f02054c +size 361109127 diff --git a/NOI/loj-2719/init.yml b/NOI/loj-2719/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d8446cce7b4e95aed0e05b57b163b8fa43200139 --- /dev/null +++ b/NOI/loj-2719/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: inverse9.in + out: inverse9.ans + points: 10 +- in: inverse24.in + out: inverse24.ans + points: 10 +- in: inverse11.in + out: inverse11.ans + points: 10 +- in: inverse16.in + out: inverse16.ans + points: 10 +- in: inverse6.in + out: inverse6.ans + points: 10 +- in: inverse22.in + out: inverse22.ans + points: 10 +- in: inverse12.in + out: inverse12.ans + points: 10 +- in: inverse19.in + out: inverse19.ans + points: 10 +- in: inverse8.in + out: inverse8.ans + points: 10 +- in: inverse5.in + out: inverse5.ans + points: 10 +- in: inverse4.in + out: inverse4.ans + points: 10 +- in: inverse18.in + out: inverse18.ans + points: 10 +- in: inverse17.in + out: inverse17.ans + points: 10 +- in: inverse21.in + out: inverse21.ans + points: 10 +- in: inverse10.in + out: inverse10.ans + points: 10 +- in: inverse3.in + out: inverse3.ans + points: 10 +- in: inverse25.in + out: inverse25.ans + points: 10 +- in: inverse20.in + out: inverse20.ans + points: 10 +- in: inverse7.in + out: inverse7.ans + points: 10 +- in: inverse2.in + out: inverse2.ans + points: 10 +- in: inverse1.in + out: inverse1.ans + points: 10 +- in: inverse14.in + out: inverse14.ans + points: 10 +- in: inverse13.in + out: inverse13.ans + points: 10 +- in: inverse23.in + out: inverse23.ans + points: 10 +- in: inverse15.in + out: inverse15.ans + points: 10 diff --git a/NOI/loj-2719/tests.zip b/NOI/loj-2719/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..956947f2f6f94c938d708ee12fe1db6ae51a26b5 --- /dev/null +++ b/NOI/loj-2719/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed941d358919e686465ff63ef6ffa936449dd7e255e7b38a15d43bc20bb45cb4 +size 60303379 diff --git a/NOI/loj-2720/init.yml b/NOI/loj-2720/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..08cdda7976db15b7c6c5f6528be7fe52791613a1 --- /dev/null +++ b/NOI/loj-2720/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: name5.in + out: name5.ans + points: 10 +- in: name9.in + out: name9.ans + points: 10 +- in: name18.in + out: name18.ans + points: 10 +- in: name1.in + out: name1.ans + points: 10 +- in: name25.in + out: name25.ans + points: 10 +- in: name20.in + out: name20.ans + points: 10 +- in: name11.in + out: name11.ans + points: 10 +- in: name15.in + out: name15.ans + points: 10 +- in: name22.in + out: name22.ans + points: 10 +- in: name4.in + out: name4.ans + points: 10 +- in: name12.in + out: name12.ans + points: 10 +- in: name23.in + out: name23.ans + points: 10 +- in: name8.in + out: name8.ans + points: 10 +- in: name7.in + out: name7.ans + points: 10 +- in: name21.in + out: name21.ans + points: 10 +- in: name10.in + out: name10.ans + points: 10 +- in: name24.in + out: name24.ans + points: 10 +- in: name3.in + out: name3.ans + points: 10 +- in: name2.in + out: name2.ans + points: 10 +- in: name13.in + out: name13.ans + points: 10 +- in: name14.in + out: name14.ans + points: 10 +- in: name19.in + out: name19.ans + points: 10 +- in: name17.in + out: name17.ans + points: 10 +- in: name16.in + out: name16.ans + points: 10 +- in: name6.in + out: name6.ans + points: 10 diff --git a/NOI/loj-2720/tests.zip b/NOI/loj-2720/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..4e28cacf97b029285e4bca004b41d8a316a8e763 --- /dev/null +++ b/NOI/loj-2720/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0937f31ef461ead0869686f07a2760f2f544cb7c264f113706c2636e2eed2773 +size 28161328 diff --git a/NOI/loj-2721/init.yml b/NOI/loj-2721/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7dcf3644d5df4f05bdf41d7a0c33ebb79c6bc726 --- /dev/null +++ b/NOI/loj-2721/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: dragon5.in + out: dragon5.ans + points: 10 +- in: dragon10.in + out: dragon10.ans + points: 10 +- in: dragon20.in + out: dragon20.ans + points: 10 +- in: dragon14.in + out: dragon14.ans + points: 10 +- in: dragon15.in + out: dragon15.ans + points: 10 +- in: dragon4.in + out: dragon4.ans + points: 10 +- in: dragon16.in + out: dragon16.ans + points: 10 +- in: dragon12.in + out: dragon12.ans + points: 10 +- in: dragon6.in + out: dragon6.ans + points: 10 +- in: dragon1.in + out: dragon1.ans + points: 10 +- in: dragon2.in + out: dragon2.ans + points: 10 +- in: dragon13.in + out: dragon13.ans + points: 10 +- in: dragon17.in + out: dragon17.ans + points: 10 +- in: dragon19.in + out: dragon19.ans + points: 10 +- in: dragon9.in + out: dragon9.ans + points: 10 +- in: dragon18.in + out: dragon18.ans + points: 10 +- in: dragon7.in + out: dragon7.ans + points: 10 +- in: dragon8.in + out: dragon8.ans + points: 10 +- in: dragon11.in + out: dragon11.ans + points: 10 +- in: dragon3.in + out: dragon3.ans + points: 10 diff --git a/NOI/loj-2721/tests.zip b/NOI/loj-2721/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a4369c2c4cce7caa47d6d67fd87c2318e2c47a9b --- /dev/null +++ b/NOI/loj-2721/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0abfddda0698fe8d1af3190064f42591e4b6e887e403f447310f920db29ed650 +size 97337202 diff --git a/NOI/loj-2722/init.yml b/NOI/loj-2722/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5c5d89fac98712e0bcc28d9a64b44944fda0fced --- /dev/null +++ b/NOI/loj-2722/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.ans + points: 10 +- in: 19.in + out: 19.ans + points: 10 +- in: 15.in + out: 15.ans + points: 10 +- in: 9.in + out: 9.ans + points: 10 +- in: 1.in + out: 1.ans + points: 10 +- in: 8.in + out: 8.ans + points: 10 +- in: 7.in + out: 7.ans + points: 10 +- in: 6.in + out: 6.ans + points: 10 +- in: 10.in + out: 10.ans + points: 10 +- in: 20.in + out: 20.ans + points: 10 +- in: 5.in + out: 5.ans + points: 10 +- in: 11.in + out: 11.ans + points: 10 +- in: 16.in + out: 16.ans + points: 10 +- in: 12.in + out: 12.ans + points: 10 +- in: 4.in + out: 4.ans + points: 10 +- in: 17.in + out: 17.ans + points: 10 +- in: 13.in + out: 13.ans + points: 10 +- in: 3.in + out: 3.ans + points: 10 +- in: 18.in + out: 18.ans + points: 10 +- in: 14.in + out: 14.ans + points: 10 diff --git a/NOI/loj-2722/tests.zip b/NOI/loj-2722/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..05bc93a4a1a1e9161e9c812305501433e1842a38 --- /dev/null +++ b/NOI/loj-2722/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57d9723ef055f6620696e44bd04da567e251e1339856d75d84d1cee3f66df24a +size 744134982 diff --git a/NOI/loj-2723/init.yml b/NOI/loj-2723/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..45ea9352e33fbbe1fe574477be6da8ff8cdd04ff --- /dev/null +++ b/NOI/loj-2723/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: polygon1.in + out: polygon1.ans + points: 10 +- in: polygon2.in + out: polygon2.ans + points: 10 +- in: polygon13.in + out: polygon13.ans + points: 10 +- in: polygon17.in + out: polygon17.ans + points: 10 +- in: polygon15.in + out: polygon15.ans + points: 10 +- in: polygon9.in + out: polygon9.ans + points: 10 +- in: polygon18.in + out: polygon18.ans + points: 10 +- in: polygon10.in + out: polygon10.ans + points: 10 +- in: polygon8.in + out: polygon8.ans + points: 10 +- in: polygon20.in + out: polygon20.ans + points: 10 +- in: polygon4.in + out: polygon4.ans + points: 10 +- in: polygon12.in + out: polygon12.ans + points: 10 +- in: polygon14.in + out: polygon14.ans + points: 10 +- in: polygon16.in + out: polygon16.ans + points: 10 +- in: polygon7.in + out: polygon7.ans + points: 10 +- in: polygon11.in + out: polygon11.ans + points: 10 +- in: polygon3.in + out: polygon3.ans + points: 10 +- in: polygon19.in + out: polygon19.ans + points: 10 +- in: polygon6.in + out: polygon6.ans + points: 10 +- in: polygon5.in + out: polygon5.ans + points: 10 diff --git a/NOI/loj-2723/tests.zip b/NOI/loj-2723/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..989bad760273576d4b867c4a2bce66d966e43af1 --- /dev/null +++ b/NOI/loj-2723/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b38afef55c26930772027f783a9dfb2aed6487dd72dbd1121ebe0d7cb25c8bd9 +size 71844 diff --git a/NOI/loj-2951/init.yml b/NOI/loj-2951/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..237321dad8788e15d347163b860e30faad4ecff5 --- /dev/null +++ b/NOI/loj-2951/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: money15.in + out: money15.ans + points: 10 +- in: money3.in + out: money3.ans + points: 10 +- in: money20.in + out: money20.ans + points: 10 +- in: money2.in + out: money2.ans + points: 10 +- in: money6.in + out: money6.ans + points: 10 +- in: money1.in + out: money1.ans + points: 10 +- in: money7.in + out: money7.ans + points: 10 +- in: money12.in + out: money12.ans + points: 10 +- in: money14.in + out: money14.ans + points: 10 +- in: money8.in + out: money8.ans + points: 10 +- in: money18.in + out: money18.ans + points: 10 +- in: money16.in + out: money16.ans + points: 10 +- in: money19.in + out: money19.ans + points: 10 +- in: money17.in + out: money17.ans + points: 10 +- in: money9.in + out: money9.ans + points: 10 +- in: money10.in + out: money10.ans + points: 10 +- in: money5.in + out: money5.ans + points: 10 +- in: money13.in + out: money13.ans + points: 10 +- in: money4.in + out: money4.ans + points: 10 +- in: money11.in + out: money11.ans + points: 10 diff --git a/NOI/loj-2951/tests.zip b/NOI/loj-2951/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..dbdb37f6ddd4a969671efec6e988a0b79d374a7b --- /dev/null +++ b/NOI/loj-2951/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bffc800047303de7ff7cc6707fc88501e182c576de20eeb57bc3a558cf1ab72 +size 55750 diff --git a/NOI/loj-2952/init.yml b/NOI/loj-2952/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2cdb54365896cd1a9c2c95717c59c19b751e57ee --- /dev/null +++ b/NOI/loj-2952/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: track14.in + out: track14.ans + points: 10 +- in: track13.in + out: track13.ans + points: 10 +- in: track16.in + out: track16.ans + points: 10 +- in: track17.in + out: track17.ans + points: 10 +- in: track11.in + out: track11.ans + points: 10 +- in: track4.in + out: track4.ans + points: 10 +- in: track1.in + out: track1.ans + points: 10 +- in: track12.in + out: track12.ans + points: 10 +- in: track15.in + out: track15.ans + points: 10 +- in: track9.in + out: track9.ans + points: 10 +- in: track3.in + out: track3.ans + points: 10 +- in: track19.in + out: track19.ans + points: 10 +- in: track18.in + out: track18.ans + points: 10 +- in: track7.in + out: track7.ans + points: 10 +- in: track5.in + out: track5.ans + points: 10 +- in: track8.in + out: track8.ans + points: 10 +- in: track10.in + out: track10.ans + points: 10 +- in: track2.in + out: track2.ans + points: 10 +- in: track6.in + out: track6.ans + points: 10 +- in: track20.in + out: track20.ans + points: 10 diff --git a/NOI/loj-2952/tests.zip b/NOI/loj-2952/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..b7f12e9522a6b6b35ab6556011d8cb9eaebf97da --- /dev/null +++ b/NOI/loj-2952/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4cbf04437bb50c68ceafc6cca0111d5d6d6328fe9172e203ff65d99cbf36a2df +size 4979688 diff --git a/NOI/loj-2953/init.yml b/NOI/loj-2953/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5ccaaf5a97a04ffe4dd8912f533cd3ba5414c93d --- /dev/null +++ b/NOI/loj-2953/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: travel9.in + out: travel9.ans + points: 10 +- in: travel5.in + out: travel5.ans + points: 10 +- in: travel22.in + out: travel22.ans + points: 10 +- in: travel18.in + out: travel18.ans + points: 10 +- in: travel2.in + out: travel2.ans + points: 10 +- in: travel11.in + out: travel11.ans + points: 10 +- in: travel12.in + out: travel12.ans + points: 10 +- in: travel25.in + out: travel25.ans + points: 10 +- in: travel10.in + out: travel10.ans + points: 10 +- in: travel7.in + out: travel7.ans + points: 10 +- in: travel21.in + out: travel21.ans + points: 10 +- in: travel15.in + out: travel15.ans + points: 10 +- in: travel24.in + out: travel24.ans + points: 10 +- in: travel6.in + out: travel6.ans + points: 10 +- in: travel17.in + out: travel17.ans + points: 10 +- in: travel14.in + out: travel14.ans + points: 10 +- in: travel3.in + out: travel3.ans + points: 10 +- in: travel13.in + out: travel13.ans + points: 10 +- in: travel20.in + out: travel20.ans + points: 10 +- in: travel16.in + out: travel16.ans + points: 10 +- in: travel23.in + out: travel23.ans + points: 10 +- in: travel1.in + out: travel1.ans + points: 10 +- in: travel19.in + out: travel19.ans + points: 10 +- in: travel4.in + out: travel4.ans + points: 10 +- in: travel8.in + out: travel8.ans + points: 10 diff --git a/NOI/loj-2953/tests.zip b/NOI/loj-2953/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..0e0391d2bb22f4e8d37f77fa2c2798e8dab377e2 --- /dev/null +++ b/NOI/loj-2953/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b0b62226b9d129d919eb5c255108d0a73e60977c7450153548e6dced1c3e30d +size 675781 diff --git a/NOI/loj-2954/init.yml b/NOI/loj-2954/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb56df818978330edac57bfb52bee6766ee0fe67 --- /dev/null +++ b/NOI/loj-2954/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: game13.in + out: game13.ans + points: 10 +- in: game8.in + out: game8.ans + points: 10 +- in: game7.in + out: game7.ans + points: 10 +- in: game12.in + out: game12.ans + points: 10 +- in: game19.in + out: game19.ans + points: 10 +- in: game10.in + out: game10.ans + points: 10 +- in: game11.in + out: game11.ans + points: 10 +- in: game16.in + out: game16.ans + points: 10 +- in: game14.in + out: game14.ans + points: 10 +- in: game17.in + out: game17.ans + points: 10 +- in: game3.in + out: game3.ans + points: 10 +- in: game2.in + out: game2.ans + points: 10 +- in: game18.in + out: game18.ans + points: 10 +- in: game6.in + out: game6.ans + points: 10 +- in: game1.in + out: game1.ans + points: 10 +- in: game15.in + out: game15.ans + points: 10 +- in: game20.in + out: game20.ans + points: 10 +- in: game5.in + out: game5.ans + points: 10 +- in: game9.in + out: game9.ans + points: 10 +- in: game4.in + out: game4.ans + points: 10 diff --git a/NOI/loj-2954/tests.zip b/NOI/loj-2954/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..d61f16184d52d704aeca101ca103556666f10936 --- /dev/null +++ b/NOI/loj-2954/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfac6e7a4b19c2151f08610646790c6d98128d209c5e64748330866737235022 +size 4095 diff --git a/NOI/loj-2955/init.yml b/NOI/loj-2955/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ba7dae149493104f2222baf5272ce454a889aac6 --- /dev/null +++ b/NOI/loj-2955/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: defense22.in + out: defense22.ans + points: 10 +- in: defense12.in + out: defense12.ans + points: 10 +- in: defense25.in + out: defense25.ans + points: 10 +- in: defense3.in + out: defense3.ans + points: 10 +- in: defense14.in + out: defense14.ans + points: 10 +- in: defense24.in + out: defense24.ans + points: 10 +- in: defense9.in + out: defense9.ans + points: 10 +- in: defense2.in + out: defense2.ans + points: 10 +- in: defense20.in + out: defense20.ans + points: 10 +- in: defense13.in + out: defense13.ans + points: 10 +- in: defense10.in + out: defense10.ans + points: 10 +- in: defense8.in + out: defense8.ans + points: 10 +- in: defense18.in + out: defense18.ans + points: 10 +- in: defense19.in + out: defense19.ans + points: 10 +- in: defense11.in + out: defense11.ans + points: 10 +- in: defense7.in + out: defense7.ans + points: 10 +- in: defense6.in + out: defense6.ans + points: 10 +- in: defense21.in + out: defense21.ans + points: 10 +- in: defense16.in + out: defense16.ans + points: 10 +- in: defense4.in + out: defense4.ans + points: 10 +- in: defense15.in + out: defense15.ans + points: 10 +- in: defense1.in + out: defense1.ans + points: 10 +- in: defense17.in + out: defense17.ans + points: 10 +- in: defense23.in + out: defense23.ans + points: 10 +- in: defense5.in + out: defense5.ans + points: 10 diff --git a/NOI/loj-2955/tests.zip b/NOI/loj-2955/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ce2d9a96ce5eed61874d56df5cc70ebed1b8c8e2 --- /dev/null +++ b/NOI/loj-2955/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:821771aa9f1162b4f45e6a19ac049219d2b476b34a758b6e957bb95aa0729482 +size 59087332 diff --git a/NOI/loj-3007/init.yml b/NOI/loj-3007/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3c733abd6482cdd1c32e30f1fb88cffe7b47730b --- /dev/null +++ b/NOI/loj-3007/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: bus16.in + out: bus16.ans + points: 10 +- in: bus1.in + out: bus1.ans + points: 10 +- in: bus12.in + out: bus12.ans + points: 10 +- in: bus8.in + out: bus8.ans + points: 10 +- in: bus20.in + out: bus20.ans + points: 10 +- in: bus6.in + out: bus6.ans + points: 10 +- in: bus17.in + out: bus17.ans + points: 10 +- in: bus4.in + out: bus4.ans + points: 10 +- in: bus13.in + out: bus13.ans + points: 10 +- in: bus10.in + out: bus10.ans + points: 10 +- in: bus19.in + out: bus19.ans + points: 10 +- in: bus2.in + out: bus2.ans + points: 10 +- in: bus9.in + out: bus9.ans + points: 10 +- in: bus18.in + out: bus18.ans + points: 10 +- in: bus15.in + out: bus15.ans + points: 10 +- in: bus7.in + out: bus7.ans + points: 10 +- in: bus14.in + out: bus14.ans + points: 10 +- in: bus11.in + out: bus11.ans + points: 10 +- in: bus5.in + out: bus5.ans + points: 10 +- in: bus3.in + out: bus3.ans + points: 10 diff --git a/NOI/loj-3007/tests.zip b/NOI/loj-3007/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..9e92e169abb16ae3fcc4a49b11d8096ed48bf459 --- /dev/null +++ b/NOI/loj-3007/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb34b34f3703e8d96e435f58bf147da4e85b5e7e71bcead5a19887a8ce9fa28d +size 51030 diff --git a/NOI/loj-3008/init.yml b/NOI/loj-3008/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7795b9d6a62af0c040e5e64c506cbe854d5f120d --- /dev/null +++ b/NOI/loj-3008/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: tree2.in + out: tree2.ans + points: 10 +- in: tree7.in + out: tree7.ans + points: 10 +- in: tree23.in + out: tree23.ans + points: 10 +- in: tree22.in + out: tree22.ans + points: 10 +- in: tree5.in + out: tree5.ans + points: 10 +- in: tree25.in + out: tree25.ans + points: 10 +- in: tree3.in + out: tree3.ans + points: 10 +- in: tree8.in + out: tree8.ans + points: 10 +- in: tree16.in + out: tree16.ans + points: 10 +- in: tree20.in + out: tree20.ans + points: 10 +- in: tree10.in + out: tree10.ans + points: 10 +- in: tree11.in + out: tree11.ans + points: 10 +- in: tree17.in + out: tree17.ans + points: 10 +- in: tree13.in + out: tree13.ans + points: 10 +- in: tree24.in + out: tree24.ans + points: 10 +- in: tree15.in + out: tree15.ans + points: 10 +- in: tree1.in + out: tree1.ans + points: 10 +- in: tree6.in + out: tree6.ans + points: 10 +- in: tree21.in + out: tree21.ans + points: 10 +- in: tree14.in + out: tree14.ans + points: 10 +- in: tree19.in + out: tree19.ans + points: 10 +- in: tree4.in + out: tree4.ans + points: 10 +- in: tree9.in + out: tree9.ans + points: 10 +- in: tree18.in + out: tree18.ans + points: 10 +- in: tree12.in + out: tree12.ans + points: 10 diff --git a/NOI/loj-3008/tests.zip b/NOI/loj-3008/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..0da6ef5b4051be5bb59598e7dcefb1cdeeb1e49b --- /dev/null +++ b/NOI/loj-3008/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05742752c84df4c86c5dfb271ba3ecb481a775f2db8c1311ea158d12d1a4d41a +size 78945316 diff --git a/NOI/loj-3156/init.yml b/NOI/loj-3156/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ddaf623b83dbb96805b017987df4665d64f1ceb --- /dev/null +++ b/NOI/loj-3156/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: route4.in + out: route4.ans + points: 10 +- in: route14.in + out: route14.ans + points: 10 +- in: route9.in + out: route9.ans + points: 10 +- in: route20.in + out: route20.ans + points: 10 +- in: route19.in + out: route19.ans + points: 10 +- in: route13.in + out: route13.ans + points: 10 +- in: route17.in + out: route17.ans + points: 10 +- in: route15.in + out: route15.ans + points: 10 +- in: route1.in + out: route1.ans + points: 10 +- in: route5.in + out: route5.ans + points: 10 +- in: route6.in + out: route6.ans + points: 10 +- in: route7.in + out: route7.ans + points: 10 +- in: route18.in + out: route18.ans + points: 10 +- in: route3.in + out: route3.ans + points: 10 +- in: route16.in + out: route16.ans + points: 10 +- in: route11.in + out: route11.ans + points: 10 +- in: route10.in + out: route10.ans + points: 10 +- in: route2.in + out: route2.ans + points: 10 +- in: route12.in + out: route12.ans + points: 10 +- in: route8.in + out: route8.ans + points: 10 diff --git a/NOI/loj-3156/tests.zip b/NOI/loj-3156/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c440515a0fa466c6a236789884093f9587ac078c --- /dev/null +++ b/NOI/loj-3156/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60ab07aa4273ebbf72fc791a3c81aaf6f62258d21097ccc281ada0a15396aa60 +size 23851675 diff --git a/NOI/loj-3157/init.yml b/NOI/loj-3157/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..67ca6601e2495cf27e78ef62bd321e015af90f2e --- /dev/null +++ b/NOI/loj-3157/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: robot4.in + out: robot4.ans + points: 10 +- in: robot6.in + out: robot6.ans + points: 10 +- in: robot7.in + out: robot7.ans + points: 10 +- in: robot9.in + out: robot9.ans + points: 10 +- in: robot16.in + out: robot16.ans + points: 10 +- in: robot10.in + out: robot10.ans + points: 10 +- in: robot12.in + out: robot12.ans + points: 10 +- in: robot15.in + out: robot15.ans + points: 10 +- in: robot11.in + out: robot11.ans + points: 10 +- in: robot13.in + out: robot13.ans + points: 10 +- in: robot14.in + out: robot14.ans + points: 10 +- in: robot19.in + out: robot19.ans + points: 10 +- in: robot18.in + out: robot18.ans + points: 10 +- in: robot5.in + out: robot5.ans + points: 10 +- in: robot3.in + out: robot3.ans + points: 10 +- in: robot20.in + out: robot20.ans + points: 10 +- in: robot2.in + out: robot2.ans + points: 10 +- in: robot8.in + out: robot8.ans + points: 10 +- in: robot17.in + out: robot17.ans + points: 10 +- in: robot1.in + out: robot1.ans + points: 10 diff --git a/NOI/loj-3157/tests.zip b/NOI/loj-3157/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..23eb5b572e03cdc7e375215e8b753f6c2a657ffe --- /dev/null +++ b/NOI/loj-3157/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f329eb2797d5633a322643948c4cfbf72fd9d7a2091da41d9c2243f7c5ab105 +size 35893 diff --git a/NOI/loj-3158/init.yml b/NOI/loj-3158/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..cb2bc9a66699579a25b9dfac3eaf6da8f39f3b55 --- /dev/null +++ b/NOI/loj-3158/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: sequence23.in + out: sequence23.ans + points: 10 +- in: sequence18.in + out: sequence18.ans + points: 10 +- in: sequence22.in + out: sequence22.ans + points: 10 +- in: sequence12.in + out: sequence12.ans + points: 10 +- in: sequence5.in + out: sequence5.ans + points: 10 +- in: sequence13.in + out: sequence13.ans + points: 10 +- in: sequence20.in + out: sequence20.ans + points: 10 +- in: sequence6.in + out: sequence6.ans + points: 10 +- in: sequence10.in + out: sequence10.ans + points: 10 +- in: sequence2.in + out: sequence2.ans + points: 10 +- in: sequence19.in + out: sequence19.ans + points: 10 +- in: sequence21.in + out: sequence21.ans + points: 10 +- in: sequence11.in + out: sequence11.ans + points: 10 +- in: sequence17.in + out: sequence17.ans + points: 10 +- in: sequence9.in + out: sequence9.ans + points: 10 +- in: sequence1.in + out: sequence1.ans + points: 10 +- in: sequence16.in + out: sequence16.ans + points: 10 +- in: sequence24.in + out: sequence24.ans + points: 10 +- in: sequence14.in + out: sequence14.ans + points: 10 +- in: sequence7.in + out: sequence7.ans + points: 10 +- in: sequence3.in + out: sequence3.ans + points: 10 +- in: sequence8.in + out: sequence8.ans + points: 10 +- in: sequence25.in + out: sequence25.ans + points: 10 +- in: sequence15.in + out: sequence15.ans + points: 10 +- in: sequence4.in + out: sequence4.ans + points: 10 diff --git a/NOI/loj-3158/tests.zip b/NOI/loj-3158/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..f0ecec8246dc9717840d1a10f6dfc3f45bd41cbf --- /dev/null +++ b/NOI/loj-3158/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b6b351491dc73af05cf28f255a84312b7799cd4898406658f9dd377fafb4f68 +size 91537190 diff --git a/NOI/loj-3159/init.yml b/NOI/loj-3159/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..4c122bc908f3951313d27a554fba7d597eb60f8a --- /dev/null +++ b/NOI/loj-3159/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: jump25.in + out: jump25.ans + points: 10 +- in: jump18.in + out: jump18.ans + points: 10 +- in: jump9.in + out: jump9.ans + points: 10 +- in: jump19.in + out: jump19.ans + points: 10 +- in: jump6.in + out: jump6.ans + points: 10 +- in: jump1.in + out: jump1.ans + points: 10 +- in: jump10.in + out: jump10.ans + points: 10 +- in: jump3.in + out: jump3.ans + points: 10 +- in: jump21.in + out: jump21.ans + points: 10 +- in: jump13.in + out: jump13.ans + points: 10 +- in: jump12.in + out: jump12.ans + points: 10 +- in: jump20.in + out: jump20.ans + points: 10 +- in: jump24.in + out: jump24.ans + points: 10 +- in: jump17.in + out: jump17.ans + points: 10 +- in: jump14.in + out: jump14.ans + points: 10 +- in: jump8.in + out: jump8.ans + points: 10 +- in: jump23.in + out: jump23.ans + points: 10 +- in: jump5.in + out: jump5.ans + points: 10 +- in: jump7.in + out: jump7.ans + points: 10 +- in: jump16.in + out: jump16.ans + points: 10 +- in: jump2.in + out: jump2.ans + points: 10 +- in: jump4.in + out: jump4.ans + points: 10 +- in: jump15.in + out: jump15.ans + points: 10 +- in: jump22.in + out: jump22.ans + points: 10 +- in: jump11.in + out: jump11.ans + points: 10 diff --git a/NOI/loj-3159/tests.zip b/NOI/loj-3159/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..cb482635651b4e9d0c8d16840e49f7e1e4a35216 --- /dev/null +++ b/NOI/loj-3159/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd51f046f6b5d17e2156a25339d49bc9162386b217e9a349de4b6a7dfb0118ac +size 49164331 diff --git a/NOI/loj-3160/init.yml b/NOI/loj-3160/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ce8037484020b82a62807758b2fb499d71334982 --- /dev/null +++ b/NOI/loj-3160/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: landlords9.in + out: landlords9.ans + points: 10 +- in: landlords4.in + out: landlords4.ans + points: 10 +- in: landlords10.in + out: landlords10.ans + points: 10 +- in: landlords7.in + out: landlords7.ans + points: 10 +- in: landlords6.in + out: landlords6.ans + points: 10 +- in: landlords2.in + out: landlords2.ans + points: 10 +- in: landlords8.in + out: landlords8.ans + points: 10 +- in: landlords5.in + out: landlords5.ans + points: 10 +- in: landlords3.in + out: landlords3.ans + points: 10 +- in: landlords1.in + out: landlords1.ans + points: 10 diff --git a/NOI/loj-3160/tests.zip b/NOI/loj-3160/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..468e02d15288e3283cc37b073e4a57afa0e2550c --- /dev/null +++ b/NOI/loj-3160/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a55198ebe910c2ad9c6d0f5f280a3888bb9418f21464bf562455c4bc81bcc570 +size 103746536 diff --git a/NOI/loj-3161/init.yml b/NOI/loj-3161/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6d75aa53d5b7243064ecd1da470708eb74b58390 --- /dev/null +++ b/NOI/loj-3161/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: explore4.in + out: explore4.ans + points: 10 +- in: explore12.in + out: explore12.ans + points: 10 +- in: explore19.in + out: explore19.ans + points: 10 +- in: explore25.in + out: explore25.ans + points: 10 +- in: explore8.in + out: explore8.ans + points: 10 +- in: explore24.in + out: explore24.ans + points: 10 +- in: explore7.in + out: explore7.ans + points: 10 +- in: explore14.in + out: explore14.ans + points: 10 +- in: explore15.in + out: explore15.ans + points: 10 +- in: explore17.in + out: explore17.ans + points: 10 +- in: explore1.in + out: explore1.ans + points: 10 +- in: explore5.in + out: explore5.ans + points: 10 +- in: explore9.in + out: explore9.ans + points: 10 +- in: explore6.in + out: explore6.ans + points: 10 +- in: explore10.in + out: explore10.ans + points: 10 +- in: explore3.in + out: explore3.ans + points: 10 +- in: explore23.in + out: explore23.ans + points: 10 +- in: explore13.in + out: explore13.ans + points: 10 +- in: explore22.in + out: explore22.ans + points: 10 +- in: explore2.in + out: explore2.ans + points: 10 +- in: explore21.in + out: explore21.ans + points: 10 +- in: explore18.in + out: explore18.ans + points: 10 +- in: explore20.in + out: explore20.ans + points: 10 +- in: explore11.in + out: explore11.ans + points: 10 +- in: explore16.in + out: explore16.ans + points: 10 diff --git a/NOI/loj-3161/tests.zip b/NOI/loj-3161/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..3d6217092de3c1321d5d3cfd538d6ef48e0dd530 --- /dev/null +++ b/NOI/loj-3161/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8900ccfa6f53537bc8fe04a93ec8a04c0efd2cd068b7f862fa62f78117b4a802 +size 53457807 diff --git a/NOI/loj-3339/init.yml b/NOI/loj-3339/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..039a1728be08fff1534c6e2a789356dd8b97e048 --- /dev/null +++ b/NOI/loj-3339/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: delicacy3.in + out: delicacy3.ans + points: 10 +- in: delicacy14.in + out: delicacy14.ans + points: 10 +- in: delicacy9.in + out: delicacy9.ans + points: 10 +- in: delicacy13.in + out: delicacy13.ans + points: 10 +- in: delicacy15.in + out: delicacy15.ans + points: 10 +- in: delicacy2.in + out: delicacy2.ans + points: 10 +- in: delicacy20.in + out: delicacy20.ans + points: 10 +- in: delicacy11.in + out: delicacy11.ans + points: 10 +- in: delicacy8.in + out: delicacy8.ans + points: 10 +- in: delicacy5.in + out: delicacy5.ans + points: 10 +- in: delicacy16.in + out: delicacy16.ans + points: 10 +- in: delicacy18.in + out: delicacy18.ans + points: 10 +- in: delicacy1.in + out: delicacy1.ans + points: 10 +- in: delicacy17.in + out: delicacy17.ans + points: 10 +- in: delicacy12.in + out: delicacy12.ans + points: 10 +- in: delicacy7.in + out: delicacy7.ans + points: 10 +- in: delicacy19.in + out: delicacy19.ans + points: 10 +- in: delicacy10.in + out: delicacy10.ans + points: 10 +- in: delicacy4.in + out: delicacy4.ans + points: 10 +- in: delicacy6.in + out: delicacy6.ans + points: 10 diff --git a/NOI/loj-3339/tests.zip b/NOI/loj-3339/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e0a450c5233995e6c898c7a0cda76ad4bc29b614 --- /dev/null +++ b/NOI/loj-3339/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec7e61ff26ee9341ecf2270ae03b8984af9015f33e599c0cce1ec17fec709fca +size 61794 diff --git a/NOI/loj-3340/init.yml b/NOI/loj-3340/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f930cd55ee49c35c8bc15fc468ab8f1577a3fd53 --- /dev/null +++ b/NOI/loj-3340/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: destiny23.in + out: destiny23.ans + points: 10 +- in: destiny2.in + out: destiny2.ans + points: 10 +- in: destiny8.in + out: destiny8.ans + points: 10 +- in: destiny7.in + out: destiny7.ans + points: 10 +- in: destiny9.in + out: destiny9.ans + points: 10 +- in: destiny24.in + out: destiny24.ans + points: 10 +- in: destiny3.in + out: destiny3.ans + points: 10 +- in: destiny16.in + out: destiny16.ans + points: 10 +- in: destiny20.in + out: destiny20.ans + points: 10 +- in: destiny14.in + out: destiny14.ans + points: 10 +- in: destiny19.in + out: destiny19.ans + points: 10 +- in: destiny12.in + out: destiny12.ans + points: 10 +- in: destiny6.in + out: destiny6.ans + points: 10 +- in: destiny4.in + out: destiny4.ans + points: 10 +- in: destiny13.in + out: destiny13.ans + points: 10 +- in: destiny17.in + out: destiny17.ans + points: 10 +- in: destiny25.in + out: destiny25.ans + points: 10 +- in: destiny5.in + out: destiny5.ans + points: 10 +- in: destiny18.in + out: destiny18.ans + points: 10 +- in: destiny1.in + out: destiny1.ans + points: 10 +- in: destiny21.in + out: destiny21.ans + points: 10 +- in: destiny22.in + out: destiny22.ans + points: 10 +- in: destiny10.in + out: destiny10.ans + points: 10 +- in: destiny11.in + out: destiny11.ans + points: 10 +- in: destiny15.in + out: destiny15.ans + points: 10 diff --git a/NOI/loj-3340/tests.zip b/NOI/loj-3340/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..9cd22b0fd656d6cc4de1c2a7fcd1619e66991dbf --- /dev/null +++ b/NOI/loj-3340/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee56b3287dfb591a287b5ff38625146e02b840fe4f56afc2fc947d2f337515cc +size 98986636 diff --git a/NOI/loj-3341/init.yml b/NOI/loj-3341/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..dc8536d127002d100d677dad2f54d138ad8e5702 --- /dev/null +++ b/NOI/loj-3341/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: tears16.in + out: tears16.ans + points: 10 +- in: tears2.in + out: tears2.ans + points: 10 +- in: tears8.in + out: tears8.ans + points: 10 +- in: tears4.in + out: tears4.ans + points: 10 +- in: tears25.in + out: tears25.ans + points: 10 +- in: tears6.in + out: tears6.ans + points: 10 +- in: tears1.in + out: tears1.ans + points: 10 +- in: tears19.in + out: tears19.ans + points: 10 +- in: tears21.in + out: tears21.ans + points: 10 +- in: tears14.in + out: tears14.ans + points: 10 +- in: tears5.in + out: tears5.ans + points: 10 +- in: tears3.in + out: tears3.ans + points: 10 +- in: tears17.in + out: tears17.ans + points: 10 +- in: tears7.in + out: tears7.ans + points: 10 +- in: tears15.in + out: tears15.ans + points: 10 +- in: tears9.in + out: tears9.ans + points: 10 +- in: tears24.in + out: tears24.ans + points: 10 +- in: tears13.in + out: tears13.ans + points: 10 +- in: tears10.in + out: tears10.ans + points: 10 +- in: tears23.in + out: tears23.ans + points: 10 +- in: tears12.in + out: tears12.ans + points: 10 +- in: tears18.in + out: tears18.ans + points: 10 +- in: tears22.in + out: tears22.ans + points: 10 +- in: tears11.in + out: tears11.ans + points: 10 +- in: tears20.in + out: tears20.ans + points: 10 diff --git a/NOI/loj-3341/tests.zip b/NOI/loj-3341/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..8414afcb9b41b4d3a9d9d451406b429379dd6bfc --- /dev/null +++ b/NOI/loj-3341/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02fa8e268e6e5a0c3b7a857e4cc6bcd47d1bed784711bf58ec700ef3793cc8bc +size 88034484 diff --git a/NOI/loj-3342/init.yml b/NOI/loj-3342/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..a025d341b7de4bea82e3fc9e47b10d66807dfd33 --- /dev/null +++ b/NOI/loj-3342/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: dish18.in + out: dish18.ans + points: 10 +- in: dish10.in + out: dish10.ans + points: 10 +- in: dish20.in + out: dish20.ans + points: 10 +- in: dish14.in + out: dish14.ans + points: 10 +- in: dish12.in + out: dish12.ans + points: 10 +- in: dish17.in + out: dish17.ans + points: 10 +- in: dish7.in + out: dish7.ans + points: 10 +- in: dish13.in + out: dish13.ans + points: 10 +- in: dish4.in + out: dish4.ans + points: 10 +- in: dish8.in + out: dish8.ans + points: 10 +- in: dish1.in + out: dish1.ans + points: 10 +- in: dish16.in + out: dish16.ans + points: 10 +- in: dish5.in + out: dish5.ans + points: 10 +- in: dish9.in + out: dish9.ans + points: 10 +- in: dish2.in + out: dish2.ans + points: 10 +- in: dish15.in + out: dish15.ans + points: 10 +- in: dish6.in + out: dish6.ans + points: 10 +- in: dish3.in + out: dish3.ans + points: 10 +- in: dish19.in + out: dish19.ans + points: 10 +- in: dish11.in + out: dish11.ans + points: 10 diff --git a/NOI/loj-3342/tests.zip b/NOI/loj-3342/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..fdf4d2b87f13f2ae320eb480d14d7be283f5a83c --- /dev/null +++ b/NOI/loj-3342/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e46d12fc3947ca12436588497595d4f9565209b9a468c060a65b866ec4912cdb +size 1551549 diff --git a/NOI/loj-3343/init.yml b/NOI/loj-3343/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5bdbbe9575acce03f59f167bb488bcfea4d998fd --- /dev/null +++ b/NOI/loj-3343/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: surreal10.in + out: surreal10.ans + points: 10 +- in: surreal17.in + out: surreal17.ans + points: 10 +- in: surreal2.in + out: surreal2.ans + points: 10 +- in: surreal7.in + out: surreal7.ans + points: 10 +- in: surreal24.in + out: surreal24.ans + points: 10 +- in: surreal1.in + out: surreal1.ans + points: 10 +- in: surreal13.in + out: surreal13.ans + points: 10 +- in: surreal4.in + out: surreal4.ans + points: 10 +- in: surreal16.in + out: surreal16.ans + points: 10 +- in: surreal5.in + out: surreal5.ans + points: 10 +- in: surreal6.in + out: surreal6.ans + points: 10 +- in: surreal21.in + out: surreal21.ans + points: 10 +- in: surreal3.in + out: surreal3.ans + points: 10 +- in: surreal12.in + out: surreal12.ans + points: 10 +- in: surreal25.in + out: surreal25.ans + points: 10 +- in: surreal22.in + out: surreal22.ans + points: 10 +- in: surreal20.in + out: surreal20.ans + points: 10 +- in: surreal15.in + out: surreal15.ans + points: 10 +- in: surreal14.in + out: surreal14.ans + points: 10 +- in: surreal11.in + out: surreal11.ans + points: 10 +- in: surreal19.in + out: surreal19.ans + points: 10 +- in: surreal9.in + out: surreal9.ans + points: 10 +- in: surreal23.in + out: surreal23.ans + points: 10 +- in: surreal18.in + out: surreal18.ans + points: 10 +- in: surreal8.in + out: surreal8.ans + points: 10 diff --git a/NOI/loj-3343/tests.zip b/NOI/loj-3343/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e480846b00228c0d161904f7b859510d0e69686b --- /dev/null +++ b/NOI/loj-3343/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6bb520a91fd8aa94cd0593278046d003d515b8c0811989474ccd3b187b8004d9 +size 82732636 diff --git a/NOI/loj-3344/init.yml b/NOI/loj-3344/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6dfddd91b1b838267adbd56dbc7bd77f81e59968 --- /dev/null +++ b/NOI/loj-3344/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: road1.in + out: road1.ans + points: 10 +- in: road10.in + out: road10.ans + points: 10 +- in: road14.in + out: road14.ans + points: 10 +- in: road5.in + out: road5.ans + points: 10 +- in: road17.in + out: road17.ans + points: 10 +- in: road19.in + out: road19.ans + points: 10 +- in: road3.in + out: road3.ans + points: 10 +- in: road13.in + out: road13.ans + points: 10 +- in: road7.in + out: road7.ans + points: 10 +- in: road15.in + out: road15.ans + points: 10 +- in: road12.in + out: road12.ans + points: 10 +- in: road2.in + out: road2.ans + points: 10 +- in: road11.in + out: road11.ans + points: 10 +- in: road20.in + out: road20.ans + points: 10 +- in: road9.in + out: road9.ans + points: 10 +- in: road18.in + out: road18.ans + points: 10 +- in: road4.in + out: road4.ans + points: 10 +- in: road8.in + out: road8.ans + points: 10 +- in: road6.in + out: road6.ans + points: 10 +- in: road16.in + out: road16.ans + points: 10 diff --git a/NOI/loj-3344/tests.zip b/NOI/loj-3344/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..48bc332a97f6e24b7fd0e4b88e6c1758dd070579 --- /dev/null +++ b/NOI/loj-3344/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66e6b559f0988c7add1684339449d8ca9eb39320ecc881f9863857f29a1d1ee4 +size 270084221 diff --git a/NOI/loj-3386/init.yml b/NOI/loj-3386/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..0e25ce91ab7a06e08c8874d487662740594e265d --- /dev/null +++ b/NOI/loj-3386/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: water4.in + out: water4.ans + points: 10 +- in: water3.in + out: water3.ans + points: 10 +- in: water1.in + out: water1.ans + points: 10 +- in: water8.in + out: water8.ans + points: 10 +- in: water7.in + out: water7.ans + points: 10 +- in: water10.in + out: water10.ans + points: 10 +- in: water5.in + out: water5.ans + points: 10 +- in: water2.in + out: water2.ans + points: 10 +- in: water6.in + out: water6.ans + points: 10 +- in: water9.in + out: water9.ans + points: 10 diff --git a/NOI/loj-3386/tests.zip b/NOI/loj-3386/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c93f23e8faeb55f9c430897b67f077e5e189393a --- /dev/null +++ b/NOI/loj-3386/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0a4327437e19b14074a29598440bdd6a344f73fa0a1fe81136d5787e780060e +size 7822590 diff --git a/NOI/loj-3387/init.yml b/NOI/loj-3387/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..933dc36e0de1620caa9851c4f02007b466ea5c81 --- /dev/null +++ b/NOI/loj-3387/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: string8.in + out: string8.ans + points: 10 +- in: string24.in + out: string24.ans + points: 10 +- in: string10.in + out: string10.ans + points: 10 +- in: string18.in + out: string18.ans + points: 10 +- in: string11.in + out: string11.ans + points: 10 +- in: string2.in + out: string2.ans + points: 10 +- in: string14.in + out: string14.ans + points: 10 +- in: string19.in + out: string19.ans + points: 10 +- in: string6.in + out: string6.ans + points: 10 +- in: string7.in + out: string7.ans + points: 10 +- in: string15.in + out: string15.ans + points: 10 +- in: string9.in + out: string9.ans + points: 10 +- in: string20.in + out: string20.ans + points: 10 +- in: string16.in + out: string16.ans + points: 10 +- in: string17.in + out: string17.ans + points: 10 +- in: string1.in + out: string1.ans + points: 10 +- in: string22.in + out: string22.ans + points: 10 +- in: string13.in + out: string13.ans + points: 10 +- in: string3.in + out: string3.ans + points: 10 +- in: string5.in + out: string5.ans + points: 10 +- in: string23.in + out: string23.ans + points: 10 +- in: string4.in + out: string4.ans + points: 10 +- in: string12.in + out: string12.ans + points: 10 +- in: string25.in + out: string25.ans + points: 10 +- in: string21.in + out: string21.ans + points: 10 diff --git a/NOI/loj-3387/tests.zip b/NOI/loj-3387/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..1bc5831a4e754ece6102be3c61133937bc887564 --- /dev/null +++ b/NOI/loj-3387/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1dec9d5787cdffc6a9d49d9284b54737352d440b2a19311f1c49328a37d1da59 +size 24915938 diff --git a/NOI/loj-3388/init.yml b/NOI/loj-3388/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..136697a06a70d9d78005ce7c6fbc780ec08f5090 --- /dev/null +++ b/NOI/loj-3388/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: ball10.in + out: ball10.ans + points: 10 +- in: ball18.in + out: ball18.ans + points: 10 +- in: ball14.in + out: ball14.ans + points: 10 +- in: ball8.in + out: ball8.ans + points: 10 +- in: ball9.in + out: ball9.ans + points: 10 +- in: ball2.in + out: ball2.ans + points: 10 +- in: ball3.in + out: ball3.ans + points: 10 +- in: ball7.in + out: ball7.ans + points: 10 +- in: ball1.in + out: ball1.ans + points: 10 +- in: ball20.in + out: ball20.ans + points: 10 +- in: ball12.in + out: ball12.ans + points: 10 +- in: ball19.in + out: ball19.ans + points: 10 +- in: ball15.in + out: ball15.ans + points: 10 +- in: ball5.in + out: ball5.ans + points: 10 +- in: ball13.in + out: ball13.ans + points: 10 +- in: ball6.in + out: ball6.ans + points: 10 +- in: ball17.in + out: ball17.ans + points: 10 +- in: ball16.in + out: ball16.ans + points: 10 +- in: ball11.in + out: ball11.ans + points: 10 +- in: ball4.in + out: ball4.ans + points: 10 diff --git a/NOI/loj-3388/tests.zip b/NOI/loj-3388/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..95d04d08a56211a77b98a457942bd63cffb23763 --- /dev/null +++ b/NOI/loj-3388/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd5f44788aa75f35acba72d70c55566ea34c1191123c6f5ed70b4bfabb97d0aa +size 39554509 diff --git a/NOI/loj-3389/init.yml b/NOI/loj-3389/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..84f3ffc49644bf8747cbb46be1aba3ae94d18554 --- /dev/null +++ b/NOI/loj-3389/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: walk20.in + out: walk20.ans + points: 10 +- in: walk17.in + out: walk17.ans + points: 10 +- in: walk4.in + out: walk4.ans + points: 10 +- in: walk3.in + out: walk3.ans + points: 10 +- in: walk2.in + out: walk2.ans + points: 10 +- in: walk18.in + out: walk18.ans + points: 10 +- in: walk12.in + out: walk12.ans + points: 10 +- in: walk7.in + out: walk7.ans + points: 10 +- in: walk6.in + out: walk6.ans + points: 10 +- in: walk19.in + out: walk19.ans + points: 10 +- in: walk5.in + out: walk5.ans + points: 10 +- in: walk13.in + out: walk13.ans + points: 10 +- in: walk1.in + out: walk1.ans + points: 10 +- in: walk15.in + out: walk15.ans + points: 10 +- in: walk9.in + out: walk9.ans + points: 10 +- in: walk8.in + out: walk8.ans + points: 10 +- in: walk11.in + out: walk11.ans + points: 10 +- in: walk16.in + out: walk16.ans + points: 10 +- in: walk10.in + out: walk10.ans + points: 10 +- in: walk14.in + out: walk14.ans + points: 10 diff --git a/NOI/loj-3389/tests.zip b/NOI/loj-3389/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..62ea039a40948135eeaf5d2f25c35e87f0b2197a --- /dev/null +++ b/NOI/loj-3389/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:749860cd2d90c6d454feaeacb3aab0357338e0a2035707e04aafcb392dcd93d5 +size 20905445 diff --git a/NOI/loj-3532/init.yml b/NOI/loj-3532/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..09186cbe650ab91e7edcb22f567d028672097eb2 --- /dev/null +++ b/NOI/loj-3532/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: edge18.in + out: edge18.ans + points: 10 +- in: edge4.in + out: edge4.ans + points: 10 +- in: edge8.in + out: edge8.ans + points: 10 +- in: edge15.in + out: edge15.ans + points: 10 +- in: edge3.in + out: edge3.ans + points: 10 +- in: edge16.in + out: edge16.ans + points: 10 +- in: edge1.in + out: edge1.ans + points: 10 +- in: edge5.in + out: edge5.ans + points: 10 +- in: edge9.in + out: edge9.ans + points: 10 +- in: edge10.in + out: edge10.ans + points: 10 +- in: edge12.in + out: edge12.ans + points: 10 +- in: edge20.in + out: edge20.ans + points: 10 +- in: edge7.in + out: edge7.ans + points: 10 +- in: edge19.in + out: edge19.ans + points: 10 +- in: edge13.in + out: edge13.ans + points: 10 +- in: edge14.in + out: edge14.ans + points: 10 +- in: edge11.in + out: edge11.ans + points: 10 +- in: edge2.in + out: edge2.ans + points: 10 +- in: edge6.in + out: edge6.ans + points: 10 +- in: edge17.in + out: edge17.ans + points: 10 diff --git a/NOI/loj-3532/tests.zip b/NOI/loj-3532/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e566af47c22d079538d33840fd8e86d9223581d1 --- /dev/null +++ b/NOI/loj-3532/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b90d81c3b6a5c05c6ab72aab5750b2353d09f2e7f690d8872c40d1ba84b83c7 +size 93417332 diff --git a/NOI/loj-3533/init.yml b/NOI/loj-3533/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..97debf76e1f7df5acd5b19ad9f8c09662073d56b --- /dev/null +++ b/NOI/loj-3533/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: xpath15.in + out: xpath15.ans + points: 10 +- in: xpath9.in + out: xpath9.ans + points: 10 +- in: xpath1.in + out: xpath1.ans + points: 10 +- in: xpath3.in + out: xpath3.ans + points: 10 +- in: xpath8.in + out: xpath8.ans + points: 10 +- in: xpath10.in + out: xpath10.ans + points: 10 +- in: xpath11.in + out: xpath11.ans + points: 10 +- in: xpath17.in + out: xpath17.ans + points: 10 +- in: xpath12.in + out: xpath12.ans + points: 10 +- in: xpath20.in + out: xpath20.ans + points: 10 +- in: xpath5.in + out: xpath5.ans + points: 10 +- in: xpath13.in + out: xpath13.ans + points: 10 +- in: xpath7.in + out: xpath7.ans + points: 10 +- in: xpath6.in + out: xpath6.ans + points: 10 +- in: xpath18.in + out: xpath18.ans + points: 10 +- in: xpath19.in + out: xpath19.ans + points: 10 +- in: xpath2.in + out: xpath2.ans + points: 10 +- in: xpath16.in + out: xpath16.ans + points: 10 +- in: xpath14.in + out: xpath14.ans + points: 10 +- in: xpath4.in + out: xpath4.ans + points: 10 diff --git a/NOI/loj-3533/tests.zip b/NOI/loj-3533/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ebbd293b698b35df7cdd5203324c5aad8c0b03dd --- /dev/null +++ b/NOI/loj-3533/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3c570d986cbee7445edca56c586b72e8c42fb402bbf7df35f5a642c750005dc +size 19725651 diff --git a/NOI/loj-3534/init.yml b/NOI/loj-3534/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..7f8b191ab36663c0612eedb67e943bb51ca8dfa5 --- /dev/null +++ b/NOI/loj-3534/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: celebration6.in + out: celebration6.ans + points: 10 +- in: celebration2.in + out: celebration2.ans + points: 10 +- in: celebration10.in + out: celebration10.ans + points: 10 +- in: celebration14.in + out: celebration14.ans + points: 10 +- in: celebration20.in + out: celebration20.ans + points: 10 +- in: celebration19.in + out: celebration19.ans + points: 10 +- in: celebration5.in + out: celebration5.ans + points: 10 +- in: celebration22.in + out: celebration22.ans + points: 10 +- in: celebration11.in + out: celebration11.ans + points: 10 +- in: celebration8.in + out: celebration8.ans + points: 10 +- in: celebration3.in + out: celebration3.ans + points: 10 +- in: celebration25.in + out: celebration25.ans + points: 10 +- in: celebration16.in + out: celebration16.ans + points: 10 +- in: celebration18.in + out: celebration18.ans + points: 10 +- in: celebration9.in + out: celebration9.ans + points: 10 +- in: celebration1.in + out: celebration1.ans + points: 10 +- in: celebration15.in + out: celebration15.ans + points: 10 +- in: celebration24.in + out: celebration24.ans + points: 10 +- in: celebration4.in + out: celebration4.ans + points: 10 +- in: celebration13.in + out: celebration13.ans + points: 10 +- in: celebration21.in + out: celebration21.ans + points: 10 +- in: celebration23.in + out: celebration23.ans + points: 10 +- in: celebration17.in + out: celebration17.ans + points: 10 +- in: celebration7.in + out: celebration7.ans + points: 10 +- in: celebration12.in + out: celebration12.ans + points: 10 diff --git a/NOI/loj-3534/tests.zip b/NOI/loj-3534/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..d04813d38a7dc43b8e582002650f3655ad5d852d --- /dev/null +++ b/NOI/loj-3534/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84eed151f4049142bbcbea027f8ef7b21fcafa5057b96ad197a23b2d592f0ff9 +size 306750286 diff --git a/NOI/loj-3535/init.yml b/NOI/loj-3535/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..79c5ac971c694347cbd7bedc27ca60fcfe878dd7 --- /dev/null +++ b/NOI/loj-3535/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: qi19.in + out: qi19.ans + points: 10 +- in: qi22.in + out: qi22.ans + points: 10 +- in: qi10.in + out: qi10.ans + points: 10 +- in: qi6.in + out: qi6.ans + points: 10 +- in: qi17.in + out: qi17.ans + points: 10 +- in: qi20.in + out: qi20.ans + points: 10 +- in: qi15.in + out: qi15.ans + points: 10 +- in: qi3.in + out: qi3.ans + points: 10 +- in: qi25.in + out: qi25.ans + points: 10 +- in: qi13.in + out: qi13.ans + points: 10 +- in: qi23.in + out: qi23.ans + points: 10 +- in: qi7.in + out: qi7.ans + points: 10 +- in: qi11.in + out: qi11.ans + points: 10 +- in: qi8.in + out: qi8.ans + points: 10 +- in: qi18.in + out: qi18.ans + points: 10 +- in: qi21.in + out: qi21.ans + points: 10 +- in: qi16.in + out: qi16.ans + points: 10 +- in: qi4.in + out: qi4.ans + points: 10 +- in: qi5.in + out: qi5.ans + points: 10 +- in: qi14.in + out: qi14.ans + points: 10 +- in: qi1.in + out: qi1.ans + points: 10 +- in: qi24.in + out: qi24.ans + points: 10 +- in: qi2.in + out: qi2.ans + points: 10 +- in: qi9.in + out: qi9.ans + points: 10 +- in: qi12.in + out: qi12.ans + points: 10 diff --git a/NOI/loj-3535/tests.zip b/NOI/loj-3535/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..02b7e177a5e34b9eec7b469f66aa5921dc0bd4bb --- /dev/null +++ b/NOI/loj-3535/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdc2c48d99669c268071835153ee228e2d88afa135498b5ba6700f12caa82726 +size 108749133 diff --git a/NOI/loj-3536/init.yml b/NOI/loj-3536/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..309ddbc33a94bdabc90de778340c1166a846a57c --- /dev/null +++ b/NOI/loj-3536/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: code6.in + out: code6.ans + points: 10 +- in: code20.in + out: code20.ans + points: 10 +- in: code7.in + out: code7.ans + points: 10 +- in: code17.in + out: code17.ans + points: 10 +- in: code4.in + out: code4.ans + points: 10 +- in: code16.in + out: code16.ans + points: 10 +- in: code19.in + out: code19.ans + points: 10 +- in: code5.in + out: code5.ans + points: 10 +- in: code14.in + out: code14.ans + points: 10 +- in: code10.in + out: code10.ans + points: 10 +- in: code9.in + out: code9.ans + points: 10 +- in: code3.in + out: code3.ans + points: 10 +- in: code11.in + out: code11.ans + points: 10 +- in: code18.in + out: code18.ans + points: 10 +- in: code12.in + out: code12.ans + points: 10 +- in: code15.in + out: code15.ans + points: 10 +- in: code1.in + out: code1.ans + points: 10 +- in: code8.in + out: code8.ans + points: 10 +- in: code2.in + out: code2.ans + points: 10 +- in: code13.in + out: code13.ans + points: 10 diff --git a/NOI/loj-3536/tests.zip b/NOI/loj-3536/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..a36c8c5570a467b270dbc8b52d7b54cbfadce5d3 --- /dev/null +++ b/NOI/loj-3536/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:431e803115311cedca9dcbc6ac3f32faf575717f5457e23e5648e64c99f87413 +size 52514501 diff --git a/NOI/loj-3537/init.yml b/NOI/loj-3537/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..9a234d2ce82c482b279fef9f47069ad2f5e9ae63 --- /dev/null +++ b/NOI/loj-3537/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: robot4.in + out: robot4.ans + points: 10 +- in: robot24.in + out: robot24.ans + points: 10 +- in: robot6.in + out: robot6.ans + points: 10 +- in: robot7.in + out: robot7.ans + points: 10 +- in: robot9.in + out: robot9.ans + points: 10 +- in: robot16.in + out: robot16.ans + points: 10 +- in: robot10.in + out: robot10.ans + points: 10 +- in: robot12.in + out: robot12.ans + points: 10 +- in: robot15.in + out: robot15.ans + points: 10 +- in: robot11.in + out: robot11.ans + points: 10 +- in: robot13.in + out: robot13.ans + points: 10 +- in: robot25.in + out: robot25.ans + points: 10 +- in: robot21.in + out: robot21.ans + points: 10 +- in: robot14.in + out: robot14.ans + points: 10 +- in: robot19.in + out: robot19.ans + points: 10 +- in: robot18.in + out: robot18.ans + points: 10 +- in: robot5.in + out: robot5.ans + points: 10 +- in: robot3.in + out: robot3.ans + points: 10 +- in: robot20.in + out: robot20.ans + points: 10 +- in: robot23.in + out: robot23.ans + points: 10 +- in: robot2.in + out: robot2.ans + points: 10 +- in: robot8.in + out: robot8.ans + points: 10 +- in: robot17.in + out: robot17.ans + points: 10 +- in: robot22.in + out: robot22.ans + points: 10 +- in: robot1.in + out: robot1.ans + points: 10 diff --git a/NOI/loj-3537/tests.zip b/NOI/loj-3537/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..e9ff806b1435afc4dcc08cd47deea0f9e42edbc3 --- /dev/null +++ b/NOI/loj-3537/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98f61575a14a9f87bed7851e4b8df6e8956817fae8146c6784647ed614c51c27 +size 195100 diff --git a/NOI/loj-3564/init.yml b/NOI/loj-3564/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b2a0fdb2fc62407c2aaee374a5852af79c9e6b7b --- /dev/null +++ b/NOI/loj-3564/init.yml @@ -0,0 +1,44 @@ +archive: tests.zip +test_cases: +- in: number6.in + out: number6.ans + points: 10 +- in: sample-number2.in + out: sample-number2.ans + points: 10 +- in: number9.in + out: number9.ans + points: 10 +- in: sample-number3.in + out: sample-number3.ans + points: 10 +- in: number4.in + out: number4.ans + points: 10 +- in: sample-number1.in + out: sample-number1.ans + points: 10 +- in: number2.in + out: number2.ans + points: 10 +- in: number3.in + out: number3.ans + points: 10 +- in: number1.in + out: number1.ans + points: 10 +- in: number7.in + out: number7.ans + points: 10 +- in: number8.in + out: number8.ans + points: 10 +- in: sample-number4.in + out: sample-number4.ans + points: 10 +- in: number5.in + out: number5.ans + points: 10 +- in: number10.in + out: number10.ans + points: 10 diff --git a/NOI/loj-3564/tests.zip b/NOI/loj-3564/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..4573c29cbe59966d605d09874f049d6b2a2ad055 --- /dev/null +++ b/NOI/loj-3564/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:451936fc8931005b3bc64656cef1e16548c331ef0c2883e39a2cee7f2401243a +size 11980768 diff --git a/NOI/loj-3565/init.yml b/NOI/loj-3565/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..1933b6d40df0a3bb072033824352199474cfa40e --- /dev/null +++ b/NOI/loj-3565/init.yml @@ -0,0 +1,68 @@ +archive: tests.zip +test_cases: +- in: sequence18.in + out: sequence18.ans + points: 10 +- in: sequence12.in + out: sequence12.ans + points: 10 +- in: sequence5.in + out: sequence5.ans + points: 10 +- in: sequence13.in + out: sequence13.ans + points: 10 +- in: sequence20.in + out: sequence20.ans + points: 10 +- in: sample-sequence1.in + out: sample-sequence1.ans + points: 10 +- in: sequence6.in + out: sequence6.ans + points: 10 +- in: sequence10.in + out: sequence10.ans + points: 10 +- in: sequence2.in + out: sequence2.ans + points: 10 +- in: sequence19.in + out: sequence19.ans + points: 10 +- in: sequence11.in + out: sequence11.ans + points: 10 +- in: sample-sequence2.in + out: sample-sequence2.ans + points: 10 +- in: sequence17.in + out: sequence17.ans + points: 10 +- in: sequence9.in + out: sequence9.ans + points: 10 +- in: sequence1.in + out: sequence1.ans + points: 10 +- in: sequence16.in + out: sequence16.ans + points: 10 +- in: sequence14.in + out: sequence14.ans + points: 10 +- in: sequence7.in + out: sequence7.ans + points: 10 +- in: sequence3.in + out: sequence3.ans + points: 10 +- in: sequence8.in + out: sequence8.ans + points: 10 +- in: sequence15.in + out: sequence15.ans + points: 10 +- in: sequence4.in + out: sequence4.ans + points: 10 diff --git a/NOI/loj-3565/tests.zip b/NOI/loj-3565/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..c13e9c415e53bc21bee83f9856a25cce0ec5ccc6 --- /dev/null +++ b/NOI/loj-3565/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a978ab6dae5cfce4a19f0fbf176f749b56c19704e69b0aceb0ee31318e136218 +size 13686 diff --git a/NOI/loj-3566/init.yml b/NOI/loj-3566/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..49e79809cbd55feb2e92df01d227af8544aefb4d --- /dev/null +++ b/NOI/loj-3566/init.yml @@ -0,0 +1,89 @@ +archive: tests.zip +test_cases: +- in: variance11.in + out: variance11.ans + points: 10 +- in: variance12.in + out: variance12.ans + points: 10 +- in: variance10.in + out: variance10.ans + points: 10 +- in: variance15.in + out: variance15.ans + points: 10 +- in: variance2.in + out: variance2.ans + points: 10 +- in: variance3.in + out: variance3.ans + points: 10 +- in: sample-variance2.in + out: sample-variance2.ans + points: 10 +- in: sample-variance3.in + out: sample-variance3.ans + points: 10 +- in: sample-variance4.in + out: sample-variance4.ans + points: 10 +- in: variance25.in + out: variance25.ans + points: 10 +- in: variance14.in + out: variance14.ans + points: 10 +- in: variance21.in + out: variance21.ans + points: 10 +- in: variance4.in + out: variance4.ans + points: 10 +- in: variance5.in + out: variance5.ans + points: 10 +- in: sample-variance1.in + out: sample-variance1.ans + points: 10 +- in: variance9.in + out: variance9.ans + points: 10 +- in: variance20.in + out: variance20.ans + points: 10 +- in: variance23.in + out: variance23.ans + points: 10 +- in: variance6.in + out: variance6.ans + points: 10 +- in: variance24.in + out: variance24.ans + points: 10 +- in: variance16.in + out: variance16.ans + points: 10 +- in: variance7.in + out: variance7.ans + points: 10 +- in: variance8.in + out: variance8.ans + points: 10 +- in: variance19.in + out: variance19.ans + points: 10 +- in: variance13.in + out: variance13.ans + points: 10 +- in: variance17.in + out: variance17.ans + points: 10 +- in: variance18.in + out: variance18.ans + points: 10 +- in: variance22.in + out: variance22.ans + points: 10 +- in: variance1.in + out: variance1.ans + points: 10 diff --git a/NOI/loj-3566/tests.zip b/NOI/loj-3566/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..200cb4d464ca4284bf7322e301db2252a933c9be --- /dev/null +++ b/NOI/loj-3566/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d1c52eac3db0f1ce1272cf737cbfb560e193e0d2c49e08874c3563d9871a6db +size 100038 diff --git a/NOI/loj-3567/init.yml b/NOI/loj-3567/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..5ace94124bc7f73defc7eef44a78c9080ce7ec60 --- /dev/null +++ b/NOI/loj-3567/init.yml @@ -0,0 +1,89 @@ +archive: tests.zip +test_cases: +- in: chess23.in + out: chess23.ans + points: 10 +- in: chess6.in + out: chess6.ans + points: 10 +- in: chess15.in + out: chess15.ans + points: 10 +- in: sample-chess3.in + out: sample-chess3.ans + points: 10 +- in: chess17.in + out: chess17.ans + points: 10 +- in: chess14.in + out: chess14.ans + points: 10 +- in: sample-chess1.in + out: sample-chess1.ans + points: 10 +- in: chess8.in + out: chess8.ans + points: 10 +- in: chess9.in + out: chess9.ans + points: 10 +- in: sample-chess2.in + out: sample-chess2.ans + points: 10 +- in: chess25.in + out: chess25.ans + points: 10 +- in: chess12.in + out: chess12.ans + points: 10 +- in: chess22.in + out: chess22.ans + points: 10 +- in: chess16.in + out: chess16.ans + points: 10 +- in: chess19.in + out: chess19.ans + points: 10 +- in: chess18.in + out: chess18.ans + points: 10 +- in: chess24.in + out: chess24.ans + points: 10 +- in: sample-chess4.in + out: sample-chess4.ans + points: 10 +- in: chess1.in + out: chess1.ans + points: 10 +- in: chess3.in + out: chess3.ans + points: 10 +- in: chess13.in + out: chess13.ans + points: 10 +- in: chess2.in + out: chess2.ans + points: 10 +- in: chess4.in + out: chess4.ans + points: 10 +- in: chess21.in + out: chess21.ans + points: 10 +- in: chess5.in + out: chess5.ans + points: 10 +- in: chess20.in + out: chess20.ans + points: 10 +- in: chess7.in + out: chess7.ans + points: 10 +- in: chess10.in + out: chess10.ans + points: 10 +- in: chess11.in + out: chess11.ans + points: 10 diff --git a/NOI/loj-3567/tests.zip b/NOI/loj-3567/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..6a95edc9e3325fb147309e1700c7e0fe9803af8a --- /dev/null +++ b/NOI/loj-3567/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ff838fef4f3141744338fa82aeb7943d1f258f6bb4176496fa113728d5c6b8b +size 202678349 diff --git a/NOI/loj-3757/init.yml b/NOI/loj-3757/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6aa2094d6af2d5e4bdf6c6b65186f334e151f459 --- /dev/null +++ b/NOI/loj-3757/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.out + points: 10 +- in: 9.in + out: 9.out + points: 10 +- in: 1.in + out: 1.out + points: 10 +- in: 8.in + out: 8.out + points: 10 +- in: 7.in + out: 7.out + points: 10 +- in: 6.in + out: 6.out + points: 10 +- in: 10.in + out: 10.out + points: 10 +- in: 5.in + out: 5.out + points: 10 +- in: 4.in + out: 4.out + points: 10 +- in: 3.in + out: 3.out + points: 10 diff --git a/NOI/loj-3757/tests.zip b/NOI/loj-3757/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..ff2cb33c03dd45b23018e4597c9d4c5096d50790 --- /dev/null +++ b/NOI/loj-3757/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f34b6f95cf4e37baca103544a1323690dcbb69300db48f79176832e1b3c554d +size 10048107 diff --git a/NOI/loj-3758/init.yml b/NOI/loj-3758/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6aa2094d6af2d5e4bdf6c6b65186f334e151f459 --- /dev/null +++ b/NOI/loj-3758/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.out + points: 10 +- in: 9.in + out: 9.out + points: 10 +- in: 1.in + out: 1.out + points: 10 +- in: 8.in + out: 8.out + points: 10 +- in: 7.in + out: 7.out + points: 10 +- in: 6.in + out: 6.out + points: 10 +- in: 10.in + out: 10.out + points: 10 +- in: 5.in + out: 5.out + points: 10 +- in: 4.in + out: 4.out + points: 10 +- in: 3.in + out: 3.out + points: 10 diff --git a/NOI/loj-3758/tests.zip b/NOI/loj-3758/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..0c143313d761204c5f19f312f5276ebeba00812d --- /dev/null +++ b/NOI/loj-3758/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57840b056d4f1cef23dbc6d337ed86d6812e6c66ae3f6e0a8821fe23aa54d45a +size 1869 diff --git a/NOI/loj-3760/init.yml b/NOI/loj-3760/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6aa2094d6af2d5e4bdf6c6b65186f334e151f459 --- /dev/null +++ b/NOI/loj-3760/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.out + points: 10 +- in: 9.in + out: 9.out + points: 10 +- in: 1.in + out: 1.out + points: 10 +- in: 8.in + out: 8.out + points: 10 +- in: 7.in + out: 7.out + points: 10 +- in: 6.in + out: 6.out + points: 10 +- in: 10.in + out: 10.out + points: 10 +- in: 5.in + out: 5.out + points: 10 +- in: 4.in + out: 4.out + points: 10 +- in: 3.in + out: 3.out + points: 10 diff --git a/NOI/loj-3760/tests.zip b/NOI/loj-3760/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..85e1e3860b952cea41e52c77fd362f4166471446 --- /dev/null +++ b/NOI/loj-3760/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:304116d3f20879ea4d6f05cc8d3d0168be773ca05a951adf36e278bcba6c4dba +size 678025 diff --git a/NOI/loj-3761/init.yml b/NOI/loj-3761/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6aa2094d6af2d5e4bdf6c6b65186f334e151f459 --- /dev/null +++ b/NOI/loj-3761/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.out + points: 10 +- in: 9.in + out: 9.out + points: 10 +- in: 1.in + out: 1.out + points: 10 +- in: 8.in + out: 8.out + points: 10 +- in: 7.in + out: 7.out + points: 10 +- in: 6.in + out: 6.out + points: 10 +- in: 10.in + out: 10.out + points: 10 +- in: 5.in + out: 5.out + points: 10 +- in: 4.in + out: 4.out + points: 10 +- in: 3.in + out: 3.out + points: 10 diff --git a/NOI/loj-3761/tests.zip b/NOI/loj-3761/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..66aea7eb45c03890f639a08b8a54d722281d4fa9 --- /dev/null +++ b/NOI/loj-3761/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:712924fb60554c8197ab8e77b8de76c8d5552c05fcc8de760476e1ab1352bbbf +size 8795760 diff --git a/NOI/loj-3762/init.yml b/NOI/loj-3762/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6aa2094d6af2d5e4bdf6c6b65186f334e151f459 --- /dev/null +++ b/NOI/loj-3762/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: 2.in + out: 2.out + points: 10 +- in: 9.in + out: 9.out + points: 10 +- in: 1.in + out: 1.out + points: 10 +- in: 8.in + out: 8.out + points: 10 +- in: 7.in + out: 7.out + points: 10 +- in: 6.in + out: 6.out + points: 10 +- in: 10.in + out: 10.out + points: 10 +- in: 5.in + out: 5.out + points: 10 +- in: 4.in + out: 4.out + points: 10 +- in: 3.in + out: 3.out + points: 10 diff --git a/NOI/loj-3762/tests.zip b/NOI/loj-3762/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..559c781a3f8c4986f10682c182836db33174d2e9 --- /dev/null +++ b/NOI/loj-3762/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9610dcafcd89537744c11e6d742580d07cb33c0b505bbbb619fc88c9af5a5b6 +size 5546 diff --git a/NOI/loj-3847/init.yml b/NOI/loj-3847/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..75088f2f96bc9a477eaecef867bfde8e6fbea67f --- /dev/null +++ b/NOI/loj-3847/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: major17.in + out: major17.ans + points: 10 +- in: major11.in + out: major11.ans + points: 10 +- in: major16.in + out: major16.ans + points: 10 +- in: major15.in + out: major15.ans + points: 10 +- in: major5.in + out: major5.ans + points: 10 +- in: major4.in + out: major4.ans + points: 10 +- in: major13.in + out: major13.ans + points: 10 +- in: major7.in + out: major7.ans + points: 10 +- in: major6.in + out: major6.ans + points: 10 +- in: major1.in + out: major1.ans + points: 10 +- in: major18.in + out: major18.ans + points: 10 +- in: major12.in + out: major12.ans + points: 10 +- in: major2.in + out: major2.ans + points: 10 +- in: major8.in + out: major8.ans + points: 10 +- in: major3.in + out: major3.ans + points: 10 +- in: major19.in + out: major19.ans + points: 10 +- in: major14.in + out: major14.ans + points: 10 +- in: major20.in + out: major20.ans + points: 10 +- in: major10.in + out: major10.ans + points: 10 +- in: major9.in + out: major9.ans + points: 10 diff --git a/NOI/loj-3847/tests.zip b/NOI/loj-3847/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..52107ed6f00862ccdf89399ec9a80506b6cd0271 --- /dev/null +++ b/NOI/loj-3847/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e775a0a6c1b9a1b2b47806e13d763d5b095f3b4e75e88abfb2fc5489aa68307 +size 83063745 diff --git a/NOI/loj-3848/init.yml b/NOI/loj-3848/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..692f7e4d28667e507997edb686712a2af439cbc5 --- /dev/null +++ b/NOI/loj-3848/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: stone19.in + out: stone19.ans + points: 10 +- in: stone20.in + out: stone20.ans + points: 10 +- in: stone8.in + out: stone8.ans + points: 10 +- in: stone13.in + out: stone13.ans + points: 10 +- in: stone2.in + out: stone2.ans + points: 10 +- in: stone5.in + out: stone5.ans + points: 10 +- in: stone14.in + out: stone14.ans + points: 10 +- in: stone4.in + out: stone4.ans + points: 10 +- in: stone3.in + out: stone3.ans + points: 10 +- in: stone11.in + out: stone11.ans + points: 10 +- in: stone6.in + out: stone6.ans + points: 10 +- in: stone18.in + out: stone18.ans + points: 10 +- in: stone17.in + out: stone17.ans + points: 10 +- in: stone15.in + out: stone15.ans + points: 10 +- in: stone16.in + out: stone16.ans + points: 10 +- in: stone7.in + out: stone7.ans + points: 10 +- in: stone1.in + out: stone1.ans + points: 10 +- in: stone9.in + out: stone9.ans + points: 10 +- in: stone12.in + out: stone12.ans + points: 10 +- in: stone10.in + out: stone10.ans + points: 10 diff --git a/NOI/loj-3848/tests.zip b/NOI/loj-3848/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..009618c0db8267443f8261ef8a2123ccfadeb69e --- /dev/null +++ b/NOI/loj-3848/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b33fa45616957ac806433371633b64aab739cb2068a09e28c329b90e5cdb8d1d +size 1000076 diff --git a/NOI/loj-3849/init.yml b/NOI/loj-3849/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..4078bdefd4800190766e8a6fa56ecd2407a63c3a --- /dev/null +++ b/NOI/loj-3849/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: count15.in + out: count15.ans + points: 10 +- in: count9.in + out: count9.ans + points: 10 +- in: count19.in + out: count19.ans + points: 10 +- in: count14.in + out: count14.ans + points: 10 +- in: count16.in + out: count16.ans + points: 10 +- in: count5.in + out: count5.ans + points: 10 +- in: count17.in + out: count17.ans + points: 10 +- in: count12.in + out: count12.ans + points: 10 +- in: count2.in + out: count2.ans + points: 10 +- in: count13.in + out: count13.ans + points: 10 +- in: count20.in + out: count20.ans + points: 10 +- in: count8.in + out: count8.ans + points: 10 +- in: count11.in + out: count11.ans + points: 10 +- in: count18.in + out: count18.ans + points: 10 +- in: count1.in + out: count1.ans + points: 10 +- in: count4.in + out: count4.ans + points: 10 +- in: count10.in + out: count10.ans + points: 10 +- in: count6.in + out: count6.ans + points: 10 +- in: count7.in + out: count7.ans + points: 10 +- in: count3.in + out: count3.ans + points: 10 diff --git a/NOI/loj-3849/tests.zip b/NOI/loj-3849/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..81251b0a26d22a69c322ad98a536aa1b5f0b3759 --- /dev/null +++ b/NOI/loj-3849/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8095d3218766570cc11c4477fef6b0390cf77c30f7f106106da510982ce94b4 +size 187097385 diff --git a/NOI/loj-3850/init.yml b/NOI/loj-3850/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..1155cb73184335dc3008b46f51ffa466a8429fc3 --- /dev/null +++ b/NOI/loj-3850/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: iso4.in + out: iso4.ans + points: 10 +- in: iso2.in + out: iso2.ans + points: 10 +- in: iso9.in + out: iso9.ans + points: 10 +- in: iso10.in + out: iso10.ans + points: 10 +- in: iso25.in + out: iso25.ans + points: 10 +- in: iso11.in + out: iso11.ans + points: 10 +- in: iso12.in + out: iso12.ans + points: 10 +- in: iso7.in + out: iso7.ans + points: 10 +- in: iso22.in + out: iso22.ans + points: 10 +- in: iso5.in + out: iso5.ans + points: 10 +- in: iso24.in + out: iso24.ans + points: 10 +- in: iso18.in + out: iso18.ans + points: 10 +- in: iso3.in + out: iso3.ans + points: 10 +- in: iso19.in + out: iso19.ans + points: 10 +- in: iso21.in + out: iso21.ans + points: 10 +- in: iso1.in + out: iso1.ans + points: 10 +- in: iso23.in + out: iso23.ans + points: 10 +- in: iso8.in + out: iso8.ans + points: 10 +- in: iso13.in + out: iso13.ans + points: 10 +- in: iso6.in + out: iso6.ans + points: 10 +- in: iso14.in + out: iso14.ans + points: 10 +- in: iso20.in + out: iso20.ans + points: 10 +- in: iso15.in + out: iso15.ans + points: 10 +- in: iso16.in + out: iso16.ans + points: 10 +- in: iso17.in + out: iso17.ans + points: 10 diff --git a/NOI/loj-3850/tests.zip b/NOI/loj-3850/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..1a0e66f06491ce973c02a8fa5bbc44f971679bed --- /dev/null +++ b/NOI/loj-3850/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0fed19dd394230031d6045382cb990806b46cfb24bc0c9763a53306dcd03ca7e +size 52235883 diff --git a/NOI/loj-3851/init.yml b/NOI/loj-3851/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..b45aab23845e90fc276bceed106bbe7294cd5daa --- /dev/null +++ b/NOI/loj-3851/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: bubble18.in + out: bubble18.ans + points: 10 +- in: bubble11.in + out: bubble11.ans + points: 10 +- in: bubble12.in + out: bubble12.ans + points: 10 +- in: bubble22.in + out: bubble22.ans + points: 10 +- in: bubble23.in + out: bubble23.ans + points: 10 +- in: bubble17.in + out: bubble17.ans + points: 10 +- in: bubble15.in + out: bubble15.ans + points: 10 +- in: bubble9.in + out: bubble9.ans + points: 10 +- in: bubble3.in + out: bubble3.ans + points: 10 +- in: bubble5.in + out: bubble5.ans + points: 10 +- in: bubble19.in + out: bubble19.ans + points: 10 +- in: bubble14.in + out: bubble14.ans + points: 10 +- in: bubble16.in + out: bubble16.ans + points: 10 +- in: bubble20.in + out: bubble20.ans + points: 10 +- in: bubble13.in + out: bubble13.ans + points: 10 +- in: bubble7.in + out: bubble7.ans + points: 10 +- in: bubble24.in + out: bubble24.ans + points: 10 +- in: bubble8.in + out: bubble8.ans + points: 10 +- in: bubble2.in + out: bubble2.ans + points: 10 +- in: bubble6.in + out: bubble6.ans + points: 10 +- in: bubble25.in + out: bubble25.ans + points: 10 +- in: bubble1.in + out: bubble1.ans + points: 10 +- in: bubble21.in + out: bubble21.ans + points: 10 +- in: bubble10.in + out: bubble10.ans + points: 10 +- in: bubble4.in + out: bubble4.ans + points: 10 diff --git a/NOI/loj-3851/tests.zip b/NOI/loj-3851/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..bcb65f93fb4e94de2803f82b5d12d21ade72f2ae --- /dev/null +++ b/NOI/loj-3851/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:044f3da0e20729541d1b87ac2acd728604de2b7abf454fe452ce3502748712b5 +size 134518651 diff --git a/NOI/loj-3852/init.yml b/NOI/loj-3852/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d3767e074ede44da194a453ab23e44190ee09533 --- /dev/null +++ b/NOI/loj-3852/init.yml @@ -0,0 +1,68 @@ +archive: tests.zip +test_cases: +- in: qip17.in + out: qip17.ans + points: 10 +- in: qip10.in + out: qip10.ans + points: 10 +- in: qip21.in + out: qip21.ans + points: 10 +- in: qip5.in + out: qip5.ans + points: 10 +- in: qip14.in + out: qip14.ans + points: 10 +- in: qip3.in + out: qip3.ans + points: 10 +- in: qip12.in + out: qip12.ans + points: 10 +- in: qip1.in + out: qip1.ans + points: 10 +- in: qip8.in + out: qip8.ans + points: 10 +- in: qip16.in + out: qip16.ans + points: 10 +- in: qip22.in + out: qip22.ans + points: 10 +- in: qip6.in + out: qip6.ans + points: 10 +- in: qip4.in + out: qip4.ans + points: 10 +- in: qip18.in + out: qip18.ans + points: 10 +- in: qip11.in + out: qip11.ans + points: 10 +- in: qip20.in + out: qip20.ans + points: 10 +- in: qip15.in + out: qip15.ans + points: 10 +- in: qip2.in + out: qip2.ans + points: 10 +- in: qip9.in + out: qip9.ans + points: 10 +- in: qip19.in + out: qip19.ans + points: 10 +- in: qip13.in + out: qip13.ans + points: 10 +- in: qip7.in + out: qip7.ans + points: 10 diff --git a/NOI/loj-3852/tests.zip b/NOI/loj-3852/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..74f06dcd9eefcdca9240bee544e57729c7f1118f --- /dev/null +++ b/NOI/loj-3852/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84ab6dabaea82f2b9d2a591ec063c5779c04b15caec7610a145e023d1239001c +size 102728623 diff --git a/NOI/loj-3896/init.yml b/NOI/loj-3896/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd4f526bc914c4adc7234f859f3ad534cc19a7cb --- /dev/null +++ b/NOI/loj-3896/init.yml @@ -0,0 +1,50 @@ +archive: tests.zip +test_cases: +- in: plant6.in + out: plant6.ans + points: 10 +- in: plant7.in + out: plant7.ans + points: 10 +- in: plant2.in + out: plant2.ans + points: 10 +- in: plant4.in + out: plant4.ans + points: 10 +- in: plant9.in + out: plant9.ans + points: 10 +- in: plant5.in + out: plant5.ans + points: 10 +- in: plant10.in + out: plant10.ans + points: 10 +- in: plant1.in + out: plant1.ans + points: 10 +- in: plant15.in + out: plant15.ans + points: 10 +- in: plant8.in + out: plant8.ans + points: 10 +- in: plant13.in + out: plant13.ans + points: 10 +- in: plant11.in + out: plant11.ans + points: 10 +- in: plant12.in + out: plant12.ans + points: 10 +- in: plant16.in + out: plant16.ans + points: 10 +- in: plant3.in + out: plant3.ans + points: 10 +- in: plant14.in + out: plant14.ans + points: 10 diff --git a/NOI/loj-3896/tests.zip b/NOI/loj-3896/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..49287283518278d8767af6dea62facc596903b30 --- /dev/null +++ b/NOI/loj-3896/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef025560439bbfdcd571539bee16404fecf4da58256e740649c9d470451f090a +size 22764629 diff --git a/NOI/loj-3897/tests.zip b/NOI/loj-3897/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..5980f976580f6e8611a0e4f1d30397db687170b5 --- /dev/null +++ b/NOI/loj-3897/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3b6d885459f863768bba093528660c0d7717bc836937f9a518fef4bafe61b27 +size 72225379 diff --git a/NOI/loj-3898/init.yml b/NOI/loj-3898/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..f4cc4874a967a543f2da6b08f3761853f803b0c7 --- /dev/null +++ b/NOI/loj-3898/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: barrack3.in + out: barrack3.ans + points: 10 +- in: barrack8.in + out: barrack8.ans + points: 10 +- in: barrack9.in + out: barrack9.ans + points: 10 +- in: barrack5.in + out: barrack5.ans + points: 10 +- in: barrack10.in + out: barrack10.ans + points: 10 +- in: barrack4.in + out: barrack4.ans + points: 10 +- in: barrack14.in + out: barrack14.ans + points: 10 +- in: barrack1.in + out: barrack1.ans + points: 10 +- in: barrack6.in + out: barrack6.ans + points: 10 +- in: barrack20.in + out: barrack20.ans + points: 10 +- in: barrack12.in + out: barrack12.ans + points: 10 +- in: barrack11.in + out: barrack11.ans + points: 10 +- in: barrack15.in + out: barrack15.ans + points: 10 +- in: barrack16.in + out: barrack16.ans + points: 10 +- in: barrack19.in + out: barrack19.ans + points: 10 +- in: barrack17.in + out: barrack17.ans + points: 10 +- in: barrack13.in + out: barrack13.ans + points: 10 +- in: barrack7.in + out: barrack7.ans + points: 10 +- in: barrack2.in + out: barrack2.ans + points: 10 +- in: barrack18.in + out: barrack18.ans + points: 10 diff --git a/NOI/loj-3898/tests.zip b/NOI/loj-3898/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..5b16ee90159b0a1b7e0b3519963b8f82aea36546 --- /dev/null +++ b/NOI/loj-3898/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4de09bc7014293c6d04f4dcc4c24aedc266a51963a5e3eb592a4cd42ecacd54e +size 83733692 diff --git a/NOI/loj-3899/init.yml b/NOI/loj-3899/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ea91b78f557d31630826e2d07d1f6ca61e259c91 --- /dev/null +++ b/NOI/loj-3899/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: match2.in + out: match2.ans + points: 10 +- in: match25.in + out: match25.ans + points: 10 +- in: match6.in + out: match6.ans + points: 10 +- in: match4.in + out: match4.ans + points: 10 +- in: match14.in + out: match14.ans + points: 10 +- in: match8.in + out: match8.ans + points: 10 +- in: match13.in + out: match13.ans + points: 10 +- in: match17.in + out: match17.ans + points: 10 +- in: match23.in + out: match23.ans + points: 10 +- in: match24.in + out: match24.ans + points: 10 +- in: match19.in + out: match19.ans + points: 10 +- in: match21.in + out: match21.ans + points: 10 +- in: match10.in + out: match10.ans + points: 10 +- in: match11.in + out: match11.ans + points: 10 +- in: match7.in + out: match7.ans + points: 10 +- in: match12.in + out: match12.ans + points: 10 +- in: match9.in + out: match9.ans + points: 10 +- in: match16.in + out: match16.ans + points: 10 +- in: match5.in + out: match5.ans + points: 10 +- in: match3.in + out: match3.ans + points: 10 +- in: match18.in + out: match18.ans + points: 10 +- in: match15.in + out: match15.ans + points: 10 +- in: match20.in + out: match20.ans + points: 10 +- in: match1.in + out: match1.ans + points: 10 +- in: match22.in + out: match22.ans + points: 10 diff --git a/NOI/loj-3899/tests.zip b/NOI/loj-3899/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..78ccce8c85dc6ca0af84a7e041a21080afeafcb1 --- /dev/null +++ b/NOI/loj-3899/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af3d86a9061f577fdf6c22241749f8849fb786dd25320ebcfdf66f66a10a4880 +size 113703525 diff --git a/NOI/loj-3979/init.yml b/NOI/loj-3979/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..306453b8d96fe17fabea8a975a097def70052266 --- /dev/null +++ b/NOI/loj-3979/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: color19.in + out: color19.ans + points: 10 +- in: color14.in + out: color14.ans + points: 10 +- in: color3.in + out: color3.ans + points: 10 +- in: color16.in + out: color16.ans + points: 10 +- in: color8.in + out: color8.ans + points: 10 +- in: color6.in + out: color6.ans + points: 10 +- in: color18.in + out: color18.ans + points: 10 +- in: color4.in + out: color4.ans + points: 10 +- in: color9.in + out: color9.ans + points: 10 +- in: color12.in + out: color12.ans + points: 10 +- in: color17.in + out: color17.ans + points: 10 +- in: color7.in + out: color7.ans + points: 10 +- in: color5.in + out: color5.ans + points: 10 +- in: color11.in + out: color11.ans + points: 10 +- in: color20.in + out: color20.ans + points: 10 +- in: color2.in + out: color2.ans + points: 10 +- in: color13.in + out: color13.ans + points: 10 +- in: color15.in + out: color15.ans + points: 10 +- in: color1.in + out: color1.ans + points: 10 +- in: color10.in + out: color10.ans + points: 10 diff --git a/NOI/loj-3979/tests.zip b/NOI/loj-3979/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..1d4e6f5276aee107bc98fdb62238899851c9fa81 --- /dev/null +++ b/NOI/loj-3979/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ce4173c0f0bca5cbf773283d25cba041b1bd6cd0372e9a3bfe7bf44ff3aa823 +size 29729020 diff --git a/NOI/loj-3980/init.yml b/NOI/loj-3980/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..8c1bc8c55f79f81e42f32fb2028e495cd8c74b84 --- /dev/null +++ b/NOI/loj-3980/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: tree2.in + out: tree2.ans + points: 10 +- in: tree7.in + out: tree7.ans + points: 10 +- in: tree5.in + out: tree5.ans + points: 10 +- in: tree3.in + out: tree3.ans + points: 10 +- in: tree8.in + out: tree8.ans + points: 10 +- in: tree16.in + out: tree16.ans + points: 10 +- in: tree20.in + out: tree20.ans + points: 10 +- in: tree10.in + out: tree10.ans + points: 10 +- in: tree11.in + out: tree11.ans + points: 10 +- in: tree17.in + out: tree17.ans + points: 10 +- in: tree13.in + out: tree13.ans + points: 10 +- in: tree15.in + out: tree15.ans + points: 10 +- in: tree1.in + out: tree1.ans + points: 10 +- in: tree6.in + out: tree6.ans + points: 10 +- in: tree14.in + out: tree14.ans + points: 10 +- in: tree19.in + out: tree19.ans + points: 10 +- in: tree4.in + out: tree4.ans + points: 10 +- in: tree9.in + out: tree9.ans + points: 10 +- in: tree18.in + out: tree18.ans + points: 10 +- in: tree12.in + out: tree12.ans + points: 10 diff --git a/NOI/loj-3980/tests.zip b/NOI/loj-3980/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..4db9fcde8505758a86e2e3196c29d53b3e11e9a2 --- /dev/null +++ b/NOI/loj-3980/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f04e68f0ab9a5867580d6add752265a27bd2ec311fe080b1f61634edb62d267b +size 12682542 diff --git a/NOI/loj-3981/init.yml b/NOI/loj-3981/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6522cce4b757acc5436947a92835701af1c17e24 --- /dev/null +++ b/NOI/loj-3981/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: dfs25.in + out: dfs25.ans + points: 10 +- in: dfs11.in + out: dfs11.ans + points: 10 +- in: dfs24.in + out: dfs24.ans + points: 10 +- in: dfs23.in + out: dfs23.ans + points: 10 +- in: dfs22.in + out: dfs22.ans + points: 10 +- in: dfs2.in + out: dfs2.ans + points: 10 +- in: dfs9.in + out: dfs9.ans + points: 10 +- in: dfs18.in + out: dfs18.ans + points: 10 +- in: dfs13.in + out: dfs13.ans + points: 10 +- in: dfs7.in + out: dfs7.ans + points: 10 +- in: dfs5.in + out: dfs5.ans + points: 10 +- in: dfs19.in + out: dfs19.ans + points: 10 +- in: dfs21.in + out: dfs21.ans + points: 10 +- in: dfs14.in + out: dfs14.ans + points: 10 +- in: dfs20.in + out: dfs20.ans + points: 10 +- in: dfs3.in + out: dfs3.ans + points: 10 +- in: dfs1.in + out: dfs1.ans + points: 10 +- in: dfs8.in + out: dfs8.ans + points: 10 +- in: dfs15.in + out: dfs15.ans + points: 10 +- in: dfs10.in + out: dfs10.ans + points: 10 +- in: dfs6.in + out: dfs6.ans + points: 10 +- in: dfs17.in + out: dfs17.ans + points: 10 +- in: dfs12.in + out: dfs12.ans + points: 10 +- in: dfs4.in + out: dfs4.ans + points: 10 +- in: dfs16.in + out: dfs16.ans + points: 10 diff --git a/NOI/loj-3981/tests.zip b/NOI/loj-3981/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..af835a41f27ad7023a2ca3aa7db93650d7833732 --- /dev/null +++ b/NOI/loj-3981/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d57ed4de97f4cbec07c4e953e9a6be626b14dd8ec290f9b3caca4441065e37f +size 83040493 diff --git a/NOI/loj-3982/init.yml b/NOI/loj-3982/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..df10a6c6172e570d5050719cb9b0977b0ae9a01d --- /dev/null +++ b/NOI/loj-3982/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: trade12.in + out: trade12.ans + points: 10 +- in: trade4.in + out: trade4.ans + points: 10 +- in: trade16.in + out: trade16.ans + points: 10 +- in: trade3.in + out: trade3.ans + points: 10 +- in: trade10.in + out: trade10.ans + points: 10 +- in: trade8.in + out: trade8.ans + points: 10 +- in: trade11.in + out: trade11.ans + points: 10 +- in: trade2.in + out: trade2.ans + points: 10 +- in: trade17.in + out: trade17.ans + points: 10 +- in: trade18.in + out: trade18.ans + points: 10 +- in: trade9.in + out: trade9.ans + points: 10 +- in: trade19.in + out: trade19.ans + points: 10 +- in: trade6.in + out: trade6.ans + points: 10 +- in: trade15.in + out: trade15.ans + points: 10 +- in: trade13.in + out: trade13.ans + points: 10 +- in: trade20.in + out: trade20.ans + points: 10 +- in: trade14.in + out: trade14.ans + points: 10 +- in: trade7.in + out: trade7.ans + points: 10 +- in: trade1.in + out: trade1.ans + points: 10 +- in: trade5.in + out: trade5.ans + points: 10 diff --git a/NOI/loj-3982/tests.zip b/NOI/loj-3982/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..699d44e6f112ea93031b2e69c0d4799e04c04838 --- /dev/null +++ b/NOI/loj-3982/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2c76323ec8cfecb0471b47e26eba11531ab09fa35b7678a8b6eb718aa0b6b57 +size 47625680 diff --git a/NOI/loj-3983/init.yml b/NOI/loj-3983/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..933dc36e0de1620caa9851c4f02007b466ea5c81 --- /dev/null +++ b/NOI/loj-3983/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: string8.in + out: string8.ans + points: 10 +- in: string24.in + out: string24.ans + points: 10 +- in: string10.in + out: string10.ans + points: 10 +- in: string18.in + out: string18.ans + points: 10 +- in: string11.in + out: string11.ans + points: 10 +- in: string2.in + out: string2.ans + points: 10 +- in: string14.in + out: string14.ans + points: 10 +- in: string19.in + out: string19.ans + points: 10 +- in: string6.in + out: string6.ans + points: 10 +- in: string7.in + out: string7.ans + points: 10 +- in: string15.in + out: string15.ans + points: 10 +- in: string9.in + out: string9.ans + points: 10 +- in: string20.in + out: string20.ans + points: 10 +- in: string16.in + out: string16.ans + points: 10 +- in: string17.in + out: string17.ans + points: 10 +- in: string1.in + out: string1.ans + points: 10 +- in: string22.in + out: string22.ans + points: 10 +- in: string13.in + out: string13.ans + points: 10 +- in: string3.in + out: string3.ans + points: 10 +- in: string5.in + out: string5.ans + points: 10 +- in: string23.in + out: string23.ans + points: 10 +- in: string4.in + out: string4.ans + points: 10 +- in: string12.in + out: string12.ans + points: 10 +- in: string25.in + out: string25.ans + points: 10 +- in: string21.in + out: string21.ans + points: 10 diff --git a/NOI/loj-3983/tests.zip b/NOI/loj-3983/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..68afed52f4477778ae793f16dde2ebe6265c17cc --- /dev/null +++ b/NOI/loj-3983/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f8143d7b0e0a81cc42ec81e1029fe475287d0edef43b82b843591ea7e87811f +size 98132306 diff --git a/NOI/loj-3984/init.yml b/NOI/loj-3984/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd013ad4561d9a70f7fa6a5559cfecb7b3841d8e --- /dev/null +++ b/NOI/loj-3984/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: book7.in + out: book7.ans + points: 10 +- in: book15.in + out: book15.ans + points: 10 +- in: book9.in + out: book9.ans + points: 10 +- in: book2.in + out: book2.ans + points: 10 +- in: book4.in + out: book4.ans + points: 10 +- in: book12.in + out: book12.ans + points: 10 +- in: book11.in + out: book11.ans + points: 10 +- in: book6.in + out: book6.ans + points: 10 +- in: book16.in + out: book16.ans + points: 10 +- in: book20.in + out: book20.ans + points: 10 +- in: book1.in + out: book1.ans + points: 10 +- in: book3.in + out: book3.ans + points: 10 +- in: book19.in + out: book19.ans + points: 10 +- in: book13.in + out: book13.ans + points: 10 +- in: book10.in + out: book10.ans + points: 10 +- in: book14.in + out: book14.ans + points: 10 +- in: book18.in + out: book18.ans + points: 10 +- in: book8.in + out: book8.ans + points: 10 +- in: book17.in + out: book17.ans + points: 10 +- in: book5.in + out: book5.ans + points: 10 diff --git a/NOI/loj-3984/tests.zip b/NOI/loj-3984/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..1d102f838990d3e2f499e1dcd9fd9537bd0000ab --- /dev/null +++ b/NOI/loj-3984/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20e25c5605a9c94201dce7bb3f98804e037bfea185e06a4c403d9681df465fb2 +size 56359 diff --git a/NOI/loj-4001/init.yml b/NOI/loj-4001/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..2aa0a1fbc426eb507f31553b6a67c2c645aa8852 --- /dev/null +++ b/NOI/loj-4001/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: dict5.in + out: dict5.ans + points: 10 +- in: dict6.in + out: dict6.ans + points: 10 +- in: dict7.in + out: dict7.ans + points: 10 +- in: dict1.in + out: dict1.ans + points: 10 +- in: dict2.in + out: dict2.ans + points: 10 +- in: dict3.in + out: dict3.ans + points: 10 +- in: dict8.in + out: dict8.ans + points: 10 +- in: dict9.in + out: dict9.ans + points: 10 +- in: dict10.in + out: dict10.ans + points: 10 +- in: dict4.in + out: dict4.ans + points: 10 diff --git a/NOI/loj-4001/tests.zip b/NOI/loj-4001/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..61ac8df754b1a1dedc6f070745f8b57343c5f341 --- /dev/null +++ b/NOI/loj-4001/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7af93efe2447fa80796c42fae97ad1913e596db39d731c8940e48629d6e7c3e3 +size 10100902 diff --git a/NOI/loj-4002/init.yml b/NOI/loj-4002/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..8da4a328ecb96e616bb7729ef0d49aed3fe6c233 --- /dev/null +++ b/NOI/loj-4002/init.yml @@ -0,0 +1,32 @@ +archive: tests.zip +test_cases: +- in: tribool6.in + out: tribool6.ans + points: 10 +- in: tribool10.in + out: tribool10.ans + points: 10 +- in: tribool1.in + out: tribool1.ans + points: 10 +- in: tribool2.in + out: tribool2.ans + points: 10 +- in: tribool4.in + out: tribool4.ans + points: 10 +- in: tribool9.in + out: tribool9.ans + points: 10 +- in: tribool8.in + out: tribool8.ans + points: 10 +- in: tribool5.in + out: tribool5.ans + points: 10 +- in: tribool7.in + out: tribool7.ans + points: 10 +- in: tribool3.in + out: tribool3.ans + points: 10 diff --git a/NOI/loj-4002/tests.zip b/NOI/loj-4002/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..da96ba1af4d1243589c63688ed3b6892e5eb6dc2 --- /dev/null +++ b/NOI/loj-4002/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a6f30ce821c984b1cc3fb20445a1e0b7e94d08d59af2c419e75d36588f690d5 +size 29060300 diff --git a/NOI/loj-4003/init.yml b/NOI/loj-4003/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..6f8d8dca8117de91c1e53ddc545c962ed1385934 --- /dev/null +++ b/NOI/loj-4003/init.yml @@ -0,0 +1,62 @@ +archive: tests.zip +test_cases: +- in: expand6.in + out: expand6.ans + points: 10 +- in: expand4.in + out: expand4.ans + points: 10 +- in: expand15.in + out: expand15.ans + points: 10 +- in: expand10.in + out: expand10.ans + points: 10 +- in: expand1.in + out: expand1.ans + points: 10 +- in: expand19.in + out: expand19.ans + points: 10 +- in: expand5.in + out: expand5.ans + points: 10 +- in: expand8.in + out: expand8.ans + points: 10 +- in: expand3.in + out: expand3.ans + points: 10 +- in: expand7.in + out: expand7.ans + points: 10 +- in: expand11.in + out: expand11.ans + points: 10 +- in: expand2.in + out: expand2.ans + points: 10 +- in: expand18.in + out: expand18.ans + points: 10 +- in: expand13.in + out: expand13.ans + points: 10 +- in: expand20.in + out: expand20.ans + points: 10 +- in: expand9.in + out: expand9.ans + points: 10 +- in: expand16.in + out: expand16.ans + points: 10 +- in: expand12.in + out: expand12.ans + points: 10 +- in: expand14.in + out: expand14.ans + points: 10 +- in: expand17.in + out: expand17.ans + points: 10 diff --git a/NOI/loj-4003/tests.zip b/NOI/loj-4003/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..dca671ff65ea29d941545bcdedc183352f58eba5 --- /dev/null +++ b/NOI/loj-4003/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4dd26c00a6ac5ec7312da86cebeed69bed80355d2e484f836871d676e4121ba1 +size 175179620 diff --git a/NOI/loj-4004/init.yml b/NOI/loj-4004/init.yml new file mode 100644 index 0000000000000000000000000000000000000000..d674c96a1ab8de17aed12087a4beea9cb1b37a5b --- /dev/null +++ b/NOI/loj-4004/init.yml @@ -0,0 +1,77 @@ +archive: tests.zip +test_cases: +- in: run23.in + out: run23.ans + points: 10 +- in: run16.in + out: run16.ans + points: 10 +- in: run2.in + out: run2.ans + points: 10 +- in: run12.in + out: run12.ans + points: 10 +- in: run9.in + out: run9.ans + points: 10 +- in: run17.in + out: run17.ans + points: 10 +- in: run13.in + out: run13.ans + points: 10 +- in: run22.in + out: run22.ans + points: 10 +- in: run7.in + out: run7.ans + points: 10 +- in: run18.in + out: run18.ans + points: 10 +- in: run14.in + out: run14.ans + points: 10 +- in: run10.in + out: run10.ans + points: 10 +- in: run25.in + out: run25.ans + points: 10 +- in: run19.in + out: run19.ans + points: 10 +- in: run5.in + out: run5.ans + points: 10 +- in: run21.in + out: run21.ans + points: 10 +- in: run3.in + out: run3.ans + points: 10 +- in: run1.in + out: run1.ans + points: 10 +- in: run8.in + out: run8.ans + points: 10 +- in: run6.in + out: run6.ans + points: 10 +- in: run24.in + out: run24.ans + points: 10 +- in: run4.in + out: run4.ans + points: 10 +- in: run20.in + out: run20.ans + points: 10 +- in: run15.in + out: run15.ans + points: 10 +- in: run11.in + out: run11.ans + points: 10 diff --git a/NOI/loj-4004/tests.zip b/NOI/loj-4004/tests.zip new file mode 100644 index 0000000000000000000000000000000000000000..773286e0516178687c261d7304d37bc9f95c4cd0 --- /dev/null +++ b/NOI/loj-4004/tests.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca5972272cdf6fbf17d86e0c92d42676d4f69d22aad66ad6298afe7d03c45b8c +size 370809704