Submission #35321295


Source Code Expand

#include"bits/stdc++.h"

using namespace std;

int dx[16] = {1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1};
int dy[16] = {0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1};

long long mm(long long x, long long y) {
    if (x == -1) return y;
    return min(x, y);
}

int main() {
    // freopen("D.in" , "r" , stdin);
    // freopen("D.out" , "w" , stdout);
    int T;
    cin >> T;
    vector<bool> s(16);
    for (; T; --T) {
        long long a, b;
        cin >> a >> b;
        for (int i = 0; i < 8; ++i) {
            char ch;
            cin >> ch;
            s[i] = ch == '1';
        }
        for (int i = 8; i < 16; ++i) s[i] = s[i-8];
        int rz = 0;
        if (a < 0 && b > 0) {
            rz = 2;
            long long c = a;
            a = b;
            b = -c;
        } else if (a < 0 && b < 0) {
            rz = 4;
            a = -a;
            b = -b;
        } else if (a > 0 && b < 0) {
            rz = 6;
            long long c = a;
            a = -b;
            b = c;
        }
        long long ans = -1;
        if (a == 0 && b == 0) ans = 0;
        else if (a == 0) {
            if (s[rz+2] || s[rz+1] && s[rz+3] && b % 2 == 0) {
                ans = b;
            } else if (s[rz+1] && s[rz+4] || s[rz+3] && s[rz]) {
                ans = b+b;
            }
        } else if (b == 0) {
            if (s[rz] || s[rz+1] && s[rz+7] && a % 2 == 0) {
                ans = a;
            } else if (s[rz+1] && s[rz+6] || s[rz+7] && s[rz+2]) {
                ans = a+a;
            }
        } else {
            int x1 = -1, x2 = -1, y1 = -1, y2 = -1, xy = -1;
            if (s[rz]) x1 = 1, x2 = 2;
            if (s[rz+2]) y1 = 1, y2 = 2;
            if (s[rz+1]) xy = 1;
            if (s[rz+1] && s[rz+3]) y2 = 2;
            if (s[rz+1] && s[rz+7]) x2 = 2;
            if (x1 == -1 && (s[rz+1] && s[rz+6] || s[rz+7] && s[rz+2])) x1 = 2;
            if (y1 == -1 && (s[rz+1] && s[rz+4] || s[rz+3] && s[rz])) y1 = 2;
            if (xy == -1 && x1 != -1 && y1 != -1) xy = x1 + y1;
            if (a == b) {
                if (xy != -1) ans = a * xy;
            } else if (a > b) {
                if (xy != -1 && x1 != -1) ans = b*xy + (a-b)*x1;
                if ((a-b) % 2 == 0 && xy != -1 && x2 != -1) ans = mm(ans, b*xy + (a-b)/2*x2);
                if (xy != -1 && x1 != -1 && x2 != -1) ans = mm(ans, b*xy + (a-b)/2*x2 + ((a-b)%2)*x1);
            } else {
                if (xy != -1 && y1 != -1) ans = a*xy + (b-a)*y1;
                if ((b-a) % 2 == 0 && xy != -1 && y2 != -1) ans = mm(ans, a*xy + (b-a)/2*y2);
                if (xy != -1 && y1 != -1 && y2 != -1) ans = mm(ans, a*xy + (b-a)/2*y2 + ((b-a)%2)*y1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task Ex - General General
User ZzZZCHS
Language C++ (GCC 9.2.1)
Score 0
Code Size 2850 Byte
Status WA
Exec Time 36 ms
Memory 3620 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:47:47: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   47 |             if (s[rz+2] || s[rz+1] && s[rz+3] && b % 2 == 0) {
      |                            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
./Main.cpp:49:32: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   49 |             } else if (s[rz+1] && s[rz+4] || s[rz+3] && s[rz]) {
      |                        ~~~~~~~~^~~~~~~~~~
./Main.cpp:53:45: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   53 |             if (s[rz] || s[rz+1] && s[rz+7] && a % 2 == 0) {
      |                          ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
./Main.cpp:55:32: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   55 |             } else if (s[rz+1] && s[rz+6] || s[rz+7] && s[rz+2]) {
      |                        ~~~~~~~~^~~~~~~~~~
./Main.cpp:65:38: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   65 |             if (x1 == -1 && (s[rz+1] && s[rz+6] || s[rz+7] && s[rz+2])) x1 = 2;
      |                              ~~~~~~~~^~~~~~~~~~
./Main.cpp:66:38: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
   66 |             if (y1 == -1 && (s[rz+1] && s[rz+4] || s[rz+3] && s[rz])) y1 = 2;
      |                              ~~~~~~~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 1
AC × 4
WA × 14
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 02_rnd_00.txt, 02_rnd_01.txt, 02_rnd_02.txt, 02_rnd_03.txt, 03_zero_00.txt, 04_one_00.txt, 04_one_01.txt, 05_two_00.txt, 05_two_01.txt, 06_max_00.txt, 06_max_01.txt, 07_255_00.txt, 07_255_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3480 KiB
01_small_00.txt WA 33 ms 3524 KiB
01_small_01.txt WA 33 ms 3484 KiB
01_small_02.txt WA 27 ms 3572 KiB
01_small_03.txt WA 6 ms 3548 KiB
02_rnd_00.txt WA 35 ms 3396 KiB
02_rnd_01.txt WA 36 ms 3608 KiB
02_rnd_02.txt WA 36 ms 3576 KiB
02_rnd_03.txt WA 36 ms 3572 KiB
03_zero_00.txt AC 29 ms 3548 KiB
04_one_00.txt WA 31 ms 3568 KiB
04_one_01.txt WA 34 ms 3496 KiB
05_two_00.txt WA 36 ms 3484 KiB
05_two_01.txt WA 35 ms 3476 KiB
06_max_00.txt WA 35 ms 3480 KiB
06_max_01.txt WA 35 ms 3548 KiB
07_255_00.txt AC 35 ms 3620 KiB
07_255_01.txt AC 35 ms 3520 KiB