QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245808 | #7688. Alea Iacta Est | zhoukangyang | WA | 1ms | 3560kb | C++11 | 3.6kb | 2023-11-10 12:51:02 | 2023-11-10 12:51:04 |
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;
}
inline bool check(int n, int m) {
vi fact;
int W = n;
L(i, 2, W) if(W % i == 0) {
fact.emplace_back(i);
while(W % i == 0) W /= i;
}
for(auto u : fact)
for(auto v : fact)
if((n / u) % v == 0 && __gcd(u, v) == 1) {
if(m >= (u - 1) * (v - 1)) {
vi f(m + u * v + u + v + 1);
L(i, 1, m)
f[i] = 1;
R(i, m, 1) if(f[i])
f[i + u * v] -= f[i];
L(i, 1, m + u * v) if(f[i]) {
f[i + u] += f[i];
}
L(i, 1, m + u * v + u) if(f[i]) {
f[i + v] += f[i];
}
R(i, m + u * v + u + v, 1) {
f[i] -= f[i - 1];
}
vi tp;
for(int j = 0; j < n; j += u * v)
L(x, 0, u - 1)
L(y, 0, v - 1)
tp.emplace_back(j + x + y + 1);
sort(tp.begin(), tp.end());
cout << n << ' ';
for(auto&x : tp)
cout << x << ' ';
cout << '\n';
L(i, 0, m + u * v + u + v)
assert(f[i] >= 0);
cout << m << ' ';
L(i, 0, m + u * v)
L(j, 1, f[i])
cout << i << ' ';
cout << '\n';
return true;
}
}
return true;
}
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) {
if(check(n, m)) return;
if(check(m, n)) return;
}
}
if(A != -1) break;
}
if(A == -1) {
cout << n * 2 << ' ';
L(i, 1, n)
cout << i << ' ' << i << ' ';
cout << '\n';
cout << m << ' ';
L(i, 1, m) {
cout << i << ' ';
}
cout << '\n';
return ;
}
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: 0ms
memory: 3532kb
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: -100
Wrong Answer
time: 1ms
memory: 3560kb
input:
1 40013 40013
output:
result:
wrong output format Unexpected end of file - int32 expected (test case 1)