# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333599 | nicholask | 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"
#include <bits/stdc++.h>
using namespace std;
int n,m;
pair <int,int> pos[1000000];
vector <vector <int> > a;
void give_initial_chart(int h,int w,vector <int> r,vector <int> c){
n=h;
m=w;
vector <vector <int> > v(h);
for (int i=0; i<h; i++){
vector <int> e(w);
v[i]=e;
}
for (int i=0; i<h*w; i++){
pos[i]={r[i],c[i]};
v[r[i]][c[i]]=i;
}
a=v;
}
int swap_seats(int a,int b){
pair <int,int> wha=pos[a],whb=pos[b];
swap(pos[a],pos[b]);
swap(a[wha.first][wha.second],a[whb.first][whb.second]);
int ans=0;
int minr=1e9,maxr=-1e9,minc=1e9,maxc=-1e9;
for (int i=0; i<m*n; i++){
//get pos[i]
minr=min(minr,pos[i].first);
maxr=max(maxr,pos[i].first);
minc=min(minc,pos[i].second);
maxc=max(maxc,pos[i].second);
int a=(maxr-minr+1)*(maxc-minc+1);
if (a==i+1) ans++;
}
return ans;
}