QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#636255 | #2291. Lopsided Lineup | oxford01# | WA | 7ms | 4004kb | C++20 | 2.6kb | 2024-10-12 23:04:27 | 2024-10-12 23:04:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (auto i = a; i < (b); ++i)
#define repr(i, a, b) for (auto i = (a) - 1; i >= (b); --i)
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pii>;
template<class T>
inline bool cmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template<class T>
inline bool cmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
const int inf = 0x3f3f3f3f;
const ll linf = 1e18;
const double dinf = numeric_limits<double>::infinity();
const int maxn = 1005;
int c[maxn][maxn];
int n;
int m;
int randInt (int b) {
return rand()%b+1;
}
double rand01 () {
return (double)rand()/RAND_MAX;
}
int set1[maxn]; // +ve
int set2[maxn]; // -ve
int sum;
int ans;
void SA () {
double T = 300;
const int REP = 1e5;
for (int t=1;t<=REP;t++) {
int a = randInt(m);
int b = randInt(m);
int delta = 0;
for (int i=1;i<=m;i++) {
if (i == a) continue;
delta -= c[set1[i]][set1[a]];
}
for (int i=1;i<=m;i++) {
if (i == b) continue;
delta += c[set2[i]][set2[b]];
}
for (int i=1;i<=m;i++) {
if (i == a) continue;
delta += c[set1[i]][set2[b]];
}
for (int i=1;i<=m;i++) {
if (i == b) continue;
delta -= c[set2[i]][set1[a]];
}
// cout << set1[a] << set2[b] << endl;
// cout << delta << endl;
if (delta > 0 && exp(-delta/T) >= rand01()) {
// cout << "det " << delta;
// cout << exp(-delta/T) << endl;
swap(set1[a], set2[b]);
sum += delta;
ans = max(ans, sum);
T *= 0.9997;
}
}
}
int main() {
srand(time(0));
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> n;
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) {
cin >> c[i][j];
}
m = n/2;
for (int i=1;i<=m;i++) {
set1[i] = i;
for (int j=1;j<i;j++) {
sum += c[i][j];
}
}
for (int i=m+1;i<=m+m;i++) {
set2[i-m] = i;
for (int j=m+1;j<i;j++) {
sum -= c[i][j];
}
}
ans = sum;
SA();
cout << ans << endl;
return 0;
}
/*
4
0 1 2 2
1 0 8 -3
2 8 0 5
2 -3 5 0
6
6
0 4 -6 2 3 -3
4 0 2 -6 0 0
-6 2 0 0 2 2
2 -6 0 0 -1 5
3 0 2 -1 0 -4
-3 0 2 5 -4 0
0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 4004kb
input:
20 0 786505 911962 -800624 363821 -960995 -492637 -246590 140762 54707 -353306 -82216 -175650 567363 113374 761152 906126 -394096 -635055 675627 786505 0 801116 -323471 -34197 -860051 865281 737621 307515 -493253 -128788 -171663 -21931 853897 -505337 72985 941995 -380960 -223577 265322 911962 801116...
output:
-9728592
result:
wrong answer 1st lines differ - expected: '21235600', found: '-9728592'