Submission #1002561

#TimeUsernameProblemLanguageResultExecution timeMemory
1002561yoav_sChess Rush (CEOI20_chessrush)C++17
28 / 100
2088 ms23900 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> v; typedef vector<v> vv; typedef vector<vv> vvv; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<vvb> vvvb; typedef pair<ll,ll> p; typedef vector<p> vp; typedef vector<vp> vvp; typedef vector<vvp> vvvp; typedef pair<ll, p> tri; typedef vector<tri> vtri; typedef vector<vtri> vvtri; typedef vector<vvtri> vvvtri; #define f first #define s second #define pb push_back #define eb emplace_back #define all(v) (v).begin(),(v).end() const ll INF = 1e18; const ll mod = 1e9 + 7; vv multiply(vv &mat1, vv &mat2) { vv res(mat1.size(), v(mat2[0].size())); for (ll i= 0; i < mat1.size(); i++) { for (ll j = 0; j < mat2[0].size(); j++) { for (ll k = 0; k < mat2.size(); k++) { res[i][j] += (mat1[i][k] * mat2[k][j]) % mod; } res[i][j] %= mod; } } return res; } vv matPow(vv &mat, ll exp) { if (exp == 0) { vv id(mat.size(), v(mat.size(), 0)); for (ll i= 0; i <mat.size(); i++) id[i][i] = 1; return id; } vv res = matPow(mat, exp / 2); res = multiply(res, res); if (exp % 2 == 1) res = multiply(res, mat); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll R, C, Q; cin >> R >> C >> Q; vv matrix(C, v(C, 0)); for (ll i = 0; i < C; i++) { matrix[i][i] = 1; if (i > 0) matrix[i][i - 1] = 1; if (i < C - 1) matrix[i][i + 1] = 1; } vv powered = matPow(matrix, R - 1); for (ll iter = 0; iter < Q; iter++) { char T; cin >> T; ll from, to; cin >> from >> to; if (T == 'K') { vv vec(C, v(1, 0)); vec[from - 1][0] = 1; vv res = multiply(powered, vec); cout << R - 1 << " " << res[to - 1][0] << "\n"; } else { cout << "-1 -1\n"; } } return 0; }

Compilation message (stderr)

chessrush.cpp: In function 'vv multiply(vv&, vv&)':
chessrush.cpp:33:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (ll i=  0; i < mat1.size(); i++)
      |                    ~~^~~~~~~~~~~~~
chessrush.cpp:35:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (ll j = 0; j < mat2[0].size(); j++)
      |                        ~~^~~~~~~~~~~~~~~~
chessrush.cpp:37:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for (ll k = 0; k < mat2.size(); k++)
      |                            ~~^~~~~~~~~~~~~
chessrush.cpp: In function 'vv matPow(vv&, ll)':
chessrush.cpp:52:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (ll i=  0; i <mat.size(); i++) id[i][i] = 1;
      |                        ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...