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 <bits/stdc++.h>
#define pb push_back
#include "seats.h"
using namespace std;
vector<vector<int> > r;
vector<pair<int, int> > pos;
void give_initial_chart(int H, int W, vector<int> R, vector<int> C){
r.resize(H);
for(int i = 0; i < H; i++){
r[i].resize(W);
}
pos.resize(H * W);
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
r[i][j] = R[i * W + j] * W + C[i * W + j];
pos[R[i * W + j] * W + C[i * W + j]] = {i, j};
}
}
}
int swap_seats(int a, int b) {
pair<int, int> posa = pos[a], posb = pos[b];
r[posa.first][posa.second] = b;
r[posb.first][posb.second] = a;
swap(pos[a], pos[b]);
int w = r[0].size(), h = pos.size() / w;
int mnx = h + w, mxx = 0, mny = h + w, mxy = 0;
int ans = 0;
for(int i = 0; i < h * w; i++){
mnx = min(mnx, pos[i].second);
mxx = max(mxx, pos[i].second);
mny = min(mny, pos[i].first);
mxy = max(mxy, pos[i].first);
if((mxx - mnx + 1) * (mxy - mny + 1) == (i + 1)){
ans++;
//cout<<i<<" .."<<endl;
}
}
return ans;
}
# | 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... |