QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#636452#2291. Lopsided Lineupoxford01#WA 425ms11704kbC++202.7kb2024-10-12 23:56:302024-10-12 23:56:30

Judging History

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

  • [2024-10-12 23:56:30]
  • 评测
  • 测评结果:WA
  • 用时:425ms
  • 内存:11704kb
  • [2024-10-12 23:56:30]
  • 提交

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())
#define int long long 

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;s
            // cout << exp(-delta/T) << endl;
            swap(set1[a], set2[b]);
            sum += delta;
            ans = max(ans, sum);
            T *= 0.9997;
        }
    }
}
signed 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: 100
Accepted
time: 7ms
memory: 4088kb

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:

21235600

result:

ok single line: '21235600'

Test #2:

score: -100
Wrong Answer
time: 425ms
memory: 11704kb

input:

1000
0 605446 -182407 927547 107811 -508108 -19793 -933848 284204 -680651 -334880 480652 -316211 -229241 824306 758089 370574 331406 -896303 363352 -118936 -806685 -548261 371353 -358325 -180497 -773893 611605 -380024 42395 570930 336539 817841 -220375 -607196 -935640 -22353 -44239 -547530 -743182 1...

output:

7118884049

result:

wrong answer 1st lines differ - expected: '7118983451', found: '7118884049'