답안 #197869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197869 2020-01-23T18:52:33 Z Osama_Alkhodairy Strah (COCI18_strah) C++17
77 / 110
1000 ms 32712 KB
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#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;
}

Compilation message

strah.cpp:4:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:1024000000,1024000000")
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2204 KB Output is correct
2 Correct 29 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2248 KB Output is correct
2 Correct 29 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2808 KB Output is correct
2 Correct 27 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 329 ms 10324 KB Output is correct
2 Correct 881 ms 18172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 832 ms 19224 KB Output is correct
2 Execution timed out 1062 ms 23800 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 523 ms 10996 KB Output is correct
2 Correct 957 ms 19584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 9648 KB Output is correct
2 Execution timed out 1042 ms 23544 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 32712 KB Time limit exceeded
2 Halted 0 ms 0 KB -