結果

問題 No.1743 Permutation Code
ユーザー FplusFplusFFplusFplusF
提出日時 2022-11-29 00:49:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,087 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 206,856 KB
実行使用メモリ 14,356 KB
最終ジャッジ日時 2024-04-15 22:10:16
合計ジャッジ時間 237,726 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
5,248 KB
testcase_01 AC 7,014 ms
5,376 KB
testcase_02 AC 7,391 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    }
}
string ten_to_two(int x){
    string s;
    while(0<x){
        s.push_back(x%2+'0');
        x/=2;
    }
    reverse(all(s));
    return s;
}
int main(){
    random_device rd;
    mt19937 mt(rd());
    auto start=chrono::system_clock::now();
    string c;
    cin >> c;
    int x=0,n=1;
    while(x<(int)c.size()){
        string s=ten_to_two(n);
        x+=s.size();
        n++;
    }
    n--;
    string v[n];
    map<string,int> mp;
    rep(i,n){
        v[i]=ten_to_two(i+1);
        mp[v[i]]=i+1;
    }
    int max_score=0;
    int p=0;
    rep(i,n){
        rep(j,v[i].size()){
            if(v[i][j]==c[p]) max_score+=100;
            p++;
        }
    }
    int now_score=0;
    while(true){
        int a=mt()%n,b=mt()%n;
        swap(v[a],v[b]);
        now_score=0;
        p=0;
        rep(i,n){
            rep(j,v[i].size()){
                if(v[i][j]==c[p]) now_score+=100;
                p++;
            }
        }
        auto now=chrono::system_clock::now();
        double sec=chrono::duration_cast<chrono::milliseconds>(now-start).count();
        double temp=100.0*8-100.0*8*sec/7950;
        double prob=exp((double)(now_score-max_score)/temp);
        double rand_double=(double)mt()/(double)(mt19937::max());
        if(rand_double<prob){
            max_score=now_score;
            /*cout << prob << "  "<< max_score << endl;
            rep(i,n){
                cout << mp[v[i]] << " ";
            }
            cout << endl;*/
        }else{
            swap(v[a],v[b]);
        }
        
        if(7950<sec||max_score==(int)c.size()*100){
            rep(i,n){
                cout << mp[v[i]] << " ";
            }
            cout << endl;
            return 0;
        }
    }
}
0