QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721081#9141. Array Spreadship2077RE 0ms3836kbC++231.8kb2024-11-07 15:11:142024-11-07 15:11:15

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 15:11:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3836kb
  • [2024-11-07 15:11:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=4005,M=2005,mod=998244353;
bool vis[N];int cnt[N],lsh[N];long long dis[N];
int n,m,l[M],r[M],Gcd[M][M];
struct frac{ int x,y;
    bool operator <(const frac &a) const
        {return x*a.y<a.x*y;}
};
int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x;
}
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;
}
bool chkmin(long long &a,long long b){return a>b?a=b,1:0;}
bool check(int a,int b){
    for (int i=0;i<=n;i++) dis[i]=0;
    for (int k=1;k<=n;k++){
        bool flag=0;
        for (int i=1;i<=m;i++)
            flag|=chkmin(dis[l[i]],dis[r[i]]-b),
            flag|=chkmin(dis[r[i]],dis[l[i]]+a);
        for (int i=1;i<=n;i++) flag|=chkmin(dis[i-1],dis[i]);
        if (!flag) return 1;
        if (dis[n]<0) return 0;
    }
    return 0;
}
void solve(){
	n=0;read();m=read();
	for (int i=1;i<=m;i++)
		lsh[++n]=l[i]=read()-1,lsh[++n]=r[i]=read();
	sort(lsh+1,lsh+n+1);n=unique(lsh+1,lsh+n+1)-lsh-1;
	for (int i=1;i<=m;i++)
		l[i]=lower_bound(lsh+1,lsh+n+1,l[i])-lsh,
		r[i]=lower_bound(lsh+1,lsh+n+1,r[i])-lsh;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=m;j++)
			Gcd[i][j]=0;
	vector<frac>Ans;
	for (int d=m;d;d--)
		for (int i=d;i<=m;i+=d)
			for (int j=d;j<=m;j+=d)
				if (!Gcd[i][j]) Gcd[i][j]=d;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=i;j++)
			if (Gcd[i][j]==1&&i+j<=m)
				Ans.push_back({i,j});
	sort(Ans.begin(),Ans.end());
	int l=0,r=(int)Ans.size()-1,ans=-1;
	while (l<=r){
		int mid=l+r>>1;
		if (check(Ans[mid].x,Ans[mid].y))
			ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",1ll*Ans[ans].x*qpow(Ans[ans].y,mod-2)%mod);
}
int main(){int T=read();while (T--) solve();return 0;}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

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: -100
Runtime Error

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:


result: