답안 #855783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855783 2023-10-01T19:23:26 Z vjudge1 Strah (COCI18_strah) C++17
110 / 110
118 ms 35792 KB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;





bool cmp(const ii &l,const ii &r) {
    if(l.st < r.st) return true;
    if(l.st > r.st) return false;
    return l.nd < r.nd;
}


int les(int x){
    return (x * (x+1))/2;
}


void solve(){
    int n,m; cin >> n >> m;
    int rel[n+1][m+1];
    for(int i=1; i<=m; i++) rel[0][i]=0;
    for(int i=1; i<=n; i++){
        string s; cin >> s;
        for(int j=1; j<=m; j++){
            if(s[j-1]=='#') rel[i][j] = 0;
            else rel[i][j] = rel[i-1][j]+1;
            //cerr << rel[i][j] << " ";
        }
        //cerr << endl;
    }

    int pref[n+1]; pref[0]=0;
    ii cur[n+1]; cur[0]={0, 0};
    int add[n+1]; add[0]=0;
    int end, ans=0;
    for(int k=1; k<=n; k++){
        end=0;

        for(int i=1; i<=m; i++){
            end = lower_bound(cur, cur+end+1, mp(rel[k][i], i)) - cur;
            cur[end] = mp(rel[k][i], i);
            add[end] = add[end-1] + (les(cur[end].st) * (cur[end].nd-cur[end-1].nd));
            pref[end] = pref[end-1] + (add[end-1] * (cur[end].nd - cur[end-1].nd)) + (les(cur[end].st) * les(cur[end].nd - cur[end-1].nd));
            //cerr << end spc add[end] spc pref[end] spc pref[end-1] << " :: ";
            ans += pref[end];
        }
        //cerr << endl;
    }
    cout << ans << endl;
}



signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif

    ll t=1;
    //cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 8540 KB Output is correct
2 Correct 57 ms 21552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 19800 KB Output is correct
2 Correct 94 ms 32840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 12888 KB Output is correct
2 Correct 63 ms 23500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2396 KB Output is correct
2 Correct 52 ms 26352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 31836 KB Output is correct
2 Correct 118 ms 35792 KB Output is correct