This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "seats.h"
#include<bits/stdc++.h>
using namespace std;
int h, w;
vector<int> r, c;
void give_initial_chart(int H, int W, vector<int> R, vector<int> C){
h = H;
w = W;
r = R;
c = C;
}
int swap_seats(int a, int b) {
swap(r[a], r[b]);
swap(c[a], c[b]);
int res = 1;
int T = r[0], B = r[0], L = c[0], R = c[0];
unordered_set<int> s;
for (int i=1; i<h*w; i++){
int next = h*r[i] + c[i];
if (r[i] < T){
for (int j=r[i]; j<T; j++){
for (int k=min(L, c[i]); k<=max(R, c[i]); k++) s.insert(h*j + k);
}
}
if (r[i] > B){
for (int j=B+1; j<=r[i]; j++){
for (int k=min(L, c[i]); k<=max(R, c[i]); k++) s.insert(h*j + k);
}
}
if (c[i] < L){
for (int j=T; j<=B; j++){
for (int k=c[i]; k<L; k++) s.insert(h*j + k);
}
}
if (c[i] > R){
for (int j=T; j<=B; j++){
for (int k=R+1; k<=c[i]; k++) s.insert(h*j + k);
}
}
T = min(T, r[i]); B = max(T, r[i]); L = min(L, c[i]); R = max(R, c[i]);
s.erase(next);
if (s.empty()) res++;
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |