이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double D;
const ll mod=998244353;
const ll inf=(1ll<<61);
const int MX=1009;
int n,m,a[MX][MX],dp[MX][MX];
ll k[MX];
int DP(int x,int y){
if(x==0)return 1;
int &ret=dp[x][y];if(ret!=-1)return ret;
if(a[x-1][y]==a[x][y])return ret=DP(x-1,y)+1;
return ret=1;
}
ll ans=0;
void solve(int x,int b,int c){
ans+=DP(x,b);k[b]=1;
ll l=0;
for(int j=b+1;j<=c;j++){
if(DP(x,j)>DP(x,j-1)){
k[j]=1;
ans+=l+DP(x,j);
l=l+DP(x,j);
}
else {k[j]=k[j-1]+1;
// cout<<x<<" "<<j<<" "<<k[j]*DP(x,j)<<endl;
ans+=k[j]*DP(x,j);
l=k[j]*DP(x,j);
}
}
}
int main(){
memset(dp,-1,sizeof(dp));
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
DP(i,j);
}
}
// puts("");
for(int i=0;i<n;i++){
int j=0,j1=0;
while(j1<m){
while(j1<m&&a[i][j1]==a[i][j])j1++;
solve(i,j,j1-1);
j=j1;
}
}
cout<<ans<<endl;
}
/*
5 3
2 2 2
2 2 1
1 1 1
2 1 2
1 2 1
*/
컴파일 시 표준 에러 (stderr) 메시지
bob.cpp: In function 'int main()':
bob.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i][j]);
~~~~~^~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |