Submission #61640139


Source Code Expand

Copy
#include <iostream>
#include <vector>
using namespace std;
int mod_exp(int base, int exp, int mod) {
int result = 1;
base = base % mod;
while (exp > 0) {
if (exp % 2 == 1) {
result = (result * base) % mod;
}
exp = exp >> 1;
base = (base * base) % mod;
}
return result;
}
int main() {
int N, p;
cin >> N >> p;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>
#include <vector>
using namespace std;

int mod_exp(int base, int exp, int mod) {
    int result = 1;
    base = base % mod;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        exp = exp >> 1;
        base = (base * base) % mod;
    }
    return result;
}

int main() {
    int N, p;
    cin >> N >> p;

    vector<vector<int>> A(N, vector<int>(N));
    vector<vector<int>> sum(N, vector<int>(N, 0));

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> A[i][j];
        }
    }

    int num_zeros = 0;
    vector<pair<int, int>> zeros;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (A[i][j] == 0) {
                num_zeros++;
                zeros.push_back({i, j});
            }
        }
    }

    int p_minus_1 = p - 1;
    for (int i = 0; i < (1 << num_zeros); ++i) {
        vector<vector<int>> B = A;
        int idx = 0;

        for (int mask = i; mask > 0; mask >>= 1) {
            int value = (mask & 1) + 1;
            auto [x, y] = zeros[idx];
            B[x][y] = value;
            ++idx;
        }

        vector<vector<int>> Bp(N, vector<int>(N, 0));
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                Bp[i][j] = mod_exp(B[i][j], p, p);
            }
        }

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                sum[i][j] = (sum[i][j] + Bp[i][j]) % p;
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cout << sum[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Submission Info

Submission Time
Task D - Matrix Pow Sum
User Ayim
Language C++ 20 (gcc 12.2)
Score 0
Code Size 1800 Byte
Status WA
Exec Time 2210 ms
Memory 3920 KB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:43:9: warning: unused variable ‘p_minus_1’ [-Wunused-variable]
   43 |     int p_minus_1 = p - 1;
      |         ^~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 900
Status
WA × 3
AC × 1
WA × 32
TLE × 8
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 03_rand_1_06.txt, 03_rand_1_07.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 04_rand_2_06.txt, 04_rand_2_07.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 05_rand_3_06.txt, 05_rand_3_07.txt, 06_rand_4_01.txt, 06_rand_4_02.txt, 06_rand_4_03.txt, 06_rand_4_04.txt, 06_rand_4_05.txt, 06_rand_4_06.txt, 06_rand_4_07.txt
Case Name Status Exec Time Memory
01_sample_01.txt WA 1 ms 3660 KB
01_sample_02.txt WA 1 ms 3588 KB
01_sample_03.txt WA 1 ms 3656 KB
02_small_01.txt WA 1 ms 3596 KB
02_small_02.txt WA 1 ms 3492 KB
02_small_03.txt WA 1 ms 3596 KB
02_small_04.txt WA 1 ms 3748 KB
02_small_05.txt WA 1 ms 3728 KB
02_small_06.txt WA 1 ms 3524 KB
02_small_07.txt TLE 2210 ms 3340 KB
02_small_08.txt TLE 2207 ms 3408 KB
02_small_09.txt WA 108 ms 3524 KB
02_small_10.txt WA 257 ms 3496 KB
03_rand_1_01.txt WA 4 ms 3752 KB
03_rand_1_02.txt TLE 2207 ms 3480 KB
03_rand_1_03.txt WA 355 ms 3588 KB
03_rand_1_04.txt WA 2 ms 3596 KB
03_rand_1_05.txt WA 125 ms 3616 KB
03_rand_1_06.txt TLE 2207 ms 3368 KB
03_rand_1_07.txt WA 280 ms 3680 KB
04_rand_2_01.txt WA 5 ms 3840 KB
04_rand_2_02.txt WA 28 ms 3760 KB
04_rand_2_03.txt WA 5 ms 3712 KB
04_rand_2_04.txt WA 415 ms 3756 KB
04_rand_2_05.txt WA 14 ms 3844 KB
04_rand_2_06.txt WA 8 ms 3828 KB
04_rand_2_07.txt TLE 2207 ms 3524 KB
05_rand_3_01.txt AC 3 ms 3636 KB
05_rand_3_02.txt WA 4 ms 3640 KB
05_rand_3_03.txt WA 8 ms 3700 KB
05_rand_3_04.txt WA 26 ms 3756 KB
05_rand_3_05.txt WA 8 ms 3764 KB
05_rand_3_06.txt WA 8 ms 3920 KB
05_rand_3_07.txt TLE 2207 ms 3620 KB
06_rand_4_01.txt WA 2 ms 3744 KB
06_rand_4_02.txt TLE 2207 ms 3504 KB
06_rand_4_03.txt WA 31 ms 3716 KB
06_rand_4_04.txt WA 2 ms 3716 KB
06_rand_4_05.txt TLE 2207 ms 3564 KB
06_rand_4_06.txt WA 9 ms 3840 KB
06_rand_4_07.txt WA 4 ms 3712 KB


2025-03-05 (Wed)
18:12:05 +00:00