QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249872#6309. Aqretpc_icpc_n#RE 0ms3560kbC++205.3kb2023-11-12 17:13:142023-11-12 17:13:14

Judging History

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

  • [2023-11-12 17:13:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3560kb
  • [2023-11-12 17:13:14]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

/*
bool BFS(vector<string> &s) {
    return true;
    int N = int(s.size()), M = int(s[0].size());
    int sx, sy;
    REP(i, N) REP(j, M) {
        if (s[i][j] == '1') {
            sx = i, sy = j;
        }
    }
    queue<pair<int, int>> que;
    que.push({sx, sy});
    vector seen(N, vector<int>(M));
    while (!que.empty()) {
        auto [cx, cy] = que.front();
        que.pop();
        REP(k, 4) {
            int nx = cx + dx[k], ny = cy + dy[k];
            if (!(0 <= nx and nx < N and 0 <= ny and ny < M)) continue;
            if (seen[nx][ny]) continue;
            if (s[nx][ny] ==)
        }
    }
}
*/


void solve() {
    int N,M; cin >> N >> M;
    if(N==6 && M==6){
        cout << 28 << '\n';
        cout << "110111\n";
        cout << "111011\n";
        cout << "101110\n";
        cout << "011101\n";
        cout << "110111\n";
        cout << "111011\n";
    }
    else if(N<=3 && M<=3){
        cout << N*M << '\n';
        rep(i,N) cout << string(M,'1') << '\n';
    }
    else if(N<=3){
        string bs(M,'1');
        int cnt = N*M;
        vector<string> A(N,bs);
        rep(i,N){
            for(int j=((i%2==0)?3:1);j<M;j+=4){
                A[i][j] = '0';
                cnt--;
            }
        }
        cout << cnt << '\n';
        rep(i,N) cout << A[i] << '\n';
    }
    else if(M<=3){
        vector<string> bs = {"111","101","111","010"};
        vector<int> mn = {0,1,0,2-(M==2)};
        int cnt = N*M;
        vector<string> A(N);
        rep(i,N){
            A[i] = bs[i%4].substr(0,M);
            cnt -= mn[i%4];
        }
        cout << cnt << '\n';
        rep(i,N) cout << A[i] << '\n';
    }
    else{
        int ans = 0;
        vector<string> Ans;
        vector<int> p = {0,2,1,3,0,2,1};
        if(N==6 || M==6){
            vector<string> bs(8);
            bs[0] = "110111";
            bs[1] = "111011";
            bs[2] = "101110";
            bs[3] = "011101";
            bs[4] = "110111";
            bs[5] = "111011";
            bs[6] = "101110";
            bs[7] = "011101";
            vector<int> mn = {1,1,2,2,1,1,2,2};
            vector<string> A(M+N-6);
            rep(p,4){
                int cnt = N*M;
                rep(i,N+M-6){
                    A[i] = bs[p+i%4];
                    cnt -= mn[p+i%4];
                }
                if(A[0][0]=='1' && A[0][1]=='0' && A[1][0]=='0'){
                    A[0][0] = '0';
                    cnt--;
                }
                if(A[0][M-1]=='1' && A[0][M-1-1]=='0' && A[1][M-1]=='0'){
                    A[0][M-1] = '0';
                    cnt--;
                }
                if(A[N-1][0]=='1' && A[N-1][1]=='0' && A[N-1-1][0]=='0'){
                    A[N-1][0] = '0';
                    cnt--;
                }
                if(A[N-1][M-1]=='1' && A[N-1][M-1-1]=='0' && A[N-1-1][M-1]=='0'){
                    A[N-1][M-1] = '0';
                    cnt--;
                }
                if(ans < cnt){
                    ans = cnt;
                    if(N==6){
                        vector<string> B(6,string(M,'-'));
                        rep(i,M) rep(j,6) B[j][i] = A[i][j];
                        A = B;
                    }
                    Ans = A;
                }
            }
        }
        rep(i,4){
            int cnt = N*M;
            string bs(M,'1');
            vector<string> A(N,bs);
            for(int y=0;y<N;y++){
                for(int j=p[i+y%4];j<M;j+=4){
                    A[y][j] = '0';
                    cnt--;
                }
            }
            if(A[0][0]=='1' && A[0][1]=='0' && A[1][0]=='0'){
                A[0][0] = '0';
                cnt--;
            }
            if(A[0][M-1]=='1' && A[0][M-1-1]=='0' && A[1][M-1]=='0'){
                A[0][M-1] = '0';
                cnt--;
            }
            if(A[N-1][0]=='1' && A[N-1][1]=='0' && A[N-1-1][0]=='0'){
                A[N-1][0] = '0';
                cnt--;
            }
            if(A[N-1][M-1]=='1' && A[N-1][M-1-1]=='0' && A[N-1-1][M-1]=='0'){
                A[N-1][M-1] = '0';
                cnt--;
            }
            if(ans < cnt){
                ans = cnt;
                Ans = A;
            }
        }
        cout << ans << '\n';
        //assert(BFS(Ans));
        rep(i,N) cout << Ans[i] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 2
3 4
3 8

output:

4
11
11
9
1110
1011
1110
18
11101110
10111011
11101110

result:

ok ok (3 test cases)

Test #2:

score: -100
Runtime Error

input:

361
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
4 19
4 20
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 1...

output:


result: