#include <iostream>
#include <string>
#include <cassert>
using std::cin;
using std::cout;
using std::string;
using int64 = long long int;
const int MAX_N = 3007;
char table[MAX_N][MAX_N];
int row[MAX_N][MAX_N], col[MAX_N][MAX_N];
int H, W;
int64 answ = 0;
void fast_io()
{
std::ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void solve()
{
cin >> H >> W;
for(int i = 0; i < H; ++i)
{
string cur;
cin >> cur;
for(int j = 0; j < W; ++j)
{
table[i][j] = cur[j];
assert(cur[j] == 'I' || cur[j] == 'O' || cur[j] == 'J');
}
}
for(int i = 0; i < H; ++i)
{
for(int j = 0; j < W; ++j)
row[i][j] = (table[i][j] == 'O');
for(int j = W - 2; j >= 0; --j)
row[i][j] += row[i][j + 1];
}
for(int j = 0; j < W; ++j)
{
for(int i = 0; i < H; ++i)
col[i][j] = (table[i][j] == 'I');
for(int i = H - 2; i >= 0; --i)
col[i][j] += col[i + 1][j];
}
for(int i = 0; i < W; ++i)
{
for(int j = 0; j < H; ++j)
{
if(table[i][j] == 'J')
answ += ((int64)row[i][j]) * ((int64)col[i][j]);
}
}
cout << answ << "\n";
}
int main()
{
fast_io();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |