답안 #862621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862621 2023-10-18T16:09:30 Z Hanksburger Nice sequence (IZhO18_sequence) C++17
100 / 100
280 ms 44100 KB
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long t;
    cin >> t;
    while (t--)
    {
        long long n, m, k=1;
        cin >> n >> m;
        if (n>m)
        {
            swap(n, m);
            k=-1;
        }
        if (m%n==0)
        {
            cout << m-1 << '\n';
            for (long long i=0; i<m-1; i++)
                cout << -k << ' ';
            cout << '\n';
            continue;
        }
        for (long long i=0; i<n; i++)
            a[i]=0;
        long long g=gcd(n, m), ind=m%n-1, x=0, y=0;
        while (ind!=(m%n-g-1+n)%n)
        {
            a[ind]=1;
            ind=(ind+m%n)%n;
            x++;
        }
        while (ind!=m%n-1)
        {
            a[ind]=-1;
            ind=(ind+m%n)%n;
            y++;
        }
        long long p, q;
        if (g==2)
        {
            for (long long i=min(1000000000LL, (1000000000*x+n-n/g)/y); i>=1; i--)
            {
                if (x==1 || (i*y-n+n/g)%x==1)
                {
                    q=i;
                    break;
                }
            }
            p=(q*y-n+n/g-1)/x;
        }
        else
        {
            for (long long i=min(1000000000LL, 1000000000*x/y); i>=1; i--)
            {
                if (x==1 || i*y%x==1)
                {
                    q=i;
                    break;
                }
            }
            p=(q*y-1)/x;
        }
        cout << n+m-g-1 << '\n';
        for (long long i=0; i<n+m-g-1; i++)
        {
            if (a[i%n]==1)
                cout << p*k << ' ';
            else if (a[i%n]==-1)
                cout << -q*k << ' ';
            else if (g==2 || i%g)
                cout << k << ' ';
            else
                cout << -(g-2)*k << ' ';
        }
        cout << '\n';
    }
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:66:17: warning: 'q' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |             p=(q*y-1)/x;
      |                ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 344 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Ok
2 Correct 0 ms 464 KB Ok
3 Correct 0 ms 344 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 2 ms 348 KB Ok
7 Correct 5 ms 856 KB Ok
8 Correct 3 ms 604 KB Ok
9 Correct 6 ms 1116 KB Ok
10 Correct 4 ms 860 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 460 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Ok
2 Correct 0 ms 352 KB Ok
3 Correct 0 ms 468 KB Ok
4 Correct 1 ms 352 KB Ok
5 Correct 0 ms 352 KB Ok
6 Correct 48 ms 6320 KB Ok
7 Correct 42 ms 6032 KB Ok
8 Correct 81 ms 9808 KB Ok
9 Correct 63 ms 9260 KB Ok
10 Correct 36 ms 4180 KB Ok
11 Correct 63 ms 8020 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 344 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 348 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 0 ms 348 KB Ok
19 Correct 0 ms 460 KB Ok
20 Correct 0 ms 348 KB Ok
21 Correct 0 ms 348 KB Ok
22 Correct 0 ms 348 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 2 ms 348 KB Ok
25 Correct 2 ms 348 KB Ok
26 Correct 1 ms 348 KB Ok
27 Correct 1 ms 348 KB Ok
28 Correct 1 ms 348 KB Ok
29 Correct 1 ms 348 KB Ok
30 Correct 1 ms 496 KB Ok
31 Correct 2 ms 344 KB Ok
32 Correct 1 ms 344 KB Ok
33 Correct 1 ms 348 KB Ok
34 Correct 2 ms 604 KB Ok
35 Correct 3 ms 604 KB Ok
36 Correct 4 ms 860 KB Ok
37 Correct 3 ms 604 KB Ok
38 Correct 2 ms 604 KB Ok
39 Correct 2 ms 604 KB Ok
40 Correct 3 ms 604 KB Ok
41 Correct 2 ms 604 KB Ok
42 Correct 3 ms 604 KB Ok
43 Correct 4 ms 604 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 344 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 1 ms 344 KB Ok
14 Correct 0 ms 464 KB Ok
15 Correct 0 ms 344 KB Ok
16 Correct 0 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 2 ms 348 KB Ok
19 Correct 5 ms 856 KB Ok
20 Correct 3 ms 604 KB Ok
21 Correct 6 ms 1116 KB Ok
22 Correct 4 ms 860 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Correct 0 ms 348 KB Ok
27 Correct 0 ms 348 KB Ok
28 Correct 0 ms 348 KB Ok
29 Correct 0 ms 460 KB Ok
30 Correct 0 ms 348 KB Ok
31 Correct 0 ms 348 KB Ok
32 Correct 0 ms 348 KB Ok
33 Correct 0 ms 348 KB Ok
34 Correct 2 ms 348 KB Ok
35 Correct 2 ms 348 KB Ok
36 Correct 1 ms 348 KB Ok
37 Correct 1 ms 348 KB Ok
38 Correct 1 ms 348 KB Ok
39 Correct 1 ms 348 KB Ok
40 Correct 1 ms 496 KB Ok
41 Correct 2 ms 344 KB Ok
42 Correct 1 ms 344 KB Ok
43 Correct 1 ms 348 KB Ok
44 Correct 2 ms 604 KB Ok
45 Correct 3 ms 604 KB Ok
46 Correct 4 ms 860 KB Ok
47 Correct 3 ms 604 KB Ok
48 Correct 2 ms 604 KB Ok
49 Correct 2 ms 604 KB Ok
50 Correct 3 ms 604 KB Ok
51 Correct 2 ms 604 KB Ok
52 Correct 3 ms 604 KB Ok
53 Correct 4 ms 604 KB Ok
54 Correct 36 ms 2396 KB Ok
55 Correct 42 ms 2636 KB Ok
56 Correct 45 ms 2900 KB Ok
57 Correct 31 ms 2128 KB Ok
58 Correct 37 ms 2448 KB Ok
59 Correct 36 ms 2152 KB Ok
60 Correct 32 ms 2024 KB Ok
61 Correct 32 ms 2228 KB Ok
62 Correct 41 ms 2388 KB Ok
63 Correct 40 ms 2236 KB Ok
64 Correct 40 ms 2432 KB Ok
65 Correct 42 ms 2612 KB Ok
66 Correct 36 ms 2268 KB Ok
67 Correct 30 ms 2384 KB Ok
68 Correct 38 ms 2200 KB Ok
69 Correct 65 ms 9268 KB Ok
70 Correct 69 ms 11228 KB Ok
71 Correct 64 ms 7760 KB Ok
72 Correct 69 ms 10064 KB Ok
73 Correct 65 ms 8408 KB Ok
74 Correct 65 ms 6784 KB Ok
75 Correct 62 ms 7504 KB Ok
76 Correct 70 ms 11088 KB Ok
77 Correct 73 ms 6172 KB Ok
78 Correct 74 ms 10732 KB Ok
79 Correct 66 ms 9336 KB Ok
80 Correct 65 ms 8788 KB Ok
81 Correct 67 ms 10064 KB Ok
82 Correct 64 ms 9048 KB Ok
83 Correct 69 ms 6996 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 1 ms 344 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 1 ms 344 KB Ok
14 Correct 0 ms 464 KB Ok
15 Correct 0 ms 344 KB Ok
16 Correct 0 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 2 ms 348 KB Ok
19 Correct 5 ms 856 KB Ok
20 Correct 3 ms 604 KB Ok
21 Correct 6 ms 1116 KB Ok
22 Correct 4 ms 860 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Correct 0 ms 348 KB Ok
27 Correct 0 ms 348 KB Ok
28 Correct 0 ms 348 KB Ok
29 Correct 0 ms 460 KB Ok
30 Correct 0 ms 348 KB Ok
31 Correct 0 ms 348 KB Ok
32 Correct 0 ms 348 KB Ok
33 Correct 0 ms 348 KB Ok
34 Correct 0 ms 352 KB Ok
35 Correct 0 ms 352 KB Ok
36 Correct 0 ms 468 KB Ok
37 Correct 1 ms 352 KB Ok
38 Correct 0 ms 352 KB Ok
39 Correct 48 ms 6320 KB Ok
40 Correct 42 ms 6032 KB Ok
41 Correct 81 ms 9808 KB Ok
42 Correct 63 ms 9260 KB Ok
43 Correct 36 ms 4180 KB Ok
44 Correct 63 ms 8020 KB Ok
45 Correct 2 ms 348 KB Ok
46 Correct 2 ms 348 KB Ok
47 Correct 1 ms 348 KB Ok
48 Correct 1 ms 348 KB Ok
49 Correct 1 ms 348 KB Ok
50 Correct 1 ms 348 KB Ok
51 Correct 1 ms 496 KB Ok
52 Correct 2 ms 344 KB Ok
53 Correct 1 ms 344 KB Ok
54 Correct 1 ms 348 KB Ok
55 Correct 2 ms 604 KB Ok
56 Correct 3 ms 604 KB Ok
57 Correct 4 ms 860 KB Ok
58 Correct 3 ms 604 KB Ok
59 Correct 2 ms 604 KB Ok
60 Correct 2 ms 604 KB Ok
61 Correct 3 ms 604 KB Ok
62 Correct 2 ms 604 KB Ok
63 Correct 3 ms 604 KB Ok
64 Correct 4 ms 604 KB Ok
65 Correct 36 ms 2396 KB Ok
66 Correct 42 ms 2636 KB Ok
67 Correct 45 ms 2900 KB Ok
68 Correct 31 ms 2128 KB Ok
69 Correct 37 ms 2448 KB Ok
70 Correct 36 ms 2152 KB Ok
71 Correct 32 ms 2024 KB Ok
72 Correct 32 ms 2228 KB Ok
73 Correct 41 ms 2388 KB Ok
74 Correct 40 ms 2236 KB Ok
75 Correct 40 ms 2432 KB Ok
76 Correct 42 ms 2612 KB Ok
77 Correct 36 ms 2268 KB Ok
78 Correct 30 ms 2384 KB Ok
79 Correct 38 ms 2200 KB Ok
80 Correct 65 ms 9268 KB Ok
81 Correct 69 ms 11228 KB Ok
82 Correct 64 ms 7760 KB Ok
83 Correct 69 ms 10064 KB Ok
84 Correct 65 ms 8408 KB Ok
85 Correct 65 ms 6784 KB Ok
86 Correct 62 ms 7504 KB Ok
87 Correct 70 ms 11088 KB Ok
88 Correct 73 ms 6172 KB Ok
89 Correct 74 ms 10732 KB Ok
90 Correct 66 ms 9336 KB Ok
91 Correct 65 ms 8788 KB Ok
92 Correct 67 ms 10064 KB Ok
93 Correct 64 ms 9048 KB Ok
94 Correct 69 ms 6996 KB Ok
95 Correct 91 ms 5456 KB Ok
96 Correct 126 ms 8392 KB Ok
97 Correct 124 ms 7504 KB Ok
98 Correct 95 ms 5968 KB Ok
99 Correct 114 ms 7248 KB Ok
100 Correct 117 ms 6480 KB Ok
101 Correct 118 ms 7248 KB Ok
102 Correct 116 ms 6944 KB Ok
103 Correct 110 ms 6992 KB Ok
104 Correct 139 ms 8052 KB Ok
105 Correct 127 ms 7508 KB Ok
106 Correct 111 ms 7796 KB Ok
107 Correct 118 ms 7252 KB Ok
108 Correct 128 ms 7504 KB Ok
109 Correct 121 ms 8256 KB Ok
110 Correct 244 ms 27736 KB Ok
111 Correct 280 ms 42836 KB Ok
112 Correct 246 ms 30036 KB Ok
113 Correct 256 ms 36948 KB Ok
114 Correct 273 ms 38228 KB Ok
115 Correct 265 ms 38708 KB Ok
116 Correct 260 ms 37396 KB Ok
117 Correct 258 ms 38996 KB Ok
118 Correct 253 ms 30528 KB Ok
119 Correct 267 ms 41112 KB Ok
120 Correct 249 ms 32476 KB Ok
121 Correct 251 ms 30804 KB Ok
122 Correct 265 ms 35188 KB Ok
123 Correct 274 ms 44100 KB Ok
124 Correct 252 ms 26024 KB Ok
125 Correct 235 ms 23916 KB Ok