QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#580887#9381. 502 Bad GatewaybuhuisuanfaTL 0ms3624kbC++20960b2024-09-22 00:40:102024-09-22 00:40:12

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-22 00:40:12]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3624kb
  • [2024-09-22 00:40:10]
  • 提交

answer

#include<bits/stdc++.h>
#define sz(x) (x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--) 
using namespace std;

using ll = long long;

struct frac {
	int a, b;
	bool operator<(const frac &rhs) {
		return 1ll * a * rhs.b < 1ll * b * rhs.a;
	}
};

void solve() {
	int T;
	cin >> T;
	int sqrtT = sqrt(2 * T);
	int lo = max(sqrtT - 100, 1);
	int hi = min(sqrtT + 100, T);
	
	auto calc = [&](int i) {
		frac res;
		res.b = 2 * i;
		res.a = 1ll * i * i - i + 2 * T;
		int d = gcd(res.a, res.b);
		res.a /= d;
		res.b /= d;
		return res;
	};
	frac ans = calc(1);

	for (int i = lo; i <= hi; i++) {
		frac temp = calc(i);
		if(ans < temp) ;
		else ans = temp;
	}
	cout << ans.a << " " << ans.b << "\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int t;
	std::cin >> t;
	for (; t; t--) {
		solve();
	}
	return 0;
}

详细

Test #1:

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

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

1000000
1
1000000000
1
1
1000000000
1
1000000000
1
1
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1
1
1000000000
1
1000000000
1000000000
1000000000
1000000000
1
1
1
10000000...

output:

1 1
-151989138 44621
1 1
1 1
-151989138 44621
1 1
-151989138 44621
1 1
1 1
1 1
-151989138 44621
1 1
1 1
-151989138 44621
1 1
-151989138 44621
-151989138 44621
1 1
-151989138 44621
1 1
1 1
-151989138 44621
1 1
-151989138 44621
-151989138 44621
1 1
-151989138 44621
-151989138 44621
-151989138 44621
-1...

result: