QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416477#8343. 玩游戏274551858530 12ms5384kbC++202.6kb2024-05-21 21:22:572024-05-21 21:22:57

Judging History

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

  • [2024-05-21 21:22:57]
  • 评测
  • 测评结果:30
  • 用时:12ms
  • 内存:5384kb
  • [2024-05-21 21:22:57]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
namespace Solve
{
    using namespace std;
    typedef long long ll;
    const int N=1000001;
    int n;
    bool h[N];
    void init(int _n)
    {
        n=_n;
    }
    pair<int,int> encode(vector<int> a)
    {
        for(int i=0;i<=n*2;++i) h[i]=false;
        int s=0;
        for(auto i:a) s=(s+i)%(n*2+1);
        for(auto i:a) h[(i-s+(n*2+1))%(n*2+1)]=true;
        auto mp=[&](int x,int y,int u)
        {
            if((u==0)^((y-x+(n*2+1))%(n*2+1)%2==0)) swap(x,y);
            return make_pair((x+s)%(n*2+1),(y+s)%(n*2+1));
        };
        for(int i=1;i<=n-1;++i)
        {
            if(h[i]&&h[(n*2+1)-i])
            {
                return mp(i,(n*2+1)-i,0);
            }
        }
        for(pair<int,int> i:vector<pair<int,int>>{{0,1},{0,n*2},{2,n},{n,n*2-1},{4,n+1},{n+1,n*2-3}})
        {
            if(h[i.first]&&h[i.second]) return mp(i.first,i.second,1);
        }
    }
    int decode(pair<int,int> a,pair<int,int> b)
    {
        auto solve=[&](int x1,int x2)
        {
            if((x2-x1+(n*2+1))%(n*2+1)%2==0) return ((ll)(x1+x2)*(n+1))%(n*2+1);
            for(pair<int,int> i:vector<pair<int,int>>{{0,1},{0,n*2},{2,n},{n,n*2-1},{4,n+1},{n+1,n*2-3}})
            {
                if((i.second-i.first+(n*2+1))%(n*2+1)%2==0) swap(i.first,i.second);
                if((i.second-i.first+(n*2+1))%(n*2+1)==(x2-x1+(n*2+1))%(n*2+1))
                {
                    return (((ll)((x1+x2)-(i.first+i.second))*(n+1))%(n*2+1)+(n*2+1))%(n*2+1);
                }
            }
        };
        int s1=solve(a.first,a.second),s2=solve(b.first,b.second);
        return ((-s1-s2)%(n*2+1)+(n*2+1))%(n*2+1);
    }
}
void init(int n)
{
    return Solve::init(n);
}
std::pair<int, int> encode(std::vector<int> a)
{
    return Solve::encode(a);
}
int decode(std::pair<int, int> a, std::pair<int, int> b)
{
    return Solve::decode(a,b);
}

// int main()
// {
//     int T,n;
//     scanf("%d%d",&T,&n);
//     Solve::init(n);
//     while(T--)
//     {
//         std::vector<int> a,b;
//         for(int i=1;i<=n*2;++i)
//         {
//             int x;
//             scanf("%d",&x);
//             if(i<=n) a.push_back(x);
//             else b.push_back(x);
//         }
//         scanf("%*d");
//         auto xa=Solve::encode(a);
//         printf("%d %d\n",xa.first,xa.second);
//         auto xb=Solve::encode(b);
//         printf("%d %d\n",xb.first,xb.second);
//         int x=Solve::decode(xa,xb);
//         printf("%d\n",x);
//     }
//     return 0;
// }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 5384kb

input:

6 16666 16807

output:

6 16666
2 11
8 3
1 3
2 6
4 10
8 11
1 3
0 6
8 1
4 6
0 5
1 7
6 10
2 8
11 4
8 10
11 6
7 8
11 0
10 7
7 0
2 8
7 2
11 0
4 6
7 0
11 8
6 12
9 11
8 3
10 12
0 9
8 9
0 1
3 12
5 6
0 8
1 3
7 11
10 3
10 1
2 3
4 5
12 7
11 3
5 0
7 4
1 5
11 7
4 6
12 7
2 10
6 7
2 10
8 9
10 1
10 5
7 12
11 6
7 9
10 1
6 7
7 2
1 5
4 5
0 ...

input:

6 16666
2 11
8 3
1 3
2 6
4 10
8 11
1 3
0 6
8 1
4 6
0 5
1 7
6 10
2 8
11 4
8 10
11 6
7 8
11 0
10 7
7 0
2 8
7 2
11 0
4 6
7 0
11 8
6 12
9 11
8 3
10 12
0 9
8 9
0 1
3 12
5 6
0 8
1 3
7 11
10 3
10 1
2 3
4 5
12 7
11 3
5 0
7 4
1 5
11 7
4 6
12 7
2 10
6 7
2 10
8 9
10 1
10 5
7 12
11 6
7 9
10 1
6 7
7 2
1 5
4 5
0 ...

output:

5
7
2
8
10
2
0
3
4
12
11
3
11
1
4
8
5
11
7
4
12
6
12
11
3
4
1
6
11
3
8
12
4
7
10
5
3
0
4
1
6
8
3
5
12
12
11
5
2
7
6
5
6
0
3
0
4
4
2
0
11
4
6
0
10
11
9
6
5
7
9
6
5
12
5
4
11
2
5
10
0
4
9
4
5
5
11
3
7
12
4
3
10
12
2
7
1
7
11
3
2
3
10
6
7
6
12
9
2
1
3
1
10
2
8
7
6
7
6
5
0
2
11
6
11
4
11
8
0
7
6
3
8
12
...

result:

wrong answer wrong answer: read 5 but expected 3 (test case 17)

Subtask #2:

score: 30
Accepted

Test #6:

score: 30
Accepted
time: 1ms
memory: 4680kb

input:

68876 1 470211272

output:

68876 1
105473 105487
96097 96101

input:

68876 1
105473 105487
96097 96101

output:

73927

result:

ok passed (1 test case)

Test #7:

score: 30
Accepted
time: 2ms
memory: 4332kb

input:

58538 1 101027544

output:

58538 1
44241 44247
69294 69296

input:

58538 1
44241 44247
69294 69296

output:

3538

result:

ok passed (1 test case)

Test #8:

score: 30
Accepted
time: 2ms
memory: 4320kb

input:

50603 1 1457850878

output:

50603 1
33821 33827
91698 91708

input:

50603 1
33821 33827
91698 91708

output:

76887

result:

ok passed (1 test case)

Test #9:

score: 30
Accepted
time: 3ms
memory: 4492kb

input:

33045 3 1458777923

output:

33045 3
52963 52969
57205 57215
36403 36409
269 271
56769 56777
60184 60186

input:

33045 3
52963 52969
57205 57215
36403 36409
269 271
56769 56777
60184 60186

output:

22006
29415
15224

result:

ok passed (3 test cases)

Test #10:

score: 30
Accepted
time: 4ms
memory: 4040kb

input:

20970 4 2007237709

output:

20970 4
4631 4633
31995 32015
6081 6083
2421 2431
16888 16894
11552 11562
11915 11917
34807 34825

input:

20970 4
4631 4633
31995 32015
6081 6083
2421 2431
16888 16894
11552 11562
11915 11917
34807 34825

output:

5304
33433
13493
37150

result:

ok passed (4 test cases)

Test #11:

score: 30
Accepted
time: 3ms
memory: 4440kb

input:

40786 2 823564440

output:

40786 2
8867 8869
48993 48995
55560 55568
70517 70531

input:

40786 2
8867 8869
48993 48995
55560 55568
70517 70531

output:

23711
37058

result:

ok passed (2 test cases)

Test #12:

score: 30
Accepted
time: 3ms
memory: 4380kb

input:

59198 1 1115438165

output:

59198 1
87448 87454
86810 86814

input:

59198 1
87448 87454
86810 86814

output:

62531

result:

ok passed (1 test case)

Test #13:

score: 30
Accepted
time: 4ms
memory: 5088kb

input:

92994 1 1784484492

output:

92994 1
149305 149309
92892 92900

input:

92994 1
149305 149309
92892 92900

output:

129775

result:

ok passed (1 test case)

Test #14:

score: 30
Accepted
time: 4ms
memory: 5380kb

input:

95914 1 74243042

output:

95914 1
127197 127201
108296 108300

input:

95914 1
127197 127201
108296 108300

output:

148161

result:

ok passed (1 test case)

Test #15:

score: 30
Accepted
time: 1ms
memory: 4372kb

input:

56585 1 114807987

output:

56585 1
97475 97495
104808 104818

input:

56585 1
97475 97495
104808 104818

output:

24044

result:

ok passed (1 test case)

Test #16:

score: 30
Accepted
time: 3ms
memory: 4784kb

input:

49131 2 1137522503

output:

49131 2
35124 35126
50124 50126
58618 58620
65614 65616

input:

49131 2
35124 35126
50124 50126
58618 58620
65614 65616

output:

13013
72292

result:

ok passed (2 test cases)

Test #17:

score: 30
Accepted
time: 2ms
memory: 4384kb

input:

58330 1 1441282327

output:

58330 1
115844 115848
104373 104375

input:

58330 1
115844 115848
104373 104375

output:

13102

result:

ok passed (1 test case)

Test #18:

score: 30
Accepted
time: 0ms
memory: 5356kb

input:

95899 1 16531729

output:

95899 1
90664 90678
19161 19177

input:

95899 1
90664 90678
19161 19177

output:

81959

result:

ok passed (1 test case)

Test #19:

score: 30
Accepted
time: 2ms
memory: 4444kb

input:

59202 1 823378840

output:

59202 1
64227 64229
110909 110911

input:

59202 1
64227 64229
110909 110911

output:

61672

result:

ok passed (1 test case)

Test #20:

score: 30
Accepted
time: 0ms
memory: 5116kb

input:

91350 1 143542612

output:

91350 1
175207 175209
88382 88384

input:

91350 1
175207 175209
88382 88384

output:

101811

result:

ok passed (1 test case)

Test #21:

score: 30
Accepted
time: 0ms
memory: 4332kb

input:

37397 2 896544303

output:

37397 2
32580 32588
6301 6319
19350 19354
70123 70133

input:

37397 2
32580 32588
6301 6319
19350 19354
70123 70133

output:

35901
60110

result:

ok passed (2 test cases)

Test #22:

score: 30
Accepted
time: 1ms
memory: 4308kb

input:

51165 1 1474833169

output:

51165 1
60144 60148
15036 15038

input:

51165 1
60144 60148
15036 15038

output:

27148

result:

ok passed (1 test case)

Test #23:

score: 30
Accepted
time: 2ms
memory: 4560kb

input:

61423 1 1264817709

output:

61423 1
78752 78782
107831 107835

input:

61423 1
78752 78782
107831 107835

output:

59094

result:

ok passed (1 test case)

Test #24:

score: 30
Accepted
time: 3ms
memory: 4204kb

input:

15177 6 1998097157

output:

15177 6
5727 5739
14866 14876
4427 4431
12741 12747
17468 17476
5862 5884
3229 3237
20368 20386
6532 6542
26689 26693
28227 28229
12089 12091

input:

15177 6
5727 5739
14866 14876
4427 4431
12741 12747
17468 17476
5862 5884
3229 3237
20368 20386
6532 6542
26689 26693
28227 28229
12089 12091

output:

9751
13182
7010
6745
27482
20392

result:

ok passed (6 test cases)

Test #25:

score: 30
Accepted
time: 0ms
memory: 5252kb

input:

91469 1 1817129560

output:

91469 1
11802 11812
169671 169673

input:

91469 1
11802 11812
169671 169673

output:

1460

result:

ok passed (1 test case)

Test #26:

score: 30
Accepted
time: 3ms
memory: 4108kb

input:

7001 14 1131570933

output:

7001 14
6837 6843
1166 1168
13433 13441
11675 11685
4690 4704
6336 6338
2556 2564
11641 11653
13161 13167
7422 7424
5647 5669
309 317
2318 2320
7482 7500
537 547
13651 13653
10876 10890
2281 2289
1712 1714
2769 2773
702 706
12825 12831
4364 4368
5589 5595
11167 11169
13488 13492
1810 1814
6316 6326

input:

7001 14
6837 6843
1166 1168
13433 13441
11675 11685
4690 4704
6336 6338
2556 2564
11641 11653
13161 13167
7422 7424
5647 5669
309 317
2318 2320
7482 7500
537 547
13651 13653
10876 10890
2281 2289
1712 1714
2769 2773
702 706
12825 12831
4364 4368
5589 5595
11167 11169
13488 13492
1810 1814
6316 6326

output:

5996
2889
2969
13799
7419
8032
4193
13812
835
9519
471
4045
3348
5870

result:

ok passed (14 test cases)

Test #27:

score: 30
Accepted
time: 3ms
memory: 4144kb

input:

13730 7 197493099

output:

13730 7
16979 16991
2122 2126
8638 8648
2570 2574
21959 21963
2052 2054
22699 22703
14501 14517
18966 18972
1579 1585
23013 23017
1663 1667
14082 14086
6840 6850

input:

13730 7
16979 16991
2122 2126
8638 8648
2570 2574
21959 21963
2052 2054
22699 22703
14501 14517
18966 18972
1579 1585
23013 23017
1663 1667
14082 14086
6840 6850

output:

8352
16246
3447
17712
6910
2781
6532

result:

ok passed (7 test cases)

Test #28:

score: 30
Accepted
time: 3ms
memory: 3884kb

input:

5908 16 1404280278

output:

5908 16
11347 11351
1011 1053
8190 8192
32 34
6334 6336
9309 9313
7160 7166
1001 1003
12 16
1163 1175
1874 1880
6342 6344
1362 1380
7576 7582
83 85
792 798
6358 6366
4388 4392
2363 2369
11604 11606
8076 8090
8539 8543
6865 6881
4729 4731
11686 11688
11133 11141
11789 11791
7852 7866
6680 6688
4753 4...

input:

5908 16
11347 11351
1011 1053
8190 8192
32 34
6334 6336
9309 9313
7160 7166
1001 1003
12 16
1163 1175
1874 1880
6342 6344
1362 1380
7576 7582
83 85
792 798
6358 6366
4388 4392
2363 2369
11604 11606
8076 8090
8539 8543
6865 6881
4729 4731
11686 11688
11133 11141
11789 11791
7852 7866
6680 6688
4753 4...

output:

11253
3593
7988
3652
10634
3597
2867
10938
1065
9663
7010
214
810
3985
379
1438

result:

ok passed (16 test cases)

Test #29:

score: 30
Accepted
time: 2ms
memory: 4304kb

input:

53685 1 893351816

output:

53685 1
76994 76998
54631 54633

input:

53685 1
76994 76998
54631 54633

output:

83114

result:

ok passed (1 test case)

Test #30:

score: 30
Accepted
time: 1ms
memory: 4168kb

input:

29258 3 1505795335

output:

29258 3
23302 23310
54068 54072
257 259
15926 15936
30957 30973
27857 27861

input:

29258 3
23302 23310
54068 54072
257 259
15926 15936
30957 30973
27857 27861

output:

39658
42328
58210

result:

ok passed (3 test cases)

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 5ms
memory: 4456kb

input:

18 5555 1954899097

output:

18 5555
15 25
10 22
4 14
30 32
8 10
12 16
9 15
12 1
14 16
9 25
9 13
10 26
28 3
13 27
13 35
29 2
10 28
4 22
29 4
24 1
28 1
20 32
21 29
31 2
13 15
21 23
35 2
12 34
28 34
31 33
16 18
8 10
29 2
20 26
17 21
2 4
13 29
19 21
4 22
24 32
26 9
0 16
16 18
17 21
29 0
31 35
10 16
17 21
21 27
30 32
15 19
26 3
3 1...

input:

18 5555
15 25
10 22
4 14
30 32
8 10
12 16
9 15
12 1
14 16
9 25
9 13
10 26
28 3
13 27
13 35
29 2
10 28
4 22
29 4
24 1
28 1
20 32
21 29
31 2
13 15
21 23
35 2
12 34
28 34
31 33
16 18
8 10
29 2
20 26
17 21
2 4
13 29
19 21
4 22
24 32
26 9
0 16
16 18
17 21
29 0
31 35
10 16
17 21
21 27
30 32
15 19
26 3
3 1...

output:

1
34
14
0
5
8
20
16
5
8
15
14
1
14
11
11
17
15
33
33
30
1
8
5
19
24
18
3
15
7
11
9
9
15
19
5
7
2
34
7
6
19
6
3
10
7
1
19
32
4
25
24
3
13
7
17
9
36
15
3
5
16
16
17
33
0
28
36
15
21
11
15
30
19
6
0
0
1
3
0
10
34
24
10
33
2
2
4
2
12
35
14
33
29
36
35
11
14
17
21
12
10
29
7
2
30
33
24
25
9
18
36
31
28
1...

result:

wrong answer wrong answer: read 28 but expected 27 (test case 2524)