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);
}
/*for(int i=0;i<H*W;i++){
cout<<vmaxx[i]<<" "<<vminx[i]<<" "<<vmaxy[i]<<" "<<vminy[i]<<endl;
}*/
//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[0],minx=r[0],maxy=c[0],miny=c[0];
int tam=vmaxx.size();
for(int i=0;i<tam;i++){
maxx=max(r[i],maxx);
minx=min(r[i],minx);
maxy=max(c[i],maxy);
miny=min(c[i],miny);
vmaxx[i]=maxx;
vmaxy[i]=maxy;
vminx[i]=minx;
vminy[i]=miny;
}
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++;
}
}
return g;
}
}
Compilation message (stderr)
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:41:7: warning: unused variable 'x1' [-Wunused-variable]
int x1,y1;
^~
seats.cpp:41:10: warning: unused variable 'y1' [-Wunused-variable]
int x1,y1;
^~
seats.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |