diff --git a/LibreOJ/2221/2221.cpp b/LibreOJ/2221/2221.cpp new file mode 100644 index 00000000..314909bb --- /dev/null +++ b/LibreOJ/2221/2221.cpp @@ -0,0 +1,58 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e6 + 5; + +int n, s_a, s_b, s_c, s_d, a[N], b[N], mod, ans; + +inline int f(int x) { + return (static_cast(s_a) % mod * x % mod * x % mod * x % mod + + static_cast(s_b) % mod * x % mod * x % mod + + static_cast(s_c) % mod * x % mod + + s_d) + % mod; +} + +bool check(int x) { + std::copy_n(a + 1, n, b + 1); + + for (int i = 1; i <= n; i++) { + b[i] = std::max(b[i - 1], b[i] - x); + + if (std::abs(a[i] - b[i]) > x) return false; + } + + return true; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> s_a >> s_b >> s_c >> s_d >> a[1] >> mod; + + for (int i = 2; i <= n; i++) { + a[i] = (f(a[i - 1]) + f(a[i - 2])) % mod; + } + + int l = 0, r = mod; + + while (l <= r) { + int mid = l + r >> 1; + + if (check(mid)) { + ans = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + + cout << ans << endl; + + return 0; +} diff --git a/LibreOJ/2221/data/musique1.in b/LibreOJ/2221/data/musique1.in new file mode 100644 index 00000000..3ed322d1 --- /dev/null +++ b/LibreOJ/2221/data/musique1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:785c778307f79a68b9d27a81d049be9ddef9dd42e12a695af23d4d1488f62643 +size 31 diff --git a/LibreOJ/2221/data/musique1.out b/LibreOJ/2221/data/musique1.out new file mode 100644 index 00000000..aa248abe --- /dev/null +++ b/LibreOJ/2221/data/musique1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c103df72e15cf510fd1acdd2fa2e71fdb7fb3ebf72441fd79d8aa1bee87169fd +size 4 diff --git a/LibreOJ/2221/data/musique10.in b/LibreOJ/2221/data/musique10.in new file mode 100644 index 00000000..aeddfc52 --- /dev/null +++ b/LibreOJ/2221/data/musique10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfa784dc3307878c75b5c2c6bbf2150608513ef83b86a15db1eb3c567d4513cb +size 39 diff --git a/LibreOJ/2221/data/musique10.out b/LibreOJ/2221/data/musique10.out new file mode 100644 index 00000000..6c7dab11 --- /dev/null +++ b/LibreOJ/2221/data/musique10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5e7e1cf971a9714c9d95294db07922f3d74ec38996b50106965ade4eccb82f2 +size 9 diff --git a/LibreOJ/2221/data/musique2.in b/LibreOJ/2221/data/musique2.in new file mode 100644 index 00000000..a47de0cc --- /dev/null +++ b/LibreOJ/2221/data/musique2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d90eb797f99f7b59cad65a3e1f800689638a43311fad84b277a06f909560d1bb +size 30 diff --git a/LibreOJ/2221/data/musique2.out b/LibreOJ/2221/data/musique2.out new file mode 100644 index 00000000..ea4d1ccb --- /dev/null +++ b/LibreOJ/2221/data/musique2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:80d1f44e05395f8b79fe2caf1964a0e50a4e24899f80e5d40bc8364886c744a1 +size 4 diff --git a/LibreOJ/2221/data/musique3.in b/LibreOJ/2221/data/musique3.in new file mode 100644 index 00000000..4471452b --- /dev/null +++ b/LibreOJ/2221/data/musique3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9b712c0490d057bd59163ec73f1bdfe54bcf6dc98ab22973cb32d19b43ba1cb +size 31 diff --git a/LibreOJ/2221/data/musique3.out b/LibreOJ/2221/data/musique3.out new file mode 100644 index 00000000..573c1a16 --- /dev/null +++ b/LibreOJ/2221/data/musique3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9189d4def691cd317d871315016ff15c1740da04c36bc4f0400ec908d96e974c +size 4 diff --git a/LibreOJ/2221/data/musique4.in b/LibreOJ/2221/data/musique4.in new file mode 100644 index 00000000..499abaec --- /dev/null +++ b/LibreOJ/2221/data/musique4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:17fd12a997f0480da43777627b877b2612bd71dba7d39a850fec498588002f77 +size 32 diff --git a/LibreOJ/2221/data/musique4.out b/LibreOJ/2221/data/musique4.out new file mode 100644 index 00000000..febc3fc5 --- /dev/null +++ b/LibreOJ/2221/data/musique4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0709e1008834c2ca8648376ac62d74ac8df5457069cbfedf2b0776dab07a3c5b +size 4 diff --git a/LibreOJ/2221/data/musique5.in b/LibreOJ/2221/data/musique5.in new file mode 100644 index 00000000..689d107a --- /dev/null +++ b/LibreOJ/2221/data/musique5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:feaf0ef0f88a9c95b70791e689ec83fe2f4ca7ebbbcd7f837668e53454f49dcd +size 32 diff --git a/LibreOJ/2221/data/musique5.out b/LibreOJ/2221/data/musique5.out new file mode 100644 index 00000000..b1a08fb7 --- /dev/null +++ b/LibreOJ/2221/data/musique5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da2adacc2e9310db8ea01e830d6cb878d3599f09acb3967690f982d8bd16b980 +size 4 diff --git a/LibreOJ/2221/data/musique6.in b/LibreOJ/2221/data/musique6.in new file mode 100644 index 00000000..2d515171 --- /dev/null +++ b/LibreOJ/2221/data/musique6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2130488b8ce75b72180bd057bb2ee78f26f749542b7d7c520e1d8e138276c45 +size 39 diff --git a/LibreOJ/2221/data/musique6.out b/LibreOJ/2221/data/musique6.out new file mode 100644 index 00000000..cb72f2b4 --- /dev/null +++ b/LibreOJ/2221/data/musique6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c78444a2263e1dd96eb80fe94070a496b62907abc04ea0345845e91ec7e582e5 +size 9 diff --git a/LibreOJ/2221/data/musique7.in b/LibreOJ/2221/data/musique7.in new file mode 100644 index 00000000..d11467be --- /dev/null +++ b/LibreOJ/2221/data/musique7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10f0edc738966ec949b169b4107102f9c9b18f716acb63a237aff8b80ce1cfbd +size 39 diff --git a/LibreOJ/2221/data/musique7.out b/LibreOJ/2221/data/musique7.out new file mode 100644 index 00000000..6f26e4be --- /dev/null +++ b/LibreOJ/2221/data/musique7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f517867a6dcacc4e7dee2e70ce99aa9c2b591fe8bcf7f8bec5510a810f82b0e +size 9 diff --git a/LibreOJ/2221/data/musique8.in b/LibreOJ/2221/data/musique8.in new file mode 100644 index 00000000..ec70e7a7 --- /dev/null +++ b/LibreOJ/2221/data/musique8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:21710c870d81ef74d43bed1f4a31e7beac73b4b4b7dd13d64a54e11dec6b0762 +size 38 diff --git a/LibreOJ/2221/data/musique8.out b/LibreOJ/2221/data/musique8.out new file mode 100644 index 00000000..85030aaa --- /dev/null +++ b/LibreOJ/2221/data/musique8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6d50cb8c04ce4b1aa0e13a10d668c214355f4a4bafb8073a987e073b02fa25f +size 9 diff --git a/LibreOJ/2221/data/musique9.in b/LibreOJ/2221/data/musique9.in new file mode 100644 index 00000000..fa371e96 --- /dev/null +++ b/LibreOJ/2221/data/musique9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5757212f010b57e99dc6eff4e73ce2ae81b73b2a45511d3beeb9a2f3fdeb3e71 +size 39 diff --git a/LibreOJ/2221/data/musique9.out b/LibreOJ/2221/data/musique9.out new file mode 100644 index 00000000..e5018fac --- /dev/null +++ b/LibreOJ/2221/data/musique9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01b730f58739bcdd35e7bf682ee1a2a32f631c126d3740e834ae3484fd8b51ee +size 9