diff --git a/BZOJ/3613/3613.cpp b/BZOJ/3613/3613.cpp new file mode 100644 index 00000000..314909bb --- /dev/null +++ b/BZOJ/3613/3613.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/BZOJ/3613/data/1.in b/BZOJ/3613/data/1.in new file mode 100644 index 00000000..af183b48 --- /dev/null +++ b/BZOJ/3613/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9c8ab687cf64b658d2e6c3f988fc1c9235a9586c27c859f40bd6b483f6103a2 +size 39 diff --git a/BZOJ/3613/data/1.out b/BZOJ/3613/data/1.out new file mode 100644 index 00000000..60699984 --- /dev/null +++ b/BZOJ/3613/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9091e1fa036b34b55f7d86a231cfbe8efce7cbec39dda8068dd642bdb4df3a81 +size 10 diff --git a/BZOJ/3613/data/10.in b/BZOJ/3613/data/10.in new file mode 100644 index 00000000..dda64d5f --- /dev/null +++ b/BZOJ/3613/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28710e45b5cff13fe87621bc04808150a9d30cd2455a7e280d7f674a0d4828dd +size 40 diff --git a/BZOJ/3613/data/10.out b/BZOJ/3613/data/10.out new file mode 100644 index 00000000..21625a75 --- /dev/null +++ b/BZOJ/3613/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f9cc96bfd01a471b718df64a96ed9e8930c2e11b8dd07e5ba01c7cab17881f9 +size 10 diff --git a/BZOJ/3613/data/2.in b/BZOJ/3613/data/2.in new file mode 100644 index 00000000..2230fd12 --- /dev/null +++ b/BZOJ/3613/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4106e7b7178c65fada7b9f770b63cae5ae70e7b27b1b6d4ef7edf7b1978f55a2 +size 33 diff --git a/BZOJ/3613/data/2.out b/BZOJ/3613/data/2.out new file mode 100644 index 00000000..b4baac6e --- /dev/null +++ b/BZOJ/3613/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9dba73bd011adcb2fde0a27b0c4c1cc78a5564dc3f9671059944d0afd38caa35 +size 5 diff --git a/BZOJ/3613/data/3.in b/BZOJ/3613/data/3.in new file mode 100644 index 00000000..433e33a5 --- /dev/null +++ b/BZOJ/3613/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66010dbc70336961f530945d0dda0e70f1adbbad82df8f96b2732e9f4431521e +size 40 diff --git a/BZOJ/3613/data/3.out b/BZOJ/3613/data/3.out new file mode 100644 index 00000000..fef2766e --- /dev/null +++ b/BZOJ/3613/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e38cab11a368f0101d2836105294f897ce996b30618b1957249dede11acfa02d +size 10 diff --git a/BZOJ/3613/data/4.in b/BZOJ/3613/data/4.in new file mode 100644 index 00000000..61329f64 --- /dev/null +++ b/BZOJ/3613/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3edee0fc875ed48a2aa1cc39629bf1087574be019f5e4849e99a9110bf62dd9c +size 32 diff --git a/BZOJ/3613/data/4.out b/BZOJ/3613/data/4.out new file mode 100644 index 00000000..c54eb219 --- /dev/null +++ b/BZOJ/3613/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3938c3f84296d36eea2c5047f1ef699ef71273e5833b8a9c958b1c8cc5b139b6 +size 5 diff --git a/BZOJ/3613/data/5.in b/BZOJ/3613/data/5.in new file mode 100644 index 00000000..9b9efa7d --- /dev/null +++ b/BZOJ/3613/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fc0d6ff111e5fd848c5747363a82874c6a59975412f6f4ec4d408efb4734e88 +size 33 diff --git a/BZOJ/3613/data/5.out b/BZOJ/3613/data/5.out new file mode 100644 index 00000000..17deb15e --- /dev/null +++ b/BZOJ/3613/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e42225a4f9e996f347ab1bc85fde28ddc7c659f1e7bfcb3ebba0e353d5784d83 +size 5 diff --git a/BZOJ/3613/data/6.in b/BZOJ/3613/data/6.in new file mode 100644 index 00000000..a13c6de2 --- /dev/null +++ b/BZOJ/3613/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58b1d1e66df3c06ea91543773f6a21f8ac9a2333b8358e25841aaab46d49a475 +size 31 diff --git a/BZOJ/3613/data/6.out b/BZOJ/3613/data/6.out new file mode 100644 index 00000000..eb366ed8 --- /dev/null +++ b/BZOJ/3613/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcad85d19d59ecfcf1a99d99f8d2022667ccbbb7bb0f91b42f5ac54d8377e669 +size 5 diff --git a/BZOJ/3613/data/7.in b/BZOJ/3613/data/7.in new file mode 100644 index 00000000..dca0373f --- /dev/null +++ b/BZOJ/3613/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:874249cd1f9500c1b77eb18123dacb0a5c39bd7fe10af26bb8840b38cb081c38 +size 32 diff --git a/BZOJ/3613/data/7.out b/BZOJ/3613/data/7.out new file mode 100644 index 00000000..0f6f1916 --- /dev/null +++ b/BZOJ/3613/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:990cd719b205611a74fbd3e318e1b22b1b185c93e159dea0a603f9fc5e850053 +size 5 diff --git a/BZOJ/3613/data/8.in b/BZOJ/3613/data/8.in new file mode 100644 index 00000000..f6c3489a --- /dev/null +++ b/BZOJ/3613/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57b954d829dfdd6a479620bf15b92f99a7a21151057d0b8c4348e9615fe6dbce +size 40 diff --git a/BZOJ/3613/data/8.out b/BZOJ/3613/data/8.out new file mode 100644 index 00000000..87fbafbc --- /dev/null +++ b/BZOJ/3613/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cf1f814656d0b0ad58468a4a4b9d92111f7431d0a48df1622656ef4d6832169 +size 10 diff --git a/BZOJ/3613/data/9.in b/BZOJ/3613/data/9.in new file mode 100644 index 00000000..870aea52 --- /dev/null +++ b/BZOJ/3613/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1074e689b9b1143c4de84deb5166bfcb3f0694dfcfe3113d86a197244c14eb78 +size 40 diff --git a/BZOJ/3613/data/9.out b/BZOJ/3613/data/9.out new file mode 100644 index 00000000..940d7fae --- /dev/null +++ b/BZOJ/3613/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea2df7b4f18cba38137ba82bfb244996d786b8cb69ef5387ece1d840bfb65588 +size 10