//#include "stub.cpp"
#include<bits/stdc++.h>
using namespace std;
#include "september.h"
#include <vector>
int n,m,p[100005],order[6][100005],st,l[100005],r[100005],par[100005],num[100005];
set<int> s[6];
int f(int a)
{
if(par[a]==a)return a;
return par[a]=f(par[a]);
}
void un(int b,int c)
{
num[f(c)]+=num[f(b)];
par[f(b)]=f(c);
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S)
{
n=N,m=M;
for(int i=1;i<=n;i++)
{
p[i-1]=F[i-1];
}
for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)order[i][j]=S[i-1][j-1];
// for(int i=1;i<n;i++)printf("%d ",p[i]);
// printf("\n");
// for(int i=1;i<=m;i++)
// {
// printf("%d\n",i);
// for(int j=1;j<=n-1;j++)printf("%d ",order[i][j]);
// printf("\n");
// }
int sz=1;
st=1;
while(st<n)
{
for(int i=st;i<n;i++)
{
for(int j=1;j<=m;j++)
{
s[j].insert(order[j][i]);
}
int kmp=0;
for(int j=2;j<=m;j++)if(s[j]==s[1])++kmp;
if(kmp==m-1)
{
l[sz]=st;
r[sz]=i;
st=i+1;
for(int j=1;j<=m;j++)s[j].clear();
++sz;
break;
}
}
}
--sz;
/*printf("%d\n",sz);
for(int i=1;i<=sz;i++)printf("%d %d\n",l[i],r[i]);*/
int target=1,ans=0;
for(int i=0;i<n;i++)par[i]=i,num[i]=1;
for(int i=sz;i>=1;i--)
{
target+=(r[i]-l[i]+1);
for(int j=l[i];j<=r[i];j++)
{
un(order[1][j],p[order[1][j]]);
}
if(num[f(0)]==target)++ans;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4580 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4440 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4680 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4576 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
98 ms |
13280 KB |
Output is correct |
5 |
Correct |
101 ms |
13272 KB |
Output is correct |
6 |
Correct |
103 ms |
13168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4580 KB |
Output is correct |
18 |
Correct |
98 ms |
13280 KB |
Output is correct |
19 |
Correct |
101 ms |
13272 KB |
Output is correct |
20 |
Correct |
103 ms |
13168 KB |
Output is correct |
21 |
Correct |
112 ms |
13020 KB |
Output is correct |
22 |
Correct |
103 ms |
13016 KB |
Output is correct |
23 |
Correct |
101 ms |
13328 KB |
Output is correct |
24 |
Correct |
102 ms |
13264 KB |
Output is correct |
25 |
Correct |
106 ms |
13156 KB |
Output is correct |
26 |
Correct |
104 ms |
13012 KB |
Output is correct |
27 |
Correct |
104 ms |
13156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
98 ms |
13280 KB |
Output is correct |
8 |
Correct |
101 ms |
13272 KB |
Output is correct |
9 |
Correct |
103 ms |
13168 KB |
Output is correct |
10 |
Correct |
74 ms |
13940 KB |
Output is correct |
11 |
Correct |
74 ms |
13804 KB |
Output is correct |
12 |
Correct |
89 ms |
13588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4580 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4440 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4680 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
2 ms |
4576 KB |
Output is correct |
34 |
Correct |
2 ms |
4444 KB |
Output is correct |
35 |
Correct |
98 ms |
13280 KB |
Output is correct |
36 |
Correct |
101 ms |
13272 KB |
Output is correct |
37 |
Correct |
103 ms |
13168 KB |
Output is correct |
38 |
Correct |
112 ms |
13020 KB |
Output is correct |
39 |
Correct |
103 ms |
13016 KB |
Output is correct |
40 |
Correct |
101 ms |
13328 KB |
Output is correct |
41 |
Correct |
102 ms |
13264 KB |
Output is correct |
42 |
Correct |
106 ms |
13156 KB |
Output is correct |
43 |
Correct |
104 ms |
13012 KB |
Output is correct |
44 |
Correct |
104 ms |
13156 KB |
Output is correct |
45 |
Correct |
74 ms |
13940 KB |
Output is correct |
46 |
Correct |
74 ms |
13804 KB |
Output is correct |
47 |
Correct |
89 ms |
13588 KB |
Output is correct |
48 |
Correct |
109 ms |
13588 KB |
Output is correct |
49 |
Correct |
77 ms |
13496 KB |
Output is correct |
50 |
Correct |
104 ms |
13604 KB |
Output is correct |
51 |
Correct |
90 ms |
13640 KB |
Output is correct |
52 |
Correct |
73 ms |
13564 KB |
Output is correct |
53 |
Correct |
74 ms |
13584 KB |
Output is correct |
54 |
Correct |
77 ms |
13592 KB |
Output is correct |