이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using ll = long long;
int const nmax = 3000;
int a[1 + nmax][1 + nmax];
int ingots[1 + nmax][1 + nmax];
/*
1 -> jewel
2 -> orb
3 -> ingot
*/
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
int n, m;
std::cin >> n >> m;
for(int i = 1;i <= n; i++) {
std::string s;
std::cin >> s;
for(int j = 1;j <= m; j++) {
if(s[j - 1] == 'J')
a[i][j] = 1;
else if(s[j - 1] == 'O')
a[i][j] = 2;
else
a[i][j] = 3;
}
}
for(int i = n;i >= 1; i--) {
for(int j = 1;j <= m; j++) {
ingots[i][j] = ingots[i + 1][j];
if(a[i][j] == 3)
ingots[i][j]++;
}
}
ll ans = 0;
for(int i = 1;i <= n; i++) {
int orbs = 0;
for(int j = m; j >= 1; j--) {
if(a[i][j] == 1) {
ans += orbs * ingots[i][j];
} else if(a[i][j] == 2) {
orbs++;
}
}
}
std::cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |