제출 #294189

#제출 시각아이디문제언어결과실행 시간메모리
294189Saboon자리 배치 (IOI18_seats)C++17
0 / 100
4070 ms39572 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, h, w; vector<int> r, c; int MxC[4*maxn], MxR[4*maxn], MnC[4*maxn], MnR[4*maxn]; void give_initial_chart(int H, int W, vector<int> R, vector<int> C){ h = H, w = W, r = R, c = C; n = h*w; for (int i = 0; i < n; i++){ MxC[i] = (i == 0 ? C[i] : max(MxC[i-1],C[i])); MnC[i] = (i == 0 ? C[i] : max(MnC[i-1],C[i])); MxR[i] = (i == 0 ? R[i] : max(MxR[i-1],R[i])); MnR[i] = (i == 0 ? R[i] : max(MnR[i-1],R[i])); } } int isGood(int r1, int r2, int c1, int c2){ int Size = (r2-r1+1) * (c2-c1+1); if (Size == n) return 1; int idx = Size - 1; if (MxR[idx] > r2) r2 = MxR[idx]; if (MnR[idx] < r1) r1 = MnR[idx]; if (MxC[idx] > c2) c2 = MxC[idx]; if (MnC[idx] < c1) c1 = MnC[idx]; if ((r2-r1+1)*(c2-c1+1) != Size) return isGood(r1, r2, c1, c2); idx ++; if (MxR[idx] > r2) r2 = MxR[idx]; if (MnR[idx] < r1) r1 = MnR[idx]; if (MxC[idx] > c2) c2 = MxC[idx]; if (MnC[idx] < c1) c1 = MnC[idx]; return 1 + isGood(r1,r2,c1,c2); } int swap_seats(int a, int b){ if (a > b) swap(a,b); swap(r[a],r[b]); swap(c[a],c[b]); for (int i = a; i < b; i++){ MxC[i] = (i == 0 ? c[i] : max(MxC[i-1],c[i])); MnC[i] = (i == 0 ? c[i] : max(MnC[i-1],c[i])); MxR[i] = (i == 0 ? r[i] : max(MxR[i-1],r[i])); MnR[i] = (i == 0 ? r[i] : max(MnR[i-1],r[i])); } int r1 = r[0], r2 = r[0], c1 = c[0], c2 = c[0]; return isGood(r1, r2, c1, c2); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...