QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226304 | #7328. Card Shuffling | PPP# | AC ✓ | 1ms | 3884kb | C++17 | 1.4kb | 2023-10-25 19:57:21 | 2023-10-25 19:57:22 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef long double ld;
ll get(vector<int> a)
{
ll A = 0;
while (true)
{
if (a[0]==0) return A+1;
if (a[0]==1)
{
vector<int> b(a.size()-1);
for (int i=0;i<b.size();i++)
{
if (a[i+1]==0) b[i] = 0;
else b[i] = a[i+1]-1;
}
return A+get(b)*2;
}
int x = a[0];
for (int j=0;j<x;j++) swap(a[j],a[j+1]);
A++;
}
assert(false);
return -1;
}
void solve()
{
int n = 32;
cin >> n;
vector<int> a(n);
for (int i=0;i<n;i++)
{
a[i] = i;
cin >> a[i];
}
//mt19937 gen(time(0));
//shuffle(a.begin(),a.end(),gen);
ll A = get(a);
cout << A-1 << "\n";
return;
ll A2 = A-1;
A = 0;
while (a[0]!=0)
{
int x = a[0];
for (int j=0;j<x;j++) swap(a[j],a[j+1]);
A++;
}
//cout << A << "\n";
assert(A==A2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//#ifdef DEBUG
// freopen("input.txt", "r", stdin);
//#endif
int T = 1;
while (T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
input:
5 1 3 2 4 0
output:
13
result:
ok 1 number(s): "13"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
2 0 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
1 0
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
10 6 5 4 7 0 8 1 3 2 9
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
10 1 2 3 4 0 8 9 7 6 5
output:
15
result:
ok 1 number(s): "15"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
10 1 8 4 5 6 7 3 2 0 9
output:
63
result:
ok 1 number(s): "63"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
11 7 3 9 0 4 1 5 10 8 6 2
output:
3
result:
ok 1 number(s): "3"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
11 0 4 8 7 5 9 3 10 6 2 1
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
11 1 3 4 5 6 7 8 10 9 2 0
output:
139
result:
ok 1 number(s): "139"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
12 9 6 3 1 2 7 0 10 11 8 4 5
output:
14
result:
ok 1 number(s): "14"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
12 1 2 6 7 5 4 3 8 9 10 11 0
output:
1975
result:
ok 1 number(s): "1975"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
12 1 3 2 5 7 11 4 6 10 9 8 0
output:
525
result:
ok 1 number(s): "525"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
13 3 6 7 5 11 1 10 4 8 12 2 0 9
output:
197
result:
ok 1 number(s): "197"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
13 1 2 8 4 5 11 7 0 3 10 12 6 9
output:
35
result:
ok 1 number(s): "35"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
13 1 3 4 5 12 7 8 9 10 11 6 2 0
output:
807
result:
ok 1 number(s): "807"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
14 6 13 5 11 12 0 3 4 8 10 1 7 9 2
output:
5
result:
ok 1 number(s): "5"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
14 2 1 4 0 5 10 12 8 6 11 9 7 3 13
output:
6
result:
ok 1 number(s): "6"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
14 3 1 4 0 6 7 8 9 10 11 12 13 2 5
output:
4
result:
ok 1 number(s): "4"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
15 10 14 2 6 3 8 1 9 12 0 4 13 11 5 7
output:
38
result:
ok 1 number(s): "38"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
15 1 2 10 4 5 0 7 6 9 3 11 12 13 14 8
output:
15
result:
ok 1 number(s): "15"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
15 2 0 8 5 1 9 4 14 6 7 11 10 13 3 12
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
16 14 15 6 3 11 12 8 13 1 4 7 5 10 2 0 9
output:
338
result:
ok 1 number(s): "338"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0
output:
32767
result:
ok 1 number(s): "32767"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
16 8 3 4 5 6 7 1 9 10 11 12 13 14 15 2 0
output:
10705
result:
ok 1 number(s): "10705"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
17 1 15 12 3 0 5 6 2 14 8 7 4 11 16 9 10 13
output:
7
result:
ok 1 number(s): "7"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
17 7 13 11 9 3 6 16 5 4 1 10 8 12 14 15 2 0
output:
14990
result:
ok 1 number(s): "14990"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
17 7 12 5 3 0 1 8 11 2 9 6 15 14 13 16 10 4
output:
4
result:
ok 1 number(s): "4"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
18 13 4 7 16 6 5 0 15 8 3 10 17 2 12 11 1 9 14
output:
7
result:
ok 1 number(s): "7"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
18 16 11 3 6 5 2 0 1 7 9 10 4 13 8 14 15 17 12
output:
7
result:
ok 1 number(s): "7"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
18 6 12 2 5 7 13 15 8 4 11 17 3 14 9 10 1 16 0
output:
52839
result:
ok 1 number(s): "52839"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
19 10 8 14 12 4 17 1 9 7 18 11 3 16 0 6 5 13 15 2
output:
43
result:
ok 1 number(s): "43"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 0
output:
262143
result:
ok 1 number(s): "262143"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
19 1 18 7 0 17 6 8 3 10 11 12 14 13 4 16 5 15 2 9
output:
5
result:
ok 1 number(s): "5"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
20 5 1 15 11 19 12 9 4 18 10 16 14 7 3 17 2 6 0 13 8
output:
434
result:
ok 1 number(s): "434"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
20 7 2 15 4 11 14 17 6 8 10 5 18 13 12 9 16 1 3 19 0
output:
338775
result:
ok 1 number(s): "338775"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
20 15 3 4 5 6 7 8 9 10 11 12 13 14 1 16 17 18 19 2 0
output:
153405
result:
ok 1 number(s): "153405"
Test #37:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
21 17 0 2 11 15 18 14 20 10 3 7 13 9 19 4 8 12 5 16 6 1
output:
1
result:
ok 1 number(s): "1"
Test #38:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
21 0 2 8 1 5 12 4 10 9 11 3 6 7 16 13 17 14 19 15 20 18
output:
0
result:
ok 1 number(s): "0"
Test #39:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
21 1 3 4 9 20 7 11 12 10 2 18 13 14 15 16 6 8 19 17 5 0
output:
143875
result:
ok 1 number(s): "143875"
Test #40:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
22 10 13 12 18 3 14 1 6 0 15 5 2 17 9 4 11 21 7 20 16 8 19
output:
11
result:
ok 1 number(s): "11"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
22 6 8 3 1 5 14 4 2 19 10 11 12 13 17 9 15 16 7 18 20 21 0
output:
1729432
result:
ok 1 number(s): "1729432"
Test #42:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
22 11 13 4 8 6 12 7 9 19 5 10 14 20 15 16 17 0 3 1 21 2 18
output:
71
result:
ok 1 number(s): "71"
Test #43:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
23 8 21 13 4 12 15 3 0 22 7 14 18 10 5 6 11 16 20 19 17 2 1 9
output:
7
result:
ok 1 number(s): "7"
Test #44:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
23 1 2 19 13 5 4 7 22 0 14 11 12 17 9 15 16 6 18 3 10 21 20 8
output:
35
result:
ok 1 number(s): "35"
Test #45:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
23 1 3 4 5 6 20 8 9 12 11 10 13 14 15 16 17 18 19 7 21 22 2 0
output:
1467315
result:
ok 1 number(s): "1467315"
Test #46:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
24 3 21 15 18 12 16 13 10 8 14 2 6 7 17 11 0 4 22 9 5 23 19 1 20
output:
23
result:
ok 1 number(s): "23"
Test #47:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
24 1 2 3 17 23 5 6 10 18 8 4 21 13 14 9 15 7 12 11 20 22 19 16 0
output:
1926095
result:
ok 1 number(s): "1926095"
Test #48:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
24 1 3 4 5 6 7 8 9 12 14 16 0 11 15 2 17 18 22 20 21 19 23 10 13
output:
143
result:
ok 1 number(s): "143"
Test #49:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
25 6 14 22 21 3 7 0 20 17 13 10 8 19 5 12 11 2 23 15 24 16 1 9 4 18
output:
6
result:
ok 1 number(s): "6"
Test #50:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
25 1 19 20 23 12 0 21 2 13 22 7 5 9 3 14 8 17 16 11 15 18 10 24 4 6
output:
9
result:
ok 1 number(s): "9"
Test #51:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
25 18 14 4 23 3 5 6 15 10 0 12 13 8 9 16 17 1 19 20 21 22 2 24 7 11
output:
14
result:
ok 1 number(s): "14"
Test #52:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
26 1 25 13 8 3 20 4 22 6 18 16 23 21 0 12 17 10 19 9 5 11 15 2 7 14 24
output:
51
result:
ok 1 number(s): "51"
Test #53:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
26 15 25 3 23 5 14 17 9 24 10 7 12 13 6 19 16 11 18 1 20 21 22 4 0 2 8
output:
858
result:
ok 1 number(s): "858"
Test #54:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
26 1 3 2 4 18 7 8 24 14 11 12 13 10 15 22 25 23 19 20 9 5 6 21 16 17 0
output:
10109245
result:
ok 1 number(s): "10109245"
Test #55:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
27 21 11 6 2 10 19 14 7 3 5 18 12 0 1 9 25 13 22 15 4 8 16 20 26 17 23 24
output:
20
result:
ok 1 number(s): "20"
Test #56:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
27 1 20 3 4 0 6 18 8 9 10 11 12 13 14 15 16 17 7 19 2 21 22 23 24 25 26 5
output:
7
result:
ok 1 number(s): "7"
Test #57:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
27 12 3 4 16 1 24 23 17 26 19 15 13 14 7 10 9 0 11 20 8 22 21 6 25 5 2 18
output:
61
result:
ok 1 number(s): "61"
Test #58:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
28 22 3 18 16 11 5 26 20 9 21 23 7 25 14 13 12 2 10 19 4 24 15 0 27 1 8 17 6
output:
131
result:
ok 1 number(s): "131"
Test #59:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
28 1 2 6 4 5 10 26 8 20 9 12 21 7 25 17 16 24 18 19 23 27 11 3 15 14 0 22 13
output:
49283
result:
ok 1 number(s): "49283"
Test #60:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
28 7 8 21 10 4 6 0 18 9 11 27 13 1 22 3 5 14 19 20 23 25 17 16 2 26 24 15 12
output:
6
result:
ok 1 number(s): "6"
Test #61:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
29 27 16 7 1 25 22 11 12 23 3 10 4 26 0 28 6 9 2 24 15 13 21 14 20 19 18 17 5 8
output:
28
result:
ok 1 number(s): "28"
Test #62:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
29 23 22 3 9 5 20 7 10 18 2 11 6 13 14 1 16 17 8 19 12 21 27 4 24 25 26 15 28 0
output:
159227612
result:
ok 1 number(s): "159227612"
Test #63:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
29 1 3 9 5 27 7 8 4 10 11 12 13 2 15 16 19 18 6 20 21 22 23 0 25 26 17 28 14 24
output:
164427
result:
ok 1 number(s): "164427"
Test #64:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
30 10 0 9 4 3 5 6 17 15 27 22 16 18 19 1 29 25 21 8 26 23 20 7 2 13 28 12 14 24 11
output:
1
result:
ok 1 number(s): "1"
Test #65:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
30 1 2 8 24 5 18 17 7 9 10 28 12 13 14 15 0 23 6 11 20 21 26 3 4 25 22 27 16 29 19
output:
111
result:
ok 1 number(s): "111"
Test #66:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
30 16 3 7 15 6 20 8 13 10 18 12 9 14 26 1 17 11 19 0 28 22 23 24 25 21 27 4 29 2 5
output:
143
result:
ok 1 number(s): "143"
Test #67:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
31 22 27 15 5 29 1 21 2 19 0 26 9 16 25 12 30 24 13 17 14 20 10 28 6 18 8 11 7 23 4 3
output:
18
result:
ok 1 number(s): "18"
Test #68:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
31 2 1 10 4 14 6 7 8 28 13 11 12 3 26 21 16 17 18 25 20 15 29 23 24 19 5 27 9 22 30 0
output:
715049774
result:
ok 1 number(s): "715049774"
Test #69:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
31 1 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 2 0
output:
328896117
result:
ok 1 number(s): "328896117"
Test #70:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
32 16 24 18 14 0 13 19 7 31 17 9 30 6 2 11 20 15 3 28 22 26 4 29 27 1 23 12 5 8 21 10 25
output:
4
result:
ok 1 number(s): "4"
Test #71:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
32 25 2 3 19 20 16 27 29 5 13 7 12 17 4 15 6 26 18 30 23 8 0 24 1 9 10 14 28 11 21 31 22
output:
167
result:
ok 1 number(s): "167"
Test #72:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
32 20 7 23 13 5 11 19 9 10 3 27 4 14 15 16 31 26 17 18 21 22 1 6 25 0 12 8 29 30 24 2 28
output:
473
result:
ok 1 number(s): "473"
Test #73:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
25 5 2 3 4 1 6 7 8 9 10 11 12 13 14 15 16 21 18 19 23 17 22 20 24 0
output:
10682346
result:
ok 1 number(s): "10682346"
Test #74:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
25 1 2 3 4 5 6 7 20 9 10 11 12 13 14 15 16 17 18 19 8 21 22 23 24 0
output:
15907071
result:
ok 1 number(s): "15907071"
Test #75:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
32 1 2 3 4 5 6 7 8 9 17 11 12 13 14 15 16 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 0
output:
2147382271
result:
ok 1 number(s): "2147382271"
Test #76:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
32 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 0
output:
2147483647
result:
ok 1 number(s): "2147483647"
Test #77:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
25 1 14 4 5 6 7 8 9 10 11 12 13 3 15 17 16 18 19 20 21 22 23 24 2 0
output:
5178727
result:
ok 1 number(s): "5178727"
Test #78:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
25 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 0
output:
5158955
result:
ok 1 number(s): "5158955"
Test #79:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
32 1 3 30 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 31 4 2 0
output:
930000911
result:
ok 1 number(s): "930000911"
Test #80:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
32 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 27 19 20 21 22 23 24 25 26 18 28 29 30 31 2 0
output:
617373785
result:
ok 1 number(s): "617373785"
Extra Test:
score: 0
Extra Test Passed