Submission #197865

# Submission time Handle Problem Language Result Execution time Memory
197865 2020-01-23T18:40:05 Z Osama_Alkhodairy Strah (COCI18_strah) C++17
77 / 110
1000 ms 32656 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 2001;

int n, m, g[N][N];
vector <string> a;
vector <int> v[N];
ll sum;
set <pair <int, int> > s;

ll f(int x){
    return 1LL * x * (x + 1) * (x + 2) / 6;
}
int len(pair <int, int> g){
    return g.second - g.first + 1;
}
void add(pair <int, int> g){
    if(g.second < g.first) return;
    s.insert(g);
    sum += f(len(g));
}
void del(pair <int, int> g){
    sum -= f(len(g));
    s.erase(g);
}
void del(int x){
    auto it = *(--s.upper_bound(make_pair(x, 10000)));
    assert(it.first <= x && x <= it.second);
    del(it);
    add(make_pair(it.first, x - 1));
    add(make_pair(x + 1, it.second));
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    a.resize(n);
    for(auto &i : a) cin >> i;
    for(int i = 0 ; i < n ; i++){
        g[i][m] = m;
        for(int j = m - 1 ; j >= 0 ; j--){
            g[i][j] = g[i][j + 1];
            if(a[i][j] == '#') g[i][j] = j;
        }
    }
    ll ans = 0;
    for(int col1 = 0 ; col1 < m ; col1++){
        for(int row = 0 ; row < n ; row++){
            v[g[row][col1]].push_back(row);
        }
        add(make_pair(0, n - 1));
        for(int col2 = col1 ; col2 < m ; col2++){
            while(v[col2].size()){
                del(v[col2].back());
                v[col2].pop_back();
            }
            ans += sum * (col2 - col1 + 1);
        }
        sum = 0;
        s.clear();
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2300 KB Output is correct
2 Correct 29 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2268 KB Output is correct
2 Correct 29 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2736 KB Output is correct
2 Correct 29 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 337 ms 10328 KB Output is correct
2 Correct 866 ms 18120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 814 ms 19244 KB Output is correct
2 Execution timed out 1070 ms 23872 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 523 ms 11176 KB Output is correct
2 Correct 952 ms 19476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 9652 KB Output is correct
2 Execution timed out 1035 ms 23340 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 32656 KB Time limit exceeded
2 Halted 0 ms 0 KB -