QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369042#5253. DenormalizationNYCU_template#RE 1ms3900kbC++141.1kb2024-03-27 19:47:572024-03-27 19:47:58

Judging History

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

  • [2024-03-27 19:47:58]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3900kb
  • [2024-03-27 19:47:57]
  • 提交

answer

#include <bits/stdc++.h>
#define loli ios::sync_with_stdio(0), cin.tie(0);
#define MP make_pair
#define F first
#define S second
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;

const int LIMIT = 10000;

const double eps = 1e-7;

struct vecs {
	double d;
	int ans, idx;
} a[10000];

pii getVal(double a, double b) {
	for (int i = 1; i <= LIMIT; i++) {
		double x = b / (a / i);
		if (abs(x - round(x)) < eps) {
			return MP(i, round(x));
		}
	}
	assert(0);
	return MP(-1, -1);
}

int lcm(int a, int b) {
	return ll(a) * b / __gcd(a, b);
}

int main() {loli
	int n, base = 1;
	pii rat[10000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].d;
		a[i].idx = i;
	}
	sort(a, a + n, [](const vecs &x, const vecs &y){
			return x.d < y.d;
		});
	for (int i = 1; i < n; i++) {
		rat[i] = getVal(a[0].d, a[i].d);
		base = lcm(base, rat[i].F);
	}
	a[0].ans = base;
	for (int i = 1; i < n; i++) {
		a[i].ans = rat[i].S * base / rat[i].F;
	}
	sort(a, a + n, [](const vecs &x, const vecs &y){
			return x.idx < y.idx;
		});
	for (int i = 0; i < n; i++) {
		cout << a[i].ans << "\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3900kb

input:

2
0.909840249060
0.414958698174

output:

9665
4408

result:

ok good solution

Test #2:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

3
0.005731604132
0.696198848562
0.717826101486

output:

75
9110
9393

result:

ok good solution

Test #3:

score: -100
Runtime Error

input:

10
0.338936215010
0.390914583549
0.048893426174
0.446152513833
0.137891103101
0.017985796057
0.459132554353
0.201452557127
0.362800863500
0.358493585479

output:


result: