QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500166 | #9141. Array Spread | triple___a | RE | 111ms | 3840kb | C++20 | 2.0kb | 2024-07-31 23:52:51 | 2024-07-31 23:52:52 |
Judging History
answer
#include<bits/stdc++.h>
// #pragma GCC optimize("trapv")
#define int long long
#define double long double
using namespace std;
const int N=4007;
const int mod=998244353;
const double EPS=1e-9;
int n,m;
int l[N],r[N];
vector<pair<int,double>> g[N];
double dist[N];
int check(double x){
// cerr<<x<<endl;
for (int i=0;i<=2*m;++i) dist[i]=0, g[i].clear();
for (int i=0;i<2*m;++i) g[i+1].push_back({i,0});
for (int i=0;i<m;++i){
// cerr<<l[i]<<" "<<r[i]<<endl;
g[l[i]].push_back({r[i],x});
g[r[i]].push_back({l[i],-1});
}
for (int i=0;i<=4*m;++i){
for (int u=0;u<=2*m;++u){
for (auto [v,d]:g[u]) dist[v]=min(dist[v],dist[u]+d);
}
}
// for (int u=0;u<=2*m;++u) cerr<<dist[u]<<" ";
// cerr<<endl;
for (int u=0;u<=2*m;++u){
for (auto [v,d]:g[u]){
if (dist[v]>dist[u]+d+2*EPS) return 0;
}
}
return 1;
}
int modpow(int u,int v){
int ans=1, t=u;
while (v){
if (v&1) ans=ans*t%mod;
t=t*t%mod, v>>=1;
}
return ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _;
cin>>_;
while (_--){
cin>>n>>m;
vector<int> lst;
for (int i=0;i<m;++i) cin>>l[i]>>r[i], l[i]--, lst.push_back(l[i]), lst.push_back(r[i]);
sort(lst.begin(), lst.end());
for (int i=0;i<m;++i) l[i]=lower_bound(lst.begin(), lst.end(),l[i])-lst.begin(), r[i]=lower_bound(lst.begin(), lst.end(), r[i])-lst.begin();
double L=1.0, R=2000.0;
while (R-L>EPS){
double md=(L+R)/2;
if (check(md)) R=md;
else L=md;
}
// cout<<L<<"\n";
int idx=-1, v=-1;
for (int i=1;i<=m*m;++i){
int x=i*L+0.001;
// cerr<<i*L-x<<endl;
if (abs(i*L-x)<10*EPS) {idx=i, v=x; break;}
}
assert(idx!=-1);
cout<<v*modpow(idx,mod-2)%mod<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3804kb
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: 13ms
memory: 3776kb
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: 24ms
memory: 3840kb
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: 46ms
memory: 3564kb
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: 0
Accepted
time: 111ms
memory: 3572kb
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 499122178 1 1 1 1 3 1 1 1 3 3 3 1 4 1 1 1 1 1 1 1 1 5 1 4 2 1 3 1 1 1 2 5 2 1 2 6 2 2 1 2 1 1 1 5 8 2 1 2 1 1 2 2 2 1 1 5 8 3 1 1 1 8 2 6 1 1 4 2 1 1 1 1 2 2 1 2 1 1 1 1 1 1 2 1 2 1 1 4 1 1 3 1 2 3 3 2 5 1 1 1 3 2 1 1 1 3 1 1 2 1 1 1 1 3 1 1 ...
result:
ok 250 numbers
Test #6:
score: -100
Runtime Error
input:
250 1000000000 4 10495745 465086423 465086424 609997778 396956207 663037010 253873206 396956206 1000000000 33 596279983 655818820 226461062 338625457 407323582 423049163 711408063 778512581 220274357 226461061 702491412 711408062 686978949 688730316 369564474 434159428 778512582 787885602 675683057 ...