90pts #2WA hack TLE 求调
查看原帖
90pts #2WA hack TLE 求调
729338
xihegudiiakioi楼主2024/6/1 13:00
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
ll step;
ll w[1100];
ll ans[1100];
int g;
bool f;
void dfs(ll x,ll y,ll d){
	if(d == step){
		if(y % x){
			return ;
		}
		if(y / x == w[d - 1]){
			return ;
		}
		f = 1;
		w[d] = y / x;
		int cmp = 0;
		for(ll i = d;i > 0;i--){
			if(ans[i] == w[i]){
				continue;
			}
			if(ans[i] < w[i]){
				break;
			}else{
				cmp = 1;
				break;
			}
		}
		if(cmp == 1){
			memcpy(ans,w,sizeof(ll) * (d + 1));
		}
		return ;
	}
	for(ll i = max(y / x + 1,w[d - 1] + 1);;i++){
		if(y * (step - d + 1) < x * i){
			break;
		}
		w[d] = i;
		ll ty = y * i;
		ll tx = x * i - y;
		g = __gcd(tx,ty);
		ty /= g;
		tx /= g;
		dfs(tx,ty,d + 1);
	}
}
int main(){
	cin >> x >> y;
	if(y % x == 0){
		cout << y / x << endl;
		return 0;
	}
	x = x / __gcd(x,y);
	y = y / __gcd(x,y);
	for(step = 2;;step++){
		ans[1] = 0;
		ans[step] = LLONG_MAX;
		dfs(x,y,1);
		if(f){
			break;
		}
	}
	for(ll i = 1;i < step;i++){
		cout << ans[i] << " ";
	}
	cout << ans[step] << endl;
}

第二个点 说 Wrong Answer.wrong output format Unexpected end of file - int32 expected

以为是输出格式有误,调了半天

2024/6/1 13:00
加载中...