結果
問題 |
No.5021 Addition Pyramid
|
ユーザー |
|
提出日時 | 2025-02-25 22:38:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,804 ms / 2,000 ms |
コード長 | 2,981 bytes |
コンパイル時間 | 2,844 ms |
コンパイル使用メモリ | 223,880 KB |
実行使用メモリ | 6,820 KB |
スコア | 44,208,920 |
最終ジャッジ日時 | 2025-02-25 22:39:43 |
合計ジャッジ時間 | 97,209 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define rrep(i, s, t) for (ll i = ((t) - 1); i >= (ll)(s); i--) template<typename T> bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template<typename T> bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; // randxor unsigned int randxor(){ static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t=(x^(x<<11)); x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } constexpr unsigned int INF = -1; // ms コピペ int timer(){ static auto st = chrono::system_clock::now(); auto en = chrono::system_clock::now(); return chrono::duration_cast<chrono::milliseconds>(en - st).count(); } constexpr int N = 50; vector<vector<int>> a(N,vector<int>(N,-1)); constexpr int MOD = 100000000; ll score(const vector<int> &c){ vector<vector<int>> tmp(N,vector<int>(N)); tmp[N-1]=c; for(int i=N-1;i>0;i--){ rep(j,0,i) tmp[i-1][j]=(tmp[i][j]+tmp[i][j+1])%MOD; } // constexpr int m=10; // priority_queue<int,vector<int>,greater<int>> pq; int mx=-1; int cnt=0; rep(i,0,N) rep(j,0,i+1){ int d=abs(tmp[i][j]-a[i][j]); chmin(d,MOD-d); // if((int)pq.size()<m) pq.push(d); // else if(pq.top()<d){ // pq.pop(); // pq.push(d); // } if(mx<d){ mx=d; cnt=1; }else if(mx==d){ cnt++; } } return (ll)mx*mx*cnt; } int main(){ timer(); { int n; cin>>n; } rep(i,0,N){ rep(j,0,i+1) cin>>a[i][j]; } vector<int> ans=a.back(); ll now_score=score(ans); rep(loop,0,10000){ vector<int> tmp(N); rep(i,0,N) tmp[i]=randxor()%MOD; ll tmp_score=score(tmp); if(now_score>tmp_score){ swap(tmp,ans); swap(now_score,tmp_score); } } constexpr double start_temp = MOD; constexpr double end_temp = 1; constexpr double end_time = 1800; // rep(loop,0,100000){ while(1){ int now_time=timer(); if(now_time>end_time) break; double temp=start_temp+(end_temp-start_temp)*(now_time/end_time); int change_size=randxor()%2+1; vector<pair<int,int>> change(change_size); if(change_size==1){ int idx=randxor()%N; int ad=randxor()%(MOD-1)+1; ans[idx]+=ad; if(ans[idx]>=MOD) ans[idx]-=MOD; change[0]={idx,ad}; }else{ int idx1=randxor()%N; int idx2=(idx1+(randxor()%(N-1))+1)%N; int ad1=randxor()%(MOD/3-1)+1; int ad2=MOD-ad1; ans[idx1]+=ad1; if(ans[idx1]>=MOD) ans[idx1]-=MOD; ans[idx2]+=ad2; if(ans[idx2]>=MOD) ans[idx2]-=MOD; change[0]={idx1,ad1}; change[1]={idx2,ad2}; } ll tmp_score=score(ans); if(exp((now_score-tmp_score)/temp)*INF>randxor()){ swap(now_score,tmp_score); }else{ for(auto[idx,ad]:change){ ans[idx]-=ad; if(ans[idx]<0) ans[idx]+=MOD; } } } rep(i,0,N) cout<<ans[i]<<" "; cout<<"\n"; }