QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#580888#9381. 502 Bad GatewaybuhuisuanfaWA 347ms3676kbC++20958b2024-09-22 00:40:332024-09-22 00:40:34

Judging History

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

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

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 - 10, 1);
	int hi = min(sqrtT + 10, 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: 3564kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 347ms
memory: 3676kb

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
-147969243 44711
1 1
1 1
-147969243 44711
1 1
-147969243 44711
1 1
1 1
1 1
-147969243 44711
1 1
1 1
-147969243 44711
1 1
-147969243 44711
-147969243 44711
1 1
-147969243 44711
1 1
1 1
-147969243 44711
1 1
-147969243 44711
-147969243 44711
1 1
-147969243 44711
-147969243 44711
-147969243 44711
-1...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '-147969243 44711'