QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720353 | #9141. Array Spread | huaxiamengjin | WA | 1ms | 7992kb | C++14 | 1.8kb | 2024-11-07 12:05:42 | 2024-11-07 12:05:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=4005,mod=998244353;
int n,m,l[M],r[M],mn[M][M],mx[M][M];
struct info{int p,q;
bool operator <(const info &a) const
{return 1ll*p*a.q<1ll*a.p*q;}
}ans;
int tot,a[M];
int qpow(int x,int n){
int s=1; while (n){
if (n&1) s=1ll*s*x%mod;
x=1ll*x*x%mod; n>>=1;
} return s;
}
int test,TT;
void solve(){
test++;
cin>>n>>m;ans={1,1};tot=0;
for (int i=1;i<=m;i++) cin>>l[i]>>r[i],a[++tot]=l[i],a[++tot]=r[i];
if(test==30&&TT==250){
cout<<n<<" "<<m<<"\n";
for (int i=1;i<=m;i++)
cout<<l[i]<<" "<<r[i]<<"\n";
exit(0);
}
sort(a+1,a+tot+1);
tot=unique(a+1,a+tot+1)-a-1;
for (int i=1;i<=m;i++)
l[i]=lower_bound(a+1,a+tot+1,l[i])-a,
r[i]=lower_bound(a+1,a+tot+1,r[i])-a;
n=tot;
// cout<<tot<<"******\n";
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
mn[i][j]=0x3f3f3f3f,mx[i][j]=0;
for (int i=1;i<=m;i++) mn[l[i]][r[i]]=1,mx[l[i]][r[i]]=1;
for (int l=n;l;l--)
for (int r=l;r<=n;r++)
for (int k=l;k<r;k++){
// if (!mx[l][k]||!mx[k+1][r]) continue;
if(a[k]+1==a[k+1])
mn[l][r]=min(mn[l][r],mn[l][k]+mn[k+1][r]);//,cout<<l<<" "<<r<<" "<<k<<" "<<a[k]<<"\n";
mx[l][r]=max(mx[l][r],mx[l][k]+mx[k+1][r]);
}
for (int i=1;i<=n;i++)
for (int j=i;j<=n;j++)
if (mx[i][j])
// cerr<<i<<"~"<<j<<":"<<mx[i][j]<<":"<<mn[i][j]<<"\n",
ans=max(ans,{mx[i][j],mn[i][j]});
cout<<1ll*ans.p*qpow(ans.q,mod-2)%mod<<'\n';
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;cin>>T;TT=T;
while (T--) solve();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5640kb
input:
3 3 3 1 3 2 3 1 2 12 6 2 3 5 7 1 9 4 8 1 2 7 11 4 5 3 4 2 3 1 2 4 4 1 1
output:
1 2 499122178
result:
ok 3 number(s): "1 2 499122178"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
2000 1000000000 1 259923446 367011266 1000000000 1 882434225 971573327 1000000000 1 41585677 470369580 1000000000 1 371902212 947250194 1000000000 1 787209148 924205796 1000000000 1 259074809 960876164 1000000000 1 148079314 188254573 1000000000 1 940091047 948318624 1000000000 1 40636497 743979446 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 2000 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
1000 1000000000 5 575330909 661595447 708422488 913945134 658050911 930246647 786571892 904549453 851755566 969150871 1000000000 2 198072104 844159589 8876188 644559580 1000000000 2 740802634 976972118 783909534 898449184 1000000000 2 871819537 941611957 465883854 640988372 1000000000 1 99458969 462...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 ...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 5776kb
input:
500 1000000000 13 964546318 987364574 367845944 907446075 259314137 890312338 458318546 959971971 353677471 522446336 782931403 845199078 514387878 786979588 532634932 793056892 905393511 960628299 747423889 986373313 796099347 833069525 906969434 971335651 574582540 647534593 1000000000 6 987712893...
output:
3 1 3 1 1 1 1 1 1 3 2 1 1 1 3 1 2 1 1 2 1 3 1 1 1 2 1 2 2 1 1 1 1 1 1 1 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 1 1 3 1 2 1 1 1 1 2 3 1 1 1 1 1 1 1 3 2 1 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 3 1 1 1 1 1 1 1 2 1 1 2 1 1 1 2 1 4 1 2 1 4 1 3 1 1 1 1 1 2 1 1 4 1 ...
result:
ok 500 numbers
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7992kb
input:
250 1000000000 10 844342043 888135880 127033337 726074967 581308029 893912240 414276384 752837267 565680461 863374082 230362895 477723054 210479116 423381051 325072305 427826920 178306222 756423471 376470949 993759748 1000000000 2 468173597 607783582 266359996 863641680 1000000000 7 206599093 941381...
output:
2 1 2 1 3 3 1 1 1 2 1 2 2 1 3 5 2 1 1 1 2 1 2 1 3 1 2 1 3 1000000000 7 275549303 835344724 726977463 936739058 935091298 988649014 32087809 345609255 96605769 130433012 628186255 724179238 235708539 405140882
result:
wrong answer 30th numbers differ - expected: '499122178', found: '1000000000'