QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168825#6563. Four Squareucup-team134#AC ✓1ms3712kbC++145.3kb2023-09-08 23:15:062023-09-08 23:15:06

Judging History

你现在查看的是最新测评结果

  • [2023-09-08 23:15:06]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3712kb
  • [2023-09-08 23:15:06]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

const int N=4;
vector<pair<int,int>> pc(N);
vector<pair<int,int>> place(N);
vector<bool> rot(N),in(N);
int n;
bool intersects(pair<int,int> a,pair<int,int> b){
	if(a.f>b.s||a.s<b.f){
		return 0;
	}
}
bool intersects(int i,int j){
	if(!in[i]||!in[j]||i==j)
		return 0;
	vector<pair<int,int>> x,y;
	if(rot[i]){
		x.pb({place[i].f,place[i].f+pc[i].f-1});
		y.pb({place[i].s,place[i].s+pc[i].s-1});
	}
	else{
		x.pb({place[i].f,place[i].f+pc[i].s-1});
		y.pb({place[i].s,place[i].s+pc[i].f-1});
	}
	if(rot[j]){
		x.pb({place[j].f,place[j].f+pc[j].f-1});
		y.pb({place[j].s,place[j].s+pc[j].s-1});
	}
	else{
		x.pb({place[j].f,place[j].f+pc[j].s-1});
		y.pb({place[j].s,place[j].s+pc[j].f-1});
	}
	return intersects(x[0],x[1])&&intersects(y[0],y[1]);
}
pair<int,int> getLast(int i,int row){
	if(!in[i])
		return {-1,-1};
	if(row<place[i].f||row>place[i].f+(rot[i]?pc[i].f:pc[i].s)-1)
		return {-1,-1};
	return {place[i].s,place[i].s+(rot[i]?pc[i].s:pc[i].f)-1};
}
bool canPlace(int i,int r,int c,int ro){
	if(r+(ro?pc[i].f:pc[i].s)-1>=n||c+(ro?pc[i].s:pc[i].f)-1>=n){
		return 0;
	}
	for(int j=0;j<N;j++){
		if(intersects(i,j)){
			return 0;
		}
	}
	return 1;
}
bool dfs(){
	int r=-1,c=-1;
	for(int row=0;row<n;row++){
		vector<pair<int,int>> inter;
		for(int j=0;j<N;j++){
			inter.pb(getLast(j,row));
		}
		sort(all(inter));
		int lst=-1;
		bool bad=0;
		for(auto p:inter){
			if(p.f>lst+1){
				bad=1;
				r=row;
				c=lst+1;
				break;
			}
			lst=p.s;
		}
		if(lst!=n-1){
			bad=1;
			r=row;
			c=lst+1;
		}
		if(bad){
			break;
		}
	}
	if(r==-1){
		return 1;
	}
	for(int j=0;j<N;j++){
		if(in[j]){
			continue;
		}
		for(int ro=0;ro<2;ro++){
			if(canPlace(j,r,c,ro)){
				place[j]={r,c};
				rot[j]=ro;
				in[j]=1;
				if(dfs()){
					return 1;
				}
				in[j]=0;
			}
		}
	}
	return 0;
}

int main()
{
	rd(pc);
	for(auto p:pc){
		n+=p.f*p.s;
	}
	int sq=-1;
	for(int i=1;i<10000;i++){
		if(i*i==n){
			sq=i;
		}
	}
	if(sq==-1){
		printf("0\n");
		return 0;
	}
	n=sq;
	printf(dfs()?"1\n":"0\n");
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3644kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

2 8
2 8
2 8
2 8

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

5 3
5 5
3 3
3 5

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 2
4 8
16 32
64 128

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

4 4
2 1
4 4
2 1

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

995 51
559 565
154 536
56 780

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

391 694
540 42
240 937
691 246

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

519 411
782 710
299 45
21 397

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

96 960
948 18
108 82
371 576

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

3 2
4 3
3 1
1 4

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

4 3
1 2
4 4
3 2

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

4 4
1 3
5 4
2 5

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

1000 1000
1000 1000
1000 1000
1000 1000

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

1000 999
998 1000
997 1000
997 997

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1 3
3 3
3 3
4 7

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

2 5
5 4
7 1
6 2

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

12 2
12 7
7 12
16 4

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

7 2
2 14
5 14
7 12

output:

1

result:

ok single line: '1'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3604kb

input:

32 36
5 1
1 37
35 5

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

28 30
30 1
31 1
2 30

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3640kb

input:

66 68
9 11
7 66
9 64

output:

1

result:

ok single line: '1'

Test #23:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

59 44
25 44
40 32
40 52

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

4 4
2 3
4 2
3 2

output:

1

result:

ok single line: '1'