結果

問題 No.1577 織姫と彦星2
ユーザー 👑 NachiaNachia
提出日時 2021-06-29 19:09:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 91,688 KB
実行使用メモリ 8,812 KB
最終ジャッジ日時 2023-09-08 04:17:55
合計ジャッジ時間 8,459 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 36 ms
4,376 KB
testcase_06 AC 11 ms
4,376 KB
testcase_07 AC 159 ms
7,440 KB
testcase_08 AC 55 ms
5,084 KB
testcase_09 AC 215 ms
8,812 KB
testcase_10 AC 53 ms
4,704 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 96 ms
5,732 KB
testcase_13 AC 41 ms
4,380 KB
testcase_14 AC 120 ms
6,372 KB
testcase_15 AC 37 ms
4,664 KB
testcase_16 AC 150 ms
7,244 KB
testcase_17 AC 74 ms
5,608 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 127 ms
6,692 KB
testcase_20 AC 104 ms
6,180 KB
testcase_21 AC 146 ms
7,176 KB
testcase_22 AC 142 ms
6,952 KB
testcase_23 AC 47 ms
4,640 KB
testcase_24 AC 195 ms
7,868 KB
testcase_25 AC 32 ms
4,376 KB
testcase_26 AC 49 ms
4,864 KB
testcase_27 AC 155 ms
6,408 KB
testcase_28 AC 110 ms
6,188 KB
testcase_29 AC 72 ms
4,892 KB
testcase_30 AC 83 ms
5,344 KB
testcase_31 AC 153 ms
7,248 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 66 ms
4,972 KB
testcase_35 AC 133 ms
7,060 KB
testcase_36 AC 141 ms
6,844 KB
testcase_37 AC 203 ms
8,420 KB
testcase_38 AC 203 ms
8,284 KB
testcase_39 AC 54 ms
4,968 KB
testcase_40 AC 59 ms
5,064 KB
testcase_41 AC 179 ms
7,192 KB
testcase_42 AC 103 ms
5,428 KB
testcase_43 AC 105 ms
5,624 KB
testcase_44 AC 5 ms
4,376 KB
testcase_45 AC 23 ms
4,376 KB
testcase_46 AC 31 ms
4,376 KB
testcase_47 AC 180 ms
6,992 KB
testcase_48 AC 62 ms
4,620 KB
testcase_49 AC 74 ms
5,180 KB
testcase_50 AC 44 ms
4,612 KB
testcase_51 AC 12 ms
4,376 KB
testcase_52 AC 208 ms
7,904 KB
testcase_53 AC 201 ms
8,028 KB
testcase_54 AC 79 ms
5,100 KB
testcase_55 AC 188 ms
7,456 KB
testcase_56 AC 38 ms
4,540 KB
testcase_57 AC 18 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;
int s,t;
vector<int> st;
vector<vector<int>> E;
map<int,int> G;

int main(){
  cin >> N;
  st.resize(N+2);
  cin >> st[N] >> st[N+1];
  rep(i,N) cin >> st[i];
  E.resize(N+2);
  rep(i,N+2) G[st[i]] = i;
  rep(i,N+2) rep(d,30){
    int to = st[i] ^ (1<<d);
    if(G.find(to) == G.end()) continue;
    E[i].push_back(G[to]);
  }
  vector<int> I = {N};
  vector<int> D(N+2,-1);
  D[N] = 0;
  rep(i,I.size()){
    int p = I[i];
    for(int e : E[p]) if(D[e] == -1){
      D[e] = D[p] + 1;
      I.push_back(e);
    }
  }
  if(D[N+1] == -1) cout << "-1\n";
  else cout << (D[N+1]-1) << "\n";
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0