結果
| 問題 |
No.5021 Addition Pyramid
|
| コンテスト | |
| ユーザー |
Shun_PI
|
| 提出日時 | 2025-02-25 22:02:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,002 ms / 2,000 ms |
| コード長 | 3,487 bytes |
| コンパイル時間 | 4,058 ms |
| コンパイル使用メモリ | 212,200 KB |
| 実行使用メモリ | 297,240 KB |
| スコア | 241,050,239 |
| 最終ジャッジ日時 | 2025-02-25 22:04:36 |
| 合計ジャッジ時間 | 54,164 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#include <string>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
constexpr int MOD = 100000000;
vector<lint> RH_B = {1532834020, 1388622299};
vector<lint> RH_M = {2147482409, 2147478017};
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int N;
vector<vector<int>> A;
double ncr[50][50];
unsigned long xor128(void)
{
static unsigned long x=123456789,y=362436069,z=541288629,w=88675123;
unsigned long t;
t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
vector<vector<int>> build_table(vector<int> &ans) {
vector<vector<int>> ans_A(N, vector<int>(N));
REP(i, N) ans_A[N-1][i] = ans[i];
IREP(i, N-1) REP(j, i+1) {
ans_A[i][j] = (ans_A[i+1][j] + ans_A[i+1][j+1]) % MOD;
}
return ans_A;
}
int calc_score(vector<int> &ans) {
vector<vector<int>> ans_A = build_table(ans);
int max_diff = 0;
REP(i, N) REP(j, i+1) {
int diff = min(abs(A[i][j] - ans_A[i][j]), MOD - abs(A[i][j] - ans_A[i][j]));
chmax(max_diff, diff);
}
return MOD/2 - max_diff;
}
struct State {
int max_diff = 0;
vector<int> ans;
bool operator < (const State &other) const { return max_diff < other.max_diff; }
State() {
ans.resize(N);
}
State get_copy() {
State new_state;
new_state.max_diff = max_diff;
new_state.ans = vector<int>(ans);
return new_state;
}
};
int calc_diff(int a, int b) {
return min(abs(a - b), MOD - abs(a - b));
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
A.resize(N, vector<int>(N));
REP(i, N) REP(j, i+1) cin >> A[i][j];
REP(i, 50) REP(j, i+1) {
if(j == 0 || j == i) ncr[i][j] = 1;
else ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
}
int BEAM_WIDTH = 1000;
vector<vector<State>> beam(N+1);
beam[0].push_back(State());
REP(z, N) {
sort(ALL(beam[z]));
int j = N-1-z;
REP(zz, min(BEAM_WIDTH, (int)beam[z].size())) {
State &state = beam[z][zz];
vector<vector<int>> table = build_table(state.ans);
vector<int> diff_list;
FOR(i, j, N) {
int diff = (A[i][j] - table[i][j] + MOD) % MOD;
diff_list.push_back(diff);
}
sort(ALL(diff_list));
int D = diff_list.size();
REP(i, D) {
int l = diff_list[i];
int r = diff_list[(D-1+i)%D];
if(i > 0) r += MOD;
int median = (l + r) / 2;
//medianからの差も探索
for(int d = 0; d <= 0; d++) {
int val = (median + (1<<abs(d)) * (d < 0 ? -1 : 1) + MOD) % MOD;
int diff = max(calc_diff(val, l), calc_diff(val, r));
State new_state = state.get_copy();
new_state.ans[j] = val;
new_state.max_diff = max(new_state.max_diff, diff);
beam[z+1].push_back(new_state);
}
}
}
}
sort(ALL(beam[N]));
vector<int> ans = beam[N][0].ans;
REP(i, N) cout << ans[i] << (i!=N-1 ? " " : "");
cout << "\n";
cerr << calc_score(ans) << "\n";
}
Shun_PI