|
|
back to boardTests or help please If you don't feel like reviewing my code at least give me some tests please. So... um... I think my code should work... I tested it along with an accepted program... and it worked fine... Here's the code: #define DM 1001 #include <bitset> #include <iostream> #include <set> using namespace std; bitset <DM> bs; bool verif; int n, c, lg[DM], mp[DM]; long long v; set <int> s; void recursiv (int a) { bs[a] = 1; ++v; if (s.find(mp[a]) != s.end()) return; s.insert(a); recursiv(mp[a]); } int main () { cin >> n; for (int i = 1; i <= n; ++i) { cin >> mp[i]; if (mp[i] == i) bs[i] = 1; } for (int i = 1; i <= n; ++i) if (!bs[i]) { recursiv(i); s.clear(); lg[++c] = v; v = 0; } for (v = lg[1]; !verif; ++v) { verif = 1; for (int i = 1; i <= c; ++i) if (v%lg[i] != 0) verif = 0, i = c + 1; } cout << v - 1; return 0; } Re: Tests or help please Your solution is good, but try to fix these problems : Test 3 1 2 3 and don't use set. You will get time limit for n = 1000 sorry for my poor english! |
|
|