QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395445 | #7075. Let's Play Jigsaw Puzzles! | suibian_xiaozhao# | TL | 0ms | 0kb | C++23 | 1.3kb | 2024-04-21 14:45:02 | 2024-04-21 14:45:02 |
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<op> ops(m * m + 1);
int st, num;
vector<int> nn(m * m + 1), ww(m * m + 1), cnt(m * m + 1);
for (int i = 1; i <= m * m; i++) {
cin >> ops[i].n >> ops[i].s >> ops[i].w >> ops[i].e;
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].s == -1)
st = i;
if (ops[i].n != -1)
nn[ops[i].n] = i;
if (ops[i].w != -1)
ww[ops[i].w] = i;
}
for (int i = 1; i <= m * m; i++) {
if (cnt[i] == 0) {
num = i;
}
}
while (1) {
int now1 = num, now2 = st;
while (1) {
cout << now1 << ' ';
int t = ops[now2].e;
if (t == -1) {
break;
}
now2 = ww[now1];
now1 = t;
}
cout << "\n";
int t = ops[st].s;
if (t == -1) {
break;
}
st = nn[num];
num = t;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 -1 3 -1 2 -1 4 1 -1 1 -1 -1 4 2 -1 3 -1
output:
1 0 0 4 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...