Task: | paleta |
Sender: | eXeP |
Submission time: | 2016-08-01 16:51:50 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.05 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | WRONG ANSWER | 0.06 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | WRONG ANSWER | 0.05 s | details |
#7 | WRONG ANSWER | 0.05 s | details |
#8 | WRONG ANSWER | 0.06 s | details |
#9 | ACCEPTED | 0.05 s | details |
#10 | WRONG ANSWER | 0.06 s | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | WRONG ANSWER | 0.05 s | details |
#13 | ACCEPTED | 0.06 s | details |
#14 | WRONG ANSWER | 0.06 s | details |
#15 | WRONG ANSWER | 0.06 s | details |
#16 | WRONG ANSWER | 0.06 s | details |
#17 | WRONG ANSWER | 0.06 s | details |
#18 | WRONG ANSWER | 0.06 s | details |
#19 | ACCEPTED | 0.06 s | details |
#20 | WRONG ANSWER | 0.20 s | details |
#21 | ACCEPTED | 0.06 s | details |
#22 | WRONG ANSWER | 0.19 s | details |
#23 | WRONG ANSWER | 0.06 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:74:9: warning: statement has no effect [-Wunused-value] 1==1; ^ input/code.cpp:83:18: warning: unused variable 'yk' [-Wunused-variable] int cyc = 0, yk; ^
Code
#include <bits/stdc++.h> #define i64 long long #define u64 unsigned long long #define i32 int #define u32 unsigned int #define pii pair<int, int> #define pll pair<long long, long long> #define ld long double #define defmod 1000000007 #define mati64(a,b) vector<vector<i64>>(a, vector<i64>(b, 0)); using namespace std; i64 n, k; int f[1010101]; int c[1010101]; int d1[1010101]; int t1[1010101]; int main(){ cin.sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 0; i < n; ++i){ cin >> f[i+1]; c[f[i+1]]++; } i64 ans = 1; int cn = 0; for(int i = 1; i <= n; ++i){ if(c[i] || d1[i]) continue; cn++; int cur = i; int ti = 1; int cyc = 0, yk; while(true){ d1[cur] = cn; t1[cur] = ti; int ne = f[cur]; if(d1[ne] && d1[ne] != cn){ while(ti--) ans = (ans*(k-1))%defmod; goto ohi; } else if(d1[ne]){ cyc = t1[cur]-t1[ne]+1; yk = t1[ne]-1; break; } ti++; cur = ne; } while(yk--) ans = (ans*(k-1))%defmod; ans = (ans*k)%defmod; cyc--; if(cyc){ ans = (ans*(k-1))%defmod; cyc--; } while(cyc > 0){ ans = (ans*(k-2))%defmod; cyc--; } ohi: 1==1; } for(int i = 1; i <= n; ++i){ if(d1[i]) continue; cn++; int cur = i; int ti = 1; int cyc = 0, yk; while(true){ d1[cur] = cn; t1[cur] = ti; int ne = f[cur]; if(d1[ne]){ cyc = t1[cur]-t1[ne]+1; break; } ti++; cur = ne; } ans = (ans*k)%defmod; cyc--; if(cyc){ ans = (ans*(k-1))%defmod; cyc--; } while(cyc > 0){ ans = (ans*(k-2))%defmod; cyc--; } } cout << ans << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 3
2 1 |
correct output |
---|
6 |
user output |
---|
6 |
Test 2
Verdict: ACCEPTED
input |
---|
3 4
2 3 1 |
correct output |
---|
24 |
user output |
---|
24 |
Test 3
Verdict: ACCEPTED
input |
---|
3 4
2 1 1 |
correct output |
---|
36 |
user output |
---|
36 |
Test 4
Verdict: WRONG ANSWER
input |
---|
10 4
3 10 7 9 1 4 8 5 6 2 |
correct output |
---|
69120 |
user output |
---|
27648 |
Test 5
Verdict: ACCEPTED
input |
---|
10 2
9 4 2 5 8 10 6 3 1 7 |
correct output |
---|
0 |
user output |
---|
0 |
Test 6
Verdict: WRONG ANSWER
input |
---|
20 6
15 16 6 12 8 2 11 4 14 17 8 11... |
correct output |
---|
749062329 |
user output |
---|
999455687 |
Test 7
Verdict: WRONG ANSWER
input |
---|
10 3
10 7 6 5 9 2 3 6 4 1 |
correct output |
---|
1296 |
user output |
---|
432 |
Test 8
Verdict: WRONG ANSWER
input |
---|
100 6
70 62 57 34 87 73 81 45 11 25 ... |
correct output |
---|
170647921 |
user output |
---|
864810153 |
Test 9
Verdict: ACCEPTED
input |
---|
5 7
2 3 4 5 5 |
correct output |
---|
9072 |
user output |
---|
9072 |
Test 10
Verdict: WRONG ANSWER
input |
---|
200 13
88 97 79 1 184 104 127 159 157... |
correct output |
---|
798243726 |
user output |
---|
412211138 |
Test 11
Verdict: ACCEPTED
input |
---|
5 2
1 2 3 4 5 |
correct output |
---|
32 |
user output |
---|
32 |
Test 12
Verdict: WRONG ANSWER
input |
---|
1000 17
321 466 231 684 53 480 95 61 5... |
correct output |
---|
799039396 |
user output |
---|
353295486 |
Test 13
Verdict: ACCEPTED
input |
---|
5 1
1 2 3 4 5 |
correct output |
---|
1 |
user output |
---|
1 |
Test 14
Verdict: WRONG ANSWER
input |
---|
2000 27
545 945 734 555 1974 1119 694 ... |
correct output |
---|
87259530 |
user output |
---|
166697887 |
Test 15
Verdict: WRONG ANSWER
input |
---|
5 4
2 3 4 5 1 |
correct output |
---|
240 |
user output |
---|
96 |
Test 16
Verdict: WRONG ANSWER
input |
---|
20000 207
4712 13482 9751 10677 2744 326... |
correct output |
---|
920405949 |
user output |
---|
275373823 |
Test 17
Verdict: WRONG ANSWER
input |
---|
10 9
2 3 4 5 6 7 8 9 10 1 |
correct output |
---|
73741825 |
user output |
---|
415065672 |
Test 18
Verdict: WRONG ANSWER
input |
---|
100000 137
35216 66352 76631 39149 68563 ... |
correct output |
---|
873619169 |
user output |
---|
88825811 |
Test 19
Verdict: ACCEPTED
input |
---|
5 2
2 1 3 4 5 |
correct output |
---|
16 |
user output |
---|
16 |
Test 20
Verdict: WRONG ANSWER
input |
---|
1000000 1337
157667 207184 572776 559466 52... |
correct output |
---|
815275681 |
user output |
---|
546842777 |
Test 21
Verdict: ACCEPTED
input |
---|
5 2
2 3 4 5 1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 22
Verdict: WRONG ANSWER
input |
---|
1000000 137037
302969 577811 4130 64 558319 7... |
correct output |
---|
387136640 |
user output |
---|
416277383 |
Test 23
Verdict: WRONG ANSWER
input |
---|
6 2
2 3 4 5 6 1 |
correct output |
---|
2 |
user output |
---|
0 |