Submission #964557

#TimeUsernameProblemLanguageResultExecution timeMemory
964557Darren0724Chess Rush (CEOI20_chessrush)C++17
0 / 100
1 ms604 KiB
#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<n-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; }
#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...