QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500164 | #9141. Array Spread | triple___a | WA | 1ms | 3800kb | C++20 | 1.9kb | 2024-07-31 23:50:02 | 2024-07-31 23:50:02 |
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=8007;
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;
if (i*L-x<EPS) {idx=i, v=x; break;}
}
assert(idx!=-1);
cout<<v*modpow(idx,mod-2)%mod<<"\n";
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3800kb
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 1 2 2 1.5 499122178
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'