結果

問題 No.1340 おーじ君をさがせ
ユーザー 夜
提出日時 2021-02-16 18:19:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 101,460 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 07:49:28
合計ジャッジ時間 4,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 13 ms
4,352 KB
testcase_14 AC 32 ms
4,348 KB
testcase_15 AC 33 ms
4,352 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 10 ms
4,352 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 20 ms
4,352 KB
testcase_22 AC 47 ms
4,348 KB
testcase_23 AC 19 ms
4,348 KB
testcase_24 AC 84 ms
4,352 KB
testcase_25 AC 7 ms
4,352 KB
testcase_26 AC 5 ms
4,352 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 7 ms
4,352 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 21 ms
4,348 KB
testcase_31 AC 102 ms
4,348 KB
testcase_32 AC 80 ms
4,348 KB
testcase_33 AC 80 ms
4,348 KB
testcase_34 AC 73 ms
4,352 KB
testcase_35 AC 88 ms
4,348 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 4 ms
4,348 KB
testcase_38 AC 102 ms
4,352 KB
testcase_39 AC 24 ms
4,348 KB
testcase_40 AC 26 ms
4,352 KB
testcase_41 AC 25 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 21 ms
4,348 KB
testcase_47 AC 22 ms
4,348 KB
testcase_48 AC 23 ms
4,348 KB
testcase_49 AC 25 ms
4,348 KB
testcase_50 AC 22 ms
4,348 KB
testcase_51 AC 24 ms
4,352 KB
testcase_52 AC 36 ms
4,352 KB
testcase_53 AC 38 ms
4,348 KB
testcase_54 AC 37 ms
4,352 KB
testcase_55 AC 33 ms
4,348 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 1 ms
4,348 KB
testcase_58 AC 1 ms
4,348 KB
testcase_59 AC 13 ms
4,348 KB
testcase_60 AC 2 ms
4,352 KB
testcase_61 AC 13 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long mod = 1000000007;
	int m_size;
	cin >> m_size;
	int m;
	cin >> m;
	vector<vector<long long>> mat(220);
	long long y;
	cin >> y;
	if (y == 0) {
		cout << 1 << endl;
		return 0;
	}
	vector<vector<long long>> ans(220);
	for (int i = 0; i < m_size; i++) {
		for (int j = 0; j < m_size; j++) {
			mat[i].emplace_back(0);
			ans[i].emplace_back(0);
		}
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		mat[b][a] = 1;
		ans[b][a] = 1;
	}
	y--;
	while (y > 0) {
		if ((y & 1) == 1) {
			vector<vector<long long>> ans_mem(220);
			for (int i = 0; i < m_size; i++) {
				for (int j = 0; j < m_size; j++) {
					ans_mem[i].emplace_back(0);
				}
			}
			for (int i = 0; i < m_size; i++) {
				for (int j = 0; j < m_size; j++) {
					for (int k = 0; k < m_size; k++) {
						ans_mem[i][j] += ans[i][k] * mat[k][j];
					}
					if (ans_mem[i][j] > 0) {
						ans_mem[i][j] = 1;
					}
				}
			}
			ans = ans_mem;
		}
		vector<vector<long long>> mat_mem(220);
		for (int i = 0; i < m_size; i++) {
			for (int j = 0; j < m_size; j++) {
				mat_mem[i].emplace_back(0);
			}
		}
		for (int i = 0; i < m_size; i++) {
			for (int j = 0; j < m_size; j++) {
				for (int k = 0; k < m_size; k++) {
					mat_mem[i][j] += mat[i][k] * mat[k][j];
				}
				if (mat_mem[i][j] > 0) {
					mat_mem[i][j] = 1;
				}
			}
		}
		mat = mat_mem;
		y >>= 1;
	}
	int co = 0;
	for (int i = 0; i < m_size; i++) {
		if (ans[i][0] != 0) {
			co++;
		}
	}
	cout << co << endl;
}
0