#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define int long long
using namespace std;
char m[4001][4001];
int cnt1[4001][4001][3],cnt[4001][4001][3];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int h,w, ans = 0; cin >> h >> w;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
cin >> m[i][j];
}
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(j != 0) {
cnt1[i][j][0] += cnt1[i][j - 1][0];
cnt1[i][j][1] += cnt1[i][j - 1][1];
cnt1[i][j][2] += cnt1[i][j - 1][2];
}
if(m[i][j] == 'J') cnt1[i][j][0]++;
else if(m[i][j] == 'I') cnt1[i][j][1]++;
else cnt1[i][j][2]++;
}
}
for(int i = 0; i < w; i++){
for(int j = 0; j < h; j++){
if(j != 0) {
cnt[j][i][0] += cnt[j - 1][i][0];
cnt[j][i][1] += cnt[j - 1][i][1];
cnt[j][i][2] += cnt[j - 1][i][2];
}
if(m[j][i] == 'J') cnt[j][i][0]++;
else if(m[j][i] == 'I') cnt[j][i][1]++;
else cnt[j][i][2]++;
}
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(m[i][j] == 'J'){
int x = cnt1[i][w - 1][2] - cnt1[i][j][2], y = cnt[h - 1][j][1] - cnt[i][j][1];
ans += (x * y);
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
2004 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
2004 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
2004 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
2 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
2004 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
2004 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
2004 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
2 ms |
1748 KB |
Output is correct |
14 |
Correct |
13 ms |
15316 KB |
Output is correct |
15 |
Correct |
3 ms |
5716 KB |
Output is correct |
16 |
Correct |
10 ms |
9476 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
15 ms |
18092 KB |
Output is correct |
19 |
Correct |
14 ms |
17616 KB |
Output is correct |
20 |
Correct |
14 ms |
17748 KB |
Output is correct |
21 |
Correct |
15 ms |
18132 KB |
Output is correct |
22 |
Correct |
15 ms |
17704 KB |
Output is correct |
23 |
Correct |
13 ms |
17756 KB |
Output is correct |
24 |
Correct |
16 ms |
18132 KB |
Output is correct |
25 |
Correct |
13 ms |
17620 KB |
Output is correct |
26 |
Correct |
14 ms |
17808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
2004 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
2004 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
2004 KB |
Output is correct |
12 |
Correct |
1 ms |
1876 KB |
Output is correct |
13 |
Correct |
2 ms |
1748 KB |
Output is correct |
14 |
Correct |
13 ms |
15316 KB |
Output is correct |
15 |
Correct |
3 ms |
5716 KB |
Output is correct |
16 |
Correct |
10 ms |
9476 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
15 ms |
18092 KB |
Output is correct |
19 |
Correct |
14 ms |
17616 KB |
Output is correct |
20 |
Correct |
14 ms |
17748 KB |
Output is correct |
21 |
Correct |
15 ms |
18132 KB |
Output is correct |
22 |
Correct |
15 ms |
17704 KB |
Output is correct |
23 |
Correct |
13 ms |
17756 KB |
Output is correct |
24 |
Correct |
16 ms |
18132 KB |
Output is correct |
25 |
Correct |
13 ms |
17620 KB |
Output is correct |
26 |
Correct |
14 ms |
17808 KB |
Output is correct |
27 |
Runtime error |
294 ms |
274432 KB |
Execution killed with signal 9 |
28 |
Halted |
0 ms |
0 KB |
- |