QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245569#5487. Movie Nightmomen159#WA 7ms5240kbC++141.6kb2023-11-10 02:36:122023-11-10 02:36:12

Judging History

你现在查看的是最新测评结果

  • [2023-11-10 02:36:12]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:5240kb
  • [2023-11-10 02:36:12]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define momen ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define ld long double
#define fp(n) for(int i=0;i<n;i++)
#define fp1(n) for(int i=1;i<=n;i++)
#define all(v) v.begin() , v.end()
const int mod = 1e9 + 7, N = 2e5 + 5, M = 8e6 + 5;
const ll LG = 20, inf = 1e9 + 6;


int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int adj[N] , in[N];
ll ans[N] ;
ll answer = 1 ;
bool vis[N] ;

ll dfs(int i){
    if (vis[i])
        return 1;
    vis[i] = 1;
    ll ret = ans[i] ;
    ret*= dfs(adj[i]) ;
    ret%=mod ;
    return ret ;
}


void solve(int z) {
    int n;
    cin>>n ;

    for (int i = 1; i <= n ; ++i) {
        int x ;
        cin>>x ;
        adj[i] = x ;
        in[x]++;
    }
    queue<int>q ;
    for (int i = 1; i <= n ; ++i) {
        if (in[i] == 0)
            q.push(i) ;
        ans[i] = 1;
    }
    while (!q.empty()){
        int u = q.front() ;
        q.pop() ;
        in[adj[u]] -- ;
        ans[adj[u]] *= (ans[u]+1) ;
        ans[adj[u]]%=mod ;
        vis[u] = 1;
        if (in[adj[u]] == 0)
            q.push(adj[u]) ;
    }
    for (int i = 1; i <= n ; ++i) {
        if (!vis[i])
            answer *= (1 +dfs(i)) ;
        answer%=mod ;
    }
    cout<<answer-1<<endl;
}


int main() {
    momen
    int t = 1;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
//    cin >> t;

    for (int i = 1; i <= t; ++i) {
        //cout<<"Case #"<<i<<": ";
        solve(t);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

4
2
3
4
3

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

5
2
3
1
5
4

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

6
2
4
2
6
1
3

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

8
2
3
4
1
3
3
1
4

output:

16

result:

ok single line: '16'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

4
3
3
4
3

output:

4

result:

ok single line: '4'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

8
8
6
8
1
3
3
3
6

output:

24

result:

ok single line: '24'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

8
6
6
6
1
8
7
1
7

output:

24

result:

ok single line: '24'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3444kb

input:

7
2
3
1
5
4
7
6

output:

7

result:

ok single line: '7'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

11
2
5
2
2
6
7
5
5
10
11
10

output:

56

result:

ok single line: '56'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

30
11
27
25
25
18
18
4
9
27
30
7
16
22
22
28
11
4
30
6
7
13
9
29
26
16
29
28
13
6
26

output:

35936

result:

ok single line: '35936'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3456kb

input:

192
2
3
2
5
6
5
8
9
8
11
12
11
14
15
14
17
18
17
20
21
20
23
24
23
26
27
26
29
30
29
32
33
32
35
36
35
38
39
38
41
42
41
44
45
44
47
48
47
50
51
50
53
54
53
56
57
56
59
60
59
62
63
62
65
66
65
68
69
68
71
72
71
74
75
74
77
78
77
80
81
80
83
84
83
86
87
86
89
90
89
92
93
92
95
96
95
98
99
98
101
102
...

output:

767713260

result:

ok single line: '767713260'

Test #12:

score: 0
Accepted
time: 7ms
memory: 5240kb

input:

100000
37545
63739
77335
76669
41730
7658
16542
96644
93229
26821
44918
85782
59893
20668
23347
7485
66696
52156
83919
58211
21501
74582
15535
95723
93846
56664
45820
76652
119
87653
94275
7476
10922
22482
97813
44052
1939
82364
97592
50820
14029
72907
60215
75940
69655
61420
91810
80030
20680
10647...

output:

547375115

result:

ok single line: '547375115'

Test #13:

score: 0
Accepted
time: 3ms
memory: 4272kb

input:

50000
2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...

output:

49999

result:

ok single line: '49999'

Test #14:

score: 0
Accepted
time: 3ms
memory: 4244kb

input:

50000
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...

output:

49999

result:

ok single line: '49999'

Test #15:

score: 0
Accepted
time: 7ms
memory: 5228kb

input:

100000
57960
17255
59039
48160
38428
5639
81797
7727
18708
13985
41346
12136
56190
53735
1276
36510
37480
62557
86522
26392
35428
31380
29697
50833
34282
87940
30357
10461
89546
67687
4208
86692
76322
93916
43063
66954
33774
17718
82112
77402
83276
8368
46588
94129
55329
29682
45681
48861
96804
7131...

output:

432418538

result:

ok single line: '432418538'

Test #16:

score: -100
Wrong Answer
time: 0ms
memory: 3452kb

input:

61
2
1
1
3
3
5
6
6
8
9
9
9
9
9
9
9
9
17
18
18
18
21
22
22
22
22
26
27
27
29
30
30
30
33
34
34
34
37
38
38
40
41
41
41
41
45
46
46
48
49
49
51
52
52
52
55
56
56
58
59
59

output:

-1

result:

wrong answer 1st lines differ - expected: '1000000006', found: '-1'