QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#635678 | #9451. Expected Waiting Time | ucup-team3670# | AC ✓ | 984ms | 48776kb | C++20 | 3.2kb | 2024-10-12 20:34:46 | 2024-10-12 20:34:46 |
Judging History
answer
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
using namespace std;
const int N = int(2e7) + 15;
int n, p, b0, A, B;
bool read(){
if (!(cin >> n >> p >> b0 >> A >> B))
return false;
return true;
}
int add(int a, int b){
long long res = a + 0ll + b;
if (res >= p) res -= p;
if (res < 0) res += p;
return res;
}
int mul(int a, int b){
return a * 1ll * b % p;
}
int binpow(int a, int b){
int res = 1;
while (b){
if (b & 1)
res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
vector<int> a;
int ans, cnt;
void brute(int i, int bal, int cur){
if (i == 2 * n){
if (bal == 0){
cnt = add(cnt, 1);
ans = add(ans, cur);
}
return;
}
brute(i + 1, bal + 1, add(cur, -a[i]));
if (bal > 0) brute(i + 1, bal - 1, add(cur, a[i]));
}
vector<int> fact, rfact;
void init(){
fact.resize(2 * n + 1);
fact[0] = 1;
fore(i, 1, 2 * n + 1)
fact[i] = mul(fact[i - 1], i);
rfact.resize(2 * n + 1);
rfact[2 * n] = binpow(fact[2 * n], p - 2);
for (int i = 2 * n - 1; i >= 0; --i)
rfact[i] = mul(rfact[i + 1], i + 1);
}
int cnk(int n, int k){
if (k < 0 || n < 0 || k > n) return 0;
return mul(fact[n], mul(rfact[k], rfact[n - k]));
}
int cat(int n){
if (n < 0) return 0;
return mul(fact[2 * n], mul(rfact[n], rfact[n + 1]));
}
void solve(){
init();
int b = b0;
a.assign(2 * n + 1, 0);
fore(i, 1, 2 * n + 1){
b = add(mul(A, b), B);
a[i] = add(a[i - 1], add(b, 1));
}
a.erase(a.begin());
vector<int> na;
//int ans = 0;
int sum = 0;
forn(i, n){
sum = add(sum, mul(cat(i), cat(n - 1 - i)));
na.push_back(sum);
na.push_back(sum);
}
na.pop_back();
reverse(na.begin(), na.end());
na.resize(n);
//for (int x : na) cerr << x << " ";
//cerr << endl;
forn(i, n){
int cl = add(cat(n), -na[i]);
na[i] = add(cl, -na[i]);
}
//for (int &x : na) x = add(0, -x);
forn(i, n) na.push_back(add(0, -na[n - 1 - i]));
//for (int x : na) cerr << x << " ";
//cerr << endl;
// int cl = add(cat(n), -op);
// ans = add(ans, )
//}
/*for (int i = 0; i < n; i += 2){
int sum = 0;//cat(n);
for (int len = 0; i + 2 + 2 * len <= 2 * n; ++len){
//sum = add(sum, -mul(cat(i / 2), mul(cat((2 * n - 2 * len - 2 - i) / 2), cat(len))));
//sum = add(sum, -mul(cat(len), cat(n - len - 1)));
sum = add(sum, mul(cat(i / 2), mul(cat((2 * n - 2 * len - 2 - i) / 2), cat(len))));
}
cerr << sum << " ";
}
cerr << endl;*/
/*vector<vector<int>> dp(2 * n + 1, vector<int>(2 * n + 1, 0));
dp[0][0] = 1;
forn(i, 2 * n){
forn(j, i + 1){
dp[i + 1][j + 1] = add(dp[i + 1][j + 1], dp[i][j]);
if (j > 0) dp[i + 1][j - 1] = add(dp[i + 1][j - 1], dp[i][j]);
}
}
forn(i, n * 2){
//cerr << add(cat(n), -dp[2 * n - i][i]) << " ";
cerr << dp[2 * n - i][i] << " ";
}
cerr << endl;*/
int ans = 0;
forn(i, 2 * n) ans = add(ans, mul(a[i], na[i]));
ans = mul(ans, binpow(cat(n), p - 2));
cout << ans << "\n";
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--){
read();
solve();
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
5 1 1000000007 0 1 0 2 1000000007 0 1 1 2 7 5 2 3 3 31 15 6 24 20 1000000007 0 1 0
output:
1 12 1 21 879705565
result:
ok 5 number(s): "1 12 1 21 879705565"
Test #2:
score: 0
Accepted
time: 866ms
memory: 3772kb
input:
4400 3954 1000000007 0 1 0 1306 1000000007 0 1 0 3774 1000000007 0 1 0 3345 1000000007 0 1 0 891 1000000007 0 1 0 2462 1000000007 0 1 0 237 1000000007 0 1 0 26 1000000007 0 1 0 2510 1000000007 0 1 0 637 1000000007 0 1 0 3250 1000000007 0 1 0 3447 1000000007 0 1 0 1222 1000000007 0 1 0 133 1000000007...
output:
440618338 378292891 979368645 915766295 343598158 80867595 161627927 517387931 396936703 42785642 945720545 764273281 186237656 635777911 164064906 548455037 991964184 468137124 561243246 118562285 856945294 642467240 23673926 808943705 897417615 462422554 656411244 204288121 997894281 244685651 762...
result:
ok 4400 numbers
Test #3:
score: 0
Accepted
time: 977ms
memory: 48776kb
input:
1019 338 1863833207 1820742817 1507924477 1822273457 770 1386304741 1088481071 1216187083 170973217 597 1604266739 620750027 196415899 456280997 105 1008587891 184044403 24836083 926135599 357 1165127407 440925347 1103369747 912263123 82 1639766993 263045351 631010551 1412721139 928 1715915153 25383...
output:
1532578211 839037587 1047387343 827110887 825754860 1399761197 267796211 1563605211 1628148612 510782452 1009499206 977929696 466163317 246777775 1781337180 700999207 522771237 42312781 172374583 319038379 563256698 1400403161 22552986 1408276343 558752169 1050819260 174447415 844160548 1382940913 1...
result:
ok 1019 numbers
Test #4:
score: 0
Accepted
time: 984ms
memory: 7516kb
input:
217 31752 1623636743 381890923 885513569 842557939 44560 1671300349 1133398261 1076377361 138151151 98395 1887613031 1552853849 1167776639 1748368931 38388 1221893927 524645339 598717199 864504559 46484 1161165839 833729009 348202331 407607601 14134 1500136753 247946861 1029519499 420912461 42361 12...
output:
921943129 1651287678 1204818336 685557670 348324702 1348834532 684106754 1802861733 294146103 1181847835 393402724 771264676 1357541910 336262290 1519052686 965265375 164416232 536332209 664177339 279762508 172270575 296113856 676553568 56580590 1662307723 551032870 849878353 899756098 1043540760 65...
result:
ok 217 numbers
Test #5:
score: 0
Accepted
time: 984ms
memory: 7452kb
input:
209 29771 1072350767 215063557 929759989 884416571 55201 1330151437 375869047 1089916759 1006803043 44446 1255569503 974485139 1100573447 468049237 38112 1088575729 690554509 139043089 318478729 59665 1197676111 958924997 1062562733 504417349 26297 1267535141 800679281 972314209 417253079 19848 1470...
output:
1019773842 530587777 960231793 799694163 777561611 5502176 357632543 758954057 966358573 1023410809 949841520 1495179331 1580320049 173875471 2220116 469298866 1337750009 369625733 747522220 143937247 1286370836 135996013 210044979 1583248565 657653951 1035620126 160616212 193166047 147168296 194451...
result:
ok 209 numbers
Test #6:
score: 0
Accepted
time: 981ms
memory: 7748kb
input:
191 4581 1215490597 542057431 695641117 341312327 76198 1830024701 1063458349 588883499 1260572737 76694 1445111947 1069466003 941483509 268919069 92431 1384691513 15731591 390776461 943271249 63234 1097808793 204272807 857954509 763222181 26427 1746295877 743699191 1671886939 1655403307 91012 19997...
output:
660812054 1707568418 155249600 645552623 671226426 50129037 971925203 1638809868 463571080 143058581 403506184 767222482 666935871 1092771100 416048275 1536775747 475955650 73199758 578511368 51576569 1380151783 515363742 1021989523 892069331 1088408017 1337534689 715624643 1241212077 730954505 1286...
result:
ok 191 numbers
Extra Test:
score: 0
Extra Test Passed