# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110109 | SirCeness | Seats (IOI18_seats) | C++14 | 0 ms | 0 KiB |
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"
int h, w;
vector<int> r, c;
void maxi(int& a, int b){
a = max(a, b);
}
void mini(int& a, int b){
a = min(a, b);
}
int getans(){
int rmax = r[0];
int rmin = r[0];
int cmax = c[0];
int cmin = c[0];
//cout << rmax << " " << rmin << " - " << cmax << " " << cmin << endl;
int ans = 1;
for (int i = 1; i < h*w; i++){
maxi(rmax, r[i]);
mini(rmin, r[i]);
maxi(cmax, c[i]);
mini(cmin, c[i]);
//cout << rmax << " " << rmin << " - " << cmax << " " << cmin << endl;
if ((rmax-rmin+1)*(cmax-cmin+1) == i+1) ans++;
}
return ans;
}
void give_initial_chart(int H, int W, vector<int> R, vector<int> C) {
h = H;
w = W;
for (int i = 0; i < h*w; i++){
r.push_back(R[i]);
c.push_back(C[i]);
}
}
int swap_seats(int a, int b) {
int tmp = r[a];
r[a] = r[b];
r[b] = tmp;
tmp = c[a];
c[a] = c[b];
c[b] = tmp;
return getans();
}