제출 #131469

#제출 시각아이디문제언어결과실행 시간메모리
131469lyc섬 항해 (CEOI13_adriatic)C++14
100 / 100
474 ms178436 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...