#pragma GCC optimize("Ofast","O3","unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define rz resize
#define pb emplace_back
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define ACorz ios_base::sync_with_stdio(false);cin.tie(0);
//#define endl '\n'
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int INF=1e9,INF2=2e9;
const int mod=1e9+7;
const int N=1000005;
int n,m;
void P(int a,int b){
if(a==b){
cout<<n-1<<' '<<1<<endl;
}
else{
cout<<0<<' '<<0<<endl;
}
}
void R(int a,int b){
if(a==b){
cout<<1<<' '<<1<<endl;
}
else{
cout<<2<<' '<<2<<endl;
}
}
void Q(int a,int b){
if(a>b)swap(a,b);
if(a==b||(n==m&&a==1&&b==m)){
cout<<1<<' '<<1<<endl;
return;
}
int ans=4;
if(m==n&&(a==1||b==n))ans++;
int k=(n-1-b+a);
if(k%2==0){
if(a-k/2>=1)ans++;
if(b+k/2<=m)ans++;
}
cout<<2<<' '<<ans<<endl;
}
vector<vector<int>> mul(vector<vector<int>> a,vector<vector<int>> b){
vector<vector<int>> ans(m,vector<int>(m));
for(int i=0;i<m;i++){
for(int k=0;k<m;k++){
for(int j=0;j<m;j++){
ans[i][j]+=a[i][k]*b[k][j];
ans[i][j]%=mod;
}
}
}
return ans;
}
vector<vector<int>> tran;
void init(){
vector<vector<int>> adj(m,vector<int>(m));
tran=adj;
for(int i=0;i<m;i++){
tran[i][i]=1;
if(i>0)adj[i][i-1]=1;
adj[i][i]=1;
if(i<m-1)adj[i][i+1]=1;
}
int n1=n-1;
while(n1>0){
if(n1&1){
tran=mul(tran,adj);
}
adj=mul(adj,adj);
n1>>=1;
}
}
void K(int a,int b){
vector<vector<int>> v(m,vector<int>(m));
cout<<n-1<<' '<<tran[a-1][b-1]<<endl;
}
signed main(){
ACorz;
int q;
cin>>n>>m>>q;
init();
for(int i=0;i<q;i++){
char c;int a,b;cin>>c>>a>>b;
if(c=='R')R(a,b);
if(c=='Q')Q(a,b);
if(c=='P')P(a,b);
if(c=='K')K(a,b);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1217 ms |
6808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
19 ms |
872 KB |
Output is correct |
3 |
Correct |
13 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
19 ms |
872 KB |
Output is correct |
3 |
Correct |
13 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
17 ms |
604 KB |
Output is correct |
8 |
Correct |
23 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
19 ms |
872 KB |
Output is correct |
3 |
Correct |
13 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
17 ms |
604 KB |
Output is correct |
8 |
Correct |
23 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
7 ms |
344 KB |
Output is correct |
11 |
Correct |
99 ms |
1100 KB |
Output is correct |
12 |
Correct |
96 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
19 ms |
872 KB |
Output is correct |
3 |
Correct |
13 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
512 KB |
Output is correct |
7 |
Correct |
17 ms |
604 KB |
Output is correct |
8 |
Correct |
23 ms |
856 KB |
Output is correct |
9 |
Correct |
4 ms |
348 KB |
Output is correct |
10 |
Correct |
7 ms |
344 KB |
Output is correct |
11 |
Correct |
99 ms |
1100 KB |
Output is correct |
12 |
Correct |
96 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
5 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
348 KB |
Output is correct |
17 |
Execution timed out |
2067 ms |
39772 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |