QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#59964 | #1845. Permute | AFewSuns | WA | 2ms | 3644kb | C++ | 4.9kb | 2022-11-02 10:46:44 | 2022-11-02 10:46:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
vector<pair<ll,ll> > ans;
ll t,aa[11],a[11],id[11],b[8]={0,1,4,6,5,2},pw[8]={1,3,2,6,4,5};
ll p[22],cnt,nd,q[22],res[22];
bl ck[22],pd;
il bl cmp(ll x,ll y){
return a[x]<a[y];
}
void dfs(ll now){
if(now==cnt){
if(!nd){
pd=1;
fr(i,1,cnt) res[i]=q[cnt-i+1];
}
return;
}
now++;
fr(i,1,cnt){
if(ck[i]) continue;
ck[i]=1;
nd=(nd+p[i]*pw[(now-1)%6]%7)%7;
q[now]=p[i];
dfs(now);
ck[i]=0;
nd=(nd-p[i]*pw[(now-1)%6]%7+7)%7;
}
}
void prf(ll x,ll y){
if(!x) return;
if(aa[y]>=x){
ans.push_back(MP(x,y));
aa[y]-=x;
}
else{
if(aa[y]) ans.push_back(MP(aa[y],y));
ans.push_back(MP(x-aa[y],y+7));
aa[y]=0;
aa[y+7]-=x-aa[y];
}
}
void prtf(){
writeln(ans.size());
fr(i,0,(ll)ans.size()-1) pf("%lld %lld\n",ans[i].fir,ans[i].sec);
}
int main(){
t=read();
while(t--){
ans.clear();
ll div=0;
fr(i,0,6) a[i]=0;
fr(i,0,9){
aa[i]=read();
a[i%7]+=aa[i];
}
fr(i,0,6) if(a[i]) id[++div]=i;
sort(id+1,id+div+1,cmp);
if(div==1){
ll tmp=b[a[id[1]]%6]*id[1]%7;
if(tmp) writeln(-1);
else{
prf(a[id[1]],id[1]);
prtf();
}
continue;
}
if(div>=4){
fr(i,1,4) a[id[i]]--;
ll tmp=pw[4],tot=0;
nd=0;
fr(i,1,div){
if(!a[id[i]]) continue;
nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
tmp=tmp*pw[a[id[i]]%6]%7;
tot++;
}
pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
cnt=4;
fr(i,1,4) p[i]=id[i];
fr(i,1,4) ck[i]=0;
dfs(0);
fr(i,1,4) prf(1,res[i]);
prtf();
continue;
}
if(div==3&&a[id[3]]>=5){
fr(i,1,2) a[id[i]]--;
a[id[3]]-=5;
ll tmp=pw[1],tot=0;
nd=0;
fr(i,1,div){
if(!a[id[i]]) continue;
nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
tmp=tmp*pw[a[id[i]]%6]%7;
tot++;
}
pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
cnt=7;
fr(i,1,7) p[i]=id[min(3ll,i)];
fr(i,1,7) ck[i]=0;
dfs(0);
fr(i,1,7) prf(1,res[i]);
prtf();
continue;
}
if(div==3&&a[id[2]]>=2&&a[id[3]]>=2){
fr(i,1,3) a[id[i]]-=min(2ll,i);
ll tmp=pw[5],tot=0;
nd=0;
fr(i,1,div){
if(!a[id[i]]) continue;
nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
tmp=tmp*pw[a[id[i]]%6]%7;
tot++;
}
pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
cnt=5;
fr(i,1,5) p[i]=id[(i+2)/2];
fr(i,1,5) ck[i]=0;
dfs(0);
fr(i,1,5) prf(1,res[i]);
prtf();
continue;
}
if(div==2&&a[id[1]]>=2&&a[id[2]]>=3){
fr(i,1,2) a[id[i]]-=i+1;
ll tmp=pw[5],tot=0;
nd=0;
fr(i,1,div){
if(!a[id[i]]) continue;
nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
tmp=tmp*pw[a[id[i]]%6]%7;
tot++;
}
pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
cnt=5;
fr(i,1,5) p[i]=id[(i+3)/3];
fr(i,1,5) ck[i]=0;
dfs(0);
fr(i,1,5) prf(1,res[i]);
prtf();
continue;
}
if(div==2&&a[id[1]]==1){
pd=0;
fr(i,0,min(6ll,a[id[2]])){
ll tmp=id[1]*pw[i%6]%7;
tmp=(tmp+b[i%6])%7;
tmp=(tmp+b[(a[id[2]]-i)%6]*pw[(i+1)%6]%7)%7;
if(!tmp){
prf(a[id[2]]-i,id[2]);
prf(1,id[1]);
prf(i,id[2]);
prtf();
pd=1;
break;
}
}
if(!pd) writeln(-1);
continue;
}
cnt=nd=0;
fr(i,1,div) fr(j,1,a[id[i]]) p[++cnt]=id[i];
fr(i,1,cnt) ck[i]=0;
pd=0;
dfs(0);
if(!pd) writeln(-1);
else{
fr(i,1,cnt) prf(1,res[i]);
prtf();
}
}
}
/*
3
1 2 3 4 1 2 1 1 0 0
0 0 1 1 1 0 0 1 0 0
0 1 0 2 0 1 0 0 2 0
3
0 0 1 0 5 0 0 1 0 0
0 2 0 0 3 0 6 0 0 0
0 0 0 0 1 0 4 5 0 0
3
0 0 2 0 0 1 0 2 0 0
0 3 0 0 4 0 4 0 0 0
0 0 0 2 0 3 0 0 2 0
3
0 0 3 0 0 2 0 0 0 0
0 4 0 0 3 0 0 0 0 0
0 0 0 5 0 0 0 0 7 0
3
0 1 0 0 1 0 0 0 0 0
0 2 0 0 0 0 1 0 0 1
0 1000000000 0 0 0 0 0 0 0 0
*/
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3644kb
input:
3 0 1 0 0 1 0 0 0 0 0 0 2 0 0 0 0 1 0 0 1 0 1000000000 0 0 0 0 0 0 0 0
output:
-1 4 1 9 1 6 1 1 1 1 -1
result:
wrong answer Jury has the answer but participant has not