結果

問題 No.5013 セクスタプル (open)
ユーザー FplusFplusFFplusFplusF
提出日時 2022-12-29 17:53:12
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,998 ms / 2,000 ms
コード長 5,367 bytes
コンパイル時間 2,346 ms
実行使用メモリ 6,952 KB
スコア 18,471
最終ジャッジ日時 2022-12-29 17:56:43
合計ジャッジ時間 208,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[36];
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;
    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);
        }
    }
    int max_score=0;
    vector<int> per={0,1,2,3,4,5};
    do{
        set<int> selected;
        for(auto &i:per){
            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 now_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) now_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) now_score+=3+(sum-6);
            }
        }
        if(max_score<now_score){
            max_score=now_score;
            rep(i,36){
                max_cell[i]=cell[i];
            }
        }
    }while(next_permutation(all(per)));
    int pre_score=max_score;
    rep(i,36){
        cell[i]=max_cell[i];
        rep(i,36){
            rep(k,6){
                dp[i][k]=d[cell[i]][k];
            }
        }
    }
    auto start=chrono::system_clock::now();
    while(true){
        auto now=chrono::system_clock::now();
        double msec=chrono::duration_cast<chrono::milliseconds>(now-start).count();
        if(1990<msec) break;
        
        if(mt()%100<10){
            int x=mt()%36,y=mt()%36;
            int a=mt()%36,b=mt()%36;
            if(x==y||a==b) 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);
            new_score-=diff(a);
            new_score-=diff(b);
            modify(a,b);
            new_score+=diff(a);
            new_score+=diff(b);
            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;
                    rep(i,36){
                        max_cell[i]=cell[i];
                    }
                }
                pre_score=new_score;
            }else{
                modify(a,b);
                modify(x,y);
            }
        }else{
            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;
                    rep(i,36){
                        max_cell[i]=cell[i];
                    }
                }
                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;
    }
}
0