QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245775 | #7688. Alea Iacta Est | zhoukangyang | WA | 6ms | 3712kb | C++11 | 2.2kb | 2023-11-10 12:00:21 | 2023-11-10 12:00:21 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
using namespace std;
const int N = 1 << 21;
const ll mod = (ll) 998244353 * 1019260817, base = 19491001;
int n, m;
pair < vi, vi > DV(int x, int y) {
vi ls, rs;
L(i, 0, x - 1)
ls.emplace_back(i * y);
L(i, 0, y - 1)
rs.emplace_back(i);
return make_pair(ls, rs);
}
vi Mul(vi a, vi b) {
vi c;
for(auto&u : a)
for(auto&v : b)
c.emplace_back(u + v);
sort(c.begin(), c.end());
return c;
}
void Main() {
cin >> n >> m;
if(n > m) swap(n, m);
ll mul = (ll) n * m;
ll ptl = 0, ptr = 0;
ll A = -1, B = -1, C = -1, D = -1;
R(i, sqrt(mul), 1)
if(mul % i == 0) {
ptl = i, ptr = mul / i;
if(ptl != n) {
L(a, 1, ptl)
if(ptl % a == 0 && n % a == 0) {
ll b = n / a;
if(ptl % a == 0) {
ll c = ptl / a;
if(m % c == 0) {
A = a;
B = b;
C = c;
D = m / c;
}
}
}
} else {
L(a, 2, n)
if(n % a == 0) {
ll b = n / a;
if(m % b == 0) {
ll d = m / b;
if(a == 1 || b == 1 || d == 1) {
continue;
}
A = a;
B = b;
C = b;
D = d;
}
}
}
if(A != -1) break;
}
auto p1 = DV(A, B);
auto p2 = DV(C, D);
ll qwq = (ll)sz(p1.first) * sz(p2.first) + (ll) sz(p1.second) * sz(p2.second);
if(qwq > n * 2 + m) {
cout << n * 2 << ' ';
L(i, 1, n)
cout << i << ' ' << i << ' ';
cout << '\n';
cout << m << ' ';
L(i, 1, m) {
cout << i << ' ';
}
cout << '\n';
return ;
}
auto T1 = Mul(p1.first, p2.first);
auto T2 = Mul(p1.second, p2.second);
cout << sz(T1) << ' ';
for(auto&x : T1)
cout << x + 1 << ' ';
cout << '\n';
cout << sz(T2) << ' ';
for(auto&x : T2)
cout << x + 1 << ' ';
cout << '\n' << '\n';
}
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t; while(t--) Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3392kb
input:
3 2 8 1 9 2 9
output:
4 1 2 5 6 4 1 2 3 4 3 1 4 7 3 1 2 3 3 1 4 7 6 1 2 2 3 3 4
result:
ok Correct. (3 test cases)
Test #2:
score: 0
Accepted
time: 6ms
memory: 3712kb
input:
1 40013 40013
output:
80026 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 ...
result:
ok Correct. (1 test case)
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3460kb
input:
1 40013 1
output:
0 0
result:
wrong answer Integer parameter [name=n1] equals to 0, violates the range [1, 40015] (test case 1)