QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395536 | #7075. Let's Play Jigsaw Puzzles! | suibian_xiaozhao# | TL | 1624ms | 97312kb | C++23 | 2.4kb | 2024-04-21 16:02:31 | 2024-04-21 16:02:32 |
Judging History
answer
//
// Created by DELLPC on 24-4-21.
//
#include<bits/stdc++.h>
using namespace std;
struct op {
int n, s, w, e;
};
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int m;
cin >> m;
// vector<vector<int>> ys()
vector<op> ops(m * m + 1);
int st, num;
vector<int> nn(m * m + 1), ww(m * m + 1), cnt(m * m + 1);
map<pair<int, int>, int> mp;
for (int i = 1; i <= m * m; i++) {
cin >> ops[i].n >> ops[i].s >> ops[i].w >> ops[i].e;
mp[make_pair(0, ops[i].n)] = i;
mp[make_pair(1, ops[i].s)] = i;
mp[make_pair(2, ops[i].w)] = i;
mp[make_pair(3, ops[i].e)] = i;
if (ops[i].s != -1)
cnt[ops[i].s]++;
if (ops[i].e != -1)
cnt[ops[i].e]++;
if (ops[i].n == -1 && ops[i].w == -1)
st = i;
if (ops[i].n != -1)
nn[ops[i].n] = i;
if (ops[i].w != -1)
ww[ops[i].w] = i;
}
vector<vector<int>> ys(m + 1, vector<int>(m + 1));
for (int i = 1; i <= m * m; i++) {
if (cnt[i] == 0) {
num = i;
}
}
stack<tuple<int, int, int>> sta;
sta.emplace(1, 1, st);
ys[1][1] = num;
while (!sta.empty()) {
auto [x, y, op] = sta.top();
sta.pop();
if (x + 1 <= m) {
auto id = mp[make_pair(0, ys[x][y])];
int down = ops[op].s;
if (!ys[x + 1][y]) {
ys[x + 1][y] = down;
sta.emplace(x + 1, y, id);
}
}
if (y + 1 <= m) {
auto id = mp[make_pair(2, ys[x][y])];
int right = ops[op].e;
if (!ys[x][y + 1]) {
ys[x][y + 1] = right;
sta.emplace(x, y + 1, id);
}
}
}
for(int i =1;i<=m;i++){
for(int j = 1;j<=m;j++){
cout<<ys[i][j]<<" \n"[j==m];
}
// cout<<endl;
}
return 0;
}
// 2 -1 3 -1 2 -1 4 1 -1
// 1 -1 -1 4
// 2 -1 3 -1
//3
//-1 7 -1 1
//2 8 -1 9
//7 -1 -1 4
//-1 9 2 6
//1 4 7 5
//9 -1 8 3
//6 3 9 -1
//5 -1 4 -1
//-1 5 1 -1
//3
//-1 7 -1 1
//2 8 -1 9
//7 -1 -1 4
//-1 9 2 6
//1 4 7 5
//9 -1 8 3
//6 3 9 -1
//5 -1 4 -1
//-1 5 1 -1
//2 1 6
//7 9 5
//8 4 3
//3
//-1 4 -1 2
//-1 5 1 3
//-1 6 2 -1
//1 7 -1 5
//2 8 4 6
//3 9 5 -1
//4 -1 -1 8
//5 -1 7 9
//6 -1 8 -1
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3512kb
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: 2ms
memory: 4068kb
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: 0
Accepted
time: 176ms
memory: 21600kb
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:
50480 9217 42060 41140 1637 44728 17637 13364 58165 13517 9342 52869 4960 43953 3003 32969 30463 21433 10454 22904 26709 44841 19606 4884 23773 30214 51867 44107 47603 10352 58401 13531 39883 58086 34112 32340 64041 62812 11430 32759 31018 61827 37348 36242 30647 49901 62107 62704 30535 21688 5267 5...
result:
ok 256 lines
Test #4:
score: 0
Accepted
time: 74ms
memory: 13400kb
input:
191 23698 13626 29860 31441 7887 24322 34398 30334 11126 35201 21463 958 11392 30085 2647 17939 28938 2441 9857 732 33598 19941 3810 35849 27476 2838 27327 4183 1072 7423 18633 35342 36174 7868 7824 34627 14627 35047 671 29078 14845 8627 34672 17120 29124 19299 2929 33330 25356 22909 24770 22061 351...
output:
14987 20493 24634 25555 3621 103 7738 10062 15034 34212 17303 19790 12234 35418 2983 28113 26044 24472 11934 9247 25461 19014 9230 8266 10741 14643 19760 17655 17595 3454 19156 35614 28261 7869 35817 16214 9608 17594 12560 31440 22235 13425 7754 11642 21401 19487 11021 15764 2000 10331 15690 24223 2...
result:
ok 191 lines
Test #5:
score: 0
Accepted
time: 1522ms
memory: 91380kb
input:
560 72203 45646 225940 84151 23200 172085 305583 148143 19187 69173 143589 115564 10858 272743 64736 305667 76731 109218 36271 20228 303160 153369 162399 44342 85997 286778 9068 169298 86396 3406 105702 124146 158790 67651 148462 224096 306846 283559 301008 245648 55166 280599 304349 281527 82496 37...
output:
224085 119845 175900 201588 239827 183008 38816 234619 5180 130373 152981 295026 134643 155470 129314 225584 99128 104274 127134 111432 183770 250071 150446 86140 82150 121370 84715 167547 10762 85146 167252 95468 153081 262541 170310 224538 133353 97274 237601 103188 67954 67257 42180 147675 193298...
result:
ok 560 lines
Test #6:
score: 0
Accepted
time: 2ms
memory: 4076kb
input:
43 1185 1849 -1 430 1682 257 899 946 1163 1530 1592 317 1678 1744 1463 1334 1592 1580 1464 1530 462 -1 571 1608 699 607 639 519 584 744 161 -1 586 703 1800 887 77 1736 1598 872 698 1076 297 45 1562 1574 718 50 435 1696 1772 589 1816 1192 258 1042 785 1841 618 1203 1231 509 1771 103 496 1522 709 1337...
output:
1821 551 1252 1073 1302 466 1787 1739 1731 1343 1784 1729 616 1551 1235 367 109 975 963 1168 1660 222 1419 1766 604 1520 754 1562 1314 396 1056 1470 1461 1123 503 577 37 1847 280 131 1637 524 1367 1268 1460 570 1638 764 1720 714 1202 978 1363 254 38 869 1782 1362 333 1839 544 1447 1239 485 1068 540 ...
result:
ok 43 lines
Test #7:
score: 0
Accepted
time: 1624ms
memory: 97312kb
input:
579 90512 102801 93308 48869 331400 137671 34396 297128 117209 179703 168627 319180 117666 17573 303023 98937 31041 309597 25283 176683 286250 29553 328705 303255 299034 163378 231128 283125 275697 18465 309254 325775 138419 203716 193839 182352 324333 6110 5508 25465 45184 109255 248198 166854 1904...
output:
122400 145213 192235 211903 40022 281070 185702 163986 86738 156055 172168 222902 117447 217450 272481 71700 122315 62749 149965 82866 5097 213046 263881 1903 197253 35164 208133 40583 212442 159976 194575 221347 118114 90386 27400 222239 205673 50446 76974 258849 141657 8123 215932 99248 45129 2061...
result:
ok 579 lines
Test #8:
score: 0
Accepted
time: 1115ms
memory: 70136kb
input:
488 110871 18943 90010 131829 213854 36909 92742 61484 74063 178728 207929 66184 163209 180828 93568 84875 164622 130490 163951 132221 182591 15082 136552 152122 215364 23828 55924 50723 150658 199318 72102 231016 62679 71620 48922 109254 75130 118108 51334 180247 67112 34806 84090 148041 175129 158...
output:
231228 106356 70555 187978 7592 23531 63412 222255 147410 232002 58890 34812 85386 115744 4391 34972 130589 93173 56740 203402 39016 107638 154674 32714 12904 85412 233480 17728 41685 34904 185708 225173 145548 57890 83520 56529 228995 84062 84952 99206 141413 80521 19291 229046 93370 38999 46973 14...
result:
ok 488 lines
Test #9:
score: -100
Time Limit Exceeded
input:
1000 169030 118433 902236 978629 84782 72306 11244 989711 960726 25357 932157 864236 224317 160222 176503 202676 991085 45686 945176 923522 216182 224394 214439 917827 63493 105551 942441 77579 133778 937237 22921 141341 235245 208679 99377 137036 175065 220128 84501 81633 18459 934111 36668 32948 9...