QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#477057#9114. Black or White 2Forever_Young#TL 0ms3908kbC++142.9kb2024-07-13 22:59:102024-07-13 22:59:10

Judging History

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

  • [2024-07-13 22:59:10]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3908kb
  • [2024-07-13 22:59:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define all(x) ((x).begin()), ((x).end())
#define pb push_back

const int N = 1511;
int a[N][N];
int n, m, k;
void print() {
    int sum = 0, x = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            printf("%d", a[i][j]);
            sum += a[i][j];
            if (i && j) {
                x += (a[i][j] + a[i - 1][j] + a[i][j - 1] + a[i - 1][j - 1] == 2);
            }
        }
        printf("\n");
    }
    assert(sum == k);
    assert(x == 0 || (n == 2 && m == 2 && k == 2));
}
void solve(int nn, int mm, int kk) {
    if (nn != -1) {
        n = nn;
        m = mm;
        k = kk;
    } else {
        scanf("%d%d%d", &n, &m, &k);
    }
    if (k == 2) {
        a[0][0] = a[n - 1][m - 1] = 1;
        print();
        return;
    }
    if (k == n * m - 2) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = !(i == 0 && j == 0 || i == n - 1 && j == m - 1);
            }
        }
        print();
        return;
    }
    bool rev = false;
    if (k > n * m / 2) {
        k = n * m - k;
        rev = true;
    }
    bool mir = false;
    if (n > m) {
        mir = true;
        swap(n, m);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            a[i][j] = 0;
        }
    }
    
    int cnt = 0;
    int len = 0;
    while(cnt < k) {
        len++;
        for (int i = 1; i <= min(len, n); i++) {
            a[i - 1][len - i] = 1;
        }
        cnt += min(len, n);
    }
    // printf("cnt =  %d\n", cnt);
    if (len >= n + 1) {
        for (int j = len - n - 1; j >= 0 && cnt > k; j -= 2) {
            cnt--;
            a[n - 1][j] = 0;
        }
    }
    for (int i = n - 1; i >= 1 && cnt > k + 1; i--) {
        for (int j = m - 1; j >= 0 && cnt > k + 1; j--) {
            if (a[i][j] == 1) {
                a[i][j] = 0;
                a[i - 1][j] = 0;
                cnt -= 2;
            }
        }
    }
    if (cnt > k) {
        a[0][0] = 0;
    }

    if (mir) {
        for (int i = 0; i < 1500; i++) {
            for (int j = 0; j < i; j++) {
                swap(a[i][j], a[j][i]);
            }
        }
        swap(n, m);
    }
    if (rev) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] ^= 1;
            }
        }
        k = n * m - k;
    }

    print();
}
int main() {
    int t;
    scanf("%d", &t);
   for(int qq = 1; qq <= t; qq++) {
    // for (int i = 2; i <= 10; i++) {
    //     for(int j = 2; j <= 10; j++) {
    //         for(int k = 0; k <= i * j; k++) {
    //             printf("%d %d %d\n", i, j, k);
    //             solve(i, j, k);
    //         }
    //     }
    // }
        solve(-1, -1, -1);
   }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
2 2 2
2 3 0

output:

10
01
000
000

result:

ok Output is valid. OK.

Test #2:

score: -100
Time Limit Exceeded

input:

27520
2 2 0
2 2 1
2 2 2
2 2 3
2 2 4
2 3 0
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
3 2 0
3 2 1
3 2 2
3 2 3
3 2 4
3 2 5
3 2 6
3 3 0
3 3 1
3 3 2
3 3 3
3 3 4
3 3 5
3 3 6
3 3 7
3 3 8
3 3 9
2 4 0
2 4 1
2 4 2
2 4 3
2 4 4
2 4 5
2 4 6
2 4 7
2 4 8
3 4 0
3 4 1
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
3 4 10...

output:

00
00
10
00
10
01
01
11
11
11
000
000
100
000
100
001
110
100
011
110
011
111
111
111
00
00
00
10
00
00
10
00
01
11
10
00
01
11
10
01
11
11
11
11
11
000
000
000
100
000
000
100
000
001
110
100
000
111
010
000
000
101
111
001
011
111
011
111
110
011
111
111
111
111
111
0000
0000
1000
0000
1000
0001
1...

result: