結果

問題 No.5021 Addition Pyramid
ユーザー 北杜
提出日時 2025-02-25 20:47:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,165 bytes
コンパイル時間 4,024 ms
コンパイル使用メモリ 327,756 KB
実行使用メモリ 6,824 KB
スコア 22,688,260
最終ジャッジ日時 2025-02-25 20:49:15
合計ジャッジ時間 98,466 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
const int INF32 = 2e9;
const ll INF64 = 4e18;
const int mod = 100000000;
const double fase1_LIMIT = 0.5, LIMIT = 1.8;
int calc_score(vector<vector<int>> a,vector<int> ans){
    int N = a.size();
    vector<vector<int>> ans_pyramid(N);
    rep(i,N)ans_pyramid[i].assign(i+1,0);
    rep(i,N)ans_pyramid[N-1][i]=ans[i];
    for(int i = N-1; i > 0; i--){
        for(int j = 0; j < i; j++){
            ans_pyramid[i-1][j]=(ans_pyramid[i][j]+ans_pyramid[i][j+1])%mod;
        }
    }
    int X = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            X = max(X, min(abs(a[i][j]-ans_pyramid[i][j]),mod-abs(a[i][j]-ans_pyramid[i][j])));
        }
    }
    return mod/2-X;
}

int main() {
    srand((unsigned int)time(NULL));
    auto startTime = chrono::high_resolution_clock::now();
    int N;
    cin >> N;
    vector<vector<int>> a(N);
    rep(i,N)a[i].assign(i+1,0);
    rep(i,N){
        rep(j,i+1){
            cin >> a[i][j];
        }
    }
    vector<int> ans(N), bestans(N);
    int bestscore = 0;
    double elapsed = 0;
    while(elapsed<fase1_LIMIT){
        rep(i,N){
            ans[i]=rand()%mod;
        }
        int score = calc_score(a,ans);
        if(score>bestscore){
            bestans = ans;
            bestscore = score;
        }
        auto currentTime = chrono::high_resolution_clock::now();
        elapsed = chrono::duration_cast<chrono::milliseconds>(currentTime - startTime).count() / 1000.0;
    }
    while(elapsed<LIMIT){
        ans = bestans;
        ans[rand()%N]+=rand()%1000000-5000;
        int score = calc_score(a,ans);
        if(score>bestscore){
            bestans = ans;
            bestscore = score;
        }
        auto currentTime = chrono::high_resolution_clock::now();
        elapsed = chrono::duration_cast<chrono::milliseconds>(currentTime - startTime).count() / 1000.0;
    }
    rep(i,N){
        cout << bestans[i];
        if(i==N-1)cout << endl;
        else cout << " ";
    }
    return 0;
}
0