이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define itn long long
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=2000;
char a[N][N];
const int mod=1e9+7;
int dp[N][N][6];
signed main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=k;i++){
char c;
int y,x;
cin>>c>>y>>x;
a[y][x]=c;
}
for(int j=0;j<=n;j++){
dp[j][0][0]=1;
dp[j][0][1]=1;
dp[j][0][2]=1;
dp[j][5][5]=1;
}
for(int j=0;j<=m;j++){
dp[0][j][0]=1;
dp[0][j][1]=1;
dp[0][j][2]=1;
dp[0][j][5]=1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='+'){
dp[i][j][2]=(dp[i-1][j][1]+dp[i-1][j][3])*dp[i][j-1][3];
dp[i][j][4]=(dp[i-1][j][4]+dp[i-1][j][2])*dp[i][j-1][1];
dp[i][j][5]=dp[i-1][j][0]*dp[i][j-1][2];
}
else if(a[i][j]=='-'){
dp[i][j][0]=dp[i-1][j][5]*dp[i][j-1][3];
dp[i][j][1]=(dp[i-1][j][1]+dp[i-1][j][3])*dp[i][j-1][4];
dp[i][j][3]=(dp[i-1][j][4]+dp[i-1][j][2])*dp[i][j-1][2];
}
else{
dp[i][j][2]=(dp[i-1][j][1]+dp[i-1][j][3])*dp[i][j-1][3];
dp[i][j][4]=(dp[i-1][j][4]+dp[i-1][j][2])*dp[i][j-1][1];
dp[i][j][5]=dp[i-1][j][0]*dp[i][j-1][2];
dp[i][j][0]=dp[i-1][j][5]*dp[i][j-1][3];
dp[i][j][1]=(dp[i-1][j][1]+dp[i-1][j][3])*dp[i][j-1][4];
dp[i][j][3]=(dp[i-1][j][4]+dp[i-1][j][2])*dp[i][j-1][2];
}
}
}
int ans=0;
for(int i=0;i<6;i++){
ans+=dp[n][m][i];
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |