QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#482897 | #7221. The Road Network | inksamurai | WA | 0ms | 3876kb | C++23 | 2.7kb | 2024-07-18 00:38:17 | 2024-07-18 00:38:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int) a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
#define _3zlqvu8 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// snuke's mod int
template <ll mod>
struct modint{
ll x;
modint(ll x=0):x((x%mod+mod)%mod){}
modint operator-()const{return modint(-x);}
modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
modint operator+(const modint a)const{modint res(*this); return res+=a;}
modint operator-(const modint a)const{modint res(*this); return res-=a;}
modint operator*(const modint a)const{modint res(*this); return res*=a;}
modint pow(ll n)const{
modint res=1,x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
modint inv()const{return pow(mod-2);}
};
using mint=modint<998244353>;
using pim=pair<int,mint>;
void slv(){
int n,d;
cin>>n>>d;
vi a(n);
rep(i,n){
cin>>a[i];
}
sort(all(a));
vi lo,hi;
rep(i,n-1){
if(a[i]+a[i+1]>=d){
rng(j,i,n){
hi.pb(a[j]);
}
per(j,i){
lo.pb(a[j]);
}
break;
}
}
if(!sz(hi)){
print(0,mint(2).pow(n).x);
return;
}
reverse(all(hi));
const int si=sz(hi);
vi f(si);
mint ad=1;
for(auto x:lo){
bool fnd=0;
per(i,si){
if(hi[i]+x>=d){
fnd=1;
f[i]+=1;
break;
}
}
if(!fnd){
ad*=2;
}
}
vec(vec(pim)) dp(si+1,vec(pim)(si+1,pim{-1,0}));
dp[0][0]={0,ad};
auto push=[&](int i,int j,int val,mint wys){
if(dp[i][j].fi<val){
dp[i][j]={val,wys};
}else if(dp[i][j].fi==val){
dp[i][j].se+=wys;
}
};
rng(i,1,si+1){
int cnt=f[i-1];
// print(cnt);
rep(j,si+1){
if(!dp[i-1][j].se.x) continue;
int lhs=j,rhs=i-j-1;
int val=dp[i-1][j].fi;
mint wys=dp[i-1][j].se;
// chasvi garet
{
push(i,j,val+lhs+cnt*max(lhs,rhs+1),wys);
}
// chasvi shignit
{
push(i,j+1,val+rhs+cnt*max(lhs+1,rhs),wys);
}
}
// rep(j,si+1){
// cout<<dp[i][j].fi<<" ";
// }
// print();
}
int ma=0;
rep(j,si+1){
ma=max(ma,dp[si][j].fi);
}
mint ans=0;
rep(j,si+1){
if(dp[si][j].fi==ma){
ans+=dp[si][j].se;
}
}
print(ma,ans.x);
}
signed main(){
_3zlqvu8;
slv();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
4 7 1 4 6 3
output:
3 6
result:
ok 2 number(s): "3 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
4 11 1 4 6 3
output:
0 16
result:
ok 2 number(s): "0 16"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
4 5 1 4 6 3
output:
4 2
result:
ok 2 number(s): "4 2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
10 0 0 0 2 8 7 0 0 9 0 2
output:
25 252
result:
ok 2 number(s): "25 252"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
10 10 2 7 3 3 4 7 6 8 2 1
output:
14 4
result:
ok 2 number(s): "14 4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
10 10 3 1 1 3 7 0 6 10 1 8
output:
13 2
result:
ok 2 number(s): "13 2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
10 100 65 51 79 36 2 47 92 30 25 94
output:
18 8
result:
ok 2 number(s): "18 8"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
10 100 59 23 34 85 86 83 80 59 49 92
output:
25 2
result:
ok 2 number(s): "25 2"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
10 64 17 29 58 43 58 28 35 32 84 68
output:
24 4
result:
ok 2 number(s): "24 4"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
10 570 491 0 917 880 817 574 687 271 903 299
output:
25 12
result:
ok 2 number(s): "25 12"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
10 777 265 15 532 621 674 970 487 852 245 705
output:
22 22
result:
ok 2 number(s): "22 22"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
10 1000 30 651 139 594 912 125 908 441 589 722
output:
16 60
result:
ok 2 number(s): "16 60"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
10 100000 20324 80646 41078 4312 99749 91381 17558 72304 34167 97507
output:
21 2
result:
ok 2 number(s): "21 2"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
10 25965 48515 58580 22596 21971 1958 461 3994 44268 2654 12852
output:
21 6
result:
ok 2 number(s): "21 6"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
10 100000 87599 60861 68874 90937 4169 60849 90431 40578 71143 87785
output:
20 504
result:
ok 2 number(s): "20 504"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
10 500000000 416597451 444080196 476404630 331629074 437148184 48965137 213850399 412531610 64886804 460736205
output:
22 2
result:
ok 2 number(s): "22 2"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
10 500000000 123639683 346161103 249546242 439299419 497828609 120785562 393541902 208320182 480084424 302413299
output:
24 2
result:
ok 2 number(s): "24 2"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
10 500000000 125649203 248242009 317655142 343970706 58509033 100637758 278266116 414174180 395282044 52122165
output:
12 32
result:
ok 2 number(s): "12 32"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
10 702707240 911690470 175733148 56419428 571168608 738900064 336169888 480225097 467294240 526974092 487860083
output:
22 2
result:
ok 2 number(s): "22 2"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
10 1000000000 417518764 104085429 609689921 815038655 245477095 409118727 778061033 949273639 144364084 776426030
output:
18 2
result:
ok 2 number(s): "18 2"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
10 865525474 964816257 32437710 457927705 353875992 678425200 187100274 412333457 357624109 393157857 138620904
output:
14 2
result:
ok 2 number(s): "14 2"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
20 6 0 2 4 10 5 6 3 5 4 9 0 5 0 5 1 0 1 1 8 0
output:
76 10
result:
ok 2 number(s): "76 10"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
20 10 2 7 9 6 7 2 9 7 9 1 9 7 4 4 8 10 3 7 9 10
output:
95 12
result:
ok 2 number(s): "95 12"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
20 10 0 7 10 2 1 2 6 9 8 4 1 7 5 3 9 1 9 3 7 4
output:
72 6
result:
ok 2 number(s): "72 6"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
20 25 75 73 66 21 14 65 83 21 58 4 2 33 45 65 2 55 100 97 40 31
output:
100 2002
result:
ok 2 number(s): "100 2002"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
20 49 0 13 90 69 30 0 39 84 49 71 76 8 85 12 46 20 30 78 25 19
output:
97 2
result:
ok 2 number(s): "97 2"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
20 97 38 97 13 17 2 46 95 56 84 36 27 40 69 92 1 97 28 25 20 72
output:
74 4
result:
ok 2 number(s): "74 4"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
20 907 681 764 47 754 775 732 894 649 833 642 725 74 12 558 98 97 534 731 232 126
output:
58 88
result:
ok 2 number(s): "58 88"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
20 371 828 788 282 726 251 126 314 230 795 39 245 302 682 738 114 484 52 865 394 614
output:
100 2
result:
ok 2 number(s): "100 2"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
20 1000 221 803 890 467 489 291 734 430 519 445 154 141 352 544 758 490 810 990 796 110
output:
74 2
result:
ok 2 number(s): "74 2"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
20 53435 60667 3099 44211 22195 45013 5110 31012 14770 49917 10314 26229 74517 15452 37054 93668 69365 37983 14686 62760 97627
output:
94 2
result:
ok 2 number(s): "94 2"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
20 100000 99751 81034 25730 15507 47224 89845 93101 86735 29299 25660 68016 88068 31149 61435 52512 94396 2046 75878 1187 64252
output:
80 2
result:
ok 2 number(s): "80 2"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
20 86167 27941 58968 72008 8819 49434 74580 14777 83045 97787 76246 74561 66378 11606 45403 87010 79013 25698 1827 80028 30878
output:
87 4
result:
ok 2 number(s): "87 4"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
20 297095690 427123861 193805074 284892492 12203198 142584093 477793343 303221033 273402447 412050932 441386148 129076913 254469495 99239611 269488414 225296967 444233109 179484225 460008728 269174021 76941541
output:
98 30
result:
ok 2 number(s): "98 30"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
20 439053522 21101609 300918694 58034104 119873544 203264518 49613767 187945247 366191961 122215838 78030529 181151235 224326356 22109628 30975415 14831949 135442268 181792636 219326511 180380121 361022993
output:
29 128
result:
ok 2 number(s): "29 128"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
20 222986589 228143841 294967830 423143946 319512118 263944944 234498676 277702174 72045958 334414399 327739396 323160131 307247701 353011417 405526901 214432357 8554232 71036564 478644295 296618935 258168929
output:
100 38896
result:
ok 2 number(s): "100 38896"
Test #37:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
20 814916070 336405873 965255840 652652222 713068201 61495714 864495608 289278684 273789489 705069803 645861692 283828514 807458721 135671792 915838066 347383048 781174151 27017020 165786268 525637386 825246400
output:
91 4
result:
ok 2 number(s): "91 4"
Test #38:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
20 1000000000 252299584 188575412 500890006 956938247 568072747 568848227 587114620 755768888 617427087 934427639 834979913 346516263 3441700 707340534 135002005 965711294 928983573 745563964 871761848 196491818
output:
80 12
result:
ok 2 number(s): "80 12"
Test #39:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
20 630547200 94564367 821960402 54160499 495775584 369617070 346829774 884950557 164119358 571253568 222993586 722567801 549137317 871211609 130246782 554024742 518844655 535982833 30374368 627951726 862704529
output:
93 8
result:
ok 2 number(s): "93 8"
Test #40:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
input:
50 2 10 4 2 7 5 10 7 6 1 10 6 2 7 9 2 5 10 6 5 2 2 6 5 2 4 1 10 9 4 2 0 4 7 9 3 10 5 10 3 6 5 0 0 4 2 0 2 10 5 3
output:
625 617395946
result:
wrong answer 2nd numbers differ - expected: '662940393', found: '617395946'