結果
| 問題 |
No.5021 Addition Pyramid
|
| コンテスト | |
| ユーザー |
斉藤+あるふぁ。
|
| 提出日時 | 2025-02-25 22:57:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 8,129 bytes |
| コンパイル時間 | 1,995 ms |
| コンパイル使用メモリ | 172,940 KB |
| 実行使用メモリ | 6,820 KB |
| スコア | 1,911,494 |
| 最終ジャッジ日時 | 2025-02-25 22:57:53 |
| 合計ジャッジ時間 | 8,224 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
// #ifndef ONLINE_JUDGE//なんか手元ではデバックモードになって、atcoder上ではデバックモードにならないらしい ABC325Dはこれで通った
// #define _GLIBCXX_DEBUG//[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4のデバックTLEなどに注意
// #endif//これと上のONLINE JUDGEが絶対必要
// //★TLEにならないはずなのにTLEになったらオンラインジャッジを消してデバックモードのまま提出をする。
#include <bits/stdc++.h>
// 使い方分かんない(泣)
// 時間を管理するクラス(ゲームで学ぶ探索アルゴリズム実践入門のサンプルとは管理方法が異なる)
// class TimeKeeper {
// private:
// std::chrono::high_resolution_clock::time_point start_time_;
// std::chrono::high_resolution_clock::time_point before_time_;
// int64_t time_threshold_;
// int64_t end_turn_;
// int64_t turn_;
// public:
// // ターン制の問題で全ターン含めての制限時間(ミリ秒)と最大ターン数を指定し、
// // インスタンスをつくる。
// TimeKeeper(const int64_t &time_threshold, const int64_t end_turn)
// : start_time_(std::chrono::high_resolution_clock::now()),
// time_threshold_(time_threshold),
// end_turn_(end_turn),
// turn_(0) {
// // メンバイニシャライザで初期化されたstart_time_の値を使うため、before_time_はメンバイニシャライザではなくコピーをする
// before_time_ = start_time_;
// }
// // ターンとターン開始時間を更新する
// void setTurn(const int t) {
// turn_ = t;
// this->before_time_ = std::chrono::high_resolution_clock::now();
// }
// // 各ターンに割り振られた制限時間を超過したか判定する。
// bool isTimeOver() {
// auto now = std::chrono::high_resolution_clock::now();
// auto whole_diff = now - this->start_time_;
// auto whole_count =
// std::chrono::duration_cast<std::chrono::milliseconds>(whole_diff)
// .count();
// auto last_diff = now - this->before_time_;
// auto last_count =
// std::chrono::duration_cast<std::chrono::milliseconds>(last_diff)
// .count();
// auto remaining_time = time_threshold_ - whole_count;
// auto now_threshold = remaining_time / (end_turn_ - this->turn_);
// return last_count >= now_threshold;
// }
// };
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld = long double;
using Pii=pair<int,int>;
using Pll=pair<ll,ll>;
using TT=tuple<int,int,int>;
#define mPP(a,b) make_pair(a,b)
#define mTT(a,b,c) make_tuple(a,b,c)
#define rep1(a) for(int i = 0; i < (int)(a); i++)
#define rep2(i, a) for(int i = 0; i < (int)(a); i++)
#define rep3(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep4(i, a, b, c) for(int i = (int)(a); i < (int)(b); i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i,n) for(int i = (int)(n-1); i >= 0; --i)
#define RREP(i,advanced,n) for(int i = (int)(n)-1; i >= advanced; --i)
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
#define ALL(a,middle,last) a.begin()+middle,a.begin()+last
#define w_np(a) while(next_permutation(a))
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define mycin(vec) for(auto &v:vec) cin >> v;
#define mycout(vec) for(auto &v:vec) cout << v << " ";
#define dame cout<<-1<<endl
#define YES cout<<"Yes"<<endl
#define YEAH { cout << "Yes" << endl; return 0; }
#define NO cout<<"No"<<endl
#define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} // if(ans[i])YN;
#define UQ(v) v.erase( unique(all(v)), v.end() );
#define MHT(x1,x2,y1,y2) (abs(x1-x2)+abs(y1-y2)) // マンハッタン距離 = |x1-x2|+|y1-y2| 座標の絶対値の和
#define YKD(x1,x2,y1,y2) ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) // ユークリッド距離 座標の差の二乗の和
// #define YKD(x1,x2,y1,y2) (pow(x1-x2,2) + pow(y1-y2,2)) // でっかい数のとき 数が 1e10 みたいに表記される場合に注意
#define displace(vec) rotate(vec.begin(),vec.begin()+1,vec.end()) // abcd -> bcda のように一つ要素をずらす
#define DISPLACE(vec,First,Middle,Last) rotate(vec.begin()+First,vec.begin()+Middle,vec.begin()+Last)
// ……a[F-1] (( a[F] a[F+1] …… a[M-1] a[M] a[M+1] …… a[L-1] )) a[L]…… -> ……a[F-1] (( a[M] a[M+1] …… a[L-1] …… a[F] a[F+1] …… a[M-1] )) a[L]……
template<typename T> using vc = vector<T>;
template<class T> using PQ = priority_queue<T, vc<T>>; // 大きい順に取り出す
template<class T> using PQ_G = priority_queue<T, vc<T>, greater<T>>; // 小さい順に取り出す
ll pow2(ll x) { return x * x; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vc<ll> dx = { 1,-1,0,0 };
vc<ll> dy = { 0,0,1,-1 };
// vc<ll> dx={1,1,0,-1,-1,-1,0,1};
// vc<ll> dy={0,1,1,1,0,-1,-1,-1};
int INF = 2e9;
// ll INF = 2e18;
int MOD = 1e8;
int n = 50;
vc<vc<int>> a(n);
int RandInt(int aa, int bb)
{
// cout << "L" << flush;
return aa + rand() % (bb - aa - 1);
}
void Change(vc<vc<int>> &vec, int I, int J, int &MaxValue)
{
// cout << I << " " << J << endl;
// cout << 'A' << flush;
rep(i,I+1,n)
{
int mm = 0; // 辻褄合わせするためにどれだけ必要か
// 負になるなんてお母さん許さないんだからね!?
// cout << 'B' << flush;
// 差を求める
if(vec[i][J] <= a[i][J]) {
mm = a[i][J] - vec[i][J];
}
else {
mm = MOD - vec[i][J] + a[i][J];
}
// cout << 'C' << flush;
// cout << "mm:" << mm << endl;
// cout << i << ",[" << J+1 << "," << J+i-I << "]" << endl;
rep(j,J+1,J+i-I)
{
// 差を求める
if(vec[i][j] <= a[i][j])
{
if(vec[i][j] + mm < a[i][j]) mm += MOD;
mm -= a[i][j] - vec[i][j];
vec[i][j] = a[i][j];
}
else if(vec[i][j] >= a[i][j])
{
if(vec[i][j] + mm - MOD < a[i][j]) mm += MOD;
mm -= vec[i][j] - MOD - a[i][j];
vec[i][j] = a[i][j];
}
}
// cout << 'D' << flush;
// 貧乏くじ引くのはいつも最後のやつ
vec[i][J+i-I] = (vec[i][J+i-I] + mm) % MOD;
chmax( MaxValue, ( vec[i][J+i-I] <= a[i][J+i-I] ? a[i][J+i-I] - vec[i][J+i-I] : vec[i][J+i-I] - a[i][J+i-I] ) );
// cout << 'E' << flush;
}
// cout << 'F' << endl;
}
vc<vc<int>> best(n),test(n);
int BestScore = -1;
int const RepeatSize = 100000;
void Solve()
{
rep(RepeatSize)
{
int I = RandInt(2,n-1);
// cout << "R" << endl;
int J = RandInt(0,I);
// cout << "R" << endl;
// cout << I << " " << J << endl;
int MaxValue = -1;
Change(test,I,J,MaxValue);
// cout << "MV:" << MaxValue << endl;
if(MaxValue < BestScore) {
best = test;
BestScore = MaxValue;
}
}
return;
}
int main()
{
cin >> n;
rep(i,n)
{
a[i].resize(i+1), best[i].resize(i+1), test[i].resize(i+1);
mycin(a[i]);
}
rep(j,n) best[n-1][j] = a[n-1][j];
// cout << "A" << endl;
rrep(i,n-1) rep(j,0,i) {
best[i][j] = (best[i+1][j] + best[i+1][j+1]) % MOD;
// cout << best[i][j] << " " << flush;
chmax( BestScore, ( best[i][j] <= a[i][j] ? a[i][j] - best[i][j] : best[i][j] - a[i][j] ) );
}
// cout << "BS:" << BestScore << endl;
test = best;
Solve();
mycout(best[n-1]); cout << endl;
}
斉藤+あるふぁ。