結果
問題 | No.5013 セクスタプル (open) |
ユーザー |
![]() |
提出日時 | 2022-12-29 15:58:34 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,993 ms / 2,000 ms |
コード長 | 3,611 bytes |
コンパイル時間 | 2,387 ms |
実行使用メモリ | 6,952 KB |
スコア | 18,381 |
最終ジャッジ日時 | 2022-12-29 16:02:03 |
合計ジャッジ時間 | 207,664 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; const ll INF=(1ll<<60); template<class T> void chmin(T &a,T b){ if(a>b){ a=b; } } template<class T> void chmax(T &a,T b){ if(a<b){ a=b; } } int to(int i,int j){ return i*6+j; } pair<int,int> back(int x){ return {x/6,x%6}; } int d[36][6]; int cell[36]; int dp[36][6]; int *max_cell=cell; int diff(int x){ int p=back(x).first,q=back(x).second; int ret=0; rep(k,6){ int sum=0; bool t=true; rep(j,6){ sum+=dp[to(p,j)][k]; if(dp[to(p,j)][k]==0){ t=false; break; } } if(t) ret+=3+(sum-6); } rep(k,6){ int sum=0; bool t=true; rep(i,6){ sum+=dp[to(i,q)][k]; if(dp[to(i,q)][k]==0){ t=false; break; } } if(t) ret+=3+(sum-6); } return ret; } void modify(int x,int y){ rep(k,6){ swap(dp[x][k],dp[y][k]); } swap(cell[x],cell[y]); } int main(){ mt19937 mt; auto start=chrono::system_clock::now(); vector<vector<pair<int,int>>> cnt(6); rep(i,36){ int x; rep(j,6){ cin >> x; x--; d[i][x]++; } rep(j,6){ cnt[j].emplace_back(d[i][j],i); } } set<int> selected; rep(i,6){ sort(all(cnt[i])); reverse(all(cnt[i])); int p=0; for(auto &[a,b]:cnt[i]){ if(selected.find(b)!=selected.end()) continue; cell[to(i,p)]=b; selected.insert(b); p++; if(6<=p) break; } } rep(i,36){ rep(k,6){ dp[i][k]=d[cell[i]][k]; } } int pre_score=0; rep(i,6){ rep(k,6){ int sum=0; bool t=true; rep(j,6){ sum+=dp[to(i,j)][k]; if(dp[to(i,j)][k]==0){ t=false; break; } } if(t) pre_score+=3+(sum-6); } } rep(j,6){ rep(k,6){ int sum=0; bool t=true; rep(i,6){ sum+=dp[to(i,j)][k]; if(dp[to(i,j)][k]==0){ t=false; break; } } if(t) pre_score+=3+(sum-6); } } int max_score=pre_score; while(true){ auto now=chrono::system_clock::now(); double msec=chrono::duration_cast<chrono::milliseconds>(now-start).count(); if(1990<msec) break; int x=mt()%36,y=mt()%36; if(x==y) continue; int new_score=pre_score; new_score-=diff(x); new_score-=diff(y); modify(x,y); new_score+=diff(x); new_score+=diff(y); double temp=3.0+(0.0-3.0)*msec/1990.0; double prob=exp((double)(new_score-pre_score)/temp); if(1.0*mt()/mt19937::max()<prob){ if(max_score<new_score){ max_score=new_score; max_cell=cell; } pre_score=new_score; }else{ modify(x,y); } } vector<pair<int,int>> ans(36); rep(i,6){ rep(j,6){ ans[max_cell[to(i,j)]]={i,j}; } } rep(i,36){ cout << ans[i].first+1 << " " << ans[i].second+1 << endl; } }