Submission #1018028

# Submission time Handle Problem Language Result Execution time Memory
1018028 2024-07-09T13:02:06 Z c2zi6 Rectangles (IOI19_rect) C++14
0 / 100
819 ms 1048576 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "rect.h"

namespace TEST1 {
    int lg[3001];
    struct SPARSETABLE {
        VVI table;
        SPARSETABLE(){};
        SPARSETABLE(VI a) {
            int n = a.size();
            table = VVI(n, VI(14));
            reprl(i, n-1, 0) {
                table[i][0] = a[i];
                for (int j = 1; i+(1<<(j-1)) < n; j++) {
                    table[i][j] = max(table[i][j-1], table[i + (1<<(j-1))][j-1]);
                }
            }
        }
        int get(int l, int r) {
            int s = lg[r - l + 1];
            return max(table[l][s], table[r-(1<<s)+1][s]);
        }
    };
    ll count_rectangles(VVI a) {
        lg[1] = 0; replr(i, 2, 3000) lg[i] = lg[i/2]+1;
        int n = a.size();
        int m = a[0].size();
        vector<SPARSETABLE> rows(n);
        vector<SPARSETABLE> cols(m);
        rep(i, n) {
            rows[i] = SPARSETABLE(a[i]);
        }
        rep(j, m) {
            VI b;
            rep(i, n) b.pb(a[i][j]);
            cols[j] = SPARSETABLE(b);
        }
        ll ans = 0;
        replr(r1, 1, n-2) replr(r2, r1, n-2) {
            replr(c1, 1, m-2) replr(c2, c1, m-2) {
                bool good = true;
                replr(i, r1, r2) {
                    if (rows[i].get(c1, c2) >= min(a[i][c1-1], a[i][c2+1])) {
                        good = false;
                        break;
                    }
                }
                if (!good) continue;
                replr(j, c1, c2) {
                    if (cols[j].get(r1, r2) >= min(a[r1-1][j], a[r2+1][j])) {
                        good = false;
                        break;
                    }
                }
                if (!good) continue;
                /*cout << r1 << " " << r2 << " " << c1 << " " << c2 << endl;*/
                ans++;
            }
        }
        return ans;
    }
}
namespace TEST6 {
    bool check(VVI a) {
        for (VI& vec : a) for (int x : vec) if (x > 1) return false;
        return true;
    }
    int n, m;
    int r1, r2, c1, c2;
    void dfs(int ux, int uy, VVI& a) {
        VPI harevan = {{ux-1, uy}, {ux+1, uy}, {ux, uy-1}, {ux, uy+1}};
        a[ux][uy] = 2;
        setmin(r1, ux);
        setmax(r2, ux);
        setmin(c1, uy);
        setmax(c2, uy);
        for (auto[vx, vy] : harevan) {
            if (vx < 0 || vx >= n) continue;
            if (vy < 0 || vy >= m) continue;
            if (a[vx][vy]) continue;
            dfs(vx, vy, a);
        }
    }
    ll count_rectangles(VVI a) {
        n = a.size();
        m = a[0].size();
        VVI pref(n+1, VI(m+1));
        replr(i, 1, n) replr(j, 1, m) {
            pref[i][j] = a[i-1][j-1] + pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1];
        }
        int ans = 0;
        rep(i, n) rep(j, m) if (a[i][j] == 0) {
            r1 = +2e9;
            r2 = -2e9;
            c1 = +2e9;
            c2 = -2e9;
            /*cout << "dfs at " << i << " " << j << endl;*/
            dfs(i, j, a);
            /*cout << r1 << " " << r2 << " " << c1 << " " << c2 << endl;*/
            if (r1 == 0 || r2 == n-1 || c1 == 0 || c2 == m-1) continue;
            if (pref[r2+1][c2+1] - pref[r1][c2+1] - pref[r2+1][c1] + pref[r1][c1] == 0) {
                /*cout << r1 << " " << r2 << " " << c1 << " " << c2 << endl;*/
                ans++;
            }
        }
        return ans;
    }
}

ll count_rectangles(VVI a) {
    if (TEST6::check(a)) return TEST6::count_rectangles(a);
    return 0ll;
    if (TEST6::check(a)) return TEST6::count_rectangles(a);
    return TEST1::count_rectangles(a);
}



Compilation message

rect.cpp: In function 'void TEST6::dfs(int, int, VVI&)':
rect.cpp:107:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  107 |         for (auto[vx, vy] : harevan) {
      |                  ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 112 ms 45300 KB Output is correct
3 Correct 266 ms 98192 KB Output is correct
4 Correct 266 ms 98580 KB Output is correct
5 Correct 264 ms 98652 KB Output is correct
6 Correct 386 ms 358776 KB Output is correct
7 Correct 819 ms 883032 KB Output is correct
8 Runtime error 673 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -