mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 14:56:27 +00:00
2976. [Poi2002]出圈游戏
https://hydro.ac/d/bzoj/record/63a45f32cf75a716a1673915
This commit is contained in:
parent
cf4ca87591
commit
db8ac77963
68
BZOJ/2976/2976.cpp
Normal file
68
BZOJ/2976/2976.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 25;
|
||||||
|
|
||||||
|
int n, a[N], p[N], d[N], m[N];
|
||||||
|
|
||||||
|
long long exgcd(long long a, long long b, long long& x, long long& y) {
|
||||||
|
if (!b) {
|
||||||
|
x = 1;
|
||||||
|
y = 0;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
long long g = exgcd(b, a % b, y, x);
|
||||||
|
y -= a / b * x;
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> a[i];
|
||||||
|
|
||||||
|
p[a[i]] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = p[i - 1]; j != p[i]; j = j == n ? 1 : j + 1) {
|
||||||
|
if (a[j] > i) d[i]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
m[i] = n - i + 1;
|
||||||
|
d[i] = (d[i] + 1) % m[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
long long res = d[1], lcm = m[1];
|
||||||
|
for (int i = 2; i <= n; i++) {
|
||||||
|
long long x, y,
|
||||||
|
g = exgcd(lcm, m[i], x, y),
|
||||||
|
c = ((d[i] - res) % m[i] + m[i]) % m[i],
|
||||||
|
m1 = m[i] / g,
|
||||||
|
m2 = lcm / g * m[i];
|
||||||
|
|
||||||
|
if (c % g) {
|
||||||
|
cout << "NIE" << endl;
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
x = (x % m[i] + m[i]) % m[i];
|
||||||
|
x = (x * c / g % m1 + m1) % m1;
|
||||||
|
res = ((lcm * x + res) % m2 + m2) % m2;
|
||||||
|
lcm = m2;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << (res ? res : lcm) << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
BZOJ/2976/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/11.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/11.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/12.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/12.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/13.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/13.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/2976/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/2976/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user