提出 #66354866


ソースコード 拡げる

#include <bits/stdc++.h>
#define REP(i, n)     for(int i = 0; i < (int)(n); ++i)
#define FOR(i, l, r)  for(int i = (int)(l); i < (int)(r); ++i)
#define RREP(i, n)    for(int i = (int)(n); i-- > 0;)
#define RFOR(i, r, l) for(int i = (int)(r); i-- > (int)(l);)
#define ALL(v)        std::begin(v), std::end(v)
using llong = long long;
using vi    = std::vector<int>;
using vvi   = std::vector<vi>;
using pii   = std::pair<int, int>;
using namespace std;
constexpr int       INF  = 1e9;
constexpr long long LINF = 1e18;
constexpr double    EPS  = 1e-10;
constexpr int       MOD  = 998'244'353;
constexpr int       MOD2 = 1e9 + 7;

template <typename Type>
inline std::istream &operator>>(std::istream &is, std::vector<Type> &v) {
    for(auto &elem : v) is >> elem;
    return is;
}

template <typename Type>
inline std::ostream &operator<<(std::ostream &os, const std::vector<Type> &v) {
    for(auto iter = v.cbegin(); iter != v.cend(); ++iter) os << (iter == v.cbegin() ? "" : " ") << *iter;
    return os;
}

#ifdef DEBUG

#include "debug.hpp"

#else

#define debug(...) static_cast<void>(0)

#endif

int main(){
    int n,m;
    cin>>n>>m;

    vector g(n,vector<pii>());
    REP(i,m){
        int u,v;
        int w;
        cin>>u>>v>>w;
        u--, v--;

        g[u].emplace_back(v,w);
        g[v].emplace_back(u,w);
    }

    int ans=0;
    auto f=[&](int i)->bool{
        int mask=~((1<<i)-1);
        int want=ans&mask;
        debug(i,bitset<30>(mask));
        debug(i,bitset<30>(want));

        queue<int> que;
        que.push(0);
        vector<bool> seen(n,false);
        while(!que.empty()){
            auto u=que.front();
            que.pop();
            if(seen[u]) continue;
            seen[u]=true;

            for(auto [v,w]:g[u]){
                if((((w&mask)^want)|want)==want) que.push(v);
            }
        }

        return seen[n-1];
    };
    RREP(i,30){
        if(!f(i)) ans|=1<<i;
    }

    cout<<ans<<endl;
}

提出情報

提出日時
問題 E - Minimum OR Path
ユーザ Today
言語 C++ 23 (gcc 12.2)
得点 450
コード長 2042 Byte
結果 AC
実行時間 1155 ms
メモリ 14240 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 35
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3420 KiB
00_sample_01.txt AC 1 ms 3488 KiB
00_sample_02.txt AC 1 ms 3476 KiB
01_handmade_00.txt AC 1 ms 3552 KiB
01_handmade_01.txt AC 1 ms 3428 KiB
01_handmade_02.txt AC 94 ms 6992 KiB
01_handmade_03.txt AC 101 ms 7948 KiB
01_handmade_04.txt AC 1 ms 3488 KiB
01_handmade_05.txt AC 1 ms 3428 KiB
01_handmade_06.txt AC 1 ms 3496 KiB
01_handmade_07.txt AC 153 ms 9764 KiB
01_handmade_08.txt AC 154 ms 9688 KiB
01_handmade_09.txt AC 154 ms 9748 KiB
02_random_00.txt AC 103 ms 10544 KiB
02_random_01.txt AC 92 ms 9048 KiB
02_random_02.txt AC 75 ms 6828 KiB
02_random_03.txt AC 149 ms 10056 KiB
02_random_04.txt AC 141 ms 10228 KiB
02_random_05.txt AC 113 ms 9320 KiB
02_random_06.txt AC 125 ms 9368 KiB
02_random_07.txt AC 153 ms 11596 KiB
02_random_08.txt AC 161 ms 13368 KiB
02_random_09.txt AC 100 ms 10196 KiB
02_random_10.txt AC 169 ms 12064 KiB
02_random_11.txt AC 263 ms 12916 KiB
02_random_12.txt AC 168 ms 11620 KiB
02_random_13.txt AC 225 ms 14060 KiB
02_random_14.txt AC 249 ms 13468 KiB
02_random_15.txt AC 129 ms 8560 KiB
02_random_16.txt AC 98 ms 9844 KiB
02_random_17.txt AC 337 ms 9760 KiB
02_random_18.txt AC 316 ms 9844 KiB
02_random_19.txt AC 168 ms 14160 KiB
02_random_20.txt AC 1155 ms 14240 KiB
02_random_21.txt AC 514 ms 14208 KiB