답안 #371620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371620 2021-02-27T03:58:51 Z jainbot27 Rectangles (IOI19_rect) C++17
72 / 100
5000 ms 673380 KB
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const char nl = '\n';
const int mxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;

ll count_rectangles(vector<vi> a){
    int n = siz(a), m = siz(a[0]); ll ans = 0;
    auto precalc = [&](vector<vi> b){
        int N = siz(b), M = siz(b[0]);
        //F0R(i, N){
        //    F0R(j, M){
        //        cout << b[i][j] << ' ';
        //    }
        //    cout << nl;
        //}
        auto go = [&](vi v){
            stack<pii> s;
            vi res(M);
            F0R(i, M){
                while(siz(s)&&s.top().f<v[i]){
                    //cout << s.top().f << ' ' << v[i] << nl;
                    s.pop();
                }
                if(!siz(s)) res[i]=-1;
                else res[i]=s.top().s;
                //cout << res[i] << ' ';
                s.push({v[i], i});
            }
            //cout << nl;
            return res;
        };
        vector<vector<vpii>> res(N, vector<vpii>(M));
        F0R(i, N){
            //F0R(j, M) cout << b[i][j] << ' ';
            //cout << nl;
            vi l = go(b[i]);
            reverse(all(b[i]));
            vi r = go(b[i]);
            reverse(all(b[i]));
            reverse(all(r));
            F0R(j, M){
                if(r[j]!=-1) r[j]=M-1-r[j];
                //cout << r[j] << ' ';
            }
            //cout << nl;
            F0R(j, M){
                //cout << l[j] << ' ';
                if(l[j]!=-1&&l[j]!=j-1){
                    assert(l[j]<=j);
                    res[i][j-1].pb({l[j]+1, 1});
                }
            }
            //cout << nl << nl;
            F0R(j, M){
                if(r[j]!=-1&&r[j]!=j+1){
                    assert(r[j]>=j);
                    res[i][r[j]-1].pb({j+1, 1});
                }
            }
            F0R(j, M){
                sort(all(res[i][j]));
                res[i][j].resize(unique(all(res[i][j]))-res[i][j].begin());
            }
        }
        F0R(i, N-1){
            F0R(j, M){
                trav(x, res[i][j]){
                    trav(y, res[i+1][j]){
                        if(x.f==y.f){
                            y.s = x.s+1;
                        }
                    }
                }
            }
        }
        return res;
    };
    vector<vector<vpii>> x = precalc(a);
    vector<vi> c(m, vi(n));
    F0R(i, n)
        F0R(j, m)
            c[j][i]=a[i][j];
    vector<vector<vpii>> y2 = precalc(c);
    vector<vector<vpii>> y(n, vector<vpii>(m));
    F0R(i, n)
        F0R(j, m)
            y[i][j]=y2[j][i];
    //F0R(i, n){
    //    F0R(j, m){
    //        trav(X, x[i][j]){
    //            cout << i << ' ' << j << ' ' <<  X.f << ' ' << X.s << nl;
    //        }
    //    }
    //} 
    //cout << nl;
    //F0R(i, n){
    //    F0R(j, m){
    //        trav(X, y[i][j]){
    //            cout << i << ' ' << j << ' ' << X.f << ' ' << X.s << nl;
    //        }
    //    }
    //}
    //cout << nl;
    F0R(i, n){
        F0R(j, m){
            trav(v, x[i][j]){
                //cout << "V: " << v.f << ' ' << v.s << nl;
                trav(v2, y[i][j]){
                        //cout << i << ' ' << j << ' ' << v.f << ' ' << v.s << ' ' << v2.f << ' ' << v2.s << nl;
                    if(v.s>=i-v2.f+1&&v2.s>=j-v.f+1) {
                        ans++;
                    }
                }
            }
            //trav(v2, y[i][j]){
            //    cout << "V2: " << v2.f << ' ' << v2.s << nl;
            //}
        }
    }
    return ans;
}

//int32_t main(){
//    ios_base::sync_with_stdio(0); cin.tie(0);
//    int N, M; cin >> N >> M;
//    vector<vi> inp(N, vi(M));
//    F0R(i, N){
//        F0R(j, M){
//            cin >> inp[i][j];
//        }
//    }
//    cout << count_rectangles(inp) << nl;

//    return 0;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 3 ms 1280 KB Output is correct
23 Correct 4 ms 1132 KB Output is correct
24 Correct 4 ms 1132 KB Output is correct
25 Correct 4 ms 1132 KB Output is correct
26 Correct 5 ms 1132 KB Output is correct
27 Correct 4 ms 1260 KB Output is correct
28 Correct 3 ms 1132 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 3 ms 1280 KB Output is correct
18 Correct 4 ms 1132 KB Output is correct
19 Correct 4 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 5 ms 1132 KB Output is correct
22 Correct 4 ms 1260 KB Output is correct
23 Correct 3 ms 1132 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 34 ms 5100 KB Output is correct
31 Correct 36 ms 4972 KB Output is correct
32 Correct 27 ms 5100 KB Output is correct
33 Correct 14 ms 4972 KB Output is correct
34 Correct 22 ms 5868 KB Output is correct
35 Correct 21 ms 6124 KB Output is correct
36 Correct 18 ms 5868 KB Output is correct
37 Correct 18 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 3 ms 1280 KB Output is correct
18 Correct 4 ms 1132 KB Output is correct
19 Correct 4 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 5 ms 1132 KB Output is correct
22 Correct 4 ms 1260 KB Output is correct
23 Correct 3 ms 1132 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 34 ms 5100 KB Output is correct
26 Correct 36 ms 4972 KB Output is correct
27 Correct 27 ms 5100 KB Output is correct
28 Correct 14 ms 4972 KB Output is correct
29 Correct 22 ms 5868 KB Output is correct
30 Correct 21 ms 6124 KB Output is correct
31 Correct 18 ms 5868 KB Output is correct
32 Correct 18 ms 5868 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 226 ms 51708 KB Output is correct
39 Correct 121 ms 56300 KB Output is correct
40 Correct 143 ms 62060 KB Output is correct
41 Correct 174 ms 67016 KB Output is correct
42 Correct 895 ms 59116 KB Output is correct
43 Correct 830 ms 59068 KB Output is correct
44 Correct 801 ms 59468 KB Output is correct
45 Correct 742 ms 56124 KB Output is correct
46 Correct 146 ms 53228 KB Output is correct
47 Correct 201 ms 57836 KB Output is correct
48 Correct 242 ms 68960 KB Output is correct
49 Correct 251 ms 70784 KB Output is correct
50 Correct 168 ms 35564 KB Output is correct
51 Correct 126 ms 35564 KB Output is correct
52 Correct 242 ms 67696 KB Output is correct
53 Correct 246 ms 68716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1516 KB Output is correct
2 Correct 12 ms 1260 KB Output is correct
3 Correct 3 ms 1260 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 4 ms 1388 KB Output is correct
6 Correct 4 ms 1388 KB Output is correct
7 Correct 4 ms 1388 KB Output is correct
8 Correct 4 ms 1536 KB Output is correct
9 Correct 4 ms 1388 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 3 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 883 ms 308976 KB Output is correct
8 Correct 1927 ms 670080 KB Output is correct
9 Correct 1918 ms 673024 KB Output is correct
10 Correct 1917 ms 673380 KB Output is correct
11 Correct 517 ms 260500 KB Output is correct
12 Correct 973 ms 494316 KB Output is correct
13 Correct 1067 ms 527136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 3 ms 1280 KB Output is correct
18 Correct 4 ms 1132 KB Output is correct
19 Correct 4 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 5 ms 1132 KB Output is correct
22 Correct 4 ms 1260 KB Output is correct
23 Correct 3 ms 1132 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 34 ms 5100 KB Output is correct
26 Correct 36 ms 4972 KB Output is correct
27 Correct 27 ms 5100 KB Output is correct
28 Correct 14 ms 4972 KB Output is correct
29 Correct 22 ms 5868 KB Output is correct
30 Correct 21 ms 6124 KB Output is correct
31 Correct 18 ms 5868 KB Output is correct
32 Correct 18 ms 5868 KB Output is correct
33 Correct 226 ms 51708 KB Output is correct
34 Correct 121 ms 56300 KB Output is correct
35 Correct 143 ms 62060 KB Output is correct
36 Correct 174 ms 67016 KB Output is correct
37 Correct 895 ms 59116 KB Output is correct
38 Correct 830 ms 59068 KB Output is correct
39 Correct 801 ms 59468 KB Output is correct
40 Correct 742 ms 56124 KB Output is correct
41 Correct 146 ms 53228 KB Output is correct
42 Correct 201 ms 57836 KB Output is correct
43 Correct 242 ms 68960 KB Output is correct
44 Correct 251 ms 70784 KB Output is correct
45 Correct 168 ms 35564 KB Output is correct
46 Correct 126 ms 35564 KB Output is correct
47 Correct 242 ms 67696 KB Output is correct
48 Correct 246 ms 68716 KB Output is correct
49 Correct 15 ms 1516 KB Output is correct
50 Correct 12 ms 1260 KB Output is correct
51 Correct 3 ms 1260 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 4 ms 1388 KB Output is correct
54 Correct 4 ms 1388 KB Output is correct
55 Correct 4 ms 1388 KB Output is correct
56 Correct 4 ms 1536 KB Output is correct
57 Correct 4 ms 1388 KB Output is correct
58 Correct 2 ms 876 KB Output is correct
59 Correct 3 ms 1132 KB Output is correct
60 Correct 1 ms 492 KB Output is correct
61 Correct 883 ms 308976 KB Output is correct
62 Correct 1927 ms 670080 KB Output is correct
63 Correct 1918 ms 673024 KB Output is correct
64 Correct 1917 ms 673380 KB Output is correct
65 Correct 517 ms 260500 KB Output is correct
66 Correct 973 ms 494316 KB Output is correct
67 Correct 1067 ms 527136 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 492 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Execution timed out 5109 ms 647360 KB Time limit exceeded
74 Halted 0 ms 0 KB -