답안 #962640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962640 2024-04-14T05:12:09 Z NeroZein Semafor (COI20_semafor) C++17
100 / 100
449 ms 856 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int md = (int) 1e9 + 7; 

int nums, msk;
int numToMask[100];
int digitToMask[] = {10, 2, 9, 7, 18, 21, 12, 3, 29, 23};

void init() {
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      numToMask[i * 10 + j] = digitToMask[i] * 32 + digitToMask[j];
    }
  }
}

void add(int& a, int b) {
  a += b;
  if (a >= md) a -= md;
}

int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

struct M1 {
  int mat[1024] = {};
  M1 operator * (M1 other) {
    M1 ret;
    for (int i = 0; i < msk; ++i) {
      for (int j = 0; j < msk; ++j) {
        add(ret.mat[i ^ j], mul(mat[i], other.mat[j]));
      }
    }
    return ret;
  };
};

struct M2 {
  int mat[100][100] = {};
  M2 operator * (M2 other) {
    M2 ret;
    for (int i = 0; i < nums; ++i) {
      for (int k = 0; k < nums; ++k) {
        for (int j = 0; j < nums; ++j) {
          add(ret.mat[i][k], mul(mat[i][j], other.mat[j][k]));
        }
      }
    }
    return ret;
  }
};

M1 f(long long k) {
  M1 ret, b;
  ret.mat[0] = 1;
  for (int i = 1; i < msk; i *= 2) {
    b.mat[i] = 1; 
  }
  while (k) {
    if (k & 1) {
      ret = ret * b;
    }
    b = b * b; 
    k >>= 1; 
  }
  return ret;
}

M2 f2(M2 b, long long k) {
  M2 ret;
  for (int i = 0; i < nums; ++i) {
    ret.mat[i][i] = 1; 
  }
  while (k) {
    if (k & 1) {
      ret = ret * b;
    }
    b = b * b;
    k >>= 1; 
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  int m, x;
  long long n, k;
  cin >> m >> n >> k >> x;
  nums = (m == 1 ? 10 : 100); 
  msk = (m == 1 ? 32 : 1024);
  M1 m1 = f(k);
  M2 m2;
  for (int i = 0; i < nums; ++i) {
    for (int j = 0; j < nums; ++j) {
      m2.mat[i][j] = m1.mat[numToMask[i] ^ numToMask[j]];
    }
  }
  M2 m3 = f2(m2, n / k);
  m1 = f(n % k);
  for (int i = 0; i < nums; ++i) {
    for (int j = 0; j < nums; ++j) {
      m2.mat[i][j] = m1.mat[numToMask[i] ^ numToMask[j]];
    }
  }
  M2 m4 = m3 * m2;
  for (int i = 0; i < nums; ++i) {
    cout << m4.mat[x][i] << '\n';     
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 604 KB Output is correct
2 Correct 32 ms 600 KB Output is correct
3 Correct 50 ms 608 KB Output is correct
4 Correct 52 ms 604 KB Output is correct
5 Correct 54 ms 604 KB Output is correct
6 Correct 55 ms 600 KB Output is correct
7 Correct 60 ms 608 KB Output is correct
8 Correct 59 ms 600 KB Output is correct
9 Correct 50 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 748 KB Output is correct
2 Correct 104 ms 852 KB Output is correct
3 Correct 145 ms 744 KB Output is correct
4 Correct 196 ms 744 KB Output is correct
5 Correct 173 ms 752 KB Output is correct
6 Correct 185 ms 744 KB Output is correct
7 Correct 197 ms 604 KB Output is correct
8 Correct 175 ms 740 KB Output is correct
9 Correct 161 ms 856 KB Output is correct
10 Correct 191 ms 748 KB Output is correct
11 Correct 24 ms 600 KB Output is correct
12 Correct 14 ms 604 KB Output is correct
13 Correct 191 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 748 KB Output is correct
2 Correct 104 ms 852 KB Output is correct
3 Correct 145 ms 744 KB Output is correct
4 Correct 196 ms 744 KB Output is correct
5 Correct 173 ms 752 KB Output is correct
6 Correct 185 ms 744 KB Output is correct
7 Correct 197 ms 604 KB Output is correct
8 Correct 175 ms 740 KB Output is correct
9 Correct 161 ms 856 KB Output is correct
10 Correct 191 ms 748 KB Output is correct
11 Correct 24 ms 600 KB Output is correct
12 Correct 14 ms 604 KB Output is correct
13 Correct 191 ms 608 KB Output is correct
14 Correct 90 ms 600 KB Output is correct
15 Correct 162 ms 604 KB Output is correct
16 Correct 194 ms 612 KB Output is correct
17 Correct 216 ms 740 KB Output is correct
18 Correct 212 ms 740 KB Output is correct
19 Correct 199 ms 748 KB Output is correct
20 Correct 211 ms 608 KB Output is correct
21 Correct 165 ms 604 KB Output is correct
22 Correct 187 ms 744 KB Output is correct
23 Correct 217 ms 744 KB Output is correct
24 Correct 234 ms 748 KB Output is correct
25 Correct 234 ms 600 KB Output is correct
26 Correct 24 ms 600 KB Output is correct
27 Correct 38 ms 604 KB Output is correct
28 Correct 192 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 604 KB Output is correct
2 Correct 32 ms 600 KB Output is correct
3 Correct 50 ms 608 KB Output is correct
4 Correct 52 ms 604 KB Output is correct
5 Correct 54 ms 604 KB Output is correct
6 Correct 55 ms 600 KB Output is correct
7 Correct 60 ms 608 KB Output is correct
8 Correct 59 ms 600 KB Output is correct
9 Correct 50 ms 624 KB Output is correct
10 Correct 55 ms 748 KB Output is correct
11 Correct 104 ms 852 KB Output is correct
12 Correct 145 ms 744 KB Output is correct
13 Correct 196 ms 744 KB Output is correct
14 Correct 173 ms 752 KB Output is correct
15 Correct 185 ms 744 KB Output is correct
16 Correct 197 ms 604 KB Output is correct
17 Correct 175 ms 740 KB Output is correct
18 Correct 161 ms 856 KB Output is correct
19 Correct 191 ms 748 KB Output is correct
20 Correct 24 ms 600 KB Output is correct
21 Correct 14 ms 604 KB Output is correct
22 Correct 191 ms 608 KB Output is correct
23 Correct 90 ms 600 KB Output is correct
24 Correct 162 ms 604 KB Output is correct
25 Correct 194 ms 612 KB Output is correct
26 Correct 216 ms 740 KB Output is correct
27 Correct 212 ms 740 KB Output is correct
28 Correct 199 ms 748 KB Output is correct
29 Correct 211 ms 608 KB Output is correct
30 Correct 165 ms 604 KB Output is correct
31 Correct 187 ms 744 KB Output is correct
32 Correct 217 ms 744 KB Output is correct
33 Correct 234 ms 748 KB Output is correct
34 Correct 234 ms 600 KB Output is correct
35 Correct 24 ms 600 KB Output is correct
36 Correct 38 ms 604 KB Output is correct
37 Correct 192 ms 740 KB Output is correct
38 Correct 108 ms 600 KB Output is correct
39 Correct 235 ms 744 KB Output is correct
40 Correct 315 ms 600 KB Output is correct
41 Correct 421 ms 812 KB Output is correct
42 Correct 415 ms 604 KB Output is correct
43 Correct 449 ms 744 KB Output is correct
44 Correct 430 ms 600 KB Output is correct
45 Correct 164 ms 740 KB Output is correct
46 Correct 170 ms 740 KB Output is correct
47 Correct 428 ms 740 KB Output is correct
48 Correct 255 ms 600 KB Output is correct
49 Correct 217 ms 604 KB Output is correct
50 Correct 26 ms 604 KB Output is correct
51 Correct 51 ms 600 KB Output is correct
52 Correct 396 ms 612 KB Output is correct