CSES - Practice Contest 2024 - Results
Submission details
Task:Judge correctness
Sender:asdf
Submission time:2024-09-28 16:29:43 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.02 sdetails
#2ACCEPTED0.91 sdetails
#3ACCEPTED2.30 sdetails
#4ACCEPTED2.47 sdetails
#5ACCEPTED2.88 sdetails
#6ACCEPTED2.86 sdetails
#7ACCEPTED2.10 sdetails
#8ACCEPTED2.09 sdetails
#9ACCEPTED2.10 sdetails
#10ACCEPTED2.85 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

using type = unsigned short;

struct Matrix {
    vector <vector <type> > data;

    int row() const { return data.size(); }

    int col() const { return data[0].size(); }

    auto & operator [] (int i) { return data[i]; }

    const auto & operator[] (int i) const { return data[i]; }

    Matrix() = default;

    Matrix(int r, int c): data(r, vector <type> (c)) { }

    Matrix(const vector <vector <type> > &d): data(d) {}

    friend ostream & operator << (ostream &out, const Matrix &d) {
        for (auto x : d.data) {
            for (auto y : x) out << y << ' ';
            out << '\n';
        }
        return out;
    }

    Matrix operator - (const Matrix &b) {
        Matrix a = *this;
        assert(a.col() == b.col());
        assert(a.row() == b.row());
        Matrix c(a.row(), a.col());
        for (int i = 0; i < a.row(); i++) {
            for (int j = 0; j < a.col(); j++) {
                c[i][j] = (a[i][j] - b[i][j] + 64) % 64;
            }
        }
        return c;
    }

    Matrix operator * (const Matrix &b) {
        Matrix a = *this;
        assert(a.col() == b.row());

        Matrix c(a.row(), b.col());
        for (int i = 0; i < a.row(); ++i)
            for (int j = 0; j < b.col(); ++j)
                for (int k = 0; k < a.col(); ++k) {
                    c[i][j] += (a[i][k] % 64) * (b[k][j] % 64);
                    c[i][j] %= 64;
                }
        return c;
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) { return l + rng() % (r - l + 1); }

unsigned short decode(char c) {
    if (isupper(c)) return c - 'A';
    if (islower(c)) return 26 + c - 'a';
    if (isdigit(c)) return 52 + c - '0';
    if (c == '+') return 62;
    return 63; 
}

void solve() {
    int n;
    cin >> n;
    Matrix a(n, n), at(n, n), x(n, n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char c;
            cin >> c;
            a[i][j] = decode(c);
            at[j][i] = decode(c);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char c;
            cin >> c;
            x[i][j] = decode(c);
        }
    }

    // cout << a << '\n';
    // cout << at << '\n';
    // cout << (a * at) << '\n';
    // cout << x << '\n';

    int ite = 5;
    bool correct = true;
    while (ite--) {
        Matrix v(n, 1);
        for (int i = 0; i < n; i++) v[i][0] = Rand(0, 1);

        Matrix p = (a * (at * v)) - (x * v);

        for (int i = 0; i < n; i++) {
            if (p[i][0]) {
                correct = false;
                break;
            }
        }

        if (!correct) break;
    }

    cout << correct << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }
}

Test details

Test 1

Verdict:

input
500
12
N49lyQuAZh1l
PwNJA+wuTBr+
HO09lJg8kbup
...

correct output
0
0
1
1
1
...

user output
0
0
1
1
1
...
Truncated

Test 2

Verdict: ACCEPTED

input
3
666
OvHf9jpB0RViia/ZD3gRQ7o1FELYh3...

correct output
0
0
1

user output
0
0
1

Test 3

Verdict: ACCEPTED

input
2
517
RWVknnH+hL6AfeKFbOu6OuAJL9dvLw...

correct output
0
1

user output
0
1

Test 4

Verdict: ACCEPTED

input
1
5000
QP9pS1MOq6eDDKGQh//TrJUIvbM53a...

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
1
5000
RSX7ZuQE6A94s8s+9oP1uCDHRkmZ+7...

correct output
1

user output
1

Test 6

Verdict: ACCEPTED

input
1
5000
b0V0j4vQ8CeiJrcUk2yssPF1B9EEDb...

correct output
1

user output
1

Test 7

Verdict: ACCEPTED

input
1
5000
VLdpW71f4Cdr+xdCRlwmAnNfMjqwMU...

correct output
0

user output
0

Test 8

Verdict: ACCEPTED

input
1
5000
kBZaGETPWmyNR4NCvCPbJnvq2+JBfP...

correct output
0

user output
0

Test 9

Verdict: ACCEPTED

input
1
5000
PES9AhJn+FZBVO5gqRLYbavSvaDUfU...

correct output
0

user output
0

Test 10

Verdict: ACCEPTED

input
1
5000
EoXwgdrAtKtV4M7jn0jAkNwkJX+be9...

correct output
1

user output
1