結果

問題 No.2565 はじめてのおつかい
ユーザー ゆにぽけゆにぽけ
提出日時 2023-12-02 15:00:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 134,804 KB
実行使用メモリ 11,712 KB
最終ジャッジ日時 2023-12-02 15:00:33
合計ジャッジ時間 4,490 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,000 KB
testcase_01 AC 3 ms
8,000 KB
testcase_02 AC 4 ms
8,000 KB
testcase_03 AC 46 ms
11,712 KB
testcase_04 AC 31 ms
11,712 KB
testcase_05 AC 5 ms
8,000 KB
testcase_06 AC 28 ms
9,152 KB
testcase_07 AC 15 ms
8,640 KB
testcase_08 AC 16 ms
8,768 KB
testcase_09 AC 25 ms
9,024 KB
testcase_10 AC 18 ms
8,896 KB
testcase_11 AC 41 ms
10,176 KB
testcase_12 AC 11 ms
8,256 KB
testcase_13 AC 27 ms
8,768 KB
testcase_14 AC 29 ms
9,664 KB
testcase_15 AC 31 ms
9,408 KB
testcase_16 AC 29 ms
10,304 KB
testcase_17 AC 8 ms
8,384 KB
testcase_18 AC 10 ms
9,024 KB
testcase_19 AC 36 ms
10,048 KB
testcase_20 AC 31 ms
9,920 KB
testcase_21 AC 29 ms
9,920 KB
testcase_22 AC 16 ms
9,280 KB
testcase_23 AC 20 ms
9,280 KB
testcase_24 AC 6 ms
8,256 KB
testcase_25 AC 28 ms
9,920 KB
testcase_26 AC 19 ms
9,152 KB
testcase_27 AC 27 ms
9,920 KB
testcase_28 AC 32 ms
9,920 KB
testcase_29 AC 37 ms
10,304 KB
testcase_30 AC 29 ms
10,048 KB
testcase_31 AC 30 ms
9,920 KB
testcase_32 AC 16 ms
9,152 KB
testcase_33 AC 28 ms
10,048 KB
testcase_34 AC 29 ms
9,792 KB
testcase_35 AC 31 ms
10,176 KB
testcase_36 AC 28 ms
10,048 KB
testcase_37 AC 19 ms
9,280 KB
testcase_38 AC 27 ms
9,792 KB
testcase_39 AC 28 ms
9,536 KB
testcase_40 AC 31 ms
10,304 KB
testcase_41 AC 39 ms
10,304 KB
testcase_42 AC 19 ms
9,024 KB
testcase_43 AC 25 ms
9,536 KB
testcase_44 AC 15 ms
8,768 KB
testcase_45 AC 9 ms
8,512 KB
testcase_46 AC 32 ms
9,536 KB
testcase_47 AC 21 ms
8,768 KB
testcase_48 AC 18 ms
8,896 KB
testcase_49 AC 11 ms
8,256 KB
testcase_50 AC 23 ms
8,768 KB
testcase_51 AC 4 ms
8,000 KB
testcase_52 AC 19 ms
8,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<functional>
#include<utility>
using namespace std;
int N,M;
vector<int> G[1 << 17];
int dp[1 << 17][1 << 2];
void solve()
{
	cin >> N >> M;
	for(int i = 0;i < M;i++)
	{
		int u,v;
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
	}
	for(int i = 0;i < N;i++)for(int j = 0;j < 1 << 2;j++) dp[i][j] = -1;
	dp[0][0] = 0;
	queue<pair<int,int>> Q;
	Q.push(make_pair(0,0));
	while(!Q.empty())
	{
		auto [u,s] = Q.front();
		Q.pop();

		for(int v:G[u])
		{
			int ns = s;
			if(v == N-2) ns |= 1 << 0;
			if(v == N-1) ns |= 1 << 1;
			if(dp[v][ns] < 0) 
			{
				dp[v][ns] = dp[u][s] + 1;
				Q.push(make_pair(v,ns));
			}
		}
	}
	cout << dp[0][3] << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) solve();
}
0