結果
問題 | No.2565 はじめてのおつかい |
ユーザー | マベマス(mavemas_413) |
提出日時 | 2023-11-26 17:07:40 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 4,056 bytes |
コンパイル時間 | 5,930 ms |
コンパイル使用メモリ | 313,160 KB |
実行使用メモリ | 13,004 KB |
最終ジャッジ日時 | 2024-09-26 11:50:36 |
合計ジャッジ時間 | 10,416 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
9,700 KB |
testcase_01 | AC | 9 ms
9,744 KB |
testcase_02 | AC | 6 ms
9,756 KB |
testcase_03 | AC | 101 ms
13,004 KB |
testcase_04 | AC | 71 ms
13,004 KB |
testcase_05 | AC | 6 ms
9,624 KB |
testcase_06 | AC | 60 ms
10,992 KB |
testcase_07 | AC | 34 ms
10,348 KB |
testcase_08 | AC | 31 ms
10,416 KB |
testcase_09 | AC | 54 ms
10,928 KB |
testcase_10 | AC | 38 ms
10,520 KB |
testcase_11 | AC | 78 ms
11,536 KB |
testcase_12 | AC | 24 ms
10,140 KB |
testcase_13 | AC | 38 ms
10,556 KB |
testcase_14 | AC | 57 ms
11,040 KB |
testcase_15 | AC | 63 ms
11,124 KB |
testcase_16 | AC | 52 ms
11,472 KB |
testcase_17 | AC | 16 ms
10,096 KB |
testcase_18 | AC | 17 ms
10,144 KB |
testcase_19 | AC | 70 ms
11,420 KB |
testcase_20 | AC | 61 ms
11,228 KB |
testcase_21 | AC | 60 ms
11,224 KB |
testcase_22 | AC | 32 ms
10,628 KB |
testcase_23 | AC | 38 ms
10,840 KB |
testcase_24 | AC | 11 ms
9,936 KB |
testcase_25 | AC | 53 ms
11,336 KB |
testcase_26 | AC | 38 ms
10,656 KB |
testcase_27 | AC | 52 ms
11,244 KB |
testcase_28 | AC | 60 ms
11,408 KB |
testcase_29 | AC | 67 ms
11,772 KB |
testcase_30 | AC | 60 ms
11,376 KB |
testcase_31 | AC | 60 ms
11,288 KB |
testcase_32 | AC | 35 ms
10,620 KB |
testcase_33 | AC | 55 ms
11,296 KB |
testcase_34 | AC | 59 ms
11,256 KB |
testcase_35 | AC | 58 ms
11,424 KB |
testcase_36 | AC | 58 ms
11,312 KB |
testcase_37 | AC | 37 ms
10,808 KB |
testcase_38 | AC | 57 ms
11,100 KB |
testcase_39 | AC | 54 ms
10,988 KB |
testcase_40 | AC | 67 ms
11,600 KB |
testcase_41 | AC | 68 ms
11,648 KB |
testcase_42 | AC | 38 ms
10,708 KB |
testcase_43 | AC | 50 ms
11,084 KB |
testcase_44 | AC | 30 ms
10,584 KB |
testcase_45 | AC | 17 ms
10,144 KB |
testcase_46 | AC | 68 ms
11,224 KB |
testcase_47 | AC | 46 ms
10,812 KB |
testcase_48 | AC | 38 ms
10,580 KB |
testcase_49 | AC | 24 ms
10,248 KB |
testcase_50 | AC | 54 ms
11,148 KB |
testcase_51 | AC | 7 ms
9,748 KB |
testcase_52 | AC | 44 ms
11,024 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; // long long using ll = long long; // unsigned long long using ull = unsigned long long; // string using str = string; // long double using ld = long double; // pair using pll = pair < ll, ll >; // tuple using tlll = tuple < ll, ll, ll >; // vector template < class T > using v = vector < T >; using vl = v < ll >; using vbl = v < bool >; // priority_queue template < class T > using pq = priority_queue < T >; template < class T > using pqg = priority_queue < T, v < T >, greater < T > >; // unordered_set template < class T > using uset = unordered_set < T > ; // unordered_map template < class T, class U > using umap = unordered_map < T, U > ; // rep #define rep(i, a, b) for(ll i = a; i <= b; i ++) #define Rep(i, a) for(ll i = 0; i < a; i ++) #define rrep(i, a, b) for(ll i = a; i >= b; i --) #define repp(i, a, b, c) for(ll i = a; i <= b; i += c) // binary search #define lobo(x, k) lower_bound(x.begin(), x.end(), k) - x.begin() #define Lobo(x, a, b, k) lower_bound(x + a, x + b + 1, k) - x #define upbo(x, k) upper_bound(x.begin(), x.end(), k) - x.begin() #define Upbo(x, a, b, k) upper_bound(x + a, x + b + 1, k) - x; // snippet #define eruni(x) x.erase(unique(x.begin(), x.end()), x.end()) #define eb emplace_back #define mp make_pair #define mt make_tuple #define all(x) x.begin(), x.end() #define rll(x) x.rbegin(), x.rend() #define sz(x) (ll)x.size() #define f first #define s second #define in insert #define pf push_front #define p_f pop_front #define pb push_back #define p_b pop_back #define p_p prev_permutation #define n_p next_permutation #define led leader #define print(a) printf("%.20Lf", a) #define func function // function 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;} // out void Yes(bool f = true) {cout << (f ? "Yes" : "No" ) << endl;} void No(bool f = true) {cout << (f ? "No" : "Yes" ) << endl;} void YES(bool f = true) {cout << (f ? "YES" : "NO" ) << endl;} void NO(bool f = true) {cout << (f ? "NO" : "YES" ) << endl;} template < class T > void out(T a) {cout << a << endl;} template < class T > void out1(T a) {cout << a << " ";} template < class T, class U > void out2(T a, U b) {cout << a << " " << b << endl;} template < class T> void allout(T &a) { for(auto x : a) cout << x << " "; cout << endl; } template < class T > void allout1(T &a) { for(auto x : a) cout << x << endl; } // modint using modi = modint998244353; using mint = modint1000000007; // constant const ll md = 998244353; const ll mo = 1000000007; const ld pi = acos(-1); const ll inf = (1LL << 60); const ll n1 = 100009; const ll n2 = 200009; const ll n3 = 300009; const ll n5 = 500009; // grid const pll ar1[4] = { {0, 0}, {1, 0}, {0, 1}, {1, 1} }; const pll ar2[4] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1} }; const pll ar3[8] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1}, {-1, 1}, {1, -1}, {1, 1}, {-1, -1} }; int main(){ ll n, m; vl G[n2]; cin >> n >> m; Rep(i, m){ ll a, b; cin >> a >> b; G[a].eb(b); } auto bfs = [&](ll x, ll y){ vl D(n2, -1); queue < ll > Q; Q.push(x); D[x] = 0; while(sz(Q)){ ll p = Q.front(); Q.pop(); for(auto nex : G[p]){ if(D[nex] == -1){ D[nex] = D[p] + 1; Q.push(nex); } } } return D[y]; }; ll d1 = -1, d2 = -1, ans = inf; bool f1 = true, f2 = true; if(bfs(1, n - 1) == -1 || bfs(n - 1, n) == -1 || bfs(n, 1) == -1) f1 = false; if(bfs(1, n) == -1 || bfs(n, n - 1) == -1 || bfs(n - 1, 1) == -1) f2 = false; if(f1){ d1 ++; d1 += bfs(1, n - 1); d1 += bfs(n - 1, n); d1 += bfs(n, 1); chmin(ans, d1); } if(f2){ d2 ++; d2 += bfs(1, n); d2 += bfs(n, n - 1); d2 += bfs(n - 1, 1); chmin(ans, d2); } if(ans == inf) ans = -1; out(ans); }