結果

問題 No.1647 Travel in Mitaru city 2
ユーザー みしあみしあ
提出日時 2021-10-22 18:22:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,903 bytes
コンパイル時間 5,424 ms
コンパイル使用メモリ 281,028 KB
実行使用メモリ 20,808 KB
最終ジャッジ日時 2023-10-24 05:08:11
合計ジャッジ時間 22,961 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
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 -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
template<class T>using uset = unordered_set<T>;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
//using T = tuple<ll, ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

#ifdef LOCAL
void O() {cerr << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#else
template<class T, class... Ts> void O(T&& o, Ts&&... args){};
#endif
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

umap<ll, vl> HP, WP;
umap<ll, ll> ind;
uset<ll> seen;
ll pos(ll h, ll w){
    return h*(ll)2e5+w;
}

bool solve(ll i, ll h, ll w){
    ll p = pos(h, w);
    if(i == 0){
        cout << 4 << el;
        return true;
    }
    if(seen.count(p)) return false;
    seen.insert(p);
    if((i&1)){
        EACH(v, HP[h]){
            if(solve(i-1, h, v)){
                cout << ind[p] << (i==4?"":" ");
                return true;
            }
        }
    }else{
        EACH(v, WP[w]){
            if(solve(i-1, v, w)){
                cout << ind[p] << (i==4?"":" ");
                return true;
            }
        }
    }
    seen.erase(p);
    return false;
}

void Main(){
    I(ll, H, W, N);
    vl X(N), Y(N);
    REP(i, N){
        I(ll, h, w);
        HP[h].push_back(w);
        WP[w].push_back(h);
        ind[pos(h, w)] = i+1;
        X[i] = h;
        Y[i] = w;
    }
    bool flag = false;
    REP(i, N){
        if(solve(4, X[i], Y[i])){
            flag = true;
            break;
        }
    }
    if(!flag){
        cout << -1;
    }
    cout << el;
}
0