Submission #131469

# Submission time Handle Problem Language Result Execution time Memory
131469 2019-07-17T07:36:02 Z lyc Adriatic (CEOI13_adriatic) C++14
100 / 100
474 ms 178436 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MAXN = 250005;
const int MAXR = 2505;
const int MAXC = 2505;

int N;
int R[MAXN], C[MAXN];
int r1[MAXR][MAXC];
int r2[MAXR][MAXC];
int S[MAXR][MAXC];
ii G[MAXR][MAXC];
ii H[MAXR][MAXC];

int dp1(int r, int c) {
    int s = S[2500][c]-S[r-1][c];
    if (s == 0) return 0;
    if (~r1[r][c]) return r1[r][c];
    int x = min(c, G[r-1][c].sc);
    int y = max(r, H[r][c+1].fi);
    r1[r][c] = s + dp1(y,x);
    //cout << "r1 " << r << " " << c << " :: " << r1[r][c] << endl;
    return r1[r][c];
}

int dp2(int r, int c) {
    //cout << "r2 " << r << " " << c << endl;
    //assert(c-1 >= 0);
    int s = S[r][2500]-S[r][c-1];
    if (s == 0) return 0;
    if (~r2[r][c]) return r2[r][c];
    int y = min(r, G[r][c-1].fi);
    int x = max(c, H[r+1][c].sc);
    //cout << "r2 " << r << " " << c << " :: y x " << y << " " << x << endl;
    //assert(y <= r and x >= c);
    r2[r][c] = s + dp2(y,x);
    //cout << "r2 " << r << " " << c << " :: " << r2[r][c] << endl;
    return r2[r][c];
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    FOR(r,0,2500) FOR(c,0,2500) G[r][c] = { MAXR, MAXC };
    FOR(i,0,N-1){
        cin >> R[i] >> C[i];
        S[R[i]][C[i]] = 1;
        G[R[i]][C[i]] = { R[i], C[i] };
        H[R[i]][C[i]] = { R[i], C[i] };
    }

    FOR(r,1,2500) FOR(c,1,2500) {
        S[r][c] += S[r-1][c] + S[r][c-1] - S[r-1][c-1];
        G[r][c].fi = min({ G[r][c].fi, G[r-1][c].fi, G[r][c-1].fi });
        G[r][c].sc = min({ G[r][c].sc, G[r-1][c].sc, G[r][c-1].sc });
    }
    RFOR(r,2500,1) RFOR(c,2500,1) {
        H[r][c].fi = max({ H[r][c].fi, H[r+1][c].fi, H[r][c+1].fi });
        H[r][c].sc = max({ H[r][c].sc, H[r+1][c].sc, H[r][c+1].sc });
    }

    memset(r1, -1, sizeof r1);
    memset(r2, -1, sizeof r2);
    FOR(i,0,N-1){
        //cout << dp1(R[i]+1, C[i]-1) << " " << dp2(R[i]-1, C[i]+1) << " :: ";
        cout << N-1 + dp1(R[i], C[i])-1 + dp2(R[i], C[i])-1 << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 205 ms 172148 KB Output is correct
2 Correct 203 ms 172280 KB Output is correct
3 Correct 203 ms 172152 KB Output is correct
4 Correct 202 ms 172020 KB Output is correct
5 Correct 203 ms 172024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 172240 KB Output is correct
2 Correct 201 ms 172220 KB Output is correct
3 Correct 204 ms 172208 KB Output is correct
4 Correct 203 ms 172152 KB Output is correct
5 Correct 203 ms 172152 KB Output is correct
6 Correct 205 ms 172152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 172220 KB Output is correct
2 Correct 201 ms 172212 KB Output is correct
3 Correct 207 ms 172204 KB Output is correct
4 Correct 205 ms 172244 KB Output is correct
5 Correct 204 ms 172152 KB Output is correct
6 Correct 204 ms 172280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 172804 KB Output is correct
2 Correct 209 ms 172664 KB Output is correct
3 Correct 244 ms 172792 KB Output is correct
4 Correct 228 ms 172664 KB Output is correct
5 Correct 244 ms 172664 KB Output is correct
6 Correct 214 ms 172792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 178436 KB Output is correct
2 Correct 417 ms 178092 KB Output is correct
3 Correct 474 ms 178040 KB Output is correct
4 Correct 395 ms 177816 KB Output is correct
5 Correct 362 ms 178316 KB Output is correct
6 Correct 373 ms 178304 KB Output is correct
7 Correct 372 ms 178424 KB Output is correct