QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#736943#5135. Kiosk ConstructionawesomemathsWA 0ms3652kbC++142.3kb2024-11-12 14:01:062024-11-12 14:01:07

Judging History

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

  • [2024-11-12 14:01:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3652kb
  • [2024-11-12 14:01:06]
  • 提交

answer

using namespace std;
#include <bits/stdc++.h>
#define ll int
#define MAXN 45
ll store[MAXN][MAXN], h, w;
ll dfs(ll i, ll j, ll fi, ll fj, vector<ll> &visited, ll track)
{
    if(visited[store[i][j]] == 1){
        return -1;
    }
    visited[store[i][j]] = 1;
    if(i == fi && j == fj){
        return track;
    }
    ll dest = store[fi][fj];
    ll curr = store[i][j];
    ll curr1 = 1e9;
    ll curr2 = 1e9;
    ll cx = 0; ll cy = 0;
    for(int x = -1; x <= 1; x+=2){
        if(i + x >= 1 && i + x <= h){
            if((abs(dest - store[i + x][j]) < curr1) || (abs(dest - store[i + x][j]) == curr1 && abs(curr - store[i + x][j]) < curr2)){
                cx = i + x; cy = j;
                curr1 = abs(dest - store[i + x][j]);
                curr2 = abs(curr - store[i + x][j]);
            }
        }
    }
    for(int y = -1; y <= 1; y+=2){
        if(j + y >= 1 && j + y <= w){
            if((abs(dest - store[i][j + y]) < curr1) || (abs(dest - store[i][j + y]) == curr1 && abs(curr - store[i][j + y]) < curr2)){
                cx = i; cy = j + y;
                curr1 = abs(dest - store[i][j + y]);
                curr2 = abs(curr - store[i][j + y]);
            }
        }
    }
    return dfs(cx, cy, fi, fj, visited, track + 1);
    
    
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> store[i][j];
        }
    }
    bool oflag = false;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            ll cnt = 0;
            bool flag = true;
            ll res = 0;
            for(int i1 = 1; i1 <= h; i1++){
                for(int j1 = 1; j1 <= w; j1++){
                    vector<ll> visited(h * w + 1);
                    ll get = dfs(i, j, i1, j1, visited, 0);
                    res = max(res, get);
                    if(get == -1){
                        flag = false;
                        break;
                    }
                }
                if(!flag) break;
            }
            if(flag){
                cout << store[i][j] << " " << res << "\n";
                oflag = true;
                break;
            }
        }
        if(oflag) break;
    }
    if(!oflag){
        cout << "impossible\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3
1 2 3
6 5 4

output:

1 3

result:

FAIL Reported distance is not correct.