diff --git a/common/testlib.h b/common/testlib.h index 703f75259..ad6af9ae7 100644 --- a/common/testlib.h +++ b/common/testlib.h @@ -3049,7 +3049,7 @@ void InStream::xmlSafeWrite(std::FILE *file, const char *msg) { std::fprintf(file, "%s", """); continue; } - if (0 <= msg[i] && msg[i] <= 31) { + if (msg[i] <= 31) { // modified for library-checker std::fprintf(file, "%c", '.'); continue; } diff --git a/datastructure/range_chmin_chmax_add_range_sum/sol/correct.cpp b/datastructure/range_chmin_chmax_add_range_sum/sol/correct.cpp index 7f9bf014d..ba7b2b2a9 100644 --- a/datastructure/range_chmin_chmax_add_range_sum/sol/correct.cpp +++ b/datastructure/range_chmin_chmax_add_range_sum/sol/correct.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) diff --git a/graph/bipartitematching/gen/kuhn_killer.cpp b/graph/bipartitematching/gen/kuhn_killer.cpp new file mode 100644 index 000000000..5c2c58774 --- /dev/null +++ b/graph/bipartitematching/gen/kuhn_killer.cpp @@ -0,0 +1,47 @@ +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +// https://codeforces.com/blog/entry/58048?#comment-417533 +int main() { + int n = min(L_MAX, R_MAX); + int k = n / 8 * 2; + + using P = pair; + vector

edges; + for(int i = 0; i < k; i++) { + edges.emplace_back(i, i); + } + for(int i = 0; i < k - 1; i++) { + edges.emplace_back(i+1, i); + } + for(int i = 0; i < k / 2; i++) { + edges.emplace_back(i, k+2*i); + edges.emplace_back(2*k+2*i, k+2*i); + edges.emplace_back(2*k+2*i, 3*k+2*i); + edges.emplace_back(k+2*i, i); + edges.emplace_back(k+2*i, 2*k+2*i); + edges.emplace_back(3*k+2*i, 2*k+2*i); + } + for(int j = 0; j < k / 2; j++) { + int i = k/2-1-j; + edges.emplace_back(k/2+j, k+2*i+1); + edges.emplace_back(2*k+2*i+1, k+2*i+1); + edges.emplace_back(2*k+2*i+1, 3*k+2*i+1); + edges.emplace_back(k+2*i+1, k/2+j); + edges.emplace_back(k+2*i+1, 2*k+2*i+1); + edges.emplace_back(3*k+2*i+1, 2*k+2*i+1); + } + + int m = int(edges.size()); + + printf("%d %d %d\n", n, n, m); + for (auto edge: edges) { + printf("%d %d\n", edge.first, edge.second); + } + return 0; +} diff --git a/graph/bipartitematching/hash.json b/graph/bipartitematching/hash.json index 1745a4518..78cc1638d 100644 --- a/graph/bipartitematching/hash.json +++ b/graph/bipartitematching/hash.json @@ -5,6 +5,8 @@ "cycle_01.out": "61bf446b23a4128b7939650819761c10e1e111fdf644d440a2a8fc58f923905b", "example_00.in": "8e14807ee203e49dde929bb92a04f1536a744b10e6dfd233b68fc4f19db57a71", "example_00.out": "d316870aa467c52e802c0b1c7bbf0a301ee0be2b5f6805859910d36727933338", + "kuhn_killer_00.in": "e8ab878ceaa36de73750dc9599080d7864585c77fd1546cf9431223d7b64e790", + "kuhn_killer_00.out": "c982d8a1164805c36b2bada6b78835990b131177c2344c4be9a4d85edf94dbfe", "line_00.in": "918e562d05cac133df5f6284b257b04c4edf25ab3c732f49aa11e13b648f9c54", "line_00.out": "4804e0bade8d81737542707d6229f138a2650064ee1f630266da890d1524914a", "line_01.in": "4f49760ff181162f05410f1a188b51f4199b0a0fe6a321b266e3430ff6ffb809", diff --git a/graph/bipartitematching/info.toml b/graph/bipartitematching/info.toml index 56cd955cf..40ee935d8 100644 --- a/graph/bipartitematching/info.toml +++ b/graph/bipartitematching/info.toml @@ -14,6 +14,9 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/37" [[tests]] name = "line.cpp" number = 2 +[[tests]] + name = "kuhn_killer.cpp" + number = 1 [[tests]] name = "many_smalls.cpp" number = 2 diff --git a/math/convolution_mod/gen/signed_overflow.cpp b/math/convolution_mod/gen/signed_overflow.cpp new file mode 100644 index 000000000..820be9e07 --- /dev/null +++ b/math/convolution_mod/gen/signed_overflow.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << ' ' << n << '\n'; + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + return 0; +} diff --git a/math/convolution_mod/gen/unsigned_overflow.cpp b/math/convolution_mod/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..7a2231612 --- /dev/null +++ b/math/convolution_mod/gen/unsigned_overflow.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << ' ' << n << '\n'; + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + return 0; +} diff --git a/math/convolution_mod/hash.json b/math/convolution_mod/hash.json index c245450fe..7fda6fcc8 100644 --- a/math/convolution_mod/hash.json +++ b/math/convolution_mod/hash.json @@ -37,6 +37,8 @@ "random_01.out": "501fb137b66268875f46296bb517b8c60fb9cba1b1819ec7804001e87b69aea6", "random_02.in": "ee0133be91e17cc3f84550e426c255736746029ba78b178b99d1cb1ee30fcf1c", "random_02.out": "8830adf5e75c568eb55b03ba14744bec8e8458a5d30dc945999475166422ce3f", + "signed_overflow_00.in": "4224cd34b6f1f3ee6713e3228395c11333c067d6066612e69f3c0489bdee3b70", + "signed_overflow_00.out": "d314fa573547dda0f41b683921221a2549643b231de42cf0f1b7766db3045c73", "small_00.in": "ac1b0c7c78c8a8de70b5dc028a11fddd30d8de6dd399b0475e0f84deaddc5816", "small_00.out": "b086d8c94719f50a63743fbba701b852975a768400520b3285f0855ab77882a8", "small_01.in": "387fe0d406947ba770dcfc76f8285a94c58aae1a0f3c4d5477755c7bae83faae", @@ -68,5 +70,7 @@ "small_14.in": "a377535ad3941915624588159bc4b5065f909f93b9bb9766d69b1ab1d6756d43", "small_14.out": "85c3fd86c69853bf54cccdf37c0a343d14850bdbd6fcefeab6c3a4132c2c0e2e", "small_15.in": "ccb7c3695a22c9c1afb1dedbbfcc58c29b8d817dd6c74f015a61c8980b5f98db", - "small_15.out": "c10e4f298ec1d47116c30c26e16b48713231fb0456775a235ae146ebf746c865" + "small_15.out": "c10e4f298ec1d47116c30c26e16b48713231fb0456775a235ae146ebf746c865", + "unsigned_overflow_00.in": "9ebbc9ee08996e7a352c1f688574cb0021ecc6e1d02ffbc1515486721452084c", + "unsigned_overflow_00.out": "0229b0cd8035b7b20369a57a10deaab40f8d3826b1816b2142731965a4c3274a" } \ No newline at end of file diff --git a/math/convolution_mod/info.toml b/math/convolution_mod/info.toml index 4a2d1cd1d..9f4a8d06e 100644 --- a/math/convolution_mod/info.toml +++ b/math/convolution_mod/info.toml @@ -29,6 +29,12 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/42" [[tests]] name = "max_ans_zero.cpp" number = 1 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 [[solutions]] name = "naive.cpp" diff --git a/math/convolution_mod_1000000007/gen/signed_overflow.cpp b/math/convolution_mod_1000000007/gen/signed_overflow.cpp new file mode 100644 index 000000000..820be9e07 --- /dev/null +++ b/math/convolution_mod_1000000007/gen/signed_overflow.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << ' ' << n << '\n'; + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + return 0; +} diff --git a/math/convolution_mod_1000000007/gen/unsigned_overflow.cpp b/math/convolution_mod_1000000007/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..7a2231612 --- /dev/null +++ b/math/convolution_mod_1000000007/gen/unsigned_overflow.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << ' ' << n << '\n'; + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + return 0; +} diff --git a/math/convolution_mod_1000000007/hash.json b/math/convolution_mod_1000000007/hash.json index 7c1a73f59..cd246c2c0 100644 --- a/math/convolution_mod_1000000007/hash.json +++ b/math/convolution_mod_1000000007/hash.json @@ -27,6 +27,8 @@ "random_01.out": "50dae1e32c347a6d66f1f11ea0e5181a24e8f986c410cecaec40a794522396e5", "random_02.in": "23673ac84811977b7f96facd73cc62aa64eb4d06de3f9829e771a6be052ad414", "random_02.out": "1f5f643b7946386e36ddf2a3653ba7a48f73cff41c7517a66b26424b106cd6be", + "signed_overflow_00.in": "0eb551a4a9fd827ee510e8b13f5f0e3014d5a99cf2fe245626774db33ed29393", + "signed_overflow_00.out": "9c1bb9845ba4d1a57daf170c713d79e07d824aa06db2fd484527b81e2033bfcb", "small_00.in": "ac1b0c7c78c8a8de70b5dc028a11fddd30d8de6dd399b0475e0f84deaddc5816", "small_00.out": "5497acdabc7dd59bfc8784550ac6bf1557bdda54727d2ade18776892ab3367d5", "small_01.in": "387fe0d406947ba770dcfc76f8285a94c58aae1a0f3c4d5477755c7bae83faae", @@ -58,5 +60,7 @@ "small_14.in": "a377535ad3941915624588159bc4b5065f909f93b9bb9766d69b1ab1d6756d43", "small_14.out": "5cff8cd0a73f627b13c0fda14f204eda42d0586452625d9c622e2e8c4cfcbbbf", "small_15.in": "ccb7c3695a22c9c1afb1dedbbfcc58c29b8d817dd6c74f015a61c8980b5f98db", - "small_15.out": "d1973399c877ddaa31ffe3c60b229a56f6eecdbf3f9b9fc1c9e1813b578c1e26" + "small_15.out": "d1973399c877ddaa31ffe3c60b229a56f6eecdbf3f9b9fc1c9e1813b578c1e26", + "unsigned_overflow_00.in": "3d848cf445935f64c462a92656896e038d5d430be519690f5ed9ee9367478fcc", + "unsigned_overflow_00.out": "0229b0cd8035b7b20369a57a10deaab40f8d3826b1816b2142731965a4c3274a" } \ No newline at end of file diff --git a/math/convolution_mod_1000000007/info.toml b/math/convolution_mod_1000000007/info.toml index df6496f9f..731ac4467 100644 --- a/math/convolution_mod_1000000007/info.toml +++ b/math/convolution_mod_1000000007/info.toml @@ -26,6 +26,12 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/145" [[tests]] name = "max_ans_zero.cpp" number = 1 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 [[solutions]] name = "naive.cpp" diff --git a/math/convolution_mod_large/gen/signed_overflow.cpp b/math/convolution_mod_large/gen/signed_overflow.cpp new file mode 100644 index 000000000..820be9e07 --- /dev/null +++ b/math/convolution_mod_large/gen/signed_overflow.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << ' ' << n << '\n'; + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + return 0; +} diff --git a/math/convolution_mod_large/gen/unsigned_overflow.cpp b/math/convolution_mod_large/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..8280cc0d2 --- /dev/null +++ b/math/convolution_mod_large/gen/unsigned_overflow.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << ' ' << n << '\n'; + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + for (int i = 0; i < n; ++i) { + cout << val << ((i == n - 1) ? '\n' : ' '); + } + + return 0; +} + diff --git a/math/convolution_mod_large/hash.json b/math/convolution_mod_large/hash.json index 03e8de93e..44a81e6c5 100644 --- a/math/convolution_mod_large/hash.json +++ b/math/convolution_mod_large/hash.json @@ -31,6 +31,8 @@ "random_01.out": "d1dcd403e574b14fec1c9eb3d7d6816d6ab7d4c9346a6982630557ae089fed7b", "random_02.in": "3f6e19c6c09430e4126602e3f8ba990be7e1dd6deef966d957b6a4b3c1874a79", "random_02.out": "26a50fcccc9b6bcc8de961edd0099bcfc66b9f50026ceb2c1806958369d5f719", + "signed_overflow_00.in": "4224cd34b6f1f3ee6713e3228395c11333c067d6066612e69f3c0489bdee3b70", + "signed_overflow_00.out": "d314fa573547dda0f41b683921221a2549643b231de42cf0f1b7766db3045c73", "small_00.in": "ac1b0c7c78c8a8de70b5dc028a11fddd30d8de6dd399b0475e0f84deaddc5816", "small_00.out": "b086d8c94719f50a63743fbba701b852975a768400520b3285f0855ab77882a8", "small_01.in": "387fe0d406947ba770dcfc76f8285a94c58aae1a0f3c4d5477755c7bae83faae", @@ -62,5 +64,7 @@ "small_14.in": "a377535ad3941915624588159bc4b5065f909f93b9bb9766d69b1ab1d6756d43", "small_14.out": "85c3fd86c69853bf54cccdf37c0a343d14850bdbd6fcefeab6c3a4132c2c0e2e", "small_15.in": "ccb7c3695a22c9c1afb1dedbbfcc58c29b8d817dd6c74f015a61c8980b5f98db", - "small_15.out": "c10e4f298ec1d47116c30c26e16b48713231fb0456775a235ae146ebf746c865" + "small_15.out": "c10e4f298ec1d47116c30c26e16b48713231fb0456775a235ae146ebf746c865", + "unsigned_overflow_00.in": "9ebbc9ee08996e7a352c1f688574cb0021ecc6e1d02ffbc1515486721452084c", + "unsigned_overflow_00.out": "0229b0cd8035b7b20369a57a10deaab40f8d3826b1816b2142731965a4c3274a" } \ No newline at end of file diff --git a/math/convolution_mod_large/info.toml b/math/convolution_mod_large/info.toml index 6db97c18c..9a23ec22e 100644 --- a/math/convolution_mod_large/info.toml +++ b/math/convolution_mod_large/info.toml @@ -26,6 +26,12 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/720" [[tests]] name = "max_ans_zero.cpp" number = 1 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 [[solutions]] name = "naive.cpp" diff --git a/math/inverse_matrix/gen/signed_overflow.cpp b/math/inverse_matrix/gen/signed_overflow.cpp new file mode 100644 index 000000000..f2b275e73 --- /dev/null +++ b/math/inverse_matrix/gen/signed_overflow.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << '\n'; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/math/inverse_matrix/gen/unsigned_overflow.cpp b/math/inverse_matrix/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..22002a3f5 --- /dev/null +++ b/math/inverse_matrix/gen/unsigned_overflow.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << '\n'; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/math/inverse_matrix/hash.json b/math/inverse_matrix/hash.json index 4bca29773..15f5a38bf 100644 --- a/math/inverse_matrix/hash.json +++ b/math/inverse_matrix/hash.json @@ -46,5 +46,9 @@ "random_03.in": "65da182beb1d893d5075e13c7ea4eaaeee0b6f4f08c2b3b10dd2c91c0d7feace", "random_03.out": "0e3df439392066de90ff3a1f57c125921670111b3a61a5c9aa863fec808b982f", "random_04.in": "be5de7ee3630de1e65d3a236644db57e5eafe50479d1a382128ea2bbc9120ac2", - "random_04.out": "225dc861e090b1db9fc38a18b3f91664a54ecad91738db9305c8018439a7d7f1" + "random_04.out": "225dc861e090b1db9fc38a18b3f91664a54ecad91738db9305c8018439a7d7f1", + "signed_overflow_00.in": "31b80c2aff345d32d117c940ec47f05fe808f34be0ca283d50df622ff899c00d", + "signed_overflow_00.out": "ee3aa64bb94a50845d5024cd4bd20202a4567aed5cd5328c0d97e9920775fc28", + "unsigned_overflow_00.in": "dfd8be53e4f5ae91e215e99136632ea635c710a6e029a296b3faa5a4fd1edfdb", + "unsigned_overflow_00.out": "ee3aa64bb94a50845d5024cd4bd20202a4567aed5cd5328c0d97e9920775fc28" } \ No newline at end of file diff --git a/math/inverse_matrix/info.toml b/math/inverse_matrix/info.toml index bd1897ad9..acc1b55d5 100644 --- a/math/inverse_matrix/info.toml +++ b/math/inverse_matrix/info.toml @@ -20,6 +20,12 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/626" [[tests]] name = "anti55588.in" number = 1 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 [params] N_MAX = 500 diff --git a/math/matrix_det/gen/signed_overflow.cpp b/math/matrix_det/gen/signed_overflow.cpp new file mode 100644 index 000000000..fbf682876 --- /dev/null +++ b/math/matrix_det/gen/signed_overflow.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +const int MOD = 998244353; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << '\n'; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/math/matrix_det/gen/unsigned_overflow.cpp b/math/matrix_det/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..49acf49b1 --- /dev/null +++ b/math/matrix_det/gen/unsigned_overflow.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +const int MOD = 998244353; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << '\n'; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/math/matrix_det/hash.json b/math/matrix_det/hash.json index 8eee14600..335ae6781 100644 --- a/math/matrix_det/hash.json +++ b/math/matrix_det/hash.json @@ -44,5 +44,9 @@ "random_03.in": "65da182beb1d893d5075e13c7ea4eaaeee0b6f4f08c2b3b10dd2c91c0d7feace", "random_03.out": "03aeecbebf2d2566d01ab243aafef046cf1ac41773c2fa0f460d06950ae7fdd7", "random_04.in": "be5de7ee3630de1e65d3a236644db57e5eafe50479d1a382128ea2bbc9120ac2", - "random_04.out": "788a05783d7501121d64274d2a79bf9c9533067daab176c1e8c4226df28ea7e0" + "random_04.out": "788a05783d7501121d64274d2a79bf9c9533067daab176c1e8c4226df28ea7e0", + "signed_overflow_00.in": "31b80c2aff345d32d117c940ec47f05fe808f34be0ca283d50df622ff899c00d", + "signed_overflow_00.out": "9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa", + "unsigned_overflow_00.in": "dfd8be53e4f5ae91e215e99136632ea635c710a6e029a296b3faa5a4fd1edfdb", + "unsigned_overflow_00.out": "9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa" } \ No newline at end of file diff --git a/math/matrix_det/info.toml b/math/matrix_det/info.toml index 6f01f5dd3..5b4be46b9 100644 --- a/math/matrix_det/info.toml +++ b/math/matrix_det/info.toml @@ -17,3 +17,9 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/43" [[tests]] name = "perm_max_random.cpp" number = 5 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 diff --git a/math/matrix_det_arbitrary_mod/gen/signed_overflow.cpp b/math/matrix_det_arbitrary_mod/gen/signed_overflow.cpp new file mode 100644 index 000000000..6aeee91c7 --- /dev/null +++ b/math/matrix_det_arbitrary_mod/gen/signed_overflow.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +const int MOD = 1000000000 - 1; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << ' ' << MOD << '\n'; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/math/matrix_det_arbitrary_mod/gen/unsigned_overflow.cpp b/math/matrix_det_arbitrary_mod/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..6996c8a10 --- /dev/null +++ b/math/matrix_det_arbitrary_mod/gen/unsigned_overflow.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +const int MOD = 1000000000 - 1; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << ' ' << MOD << '\n'; + + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + + return 0; +} diff --git a/math/matrix_det_arbitrary_mod/hash.json b/math/matrix_det_arbitrary_mod/hash.json index 0da53cf25..c177b7171 100644 --- a/math/matrix_det_arbitrary_mod/hash.json +++ b/math/matrix_det_arbitrary_mod/hash.json @@ -34,5 +34,9 @@ "random_03.in": "69ed32756f31cfd897a4349723be522f359f6afa52e44b9f6ca43c88281ec51e", "random_03.out": "93b5dd743ecfa037e99a45aeb6eb008c73914d7cd2e6b55e4ec6c57ef1a43140", "random_04.in": "5fe2369d60269113bb8e59c409a73a78cc684425e223bc08c7fd3672b22d2d38", - "random_04.out": "bfc82bcf2edc504a86e551f44ff595db46a4639842ff3f5bdba04bc6e1cc0644" + "random_04.out": "bfc82bcf2edc504a86e551f44ff595db46a4639842ff3f5bdba04bc6e1cc0644", + "signed_overflow_00.in": "d41abc1bcf8d3a1d4818a4c6618cf579389d2b4d6520adb6098645ff017344fa", + "signed_overflow_00.out": "9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa", + "unsigned_overflow_00.in": "b8f161d6ee366620db3faaf7588f0ef96a8b05293ce3a4149958b11cf8a20be5", + "unsigned_overflow_00.out": "9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa" } \ No newline at end of file diff --git a/math/matrix_det_arbitrary_mod/info.toml b/math/matrix_det_arbitrary_mod/info.toml index 26a187a0b..2aabe337a 100644 --- a/math/matrix_det_arbitrary_mod/info.toml +++ b/math/matrix_det_arbitrary_mod/info.toml @@ -14,6 +14,12 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/750" [[tests]] name = "perm_max_random.cpp" number = 5 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 [[solutions]] name = "charpoly.cpp" [params] diff --git a/math/matrix_product/gen/signed_overflow.cpp b/math/matrix_product/gen/signed_overflow.cpp new file mode 100644 index 000000000..a56ee7cfe --- /dev/null +++ b/math/matrix_product/gen/signed_overflow.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD/2 - 1; + unsigned long long max_ll = numeric_limits::max(); + + // Find smallest size n where n * val * val > max_ll + int n = 0; + for (unsigned long long res = 0; res <= max_ll; res += (long long) val * val, ++n); + + cout << n << ' ' << n << ' ' << n << '\n'; + + for (int x = 0; x < 2; ++ x) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + } + + return 0; +} diff --git a/math/matrix_product/gen/unsigned_overflow.cpp b/math/matrix_product/gen/unsigned_overflow.cpp new file mode 100644 index 000000000..958ca7432 --- /dev/null +++ b/math/matrix_product/gen/unsigned_overflow.cpp @@ -0,0 +1,36 @@ + + +#include +#include +#include + +#include "random.h" +#include "../params.h" + +using namespace std; + +int main() { + int val = MOD - 2; + + // Find smallest size n where n * val * val > numeric_limits::max() + int n = 0; + unsigned long long res = 0; + long long val2 = (long long) val * val; + while (res + val2 >= res) // Check if adding val2 to res will overflow + { + res += val2; + ++n; + } + + cout << n << ' ' << n << ' ' << n << '\n'; + + for (int x = 0; x < 2; ++ x) { + for (int i = 0; i < n; ++i) { + for (int j = 0; j < n; ++j) { + cout << val << ((j == n - 1) ? '\n' : ' '); + } + } + } + + return 0; +} diff --git a/math/matrix_product/hash.json b/math/matrix_product/hash.json index 24cdea776..aa26a1ec3 100644 --- a/math/matrix_product/hash.json +++ b/math/matrix_product/hash.json @@ -17,6 +17,8 @@ "random_01.out": "4ef65f035039f0fd63ae521bba25619bad11494fb229b66191284b2cb34a3dec", "random_02.in": "16782d756ecfdfde27f21e2614c9446fc65c47cc578897f4356c1b072f03b7e9", "random_02.out": "799daed7d7de965b9d63e9c0476989b56ae04d7ad5f7bb96c0c65e2ccd9e0feb", + "signed_overflow_00.in": "0b457f1e9a77c727e5fbd4034a108524db6cd5556da0f901c22e36a98e96ea49", + "signed_overflow_00.out": "cd218dd338883d7d1f17c756e60150e8a2cd2c93c7c738e459680960756dd874", "small_00.in": "c506b9318ae8fe3d509d3803dcf002663dacaf29e0b911469555fabbf12b03c1", "small_00.out": "5a75afe0b109984b1bba130182ba7dabe5824ec9b72e22e8f2a0a36006bd449b", "small_01.in": "aa708d518bfcf05abc641673bdd27b8ff372c0a57498f4a0cb2387b4270b3e51", @@ -36,5 +38,7 @@ "small_08.in": "eaf46a03f81de5d76f06ad46be7af75a8ec84261a90cd57b349d5a217cabe3eb", "small_08.out": "31681f7cb21d37bc85310b6699eb020cf7091082f0876b4b449020adfa0a97c0", "small_09.in": "a5b051bd88e93503771c9681352029cb501aba6ff34136ae571ac148075d781d", - "small_09.out": "2b456d5070b924b76d31b85945eb42362918491c0c7e2e8aedb4e3941563acfa" + "small_09.out": "2b456d5070b924b76d31b85945eb42362918491c0c7e2e8aedb4e3941563acfa", + "unsigned_overflow_00.in": "b30d8bfb1e59cc60670096505b5eda866052fd8e839244263da5f75f108aeb9a", + "unsigned_overflow_00.out": "b776f9584be10a2f16b3fc22111c6123ddf89a4b6b6058e7a9cec320c2b6a6ab" } \ No newline at end of file diff --git a/math/matrix_product/info.toml b/math/matrix_product/info.toml index 6759488bb..34ccb7227 100644 --- a/math/matrix_product/info.toml +++ b/math/matrix_product/info.toml @@ -14,6 +14,12 @@ forum = "https://github.com/yosupo06/library-checker-problems/issues/654" [[tests]] name = "small.cpp" number = 10 +[[tests]] + name = "signed_overflow.cpp" + number = 1 +[[tests]] + name = "unsigned_overflow.cpp" + number = 1 [params] N_MAX = 1_024 diff --git a/math/stern_brocot_tree/task.md b/math/stern_brocot_tree/task.md index cdb1932ec..03cfbd361 100644 --- a/math/stern_brocot_tree/task.md +++ b/math/stern_brocot_tree/task.md @@ -5,19 +5,15 @@ The following are true for all problems. - Positive rational number in input/output is represented by irreducible fraction $a/b$. - Positive rational numbers are identified with nodes in Stern–Brocot Tree (SBT). -- If a node $a/b$ of SBT appears in **input**, $a, b$ satisfies following constraints: - - $1\leq a \leq @{param.TARGET_FRAC_MAX}$ - - $1\leq b \leq @{param.TARGET_FRAC_MAX}$ - - $a$ and $b$ are coprime. +- If a node $a/b$ of SBT appears in **input**, $a, b$ satisfies following constraints: $1\leq a \leq @{param.TARGET_FRAC_MAX}$ , $1\leq b \leq @{param.TARGET_FRAC_MAX}$ , $a$ and $b$ are coprime. + @{lang.ja} 次の項目は以下のすべての問題で共通します: - 入出力に現れる正の有理数は、既約分数 $a/b$ で表します。 - $0$ より大きい有理数と、 Stern–Brocot Tree (SBT) のノードを同一視します。 -- SBT のノード $a/b$ が **入力** に現れる場合、次の制約が付きます。 - - $1\leq a \leq @{param.TARGET_FRAC_MAX}$ - - $1\leq b \leq @{param.TARGET_FRAC_MAX}$ - - $a$ と $b$ は互いに素 +- SBT のノード $a/b$ が **入力** に現れる場合、次の制約が付きます。 $1\leq a \leq @{param.TARGET_FRAC_MAX}$ , $1\leq b \leq @{param.TARGET_FRAC_MAX}$ , $a$ と $b$ は互いに素 + @{lang.end} @{lang.en} @@ -26,126 +22,146 @@ $T$ problems related to SBT in the following list are given. Stern–Brocot Tree に関して、次のリストに含まれる問題が合計 $T$ 個与えられます。 @{lang.end} -- ENCODE_PATH - - @{lang.ja} - $1/1$ から $a/b$ までの SBT におけるパスを、左の子に向かう移動を `L` 、右の子に向かう移動を `R` とした文字列で表します。この文字列を連長圧縮して、次の形式で出力してください。 - @{lang.en} - Represent the path from $1/1$ to $a/b$ in SBT as a string, using `L` for leftward move and `R` for rightward move. - Compress the string using run-length encoding and output it in the following format. - @{lang.end} - ``` - $k$ $c_0$ $n_0$ $c_1$ $n_1$ $\ldots$ $c_{k-1}$ $n_{k-1}$ - ``` - - @{lang.ja} - $c_i$ は `L` または `R` で、$n_i$ は $c_i$ が連続して並ぶ回数を表す正整数です。 - @{lang.en} - Here, $c_i$ is `L` or `R`, and $n_i$ is a positive integer representing the number of consecutive $c_i$s. - @{lang.end} - - - @{keyword.input} - ``` - ENCODE_PATH $a$ $b$ - ``` - - - @{keyword.output} - ``` - $k$ $c_0$ $n_0$ $c_1$ $n_1$ $\ldots$ $c_{k-1}$ $n_{k-1}$ - ``` - -- DECODE_PATH - - @{lang.ja} - $1/1$ から $a/b$ までのパスが ENCODE_PATH の形式で与えられるので、$a$ , $b$ を出力してください。 - @{lang.en} - The path from $1/1$ to $a/b$ is given in the format of ENCODE_PATH. - Print $a, b$. - @{lang.end} - - - @{keyword.constraints} - - @{lang.ja} - - $c_i\neq c_{i+1}$ - - $1\leq n_i\leq 10^9$ - - 正しい出力において $1\leq a\leq 10^9$ および $1\leq b\leq 10^9$ となることが保証される - @{lang.en} - - $c_i\neq c_{i+1}$ - - $1\leq n_i\leq 10^9$ - - It is guaranteed that the answer satisfies $1\leq a\leq 10^9$ and $1\leq b\leq 10^9$. - @{lang.end} - - - @{keyword.input} - ``` - DECODE_PATH $k$ $c_0$ $n_0$ $c_1$ $n_1$ $\ldots$ $c_{k-1}$ $n_{k-1}$ - ``` - - - @{keyword.output} - ``` - $a$ $b$ - ``` - -- LCA - @{lang.ja} - $a/b$ と $c/d$ の LCA $f/g$ を求め、出力してください。 - @{lang.en} - Print the LCA $f/g$ of $a/b$ and $c/d$. - @{lang.end} - - - @{keyword.input} - ``` - LCA $a$ $b$ $c$ $d$ - ``` - - - @{keyword.output} - ``` - $f$ $g$ - ``` - -- ANCESTOR - - @{lang.ja} - $a/b$ の祖先であって深さが $k$ のノード $f/g$ を出力してください。存在しなければ代わりに `-1` とだけ出力してください。 - @{lang.en} - Print the ancestor $f/g$ of $a/b$ with depth $k$. If it does not exists, just print `-1`. - @{lang.end} - - - @{keyword.constraints} - - - $@{param.K_MIN_ANCESTOR} \leq k\leq @{param.K_MAX_ANCESTOR}$ - - - @{keyword.input} - ``` - ANCESTOR $k$ $a$ $b$ - ``` - - - @{keyword.output} - - ``` - $f$ $g$ - ``` - -- RANGE - - @{lang.ja} - 頂点 a/b の子孫の集合は、ある有理数開区間です。その下限 $f/g$ と上限 $h/k$ を出力してください。ただし、 $+\infty$ の場合は `1 0` 、 $0$ の場合は `0 1` と出力してください。 - @{lang.en} - The set of descendants of a/b forms an open interval of rational numbers. - Print the infimum $f/g$ and the supremum $h/k$ of the interval. - Exceptionally, print `0 1` for a $0$ , `1 0` for a $+\infty$ . - @{lang.end} - - - @{keyword.input} - - ``` - RANGE $a$ $b$ - ``` - - - @{keyword.output} - - ``` - $f$ $g$ $h$ $k$ - ``` +---- + +### ENCODE_PATH + +@{lang.ja} +$1/1$ から $a/b$ までの SBT におけるパスを、左の子に向かう移動を `L` 、右の子に向かう移動を `R` とした文字列で表します。この文字列を連長圧縮して、次の形式で出力してください。 +@{lang.en} +Represent the path from $1/1$ to $a/b$ in SBT as a string, using `L` for leftward move and `R` for rightward move. +Compress the string using run-length encoding and output it in the following format. +@{lang.end} + +``` +$k$ $c_0$ $n_0$ $c_1$ $n_1$ $\ldots$ $c_{k-1}$ $n_{k-1}$ +``` + +@{lang.ja} +$c_i$ は `L` または `R` で、$n_i$ は $c_i$ が連続して並ぶ回数を表す正整数です。 +@{lang.en} +Here, $c_i$ is `L` or `R`, and $n_i$ is a positive integer representing the number of consecutive $c_i$s. +@{lang.end} + +#### @{keyword.input} + +``` +ENCODE_PATH $a$ $b$ +``` + +#### @{keyword.output} + +``` +$k$ $c_0$ $n_0$ $c_1$ $n_1$ $\ldots$ $c_{k-1}$ $n_{k-1}$ +``` + +---- + +### DECODE_PATH + +@{lang.ja} +$1/1$ から $a/b$ までのパスが ENCODE_PATH の形式で与えられるので、$a$ , $b$ を出力してください。 +@{lang.en} +The path from $1/1$ to $a/b$ is given in the format of ENCODE_PATH. +Print $a, b$. +@{lang.end} + +#### @{keyword.constraints} + +@{lang.ja} +- $c_i\neq c_{i+1}$ +- $1\leq n_i\leq 10^9$ +- 正しい出力において $1\leq a\leq 10^9$ および $1\leq b\leq 10^9$ となることが保証される +@{lang.en} +- $c_i\neq c_{i+1}$ +- $1\leq n_i\leq 10^9$ +- It is guaranteed that the answer satisfies $1\leq a\leq 10^9$ and $1\leq b\leq 10^9$. +@{lang.end} + +#### @{keyword.input} + +``` +DECODE_PATH $k$ $c_0$ $n_0$ $c_1$ $n_1$ $\ldots$ $c_{k-1}$ $n_{k-1}$ +``` + +#### @{keyword.output} + +``` +$a$ $b$ +``` + +---- + +### LCA +@{lang.ja} +$a/b$ と $c/d$ の LCA $f/g$ を求め、出力してください。 +@{lang.en} +Print the LCA $f/g$ of $a/b$ and $c/d$. +@{lang.end} + +#### @{keyword.input} + +``` +LCA $a$ $b$ $c$ $d$ +``` + +#### @{keyword.output} + +``` +$f$ $g$ +``` + +---- + +### ANCESTOR + +@{lang.ja} +$a/b$ の祖先であって深さが $k$ のノード $f/g$ を出力してください。存在しなければ代わりに `-1` とだけ出力してください。 +@{lang.en} +Print the ancestor $f/g$ of $a/b$ with depth $k$. If it does not exists, just print `-1`. +@{lang.end} + +#### @{keyword.constraints} + +- $@{param.K_MIN_ANCESTOR} \leq k\leq @{param.K_MAX_ANCESTOR}$ + +#### @{keyword.input} + +``` +ANCESTOR $k$ $a$ $b$ +``` + +#### @{keyword.output} + +``` +$f$ $g$ +``` + +---- + +### RANGE + +@{lang.ja} +頂点 a/b の子孫の集合は、ある有理数開区間です。その下限 $f/g$ と上限 $h/k$ を出力してください。ただし、 $+\infty$ の場合は `1 0` 、 $0$ の場合は `0 1` と出力してください。 +@{lang.en} +The set of descendants of a/b forms an open interval of rational numbers. +Print the infimum $f/g$ and the supremum $h/k$ of the interval. +Exceptionally, print `0 1` for a $0$ , `1 0` for a $+\infty$ . +@{lang.end} + +#### @{keyword.input} + +``` +RANGE $a$ $b$ +``` + +#### @{keyword.output} + +``` +$f$ $g$ $h$ $k$ +``` + +---- ## @{keyword.constraints} diff --git a/problem.py b/problem.py index 49af3565d..b2ac32851 100644 --- a/problem.py +++ b/problem.py @@ -23,7 +23,7 @@ logger = getLogger(__name__) # type: Logger CASENAME_LEN_LIMIT = 40 -STACK_SIZE = 2 ** 31 # 2GB +STACK_SIZE = 2 ** 28 # 256 MB def casename(name: Union[str, Path], i: int) -> str: