QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95835#5438. Half Mixedreshke#WA 2ms3416kbC++145.1kb2023-04-12 00:24:082023-04-12 00:24:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-12 00:24:12]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3416kb
  • [2023-04-12 00:24:08]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>

#include "vector"

int len;
const int maxlen = 1e5 + 32;
using namespace std;


int f[10][10];
int preff[10][10];

int n = 3;
int m = 5;

int sm(int x1, int y1, int x2, int y2) {
    return preff[x2][y2] + preff[x1 - 1][y1 - 1] - preff[x1 - 1][y2] - preff[x2][y1- 1];
}

int check() {

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int x = i; x < n; ++ x) {
                for (int y = j; y < m; ++ y) {
                    if (sm(i + 1, j + 1, x + 1, y + 1) == 0 ||sm(i + 1, j + 1, x + 1, y + 1)  == (x - i + 1)  * (y - j + 1)) {
                        ++cnt;
                    }
                }
            }
        }
    }


    return 2 * cnt - n * (n + 1) / 2 * m * (m + 1) / 2;
}

void solved() {

    int n, m;
    cin >> n >> m;

    bool rev = false;

    if (n == 3 && m == 2) {
        swap(n, m);
        rev = true;
    } else if(n == 4 && m == 3) {
        swap(n, m);
        rev = true;
    } else if (n >= 4 && m % 4 == 0) {
        swap(n, m);
        rev = true;
    } else if (m > 3 && m % 4 == 3) {
        swap(n, m);
        rev = true;
    }

    vector<vector<int>> solu(n, vector<int>(m, 0));


    if (n == 2 && m == 3) {
        cout << "Yes\n";
        solu[0][2] = solu[1][0] = 1;

    } else if (n == 3 && m == 4) {

        cout << "Yes\n";
        solu[0][1] = solu[1][1] = solu[2][1] = 1;
    }else if (n == 4 && m == 4){

        cout << "Yes\n";
        solu[0][0] = solu[0][2] = 1;
        solu[1][1] = 1;
    }else if (n == 3 && m == 3){

        cout << "Yes\n";
        solu[2][0] = solu[2][2] = 1;
        solu[0][2] = 1;
    }  else if (n % 4 == 0) {
        cout << "Yes\n";

        for (int i = 0; i < n; i += 4) {
            for (int j = 0; j < m; ++j) {
                solu[i][j] = 1;
            }
            solu[i + 1][0] = solu[i + 1][1] = solu[i + 1][2] = 1;
            for (int j = 3; j < m; ++j) {
                solu[i + 1][j] = 0;
            }
            solu[i + 2][0] = solu[i + 2][1] = solu[i + 2][2] = 1;
            for (int j = 3; j < m; ++j) {
                solu[i + 2][j] = 0;
            }
            for (int j = 0; j < m; ++j) {
                solu[i + 3][j] = 0;
            }
        }

    } else if (n % 4 == 3) {
        cout << "Yes\n";


        solu[0][0] = 0;
        for (int j = 1; j < m; ++j) {
            solu[0][j] = 1;
        }



        solu[1][0] = 0;

        for (int j = 1; j < m; ++j) {
            solu[1][j] = 1;
        }
        solu[2][0] = 0;
        solu[2][1] = 0;
        solu[2][2] = 0;
        solu[2][3] = 1;
        solu[2][4] = 0;
        for (int j = 5; j < m; ++j) {
            solu[2][j] = 0;
        }

        for (int i = 3; i < n; i += 4) {
            for (int j = 0; j < m; ++j) {
                solu[i][j] = 1;
            }
            solu[i + 1][0] = solu[i + 1][1] = solu[i + 1][2] = 1;
            for (int j = 3; j < m; ++j) {
                solu[i + 1][j] = 0;
            }
            solu[i + 2][0] = solu[i + 2][1] = solu[i + 2][2] = 1;
            for (int j = 3; j < m; ++j) {
                solu[i + 2][j] = 0;
            }
            for (int j = 0; j < m; ++j) {
                solu[i + 3][j] = 0;
            }
        }

    } else {
        cout << "NO\n";
        return;
    }


    if (!rev) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < m; ++ j) {
                cout << solu[i][j] << " ";
            }
            cout << "\n";
        }
    } else {
        for (int j = 0; j < m; ++ j) {
            for (int i = 0; i < n; ++ i) {
                cout << solu[i][j] << " ";
            }
            cout << "\n";
        }
    }


    return;
//

    for (int i = 0; i < n; ++ i) {
        for (int j = 0; j < m; ++ j) {
            cin >> f[i][j];
        }
    }

    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            preff[i][j] = f[i - 1][j - 1] + preff[i - 1][j] + preff[i][j - 1] - preff[i - 1][j - 1];
        }
    }

    cout << check() << "\n";
    return;

    for (uint64_t mask = 0; mask < (1ll << (n * m)); ++ mask) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < m; ++ j) {
                f[i][j] = (mask & (1ll << (i * m + j))) ? 1 : 0;
            }
        }
        for (int i = 1; i <= n; ++ i) {
            for (int j = 1; j <= m; ++ j) {
                preff[i][j] = f[i - 1][j - 1] + preff[i - 1][j] + preff[i][j - 1] - preff[i - 1][j - 1];
            }
        }
        if (check()) {
            for (int i = 0; i < n; ++ i) {
                for (int j = 0; j < m; ++ j) {
                    cout << f[i][j] << " ";
                }
                cout << "\n";
            }
            cout << "\n";
        }
    }

}

void solve () {
    int t;
    cin >> t;
    while (t--) solved();
}

int main() {
    std::cin.tie(0);
    std::cout.tie(0);
    std::ios_base::sync_with_stdio(false);

    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3416kb

input:

2
2 3
1 1

output:

Yes
0 0 1 
1 0 0 
NO

result:

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