結果
| 問題 | No.5021 Addition Pyramid | 
| コンテスト | |
| ユーザー |  Shun_PI | 
| 提出日時 | 2025-02-25 21:53:09 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 2,699 bytes | 
| コンパイル時間 | 3,989 ms | 
| コンパイル使用メモリ | 200,696 KB | 
| 実行使用メモリ | 6,820 KB | 
| スコア | 1,751,341 | 
| 最終ジャッジ日時 | 2025-02-25 21:53:15 | 
| 合計ジャッジ時間 | 5,614 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
| 純コード判定しない問題か言語 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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;
}
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];
  }
  vector<int> ans(N);
  IREP(j, N) {
    vector<vector<int>> table = build_table(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));
    REP(i, diff_list.size()) cout << diff_list[i] << (i!=diff_list.size()-1 ? " " : "");
    cout << "\n";
    int best_diff = 1e9;
    int best_median = 0;
    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;
      int diff = r - median;
      if(diff < best_diff) {
        best_diff = diff;
        best_median = median;
      }
    }
    ans[j] = best_median % MOD;
  }
  REP(i, N) cout << ans[i] << (i!=N-1 ? " " : "");
  cout << "\n";
  cerr << calc_score(ans) << "\n";
}
            
            
            
        