# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
683122 | Ahmed57 | Bob (COCI14_bob) | C++14 | 150 ms | 17956 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n , m ;
scanf("%d %d" , &n , &m) ;
int arr[n+2][m+2] , now[n+2][m+2];
for(int i = 1 ; i <= n ; ++i)
{
for(int j = 1 ; j <= m ; ++j)
scanf("%d" , &arr[i][j]) ;
}
//prepare now for every element
for(int i = 1 ; i <= n ; ++i)
{
now[i][m] = 1ll ;
for(int j = m-1 ; j >= 1 ; --j)
{
if(arr[i][j] == arr[i][j+1])
now[i][j] = now[i][j+1] + 1ll;
else
now[i][j] = 1ll ;
}
}
long long ans = 0ll ;
long long sol[n+2][m+2] ;
//loop on every column
for(int j = 1 ; j <= m ; ++j)
{
arr[0][j] = -1 ;
stack< pair<int , int> >s ;
for(int i = 1 ; i <= n ; ++i)
{
pair<int , int>cur ;
cur.first = i , cur.second = 1ll ;
sol[i][j] = 0ll ;
//new value
if(arr[i][j] != arr[i-1][j])
{
while(!s.empty())
s.pop() ;
sol[i][j] = now[i][j] * 1ll;
ans += sol[i][j] ;
s.push(cur) ;
continue ;
}
//loop in stack
while(!s.empty() && now[s.top().first][j] >= now[i][j])
{
pair<int , int>p = s.top() ;
s.pop() ;
cur.second += p.second ;
}
sol[i][j] = (cur.second * 1ll * now[i][j]) ;
if(s.size() > 0)
{
pair<int , int>p = s.top() ;
sol[i][j] += sol[p.first][j] ;
}
ans += sol[i][j] ;
s.push(cur) ;
}
}
return printf("%lld" , ans) , 0 ;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |