QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397833#5135. Kiosk Constructionucup-team1001#WA 0ms3548kbC++233.0kb2024-04-24 17:26:152024-04-24 17:26:15

Judging History

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

  • [2024-04-24 17:26:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-04-24 17:26:15]
  • 提交

answer

/*

Author: Haze

2024/4/24

*/

#include <bits/stdc++.h>

#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define drep(i, r, l) for(int i = (r); i >= (l); -- i)
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
typedef long long ll;

inline ll read() {
    ll s = 0;
    bool fl = false;
    char ch = (char) getchar();
    while (!isdigit(ch)) {
        if (ch == '-')fl = true;
        ch = (char) getchar();
    }
    while (isdigit(ch)) {
        s = s * 10 + (ch ^ 48);
        ch = (char) getchar();
    }
    return fl ? -s : s;
}

const int mod = 1000000000 + 7;
const int itinf = 1000000999;
const ll llinf = 2e18;
const int N = 500099;

int a[44][44];
int usd[41][41];
void solve() {
    int n = read(), m = read();
    irep(i ,1, n){
        irep(j, 1, m){
            a[i][j] = read();
        }
    }
    vector<array<int, 2>> d = {
            {1, 0},
            {-1,0},
            {0, 1},
            {0, -1}
    };
    irep(i, 1, n){
        irep(j, 1, m){
            int D = -1, ok = 1;
            irep(k, 1, n){
                irep(l, 1, m){

                    int num = a[k][l];
                    //(i, j) -> (k, l)
                    int x = i, y = j;
                    memset(usd, -1, sizeof usd);
                    usd[x][y] = 0;
                    while(x != k || y != l){
                        int x1, y1, del = 9980000, curnum = 9980000;
                        for(auto [dx, dy] : d){
                            if(x + dx <= n && x + dx >= 1 && y + dy <= m && y + dy >= 1){
                                if(abs(a[x + dx][y + dy] - num) < del ||
                                abs(a[x + dx][y + dy] - num) == del && abs(a[x + dx][y + dy] - a[x][y]) < curnum){
                                    curnum = abs(a[x + dx][y + dy] - a[x][y]);
                                    del = abs(a[x + dx][y + dy] - num);
                                    x1 = x + dx, y1 = y + dy;
                                }
                            }
                        }
//                        cerr << "[]" << x1 << ' ' << y1 << endl;
                        if(usd[x1][y1] != -1){
                            ok = 0;
                            break;
                        }
                        usd[x1][y1] = usd[x][y] + 1;
                        x = x1, y = y1;
                    }

                    if(ok == 0)break;
                    D = max(D, usd[k][l]);
//                    irep(p,1,n){
//                        irep(q,1,m)cerr << usd[p][q] << ' ';
//                        cerr << endl;
//                    }
//                    cerr << endl;
                }
                if(ok == 0)break;
            }
            if(ok){
                cout << a[i][j] << ' ' << D;
                return;
            }
        }
    }
    cout << "impossible";
}

int main() {
    // IOS
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

2 3
1 2 3
6 5 4

output:

1 3

result:

FAIL Reported distance is not correct.