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;
#define pb push_back
std::vector<int> r;
std::vector<int> c;
typedef pair<int,int> ii;
vector<int> vmaxx;
vector<int> vmaxy;
vector<int> vminy;
vector<int> vminx;
int g=0,e,d;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
r = R;
c = C;
int maxx=r[0],minx=r[0],maxy=c[0],miny=c[0];
for(int i=0;i<H*W;i++){
int x1,y1;
x1=r[i];
y1=c[i];
maxx=max(maxx,x1);
minx=min(minx,x1);
maxy=max(maxy,y1);
miny=min(miny,y1);
d=abs(maxx-minx)+1;
e=abs(maxy-miny)+1;
if(d*e==i+1){
g++;
}
vmaxx.pb(maxx);
vmaxy.pb(maxy);
vminx.pb(minx);
vminy.pb(miny);
}
//cout<<g<<endl;
}
int swap_seats(int a, int b) {
int x1,y1;
//int x2,y2;
swap(r[a],r[b]);
swap(c[a],c[b]);
int maxx=r[0],minx=r[0],maxy=c[0],miny=c[0];
if(abs(a-b)<=10000){
int j=min(a,b);
int k=max(a,b);
for(int i=j;i<=k;i++){
d=abs(vmaxx[i]-vminx[i])+1;
e=abs(vmaxy[i]-vminy[i])+1;
if(e*d==i+1){
g--;
}
}
int maxx=r[j],minx=r[j],maxy=c[j],miny=c[j];
for(int i=j;i<=k;i++){
x1=r[i];
y1=c[i];
maxx=max(maxx,x1);
minx=min(minx,x1);
maxy=max(maxy,y1);
miny=min(miny,y1);
vmaxx[i]=maxx;
vmaxy[i]=maxy;
vminx[i]=minx;
vminy[i]=miny;
d=abs(vmaxx[i]-vminx[i])+1;
e=abs(vmaxy[i]-vminy[i])+1;
if(e*d==i+1){
g++;
}
}
return g;
}
int tam=r.size();
g=1;
for(int i=0;i<tam-1;i++){
x1=r[i];
y1=c[i];
maxx=max(maxx,x1);
minx=min(minx,x1);
maxy=max(maxy,y1);
miny=min(miny,y1);
d=abs(maxx-minx)+1;
e=abs(maxy-miny)+1;
if(e*d==i+1){
g++;
}
//cout<<d*e<<" "<<g<<endl;
}
return g;
}
# | 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... |