ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1024. Permutations

Tests or help please
Posted by Ghiorghiu Ioan-Viorel 16 Apr 2017 00:12
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
Posted by Khujamurod97 10 Dec 2017 14:53
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!