ABC343E 题解

· · 题解

题目传送门。

PS:比赛时题目数据过弱,把我的错误做法放过去了,感谢@CheZiHe929 提供的 hack。

错误代码可以看这里。

思路

固定第一个立方体位置不动,那么第二个立方体三个坐标从 [-7,7] 枚举,第三个立方体也一样。

正确性证明

因此,该算法在实际上是可以找到答案的。

时间复杂度

第一个立方体 \operatorname{O}(1),后面两个需要 15^6=11390625 的时间复杂度,完全可以跑得过。

Code

#include<bits/stdc++.h>
using namespace std;
int f1(int a1,int b1,int c1,int a2,int b2,int c2) {
    int res=1;
    res*=max(0,min(a1,a2)+7-max(a1,a2));
    res*=max(0,min(b1,b2)+7-max(b1,b2));
    res*=max(0,min(c1,c2)+7-max(c1,c2));
    return res;
}
int f2(int a1,int b1,int c1,int a2,int b2,int c2,int a3,int b3,int c3) {
    int res=1;
    res*=max(0,min(min(a1,a2),a3)+7-max(max(a1,a2),a3));
    res*=max(0,min(min(b1,b2),b3)+7-max(max(b1,b2),b3));
    res*=max(0,min(min(c1,c2),c3)+7-max(max(c1,c2),c3));
    return res;
}
int a,b,c;
int main() {
    scanf("%d%d%d",&a,&b,&c);
    if(a+2*b+3*c!=1029) {
        printf("No");
        return 0;
    }
    int x[4],y[4],z[4],rx;
    int x2,y2,z2,x3,y3,z3;
    for(x2=-7; x2<=7; x2++) {
        for(y2=-7; y2<=7; y2++) {
            for(z2=-7; z2<=7; z2++) {
                for(x3=-7; x3<=7; x3++) {
                    for(y3=-7; y3<=7; y3++) {
                        for(z3=-7; z3<=7; z3++) {
                            int three= f2(0,0,0,x2,y2,z2,x3,y3,z3);
                            int ab= f1(0,0,0,x2,y2,z2),
                                bc= f1(x2,y2,z2,x3,y3,z3),
                                ac= f1(0,0,0,x3,y3,z3);
                            int two=bc+ac+ab-3*three;
                            if(two==b&&three==c){
                                printf("Yes\n0 0 0 %d %d %d %d %d %d",x2,y2,z2,x3,y3,z3);
                                exit(0);
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<"No";
    return 0;
}