QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395516#7075. Let's Play Jigsaw Puzzles!suibian_xiaozhao#WA 0ms3648kbC++232.2kb2024-04-21 15:46:442024-04-21 15:46:44

Judging History

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

  • [2024-04-21 15:46:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2024-04-21 15:46:44]
  • 提交

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]<<" ";
        }
        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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3648kb

input:

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

output:

1 2 
3 4 

result:

wrong answer 1st lines differ - expected: '1 2', found: '1 2 '