제출 #1341796

#제출 시각아이디문제언어결과실행 시간메모리
1341796shynycBitaro the Brave (JOI19_ho_t1)C++20
100 / 100
282 ms150772 KiB
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
    long long h,w,count = 0;
    cin >> h >> w;
    string temp;
    vector<string> mp;
    vector<vector<int> > ingots(h,vector<int> (w,0)), ores(h,vector<int> (w,0));
    vector<vector<int> > ingotsum(h,vector<int> (w,0)),oresum(h,vector<int> (w,0));
    for(int i = 0; i < h; i++){
        cin >> temp;
        mp.push_back(temp);
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mp[i][j] == 'I'){
                ingots[i][j] = 1;
            }
            if(mp[i][j] == 'O'){
                ores[i][j] = 1;
            }
        }
    }

    
    for(int i = h-1; i >= 0; i--){
        for(int j = w-1; j >= 0; j--){
            if(i == h-1){
                ingotsum[i][j] = ingots[i][j];
            }else{
                ingotsum[i][j] = ingotsum[i+1][j] + ingots[i][j];
            }
            if(j == w-1){
                oresum[i][j] = ores[i][j];
            }else{
                oresum[i][j] = oresum[i][j+1] + ores[i][j];
            }
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mp[i][j] == 'J'){
                count = count + (oresum[i][j]*ingotsum[i][j]);
            }
        }
    }
    cout << count;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...