# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1267537 | ilovewaguri | Cutting a Rectangle (BOI24_rectangle) | C++20 | 690 ms | 124972 KiB |
#include<bits/stdc++.h>
using namespace std;
#define NAME "REGTANGLE"
#define nl '\n'
#define allofa(x,sz) x,x+sz+1
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,val) memset(x,val,sizeof(x))
#define couf(x) cout << fixed << setprecision(x)
template<class T> T Abs(T &x) {return (x>=0 ? x : -x);};
template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;};
template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;};
typedef long long ll;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e15;
const int INF = (int)1e9;
const int MAXN = (int)5e6+5;
ll w[MAXN],h[MAXN];
bool visited[MAXN];
vector<ll> big[MAXN],small[MAXN];
int K;
void ccps() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen(NAME".inp","r")) {
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
}
}
signed main() {
ccps();
cin >> K;
ll area = 0;
for (int i = 1; i<=K; i++) {
cin >> w[i] >> h[i];
area+=1LL*w[i]*h[i];
big[w[i]].push_back(i);
small[h[i]].push_back(i);
}
vector<ll> res;
for (ll len = 1; len<MAXN; len++) {
if(area%len==0 and len<=area/len) {
ll a = len;
ll b = area/len;
mset(visited,false);
while(true) {
bool check = false;
if(a<b) swap(a,b);
if(a<MAXN) {
for (int idx : big[a]) {
if(!visited[idx]) {
visited[idx]=true;
b-=h[idx];
check = true;
}
}
}
if(check) continue;
for (int idx : small[b]) {
if(!visited[idx]) {
visited[idx]=true;
a-=w[idx];
check=true;
}
}
if(check) continue;
for (int idx : big[b]) {
if(!visited[idx]) {
visited[idx]=true;
a-=h[idx];
check = true;
}
}
if(!check) break;
}
if(a*b==0) res.push_back(len);
}
}
cout << (ll)res.size() << nl;
for (int x : res) cout << x << nl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |