QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#151110 | #6806. Landlord | do_while_true# | AC ✓ | 133ms | 3588kb | C++20 | 2.3kb | 2023-08-26 15:27:51 | 2023-08-26 15:27:52 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
#include<cstring>
#include<random>
#include<functional>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define dbg(x) cerr<<"In the line "<<__LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In the line "<<__LINE__<<" the "<<#x<<" = "<<x<<" the "<<#y<<" = "<<y<<'\n';
typedef long long ll;
typedef vector<int> vi;
template<typename T>T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+ch-'0',ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
int V=30;
struct point{
int x,y;
}a,b,c,d;
vi vx,vy;
int vis[40][40];
void solve(){
read(a.x,a.y);
read(b.x,b.y);
read(c.x,c.y);
read(d.x,d.y);
vi().swap(vx);
vi().swap(vy);
vx.pb(a.x);
vx.pb(b.x);
vx.pb(c.x);
vx.pb(d.x);
vy.pb(a.y);
vy.pb(b.y);
vy.pb(c.y);
vy.pb(d.y);
sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());
sort(vy.begin(),vy.end());vy.erase(unique(vy.begin(),vy.end()),vy.end());
auto LB=[&](const vi &ve,int &x){
return lower_bound(ve.begin(),ve.end(),x)-ve.begin();
};
a.x=LB(vx,a.x);b.x=LB(vx,b.x);c.x=LB(vx,c.x);d.x=LB(vx,d.x);
a.y=LB(vy,a.y);b.y=LB(vy,b.y);c.y=LB(vy,c.y);d.y=LB(vy,d.y);
a.x=a.x*5+2;b.x=b.x*5+2;c.x=c.x*5+2;d.x=d.x*5+2;
a.y=a.y*5+2;b.y=b.y*5+2;c.y=c.y*5+2;d.y=d.y*5+2;
memset(vis,0,sizeof(vis));
for(int i=a.x;i<=b.x;i++)vis[i][a.y]=vis[i][b.y]=1;
for(int i=a.y;i<=b.y;i++)vis[a.x][i]=vis[b.x][i]=1;
for(int i=c.x;i<=d.x;i++)vis[i][c.y]=vis[i][d.y]=1;
for(int i=c.y;i<=d.y;i++)vis[c.x][i]=vis[d.x][i]=1;
int cnt=0;
static int dx[]={1,-1,0,0};
static int dy[]={0,0,1,-1};
function<void(int,int)>dfs=[&](int x,int y){
vis[x][y]=1;
for(int i=0;i<4;i++){
int u=x+dx[i],v=y+dy[i];
if(u>=1&&u<=V&&v>=1&&v<=V&&!vis[u][v])
dfs(u,v);
}
};
for(int i=1;i<=V;i++)
for(int j=1;j<=V;j++)
if(!vis[i][j]){
++cnt;
dfs(i,j);
}
cout<<cnt<<'\n';
}
signed main(){
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
int T;read(T);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
input:
3 0 0 1 1 2 2 3 4 1 0 3 2 0 1 2 3 0 0 1 1 0 0 1 1
output:
3 4 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 133ms
memory: 3588kb
input:
10000 399413444 601729739 838979329 605646850 176742602 192902430 399413444 601729739 19226489 2915752 27806715 977516728 4075670 1872865 19226489 925008461 45547871 393001695 58201503 713825285 18241876 197851829 45547871 713825285 237513514 504913958 868997719 543598899 134432693 110279295 2375135...
output:
3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 3 3 4 3 3 4 3 3 4 3 3 4 4 3 3 5 3 3 4 3 3 5 4 3 5 4 3 3 6 3 3 4 4 5 3 3 4 3 4 3 3 3 3 3 4 3 4 3 2 3 3 4 3 3 4 3 3 4 3 3 4 3 3 4 4 3 3 5 3 3 4 4 5 3 3 4 3 4 3 3 3 3 3 4 4 4 4 4 4 4 4 3 3 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 5 6 3 4 5 ...
result:
ok 10000 lines