結果

問題 No.5005 3-SAT
ユーザー umezoumezo
提出日時 2022-04-29 17:16:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,803 ms / 2,000 ms
コード長 4,363 bytes
コンパイル時間 2,279 ms
実行使用メモリ 3,752 KB
スコア 47,035
最終ジャッジ日時 2022-04-29 17:19:29
合計ジャッジ時間 188,428 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,803 ms
3,656 KB
testcase_01 AC 1,801 ms
3,672 KB
testcase_02 AC 1,803 ms
3,576 KB
testcase_03 AC 1,802 ms
3,748 KB
testcase_04 AC 1,802 ms
3,516 KB
testcase_05 AC 1,802 ms
3,636 KB
testcase_06 AC 1,802 ms
3,612 KB
testcase_07 AC 1,802 ms
3,632 KB
testcase_08 AC 1,803 ms
3,660 KB
testcase_09 AC 1,802 ms
3,664 KB
testcase_10 AC 1,802 ms
3,576 KB
testcase_11 AC 1,802 ms
3,508 KB
testcase_12 AC 1,802 ms
3,652 KB
testcase_13 AC 1,801 ms
3,512 KB
testcase_14 AC 1,802 ms
3,744 KB
testcase_15 AC 1,803 ms
3,604 KB
testcase_16 AC 1,802 ms
3,608 KB
testcase_17 AC 1,803 ms
3,744 KB
testcase_18 AC 1,802 ms
3,532 KB
testcase_19 AC 1,802 ms
3,516 KB
testcase_20 AC 1,801 ms
3,520 KB
testcase_21 AC 1,802 ms
3,652 KB
testcase_22 AC 1,803 ms
3,748 KB
testcase_23 AC 1,802 ms
3,584 KB
testcase_24 AC 1,803 ms
3,644 KB
testcase_25 AC 1,802 ms
3,520 KB
testcase_26 AC 1,801 ms
3,696 KB
testcase_27 AC 1,802 ms
3,512 KB
testcase_28 AC 1,802 ms
3,656 KB
testcase_29 AC 1,802 ms
3,568 KB
testcase_30 AC 1,802 ms
3,748 KB
testcase_31 AC 1,802 ms
3,608 KB
testcase_32 AC 1,801 ms
3,608 KB
testcase_33 AC 1,802 ms
3,704 KB
testcase_34 AC 1,803 ms
3,608 KB
testcase_35 AC 1,802 ms
3,608 KB
testcase_36 AC 1,803 ms
3,652 KB
testcase_37 AC 1,802 ms
3,608 KB
testcase_38 AC 1,802 ms
3,664 KB
testcase_39 AC 1,802 ms
3,632 KB
testcase_40 AC 1,802 ms
3,512 KB
testcase_41 AC 1,803 ms
3,668 KB
testcase_42 AC 1,802 ms
3,512 KB
testcase_43 AC 1,802 ms
3,752 KB
testcase_44 AC 1,803 ms
3,700 KB
testcase_45 AC 1,801 ms
3,608 KB
testcase_46 AC 1,802 ms
3,644 KB
testcase_47 AC 1,803 ms
3,612 KB
testcase_48 AC 1,803 ms
3,612 KB
testcase_49 AC 1,802 ms
3,656 KB
testcase_50 AC 1,803 ms
3,572 KB
testcase_51 AC 1,802 ms
3,704 KB
testcase_52 AC 1,802 ms
3,580 KB
testcase_53 AC 1,802 ms
3,520 KB
testcase_54 AC 1,803 ms
3,652 KB
testcase_55 AC 1,802 ms
3,560 KB
testcase_56 AC 1,802 ms
3,752 KB
testcase_57 AC 1,801 ms
3,616 KB
testcase_58 AC 1,802 ms
3,528 KB
testcase_59 AC 1,803 ms
3,564 KB
testcase_60 AC 1,802 ms
3,692 KB
testcase_61 AC 1,802 ms
3,672 KB
testcase_62 AC 1,802 ms
3,660 KB
testcase_63 AC 1,802 ms
3,572 KB
testcase_64 AC 1,801 ms
3,748 KB
testcase_65 AC 1,802 ms
3,576 KB
testcase_66 AC 1,802 ms
3,512 KB
testcase_67 AC 1,802 ms
3,640 KB
testcase_68 AC 1,802 ms
3,576 KB
testcase_69 AC 1,803 ms
3,608 KB
testcase_70 AC 1,802 ms
3,604 KB
testcase_71 AC 1,803 ms
3,584 KB
testcase_72 AC 1,802 ms
3,632 KB
testcase_73 AC 1,802 ms
3,520 KB
testcase_74 AC 1,803 ms
3,580 KB
testcase_75 AC 1,803 ms
3,652 KB
testcase_76 AC 1,801 ms
3,704 KB
testcase_77 AC 1,801 ms
3,656 KB
testcase_78 AC 1,802 ms
3,588 KB
testcase_79 AC 1,803 ms
3,692 KB
testcase_80 AC 1,803 ms
3,612 KB
testcase_81 AC 1,803 ms
3,612 KB
testcase_82 AC 1,802 ms
3,664 KB
testcase_83 AC 1,801 ms
3,628 KB
testcase_84 AC 1,802 ms
3,512 KB
testcase_85 AC 1,802 ms
3,632 KB
testcase_86 AC 1,802 ms
3,608 KB
testcase_87 AC 1,803 ms
3,632 KB
testcase_88 AC 1,802 ms
3,560 KB
testcase_89 AC 1,801 ms
3,576 KB
testcase_90 AC 1,802 ms
3,512 KB
testcase_91 AC 1,802 ms
3,580 KB
testcase_92 AC 1,803 ms
3,600 KB
testcase_93 AC 1,803 ms
3,512 KB
testcase_94 AC 1,802 ms
3,564 KB
testcase_95 AC 1,801 ms
3,576 KB
testcase_96 AC 1,802 ms
3,608 KB
testcase_97 AC 1,802 ms
3,576 KB
testcase_98 AC 1,803 ms
3,512 KB
testcase_99 AC 1,802 ms
3,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

const int MAX=2048;

static uint32_t randXor(){
  static uint32_t x=123456789;
  static uint32_t y=362436069;
  static uint32_t z=521288629;
  static uint32_t w=88675123;
  uint32_t t;
 
  t=x^(x<<11);
  x=y;y=z;z=w;
  return w=(w^(w>>19))^(t^(t>>8));
}

static double rand01(){
    return (randXor()+0.5)*(1.0/UINT_MAX);
}

int calc(vector<int>&A,vector<int>&B,vector<int>&C,vector<int>&P,vector<int>&Q,vector<int>&R,vector<int>&S){
  int num=0;
  rep(i,MAX){
    bool b=false;
    if(S[A[i]]==P[i]) b=true;
    if(S[B[i]]==Q[i]) b=true;
    if(S[C[i]]==R[i]) b=true;
    if(b) num++;
    else break;
  }
  return num;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  vector<int> A(MAX),B(MAX),C(MAX),P(MAX),Q(MAX),R(MAX);
  vector<int> A0,A1,B0,B1,C0,C1;
  rep(i,MAX){
    cin>>A[i]>>B[i]>>C[i]>>P[i]>>Q[i]>>R[i];
    if(P[i]==0) A0.push_back(i);
    else A1.push_back(i);
    if(Q[i]==0) B0.push_back(i);
    else B1.push_back(i);
    if(R[i]==0) C0.push_back(i);
    else C1.push_back(i);
  }
  A0.push_back(MAX),A1.push_back(MAX),B0.push_back(MAX);
  B1.push_back(MAX),C0.push_back(MAX),C1.push_back(MAX);
  
  auto startClock=system_clock::now();
  int bestscore=0;
  vector<int> bestS;
  
  const static double START_TEMP=1500;
  const static double END_TEMP  = 100;
  const static double END_TIME=1.8;
 
  double time=0.0;
  do{
    const double progressRatio=time/END_TIME;
    const double temp=START_TEMP+(END_TEMP-START_TEMP)*progressRatio;
    
    int score=0;
    vector<int> S(256),used(256);
    rep(i,MAX){
      score++;
      double e=1.0-(double)i/MAX;
      if(used[A[i]] && S[A[i]]==P[i]) continue;
      if(used[B[i]] && S[B[i]]==Q[i]) continue;
      if(used[C[i]] && S[C[i]]==R[i]) continue;       
      int a=-1,b=-1,c=-1;
      if(used[A[i]]==0 && P[i]==0){
        auto itr=lower_bound(ALL(A1),i)-A1.begin();
        a=A1[itr];
      }
      if(used[A[i]]==0 && P[i]==1){
        auto itr=lower_bound(ALL(A0),i)-A0.begin();
        a=A0[itr];
      }
      if(used[B[i]]==0 && Q[i]==0){
        auto itr=lower_bound(ALL(B1),i)-B1.begin();
        b=B1[itr];
      }
      if(used[B[i]]==0 && Q[i]==1){
        auto itr=lower_bound(ALL(B0),i)-B0.begin();
        b=B0[itr];
      }
      if(used[C[i]]==0 && R[i]==0){
        auto itr=lower_bound(ALL(C1),i)-C1.begin();
        c=C1[itr];
      }
      if(used[C[i]]==0 && R[i]==1){
        auto itr=lower_bound(ALL(C0),i)-C0.begin();
        c=C0[itr];
      }
      if(a==-1 && b==-1 && c==-1){
        score--;
        break;
      }
      double t=rand01();
      if(a>0 && b>0 && c>0){
        double aa=(double)(a-i)/(a+b+c-3*i)*(1.0-e)+e/3.0;
        double bb=(double)(b-i)/(a+b+c-3*i)*(1.0-e)+e/3.0;
        if(t<aa){
          S[A[i]]=P[i];
          used[A[i]]=1;
        }
        else if(t<aa+bb){
          S[B[i]]=Q[i];
          used[B[i]]=1;
        }
        else{
          S[C[i]]=R[i];
          used[C[i]]=1;
        }
      }
      else if(a>0 && b>0){
        double aa=(double)(a-i)/(a+b-2*i)*(1-e)+e/2;
        if(t<aa){
          S[A[i]]=P[i];
          used[A[i]]=1;
        }
        else{
          S[B[i]]=Q[i];
          used[B[i]]=1;
        }
      }
      else if(c>0 && b>0){
        double cc=(double)(c-i)/(c+b-2*i)*(1-e)+e/2;
        if(t<cc){
          S[C[i]]=R[i];
          used[C[i]]=1;
        }
        else{
          S[B[i]]=Q[i];
          used[B[i]]=1;
        }
      }
      else if(c>0 && a>0){
        double cc=(double)(c-i)/(c+a-2*i)*(1-e)+e/2;
        if(t<cc){
          S[C[i]]=R[i];
          used[C[i]]=1;
        }
        else{
          S[A[i]]=P[i];
          used[A[i]]=1;
        }
      }
      else if(a>0){
        S[A[i]]=P[i];
        used[A[i]]=1;
      }
      else if(b>0){
        S[B[i]]=Q[i];
        used[B[i]]=1;
      }
      else if(c>0){
        S[C[i]]=R[i];
        used[C[i]]=1;
      }
    }
    if(score>bestscore){
      bestscore=score;
      bestS=S;
    }
    
    time=(duration_cast<microseconds>(system_clock::now()-startClock).count()*1e-6);
  }while(time<END_TIME);

  for(int i=255;i>=0;i--) cout<<bestS[i];
  cout<<endl;
  
  cout<<calc(A,B,C,P,Q,R,bestS)<<endl;

  return 0;
}
0