Submission #30883174
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;using ll = long long;void fast_io() {cin.tie(0)->sync_with_stdio(0);}const int MAX = 2e5, MOD = 998244353;int p[MAX], q[MAX];vector<int> graph[MAX + 1];ll lucas[MAX + 1];bool vis[MAX + 1];int cyc;void dfs(int v) {vis[v] = 1;for (int u : graph[v]) {if (!vis[u]) dfs(u);}cyc++;
#include <bits/stdc++.h> using namespace std; using ll = long long; void fast_io() { cin.tie(0)->sync_with_stdio(0); } const int MAX = 2e5, MOD = 998244353; int p[MAX], q[MAX]; vector<int> graph[MAX + 1]; ll lucas[MAX + 1]; bool vis[MAX + 1]; int cyc; void dfs(int v) { vis[v] = 1; for (int u : graph[v]) { if (!vis[u]) dfs(u); } cyc++; } void solve() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> q[i]; for (int i = 0; i < n; i++) { graph[p[i]].push_back(q[i]); graph[q[i]].push_back(p[i]); } ll ans = 1; for (int i = 1; i <= n; i++) { if (!vis[i]) { cyc = 0; dfs(i); ans = (ans * lucas[cyc]) % MOD; } } cout << ans << '\n'; } int main() { fast_io(); lucas[0] = 2, lucas[1] = 1; for (int i = 2; i <= MAX; i++) lucas[i] = (lucas[i - 1] + lucas[i - 2]) % MOD; int t = 1; // cin >> t; while (t--) solve(); }
Submission Info
Submission Time | |
---|---|
Task | F - Cards |
User | megagenie |
Language | C++ (GCC 9.2.1) |
Score | 500 |
Code Size | 1001 Byte |
Status | AC |
Exec Time | 88 ms |
Memory | 24048 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
random_01.txt | AC | 86 ms | 24048 KB |
random_02.txt | AC | 22 ms | 12696 KB |
random_03.txt | AC | 88 ms | 21044 KB |
random_04.txt | AC | 11 ms | 10028 KB |
random_05.txt | AC | 68 ms | 17804 KB |
random_06.txt | AC | 15 ms | 10716 KB |
random_07.txt | AC | 62 ms | 17856 KB |
random_08.txt | AC | 44 ms | 15296 KB |
random_09.txt | AC | 10 ms | 9780 KB |
random_10.txt | AC | 83 ms | 21464 KB |
random_11.txt | AC | 20 ms | 11732 KB |
random_12.txt | AC | 85 ms | 21484 KB |
random_13.txt | AC | 30 ms | 13772 KB |
random_14.txt | AC | 83 ms | 23232 KB |
random_15.txt | AC | 35 ms | 13500 KB |
random_16.txt | AC | 84 ms | 20988 KB |
random_17.txt | AC | 40 ms | 15512 KB |
random_18.txt | AC | 81 ms | 21576 KB |
random_19.txt | AC | 38 ms | 14396 KB |
sample_01.txt | AC | 7 ms | 9780 KB |
sample_02.txt | AC | 8 ms | 9856 KB |
sample_03.txt | AC | 12 ms | 9840 KB |