QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#239983 | #7688. Alea Iacta Est | ucup-team197# | WA | 816ms | 241424kb | C++14 | 2.6kb | 2023-11-05 01:59:29 | 2023-11-05 01:59:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define fi first
#define se second
const int N=3e6+5;
const int iu=3e6;
vector<int>pf[N];
ll n,m;
int sz=0;
ll v[N];
void gen(vector<pair<ll,ll> >&g,int id,ll cur){
if(id==g.size()){
v[++sz]=cur;
return;
}
for(int i=0; i<g[id].fi ;i++){
ll dx=i*g[id].se;
gen(g,id+1,cur+dx);
}
}
ll gcd(ll x,ll y){
if(y==0) return x;
return gcd(y,x%y);
}
void dumb(){
cout << 2*n << ' ';
for(int i=1; i<=n ;i++) cout << i << ' ' << i << ' ';
cout << '\n';
cout << m << ' ';
for(int i=1; i<=m ;i++) cout << i << ' ';
cout << '\n';
}
ll test_dumb(){
return 2*n+m;
}
void solve(){
cin >> n >> m;
if((n==1 && m!=1 || n!=1 && m==1) && pf[n*m].size()==1){
cout << m << ' ';
for(int i=1; i<=m ;i++) cout << i << ' ';
cout << '\n';
cout << n << ' ';
for(int i=1; i<=n ;i++) cout << i << ' ';
cout << '\n';
return;
}
if(n>m) swap(n,m);
if(n==1 && pf[m].size()<=1){
dumb();
return;
}
ll xs=n;
for(ll s=n+1; s<=m ;s++){
if(s*s>n*m) break;
if(n*m%s==0) xs=s;
}
ll g=gcd(n,m);
if(n==m && pf[n].size()==1) g=1;
vector<pair<ll,ll> >gl,gr;
if(xs==n && g!=1){//score = n+m
ll p=pf[g][0];
for(int i=0; i<pf[n].size() ;i++){
if(pf[n][i]==p){
swap(pf[n][0],pf[n][i]);
break;
}
}
{
ll step=1;
for(auto c:pf[n]){
gl.push_back({c,step});
step*=c;
}
}
for(int i=0; i<pf[m].size() ;i++){
if(pf[m][i]==p){
swap(pf[m][0],pf[m][i]);
break;
}
}
swap(pf[m][0],pf[m].back());
{
ll step=1;
for(auto c:pf[m]){
gr.push_back({c,step});
step*=c;
}
}
swap(gl[0],gr.back());
}
else{
if(xs==n){
xs--;
while(n*m%xs!=0) --xs;
}
if(test_dumb()<=xs+(n*m)/xs){
dumb();
return;
}
vector<pair<ll,ll> >gn;
{
ll step=1;
for(auto c:pf[n]){
gn.push_back({c,step});
step*=c;
}
}
{
ll step=1;
for(auto c:pf[m]){
gn.push_back({c,step});
step*=c;
}
}
for(auto c:gn){
if(xs%c.fi==0){
xs/=c.fi;
gl.push_back(c);
}
else gr.push_back(c);
}
}
sz=0;
gen(gl,0,0);
cout << sz << ' ';
for(int i=1; i<=sz ;i++) cout << v[i]+1 << ' ';
cout << '\n';
sz=0;
gen(gr,0,0);
cout << sz << ' ';
for(int i=1; i<=sz ;i++) cout << v[i]+1 << ' ';
cout << '\n';
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);
for(int i=2; i<=iu ;i++){
if(!pf[i].empty()) continue;
for(int j=i; j<=iu ;j+=i){
int z=j;
while(z%i==0){
z/=i;
pf[j].push_back(i);
}
}
}
int t;cin >> t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 755ms
memory: 241424kb
input:
3 2 8 1 9 2 9
output:
4 1 2 2 3 4 1 5 3 7 3 1 2 3 3 1 4 7 3 1 2 3 6 1 4 7 2 5 8
result:
ok Correct. (3 test cases)
Test #2:
score: 0
Accepted
time: 816ms
memory: 240732kb
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: 767ms
memory: 240408kb
input:
1 40013 1
output:
1 1 40013 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...
result:
wrong answer Same as input (test case 1)