QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#262630 | #7753. Energy Distribution | ayersz | WA | 0ms | 4004kb | C++23 | 3.1kb | 2023-11-23 21:00:50 | 2023-11-23 21:00:51 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
const int N = 15;
bool vis[N];
double ans[N];
bool gauss(vector<vector<double>>& a) {
int n = a.size();
// for (int i = 0; i < n; i++) {
// for (int j = 0; j <= n; j++) {
// cout << a[i][j] << " ";
// }
// cout << "\n";
// }
for (int i = 0; i < n; i++) {
if (!vis[i]) continue;
int p = -1;
for (int j = i; j < n; j++) {
if (!vis[j]) continue;
if (p == -1 || abs(a[j][i]) > abs(a[p][i])) p = j;
}
if (p == -1) return 0;
if (i != p) swap(a[p], a[i]);
for (int j = i + 1; j < n; j++) {
for (int k = i + 1; k <= n; k++) {
a[j][k] -= a[j][i] / a[i][i] * a[i][k];
}
a[j][i] = 0;
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j <= n; j++) {
// cout << a[i][j] << " ";
// }
// cout << "\n";
// }
for (int i = n - 1; i >= 0; i--) {
if (!vis[i]) continue;
for (int j = 0; j < i; j++) {
if (!vis[j]) continue;
// cout << "i = " << i << " j = " << j << " " << a[j][n] << " " << a[i][n] << " " << a[j][i] << " " << a[i][i] << "\n";
a[j][n] -= a[i][n] * a[j][i] / a[i][i];
a[j][i] = 0;
}
}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j <= n; j++) {
// cout << a[i][j] << " ";
// }
// cout << "\n";
// }
for (int i = 0; i < n - 1; i++) {
if (!vis[i]) {
ans[i] = 0;
} else {
ans[i] = a[i][n] / a[i][i];
if (ans[i] < 0) return 0;
}
}
return 1;
}
int n;
int a[N][N];
double solve(int ms) {
for (int i = 0; i < n; i++) {
vis[i] = ms >> i & 1;
}
vector coef(n + 1, vector<double>(n + 2, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (vis[j]) {
coef[i][j] = a[i][j];
}
}
coef[i][n] = 1, coef[i][n + 1] = 0;
}
for (int i = 0; i < n; i++) {
coef[n][i] = vis[i];
}
vis[n] = 1;
coef[n][n] = 0, coef[n][n + 1] = 1;
// cout << "mask = " << ms << " ========= \n";
// for (int i = 0; i <= n; i++) {
// for (int j = 0; j <= n + 1; j++) {
// cout << coef[i][j] << " ";
// }
// cout << "\n";
// }
if (gauss(coef)) {
double tmp = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
tmp += ans[i] * ans[j] * a[i][j];
}
}
return tmp;
}
return 0;
}
int main() {
cout << fixed << setprecision(6);
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
double res = 0;
for (int ms = 0; ms < (1 << n); ms++) {
res = max(res, solve(ms));
}
cout << res << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
input:
2 0 1 1 0
output:
0.250000
result:
ok found '0.2500000', expected '0.2500000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
3 0 2 1 2 0 2 1 2 0
output:
0.571429
result:
ok found '0.5714290', expected '0.5714290', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
3 0 1 2 1 0 1 2 1 0
output:
0.500000
result:
ok found '0.5000000', expected '0.5000000', error '0.0000000'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 4004kb
input:
4 0 3 1 0 3 0 1 0 1 1 0 2 0 0 2 0
output:
0.500000
result:
wrong answer 1st numbers differ - expected: '0.7500000', found: '0.5000000', error = '0.2500000'