Submission #207368

# Submission time Handle Problem Language Result Execution time Memory
207368 2020-03-07T10:48:35 Z balbit Rectangles (IOI19_rect) C++14
0 / 100
6 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) x.begin(),x.end()

#define pii pair<int, int>
#define f first
#define s second

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = ", _do(__VA_ARGS__)
template<typename T> void _do(T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

const int MX = 205;


#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define FOR(i,a,b) for (int i = a; i<b; i++)

stack<pii> bb; // big boys
void add(pii x) {
    while (!bb.empty() && bb.top().f <= x.f) bb.pop();
    bb.push(x);
}

ll count_rectangles(vector<vector<int> > a) {
    int n = SZ(a);
    int m = SZ(a[0]);
    if (m<=2) return 0;
    int lb = 0;
    ll re = 0;
    add ({a[1][0],0});
    add({a[1][1],1});
    bb.pop();
    vector<int> L(m);
    for (int i = 0; i<m-1; ++i) {
        int x = a[1][i];
        L[i] = x > a[1][i+1];
    }
    for (int i = 1; i<m-1; ++i) {
        int x = a[1][i];
        bool ok = x < a[0][i] && x < a[2][i];
        bool R = ok && x < a[1][i+1];

        if (!ok) {
            while (!bb.empty()) bb.pop();
            bb.push({x,i});
        }
        else{
            while (!bb.empty() && bb.top().f <= a[1][i+1] ) {
                if (L[bb.top().s]) re += R;
                bb.pop();
            }
            if (!bb.empty()) if (L[bb.top().s]) re += R;
            bb.push({x,i});
        }
    }
    return re;
}

#ifdef BALBIT
signed main(){
    IOS();
    ll ro = count_rectangles({{1,1,1,1},{1,0,0,1},{1,1,1,1}});
    bug(ro);
}
#endif

Compilation message

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:38:9: warning: unused variable 'n' [-Wunused-variable]
     int n = SZ(a);
         ^
rect.cpp:41:9: warning: unused variable 'lb' [-Wunused-variable]
     int lb = 0;
         ^~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Runtime error 5 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -