QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#848860 | #9847. Security Plan | chenxinyang2006 | AC ✓ | 332ms | 3940kb | C++23 | 4.5kb | 2025-01-09 10:16:36 | 2025-01-09 10:16:37 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
template <int P>
class mod_int
{
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const
{
Z res = 1, t = *this;
while (k)
{
if (k & 1)
res *= t;
if (k >>= 1)
t *= t;
}
return res;
}
Z &operator++()
{
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--()
{
x ? --x : x = P - 1;
return *this;
}
Z operator++(int)
{
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int)
{
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs)
{
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs)
{
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z operator-()
{
return -x;
}
Z &operator*=(const Z &rhs)
{
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) \
{ \
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
friend istream& operator>>(istream& is, mod_int& x)
{
long long tmp;
is >> tmp;
x = tmp;
return is;
}
friend ostream& operator<<(ostream& os, const mod_int& x)
{
os << x.val();
return os;
}
};
using Z = mod_int<mod>;
Z power(Z p,ll k){
Z ans = 1;
while(k){
if(k % 2 == 1) ans *= p;
p *= p;
k /= 2;
}
return ans;
}
Z CC(ll n,int m){
Z answer = 1;
rep(i,1,m) answer *= n + 1 - i;
rep(i,1,m) answer /= i;
return answer;
}
Z fix2o(int n,int m){
return CC(2 * (n - 2),2);
}
Z fix2(int n,int m){
return fix2o(n,m) + fix2o(m,n);
}
Z fixo(int n,int m){
Z temp = CC(2 * (n - 2),2) * Z(1ll * n * (m - 2));
temp += CC(2 * (n - 2),3);
return temp;
}
Z fix(int n,int m){
return fixo(n,m) + fixo(m,n);
}
const Z i6 = Z(1) / 6;
Z fix3o(int n,int m){
n -= 6;
if(n < 0) return 0;
Z answer = 0;
answer += CC(n + 1,2) * (n + 1) - Z(n) * (n + 1) * (2 * n + 1) * i6;
answer *= 2 * Z(m - 2) * Z(m - 2);
return answer;
}
Z fix3(int n,int m){
return fix3o(n,m) + fix3o(m,n);
}
int T,n,m;
void solve(){
scanf("%d%d",&n,&m);
if(m == 1) swap(n,m);
if(n == 1){
if(m == 1){
printf("1\n");
return;
}
printf("%d\n",(CC(m - 2,2) + 2).val());
return;
}
Z answer = CC(1ll * (n - 2) * (m - 2),4);
answer += CC(1ll * n * m - 4,3) - CC(1ll * (n - 2) * (m - 2),3) - fix(n,m) - fix3(m,n);
// printf("%d %d %d\n",answer.val(),CC(1ll * n * m - 4,3).val(),fix(n,m).val());
answer += fix2(n,m);
answer += 4;
printf("%d\n",answer.val());
}
int main(){
#ifdef cxy
freopen("test.in","r",stdin);
#endif
scanf("%d",&T);
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
6 2 2 4 4 8 8 3 3 3 5 3 7
output:
4 129 78769 10 80 273
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
32 1 1 1 2 1 3 1 4 1 10 1 1000000000 2 1 2 2 2 3 2 4 2 11 2 1000000000 3 1 3 2 3 3 3 4 3 13 3 1000000000 4 1 4 2 4 3 4 4 4 101 4 1000000000 1000000000 1000000000 998244353 998244353 998244353 1000000000 10086 2333333 10007 1000007 5 5 100000000 99999999 100000000 999999999
output:
1 2 2 3 30 852768513 2 4 5 10 157 418096634 2 5 10 33 2202 167942187 3 10 33 129 65053470 16765744 97600132 361 767496180 544716794 658473844 916 507579369 838777510
result:
ok 32 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
100 69 34 89 48 75 22 87 3 83 39 57 75 33 51 95 27 60 77 36 89 16 41 71 15 90 100 11 55 22 6 12 27 8 90 87 30 10 66 10 77 64 72 34 59 85 10 71 69 91 26 100 26 83 7 24 40 7 26 58 18 34 78 10 76 63 53 69 34 18 88 5 74 97 23 23 5 29 7 32 33 63 10 68 90 11 42 82 52 24 71 57 43 97 100 24 96 18 62 72 49 8...
output:
844735252 345907935 28586429 2498333 488377238 942953328 487609202 6387550 705350958 854342223 681010480 891769844 675198269 144965651 1733560 160888719 226806279 351471008 848277946 378038496 869514320 719885729 71253797 881211829 821932261 570789100 117004990 276160389 8609315 766887746 62835495 9...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 4ms
memory: 3876kb
input:
1000 693 448 522 128 734 292 39 500 674 488 741 349 435 16 387 539 83 110 946 88 252 343 498 621 329 428 138 947 666 186 380 147 164 386 206 823 455 442 738 342 670 481 798 212 114 983 125 55 616 867 205 619 606 995 103 847 138 32 706 174 779 879 865 368 918 985 440 718 938 379 930 601 700 919 278 3...
output:
734353341 123938970 638720098 99480889 45755531 60438254 334240489 328423327 69642545 329776145 449587504 631740095 420016666 766086244 682367864 63393960 539316316 598272575 609449562 518346062 108580099 53857412 377251971 463895994 279595152 857916396 156295957 715834409 253131435 747142668 913120...
result:
ok 1000 numbers
Test #5:
score: 0
Accepted
time: 4ms
memory: 3884kb
input:
1000 646649471 300856132 258546501 856735895 1054383 618481963 714454302 553857681 543357466 560569528 745974354 814790544 656224737 283726575 223167186 831188152 229958118 242031417 296164244 478306773 190085456 370448866 538531088 584661972 61581579 818790042 796453827 612078408 136485445 67908120...
output:
936356743 692738897 536334664 497090628 137405835 855341208 850122060 737685630 859446507 10183890 629672738 730330292 188163195 755395630 583537380 3897190 198375879 674478313 962103461 869673891 440733315 127511280 142196279 462988628 201262486 592926610 353724472 705491421 546217368 683992452 214...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 332ms
memory: 3880kb
input:
100000 396087033 851919454 272633663 693544215 134154950 652656189 572487516 700424176 500239593 176117565 251559708 968180827 286792006 501694258 342854277 136982556 147170341 985222382 238365250 53658681 311527089 715587788 363840544 556012925 75173755 702572328 235770257 837485304 213435639 91300...
output:
680415885 854935562 574194455 239752979 295195100 862556107 205771842 157078195 246006763 849343117 738262223 518017375 317538920 755353940 788239273 725428685 37245154 128920658 785353768 417644088 581116546 308678670 173043566 614160812 266567568 383295052 349329429 980197306 869343217 717063770 7...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 324ms
memory: 3880kb
input:
100000 141 552 445 281 351 965 848 67 708 702 236 988 880 666 775 808 470 497 53 415 921 349 701 957 59 780 987 123 145 320 572 148 244 246 124 9 881 147 803 422 226 98 155 963 732 783 644 915 399 55 905 608 985 765 817 877 387 55 270 491 618 511 769 477 631 756 372 251 232 38 414 19 653 901 19 779 ...
output:
462670722 525054817 588971520 246101914 767097239 54039137 68465875 169533373 300956005 209697526 2281163 351373025 707330016 555515039 744893104 556993562 867719289 114924088 789158994 586794116 181129766 104044094 617021562 641329389 49555278 840018038 275473284 671034111 930430062 108764006 67400...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 332ms
memory: 3884kb
input:
100000 95757457 168696057 246194599 657776891 721156035 295216522 60141839 173897297 72142203 996520448 705437541 22492882 892105150 145550294 141786412 390498407 525334887 390855102 450494213 387351110 110666886 137920825 822826658 335003085 751220980 391407057 977029072 807147061 678325259 4081747...
output:
841734664 266392797 915756132 488589632 366286363 569533466 418200644 49784864 586836466 953367262 39878281 407231429 572711059 198744422 891563192 661883015 670225249 790514058 536400309 388009226 926674932 497723196 260029955 241774909 588362447 151947289 397470378 717751986 224513327 902434342 50...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 144ms
memory: 3940kb
input:
44100 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
1 2 2 3 5 8 12 17 23 30 38 47 57 68 80 93 107 122 138 155 173 192 212 233 255 278 302 327 353 380 408 437 467 498 530 563 597 632 668 705 743 782 822 863 905 948 992 1037 1083 1130 1178 1227 1277 1328 1380 1433 1487 1542 1598 1655 1713 1772 1832 1893 1955 2018 2082 2147 2213 2280 2348 2417 2487 2558...
result:
ok 44100 numbers
Test #10:
score: 0
Accepted
time: 332ms
memory: 3756kb
input:
100000 999999501 999999501 999999501 999999502 999999501 999999503 999999501 999999504 999999501 999999505 999999501 999999506 999999501 999999507 999999501 999999508 999999501 999999509 999999501 999999510 999999501 999999511 999999501 999999512 999999501 999999513 999999501 999999514 999999501 999...
output:
518655944 786085183 529126368 372145282 306767828 690124382 248361087 69617265 609292358 691801575 505308951 603482994 907252332 704805713 648080711 756275020 415846454 377001653 757207377 42946153 80938040 88674511 647395865 707358168 582566312 952529662 865773350 734571334 338457692 820715328 6953...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
64 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8
output:
1 2 2 3 5 8 12 17 2 4 5 10 19 32 49 70 2 5 10 33 80 158 273 432 3 10 33 129 334 700 1287 2171 5 19 80 334 916 2042 3991 7123 8 32 158 700 2042 4824 9910 18420 12 49 273 1287 3991 9910 21144 40418 17 70 432 2171 7123 18420 40418 78769
result:
ok 64 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
1 1 3072038
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed