| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 711312 | scottchou | Bob (COCI14_bob) | C++17 | 125 ms | 14048 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int const N = 1005;
int a[N][N];
int color[N], cnt[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
LL ans = 0;
for(int i = 1; i <= n; i++){
int c = 0;
vector<pair<int, int> > stk;
stk.push_back({0, 0});
for(int j = 1; j <= m; j++){
if(color[j] == a[i][j]){
cnt[j]++;
}else{
cnt[j] = 1;
color[j] = a[i][j];
}
if(color[j] != c){
while(stk.size() > 1){
int sc = stk.size() - 2;
ans += ((j - stk[sc].second - 1) * (j - stk[sc].second - 2) / 2 + j - stk[sc].second - 1) * (stk.back().first - stk[sc].first);
stk.pop_back();
}
stk.back().second = j - 1;
c = color[j];
stk.push_back({cnt[j], j});
}else{
while(stk.back().first >= cnt[j]){
if(stk.back().first > cnt[j]){
int sc = stk.size() - 2;
ans += ((j - stk[sc].second - 1) * (j - stk[sc].second - 2) / 2 + j - stk[sc].second - 1) * (stk.back().first - max(cnt[j], stk[sc].first));
}
stk.pop_back();
}
stk.push_back({cnt[j], j});
}
}
while(stk.size() > 1){
int sc = stk.size() - 2;
ans += ((m - stk[sc].second) * (m - stk[sc].second - 1) / 2 + m - stk[sc].second) * (stk.back().first - stk[sc].first);
stk.pop_back();
}
}
cout << ans << '\n';
}| # | 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... | ||||
