QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708793#5675. Quotdokumgoldy925#AC ✓170ms3948kbC++112.1kb2024-11-04 06:43:402024-11-04 06:43:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 06:43:41]
  • 评测
  • 测评结果:AC
  • 用时:170ms
  • 内存:3948kb
  • [2024-11-04 06:43:40]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
bool okelement[10][10][10],okrow[10][10],okcol[10][10],okgrid[10][10][10],fix[10][10];
int ans[10][10];
int cons[10][10],cons2[10][10];
void init(){
    memset(fix,0,sizeof(fix));
    memset(cons,0,sizeof(cons));
    memset(cons2,0,sizeof(cons2));
    for(int i=0;i<10;++i)
    for(int j=0;j<10;++j){
        okrow[i][j]=okcol[i][j]=1;
        for(int k=0;k<10;++k)
        okelement[i][j][k]=okgrid[i][j][k]=1;
    }
    int n;
    cin>>n;
    for(int i=1;i<=9;++i){
        cin>>cons[i][1]>>cons[i][2]>>cons[i][4]>>cons[i][5]>>cons[i][7]>>cons[i][8];
        if(i%3!=0){
            for(int j=1;j<=9;++j)cin>>cons2[i][j];
        }
    }
    for(int i=1;i<=n;++i){
        int a,b,c;
        cin>>a>>b>>c;
        fix[a][b]=1;
        ans[a][b]=c;
        okrow[a][c]=0;//cerr<<a<<" "<<c<<endl;
        okcol[b][c]=0;
        okgrid[(a+2)/3][(b+2)/3][c]=0;
    }
}
bool ppp=0;
void dfs(int x,int y){
    if(y>9){
        x+=1,y=1;
        if(x>9){
            ppp=1;
            return;
        }
    }
    if(fix[x][y]){
        dfs(x,y+1);
        return;
    }
    for(int i=1;i<=9;++i)
    if(okelement[x][y][i]&&okrow[x][i]&&okcol[y][i]&&okgrid[(x+2)/3][(y+2)/3][i]){
        if(y>1){
            int tmp=cons[x][y-1];
            if(tmp){
                if(max(i,ans[x][y-1])/min(i,ans[x][y-1])!=tmp)continue;
            }
        }
        if(x>1){
            int tmp=cons2[x-1][y];
            if(tmp){
                if(max(i,ans[x-1][y])/min(i,ans[x-1][y])!=tmp)continue;
            }
        }
        ans[x][y]=i;
        okrow[x][i]=0;
        okcol[y][i]=0;
        okgrid[(x+2)/3][(y+2)/3][i]=0;
        dfs(x,y+1);
        if(ppp)return;
        okrow[x][i]=1;
        okcol[y][i]=1;
        okgrid[(x+2)/3][(y+2)/3][i]=1;
    }
}
void solve(){
    dfs(1,1);
    for(int i=1;i<=9;++i){
        for(int j=1;j<=9;++j){
            printf("%d",ans[i][j]);
            if(j<9)putchar(' ');
        }
        puts("");
    }
}
int main(){
    init();
    solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 170ms
memory: 3744kb

input:

0
1 1 0 0 1 2
1 1 1 0 0 0 6 1 2
1 1 0 0 7 3
2 6 1 0 0 0 3 1 2
2 7 0 0 3 1
0 0 1 4 0 0
0 0 0 3 3 2 0 0 0
0 0 1 1 0 0
0 0 0 1 6 1 0 0 0
0 0 7 5 0 0
1 3 0 0 1 1
1 2 2 0 0 0 4 1 6
2 1 0 0 2 4
8 1 1 0 0 0 3 1 9
4 1 0 0 2 3

output:

3 5 9 2 7 1 6 8 4
4 6 8 5 3 9 1 7 2
2 1 7 4 8 6 3 9 5
5 9 1 3 2 8 4 6 7
7 2 3 9 6 4 5 1 8
6 8 4 7 1 5 9 2 3
9 7 2 1 4 3 8 5 6
8 3 5 6 9 7 2 4 1
1 4 6 8 5 2 7 3 9

result:

ok 9 lines

Test #2:

score: 0
Accepted
time: 5ms
memory: 3948kb

input:

3
2 4 0 0 1 1
1 3 9 0 0 0 1 1 1
1 6 0 0 1 3
1 1 3 0 0 0 1 9 1
1 2 0 0 5 2
0 0 1 9 0 0
0 0 0 2 2 5 0 0 0
0 0 1 1 0 0
0 0 0 2 2 1 0 0 0
0 0 3 4 0 0
4 1 0 0 4 1
2 1 1 0 0 0 4 2 1
1 2 0 0 2 1
4 2 1 0 0 0 9 1 1
1 1 0 0 3 1
1 6 7
6 9 9
4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3 6 5 9 2 7 8 1
2 5 8 7 3 1 4 6 9

result:

ok 9 lines

Test #5:

score: 0
Accepted
time: 3ms
memory: 3884kb

input:

2
9 1 0 0 1 1
7 3 1 0 0 0 4 1 3
2 1 0 0 9 4
1 2 2 0 0 0 8 1 1
1 3 0 0 1 1
0 0 2 2 0 0
0 0 0 2 1 2 0 0 0
0 0 1 1 0 0
0 0 0 6 1 4 0 0 0
0 0 7 3 0 0
9 6 0 0 1 1
4 5 2 0 0 0 2 2 1
2 1 0 0 1 1
4 1 1 0 0 0 1 4 9
1 1 0 0 3 2
5 2 8
4 8 7

output:

1 9 8 2 3 5 4 6 7
7 3 5 8 4 6 1 9 2
4 6 2 9 1 7 8 5 3
5 2 1 3 8 4 9 7 6
3 8 7 6 5 9 2 1 4
6 4 9 1 7 2 5 3 8
9 1 6 7 2 8 3 4 5
2 5 3 4 6 1 7 8 9
8 7 4 5 9 3 6 2 1

result:

ok 9 lines

Test #6:

score: 0
Accepted
time: 2ms
memory: 3796kb

input:

3
2 2 0 0 1 2
7 1 1 0 0 0 1 1 4
5 1 0 0 1 2
4 1 4 0 0 0 6 1 2
1 3 0 0 7 2
0 0 3 6 0 0
0 0 0 1 7 1 0 0 0
0 0 3 1 0 0
0 0 0 4 1 2 0 0 0
0 0 1 1 0 0
8 4 0 0 1 3
4 9 1 0 0 0 1 2 2
4 1 0 0 1 1
1 1 1 0 0 0 1 3 4
2 1 0 0 4 2
3 4 8
5 6 4
4 2 2

output:

7 3 8 4 6 1 9 5 2
1 5 9 7 3 2 6 4 8
4 6 2 8 9 5 1 7 3
9 2 7 3 1 6 4 8 5
5 8 1 2 7 4 3 9 6
6 4 3 9 5 8 2 1 7
8 1 4 6 2 7 5 3 9
2 9 5 1 8 3 7 6 4
3 7 6 5 4 9 8 2 1

result:

ok 9 lines

Test #7:

score: 0
Accepted
time: 17ms
memory: 3728kb

input:

2
1 6 0 0 1 3
1 1 8 0 0 0 2 2 1
2 2 0 0 3 1
1 1 4 0 0 0 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2
4 2 1 0 0 0 1 3 2
4 1 0 0 1 1
6 8 7

output:

7 3 2 8 6 9 4 5 1
5 1 6 7 4 2 9 8 3
4 9 8 5 1 3 2 6 7
3 7 9 2 8 6 1 4 5
6 5 4 1 3 7 8 2 9
8 2 1 9 5 4 3 7 6
1 6 3 4 2 5 7 9 8
9 4 5 3 7 8 6 1 2
2 8 7 6 9 1 5 3 4

result:

ok 9 lines

Test #10:

score: 0
Accepted
time: 4ms
memory: 3748kb

input:

4
9 1 0 0 2 3
2 2 1 0 0 0 3 1 2
2 1 0 0 8 1
2 1 1 0 0 0 9 1 1
1 2 0 0 1 1
0 0 5 1 0 0
0 0 0 9 1 1 0 0 0
0 0 1 2 0 0
0 0 0 3 1 2 0 0 0
0 0 2 3 0 0
2 4 0 0 2 2
1 1 2 0 0 0 3 3 1
1 5 0 0 4 1
2 1 9 0 0 0 2 2 8
1 1 0 0 1 4
1 3 8
1 4 4
1 5 6
2 5 3

output:

1 9 8 4 6 5 3 7 2
2 4 6 7 3 9 1 8 5
5 3 7 2 1 8 9 6 4
8 7 3 1 5 6 4 2 9
6 2 5 9 8 4 7 1 3
9 1 4 3 7 2 8 5 6
4 8 2 5 9 1 6 3 7
3 5 1 6 4 7 2 9 8
7 6 9 8 2 3 5 4 1

result:

ok 9 lines