QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#731989#7075. Let's Play Jigsaw Puzzles!Yurily#TL 1ms5812kbC++201.1kb2024-11-10 12:38:462024-11-10 12:38:46

Judging History

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

  • [2024-11-10 12:38:46]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5812kb
  • [2024-11-10 12:38:46]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<queue>
#define N 5010
using namespace std;

int m,cnct[N][4];
int id[N][N];
struct node{
    int i,x,y;
};
queue<node> q;

void bfs(){
    while(!q.empty()){
        int i=q.front().i,x=q.front().x,y=q.front().y;
        if(cnct[i][1]!=-1&&cnct[i][2]==-1){
            id[x+1][y]=cnct[i][1];
            node tmp={cnct[i][1],x+1,y};
            q.push(tmp);
        }
        if(cnct[i][3]!=-1){
            id[x][y+1]=cnct[i][3];
            node tmp={cnct[i][3],x,y+1};
            q.push(tmp);
        }
        q.pop();
    }
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin>>m;
    for(int i=1;i<=m*m;i++){
        for(int t=0;t<4;t++){
            cin>>cnct[i][t];
        }
        if(cnct[i][0]==-1&&cnct[i][2]==-1){
            node tmp={i,1,1};
            id[1][1]=i;
            q.push(tmp);
        }
    }
    bfs();
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            if(j==m) cout<<id[i][j];
            else cout<<id[i][j]<<" ";
        }
        if(i!=m) cout<<"\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5616kb

input:

2
-1 3 -1 2
-1 4 1 -1
1 -1 -1 4
2 -1 3 -1

output:

1 2
3 4

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5812kb

input:

42
1244 1713 1584 265
1100 1445 250 397
108 1161 26 940
1084 1119 1579 576
485 176 1251 781
917 1361 883 209
568 1162 44 368
1614 914 378 604
1059 687 1373 988
537 911 559 1649
1155 1685 352 1724
434 863 1367 298
963 41 1261 288
601 590 1554 1281
1714 -1 608 979
83 199 1072 1075
984 1411 1592 293
10...

output:

1559 1618 550 492 198 145 1622 466 443 646 676 1428 1586 1569 287 76 1144 445 184 760 1038 888 96 722 24 1683 1096 867 619 1632 683 58 290 512 422 1489 621 1736 1478 1221 1507 1316
878 1142 194 1504 344 1278 1065 615 1582 321 1486 1000 295 1481 916 1198 1274 596 1617 307 110 706 860 708 499 1077 109...

result:

ok 42 lines

Test #3:

score: -100
Time Limit Exceeded

input:

256
59514 55419 18661 2338
18386 44586 37892 7259
45565 43343 44074 39100
8065 51340 31460 61704
1973 54946 26716 14567
8587 43850 10746 46526
1524 55529 62814 1688
13757 56306 9426 55901
52993 2600 16483 10803
35724 11123 64064 24411
58936 6877 50578 15423
36123 3907 25662 1943
17529 53198 11065 21...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result: