QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250033#4638. Xiangqiucup-team1209WA 141ms4100kbC++205.2kb2023-11-12 20:35:092023-11-12 20:35:10

Judging History

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

  • [2023-11-12 20:35:10]
  • 评测
  • 测评结果:WA
  • 用时:141ms
  • 内存:4100kb
  • [2023-11-12 20:35:09]
  • 提交

answer

#include <bits/stdc++.h> 
#define cs const
#define pb push_back
using namespace std;
#define fi first
#define se second 
cs int oo = 1e9; 
typedef long long ll; 
typedef pair <int, int> pi;

int T, ans; 
int px[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int py[8] = {2, 1, -1, -2, -2, -1, 1, 2}; 
cs int B = 100; 
int d[B + B + 5][B + B + 5];

int work(int x, int y) {
    x = abs(x), y = abs(y);
    if(x <= B && y <= B) return d[x + B][y + B];
    if(x > y) swap(x, y);
    int s = min(x, y - x); 
    if(s == x) {
        y -= 2 * s, x -= s; 
        if(y > B) y -= (y - B + 4) / 4 * 4; 
        return d[x + B][y + B] + s; 
    }
    int l = 0, r = s; 
    while(l < r) {
        int mid = (l + r) >> 1; 
        int x_ = x - mid, y_ = y - 2 * mid; 
        if(x_ <= B && y_ <= B) r = mid; 
        else l = mid + 1; 
    }
    x -= l, y -= l * 2; 
    if(x > B) {
        int s = (x - B + 3) / 3; 
        x -= s * 3, y -= s * 3; 
        l += s * 2; 
    }
    return d[x + B][y + B] + l; 
}

void ck(int Y, int x, int y, int s) {
    // cout << "Ck " << Y << ' ' << x <<  ' ' << y << ' ' << s << endl; 
    if(x != 0) {
        if(y <= Y) {
            ans = min(ans, s + 3);
        }
        else {
            ans = min(ans, s + 2);
        }
    }
    else {
        if(y <= Y) {
            if(y < 0) { 
                ans = min(ans, s + 4); 
            }
            else {
                if(s > 0) {
                    ans = min(ans, s + 2);
                }
                else {
                    // 4 or 2 
                    if(Y - y == 1 && y > 1) {
                        ans = min(ans, s + 3);
                    }
                    if(Y - y == 2 && Y > 4) {
                        ans = min(ans, s + 3);
                    }
                    if(Y - y == 3 && Y > 4) {
                        
                        ans = min(ans, s + 3);
                    }
                    ans = min(ans, s + 4); 
                }
            }
        }
        else {
            ans = min(ans, s + 1); 
        }
    }
}

int main() {
    #ifdef FSYo
    freopen("1.in","r",stdin);
    #endif
    cin >> T; 

    memset(d, -1, sizeof(d));
    d[B][B] = 0; 
    queue <pi> q; 
    q.push(pi(B, B));
    while(!q.empty()) {
        pi x = q.front(); q.pop();
        for(int e = 0; e < 8; e++) {
            int ux = x.fi + px[e], uy = x.se + py[e];
            if(ux >= 0 && uy >= 0 && ux <= B * 2 && uy <= B * 2) {
                if(d[ux][uy] == -1) 
                    q.push(pi(ux, uy)), d[ux][uy] = d[x.fi][x.se] + 1; 
            }
        }
    }
    /*
    for(int i = 95; i <= 105; i++, puts(""))
    for(int j = 95; j <= 105; j++) cout << d[i][j] << ' ';
    */
    while(T--) {
        int xh, yh, xc, yc; 
        scanf("%d%d%d%d", &xh, &yh, &xc, &yc);

        static int f[8]; 
        for(int i = 0; i < 8; i++) 
            f[i] = work(xh - px[i], yh - py[i]); 
        /*  
        int px[8] = {1, 2, 2, 1, -1, -2, -2, -1};
        int py[8] = {2, 1, -1, -2, -2, -1, 1, 2}; 
        */
        if(xc == 1 && yc == 1) {
            f[0] ++, f[1] ++; 
        }
        if(xc == 1 && yc == -1) {
            f[2] ++, f[3] ++; 
        }
        if(xc == -1 && yc == -1) {
            f[4] ++, f[5] ++; 
        }
        if(xc == -1 && yc == 1) {
            f[6] ++, f[7] ++; 
        }

        ans = oo; 
        for(int i = 0; i < 8; i++)
            ans = min(ans, f[i] + 1);
        // cout << ans << ' ' << xh << ' ' << yh << endl; 

        if(xh < 0 && yh < 0) {
            xh = -xh, yh = -yh, xc = -xc, yc = -yc; 
        }
        if(xh < 0 && yh > 0) {
            swap(xh, yh); yh = -yh; 
            swap(xc, yc); yc = -yc; 
        }
        if(xh > 0 && yh < 0) {
            swap(xh, yh); xh = -xh; 
            swap(xc, yc); xc = -xc; 
        }
        
        // cout << ans << ' ' << xh << ' ' << yh << endl; 
        

        int s = (xh + 1) / 2, dy = s + 2 * (xh & 1);
        // [-dy, dy] 
        int U = yh - dy, D = yh + dy; 

        // cout << U << ' ' << D << endl; 

        if(U < 0) {
            U = -U; 
            if(U & 1) D = max(-D, 1); 
            else D = max(-D, 2);
            ck(D, xc, - yc, s); 
        } 
        if(D > 0) {
            if(D & 1) U = max(U, 1);
            else U = max(U, 2);
            ck(U, xc, yc, s); 
        }
        
        for(int i = 1; i <= 10; i++) 
        ck(i, xc, yc, work(xh, yh - i)),
        ck(i, xc, - yc, work(xh, yh + i)); 

        swap(xh, yh); swap(xc, yc); 

        s = (xh + 1) / 2, dy = s + 2 * (xh & 1);
        // [-dy, dy] 
        U = yh - dy, D = yh + dy; 

        // cout << U << ' ' << D << endl; 

        if(U < 0) {
            U = -U; 
            if(U & 1) D = max(-D, 1); 
            else D = max(-D, 2);
            ck(D, xc, - yc, s); 
        } 
        if(D > 0) {
            if(D & 1) U = max(U, 1);
            else U = max(U, 2);
            ck(U, xc, yc, s); 
        }

        for(int i = 1; i <= 10; i++) 
        ck(i, xc, yc, work(xh, yh - i)),
        ck(i, xc, - yc, work(xh, yh + i)); 

        cout << ans << '\n';

    }
    return 0; 
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4100kb

input:

5
-2 1 5 5
5 0 6 0
2 1 1 1
100 2 -1 0
4 2 1 1

output:

1
1
2
5
3

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 141ms
memory: 3880kb

input:

388752
-12 -12 -12 -11
-12 -12 -12 -10
-12 -12 -12 -9
-12 -12 -12 -8
-12 -12 -12 -7
-12 -12 -12 -6
-12 -12 -12 -5
-12 -12 -12 -4
-12 -12 -12 -3
-12 -12 -12 -2
-12 -12 -12 -1
-12 -12 -12 0
-12 -12 -12 1
-12 -12 -12 2
-12 -12 -12 3
-12 -12 -12 4
-12 -12 -12 5
-12 -12 -12 6
-12 -12 -12 7
-12 -12 -12 8
...

output:

8
8
8
8
8
8
8
8
8
8
8
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
7
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
8
7
8
8
8
8
8
8
8
8
8
8
8
8
8
...

result:

wrong answer 805th lines differ - expected: '9', found: '8'