QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395429 | #7075. Let's Play Jigsaw Puzzles! | suibian_xiaozhao# | TL | 0ms | 0kb | C++23 | 1.2kb | 2024-04-21 14:34:23 | 2024-04-21 14:34:23 |
answer
//
// Created by DELLPC on 24-4-21.
//
#include<bits/stdc++.h>
using namespace std;
struct op {
int n, s, w, e;
};
int main() {
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)
cnt[ops[i].s]++;
if(ops[i].e)
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 << endl;
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...