# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
97154 |
2019-02-14T07:18:21 Z |
win11905 |
Bob (COCI14_bob) |
C++11 |
|
205 ms |
10376 KB |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author win11905
*/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1005;
class bob {
private:
int n, m;
int arr[N][N], pref[N][N];
long ans;
public:
void solve(istream& cin, ostream& cout) {
cin >> n >> m;
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) {
cin >> arr[i][j];
pref[i][j] = 1 + (arr[i][j] == arr[i-1][j] ? pref[i-1][j] : 0);
}
for(int i = 1; i <= n; ++i) {
int cnt = 0, ft = 0;
stack<pii> stk; // pos, sum;
for(int j = 1; j <= m; ++j) {
if(arr[i][j] != arr[i][j-1]) while(!stk.empty()) stk.pop(), cnt = 0, ft = j-1;
int now = pref[i][j];
while(!stk.empty() && pref[i][stk.top().x] >= pref[i][j]) {
int z = stk.top().x; cnt -= stk.top().y;
stk.pop(); now += pref[i][j] * (z - (stk.empty() ? ft : stk.top().x));
}
cnt += now, stk.emplace(j, now);
ans += cnt;
}
}
cout << ans << endl;
}
};
class Solver {
public:
void solve(std::istream& in, std::ostream& out) {
bob *obj = new bob();
obj->solve(in, out);
}
};
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
8244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
8292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
8296 KB |
Output is correct |
2 |
Correct |
140 ms |
10232 KB |
Output is correct |
3 |
Correct |
96 ms |
10376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
8300 KB |
Output is correct |
2 |
Correct |
106 ms |
10236 KB |
Output is correct |
3 |
Correct |
106 ms |
10360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
205 ms |
8192 KB |
Output is correct |
2 |
Correct |
116 ms |
10232 KB |
Output is correct |
3 |
Correct |
104 ms |
10232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
8312 KB |
Output is correct |
2 |
Correct |
92 ms |
10376 KB |
Output is correct |
3 |
Correct |
99 ms |
10204 KB |
Output is correct |