Submission #1127468

#TimeUsernameProblemLanguageResultExecution timeMemory
1127468fzyzzz_zSeptember (APIO24_september)C++20
100 / 100
187 ms11800 KiB
#include <ios> #include <iostream> #include <vector> using namespace std; // X X X X-X X X // X-X X X-X X X int solve(int n, int m, vector<int> p, vector<vector<int>> s) { vector<vector<int>> g(n); for (int i = 1; i < n; ++i) { g[p[i]].push_back(i); } vector<int> good(n - 1, 1); for (int t = 0; t < m; ++t) { vector<int> vis(n, 0), bad(n, 0); for (int i = 0; i < n; ++i) bad[i] = g[i].size(); int cnt = 0; for (int i = 0; i < n - 1; ++i) { int x = s[t][i]; vis[x] = 1; if (bad[x] > 0) { cnt++; } if (p[x] != -1) { bad[p[x]]--; if (bad[p[x]] == 0 && vis[p[x]]) { cnt--; } } good[i] &= (cnt == 0); } } vector<int> has(n, 0); int ans = 0, uni = 0; for (int i = 0; i < n - 1; ++i) { for (int j = 0; j < m; ++j) { int x = s[j][i]; if (has[x] == 0) { uni++; } has[x]++; } if (uni == i + 1 && good[i]) ans++; } return ans; } // int main(){ // ios_base::sync_with_stdio(false); // cin.tie(0); // cout << solve(5, 2, {-1, 0, 0, 1, 1}, {{4, 3, 2, 1}, {2, 3, 4, 1}});; // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...