QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787005 | #9141. Array Spread | cyl001 | RE | 5ms | 4092kb | C++14 | 1.7kb | 2024-11-27 08:32:41 | 2024-11-27 08:32:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4010,mod = 998244353;
int T,n,m,k,cnt,p[N],L[N],R[N],dis[N];
vector <pair <int,int>> v[N];
struct Frac{int p,q;} ans[N];
bool operator < (Frac x,Frac y){return x.p * y.q < x.q * y.p;}
int ksm(int x,int y)
{
int ret = 1;
while(y)
{
if(y & 1) ret = 1LL * ret * x % mod;
x = 1LL * x * x % mod,y >>= 1;
}
return ret;
}
bool check(Frac x)
{
for(int i = 1;i <= k;i++) v[i].clear();
for(int i = 2;i <= k;i++) v[i].push_back(make_pair(i - 1,0));
for(int i = 1;i <= m;i++)
{
v[R[i]].push_back(make_pair(L[i],-x.q));
v[L[i]].push_back(make_pair(R[i],x.p));
}
memset(dis,0x3f,sizeof(dis));
dis[0] = 0;
for(int i = 1;i <= k;i++)
for(int x = 1;x <= k;x++)
for(pair <int,int> p : v[x])
dis[p.first] = min(dis[p.first],dis[x] + p.second);
for(int x = 1;x <= k;x++)
for(pair <int,int> p : v[x])
if(dis[p.first] > dis[x] + p.second)
return false;
return true;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
k = 0;
for(int i = 1;i <= m;i++)
{
scanf("%d%d",&L[i],&R[i]);
p[++k] = --L[i],p[++k] = R[i];
}
sort(p + 1,p + k + 1);
k = unique(p + 1,p + k + 1) - p - 1;
for(int i = 1;i <= m;i++)
{
L[i] = lower_bound(p + 1,p + k + 1,L[i]) - p;
R[i] = lower_bound(p + 1,p + k + 1,R[i]) - p;
}
ans[cnt = 1] = (Frac){1,1};
for(int i = 2;i <= m;i++)
for(int j = 1;j < i;j++)
ans[++cnt] = (Frac){i,j};
sort(ans + 1,ans + cnt + 1);
int l = 0,r = cnt,mid;
while(r - l > 1)
{
mid = (l + r) / 2;
if(check(ans[mid])) r = mid;
else l = mid;
}
printf("%lld\n",1LL * ans[r].p * ksm(ans[r].q,mod - 2) % mod);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3992kb
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: 4064kb
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: 0ms
memory: 3928kb
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: 2ms
memory: 3936kb
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: 5ms
memory: 3940kb
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: 0
Accepted
time: 0ms
memory: 4092kb
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 ...
output:
1 2 748683266 5 6 453747435 1 10 6 1 499122183 1 4 3 1 3 1 748683266 2 499122179 10 499122178 1 499122179 4 1 7 1 665496238 2 2 2 332748119 249561090 816745381 499122178 2 499122179 5 3 4 17 1 2 2 3 249561092 1 3 924300328 499122179 2 3 332748120 2 7 3 499122187 6 374341634 1 2 332748120 2 2 2 49912...
result:
ok 250 numbers
Test #7:
score: -100
Runtime Error
input:
100 1000000000 17 272213590 960979163 970159974 987653658 201788340 556786243 46564706 948945765 786605927 819103747 510930374 747773556 729597186 850647589 412727504 443334406 685627406 773178988 793614323 909668193 830162056 837607472 416766039 753918198 237455713 993045890 848459092 851118478 463...