結果

問題 No.5021 Addition Pyramid
ユーザー iauyutoph
提出日時 2025-09-13 12:42:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,912 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 90,576 KB
実行使用メモリ 7,716 KB
スコア 50,373,520
最終ジャッジ日時 2025-09-13 12:43:39
合計ジャッジ時間 95,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <ctime>
#include <cmath>
using namespace std;

int n;
const int mod = 100000000;
long long goal[55][55];
long long ans[55][55];

long long get_score() {
	for (int i = n - 1; i >= 1; i--) {
		for (int j = 1; j <= i; j++) {
			ans[i][j] = (ans[i + 1][j] + ans[i + 1][j + 1]) % mod;
		}
	}
	
	long long X = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			long long d = min(abs(goal[i][j] - ans[i][j]), abs(mod - abs(goal[i][j] - ans[i][j])));
			X = max(X, d);
		}
	}
	
	long long score = 50000000 - X;
	return score;
}

void solve() {
	srand((unsigned)time(NULL));
	for (int i = 1; i <= n; i++) ans[n][i] = goal[n][i];
	long long now_score = get_score();
	
	for (int i = 1; i <= 400000; i++) {
		int a = rand() % n + 1, b = rand() % 10000000 - 5000000;
		int befo = ans[n][a];
		ans[n][a] += b;
		ans[n][a] %= mod;
		if (ans[n][a] < 0) ans[n][a] += mod;
		
		long long new_score = get_score();
		
		double Randouble = 1.0 * rand() / RAND_MAX;
		double T = 50.0 - 49.0 * i / 400000.0;
		double Probability = exp(min(0.0, (new_score - now_score) / T));
		if (Probability > Randouble) now_score = new_score;
		else ans[n][a] = befo;
	}
	
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= i; j++) cin >> goal[i][j];
	
	solve();
	
	for (int i = 1; i <= n; i++) cout << ans[n][i] << " ";
	return 0;
}
0