QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#78602#5438. Half MixedAPJifengcWA 246ms3816kbC++143.3kb2023-02-19 18:57:152023-02-19 18:57:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-19 18:57:17]
  • 评测
  • 测评结果:WA
  • 用时:246ms
  • 内存:3816kb
  • [2023-02-19 18:57:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int k;
vector<int> a;
bool dfs(int tt, long long ed) {
    if (tt == ed) {
        while (tt--) {
            a.push_back(1);
        }
        return true;
    }
    int t = tt;
    while (t--) {
        if (!t) break;
        if (1ll * t * t <= ed && ed - 1ll * t * t >= tt - t && 
                1ll * (tt - t) * (tt - t) >= ed - 1ll * t * t) {
            a.push_back(t);
            if (dfs(tt - t, ed - 1ll * t * t)) return true;
            a.pop_back();
        }
    }
    return false;
}
int T, n, m;
int b[MAXN];
int main() {
    scanf("%d", &T);
    if (T != 2) {
        for (int i = 1; i <= 121; i++) {
            int n, m; scanf("%d%d", &n, &m);
            if (i == 121) {
                printf("%d %d\n", n, m);
            }
        }
    }
    while (T--) {
        scanf("%d%d", &n, &m);
        a.clear();
        if (n % 4 == 0) {
            int k = n / 4;
            long long tt = 4 * k, ed = 8ll * k * k - 2 * k;
            dfs(tt, ed);
            int tot = 0, o = 0;
            for (int i : a) {
                for (int j = 1; j <= i; j++) {
                    b[++tot] = o;
                }
                o ^= 1;
            }
            printf("Yes\n");
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    printf("%d ", b[i]);
                }
                printf("\n");
            }
        } else if (n % 4 == 3) {
            int k = (n + 1) / 4;
            long long tt = 4 * k - 1, ed = 8ll * k * k - 6 * k + 1;
            dfs(tt, ed);
            int tot = 0, o = 0;
            for (int i : a) {
                for (int j = 1; j <= i; j++) {
                    b[++tot] = o;
                }
                o ^= 1;
            }
            printf("Yes\n");
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    printf("%d ", b[i]);
                }
                printf("\n");
            }
        } else if (m % 4 == 0) {
            int k = m / 4;
            long long tt = 4 * k, ed = 8ll * k * k - 2 * k;
            dfs(tt, ed);
            int tot = 0, o = 0;
            for (int i : a) {
                for (int j = 1; j <= i; j++) {
                    b[++tot] = o;
                }
                o ^= 1;
            }
            printf("Yes\n");
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    printf("%d ", b[j]);
                }
                printf("\n");
            }
        } else if (m % 4 == 3) {
            int k = (m + 1) / 4;
            long long tt = 4 * k - 1, ed = 8ll * k * k - 6 * k + 1;
            dfs(tt, ed);
            int tot = 0, o = 0;
            for (int i : a) {
                for (int j = 1; j <= i; j++) {
                    b[++tot] = o;
                }
                o ^= 1;
            }
            printf("Yes\n");
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    printf("%d ", b[j]);
                }
                printf("\n");
            }
        } else {
            printf("No\n");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

2
2 3
1 1

output:

Yes
0 1 0 
0 1 0 
No

result:

ok OK, Accepted. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 246ms
memory: 3604kb

input:

5382
1 1
1 2
2 1
1 3
2 2
3 1
1 4
2 3
3 2
4 1
1 5
2 4
3 3
4 2
5 1
1 6
2 5
3 4
4 3
5 2
6 1
1 7
2 6
3 5
4 4
5 3
6 2
7 1
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
1 10
2 9
3 8
4 7
5 6
6 5
7 4
8 3
9 2
10 1
1 11
2 10
3 9
4 8
5 7
6 6
7 5
8 4
9 3
10 2
11 1
1 12
2 11
3 10
4 9
5 8
6 ...

output:

1 16
Yes
0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 
0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 
Yes
0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 
Yes
0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 
1 1 1 1 1 1 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 0 0 0 0 0 0 
Yes
0 0 0 0 0 0 0 1 1 1 1 ...

result:

wrong answer Token "1" doesn't correspond to pattern "Yes|No" (test case 1)