Submission #1267522

#TimeUsernameProblemLanguageResultExecution timeMemory
1267522ilovewaguriCutting a Rectangle (BOI24_rectangle)C++20
0 / 100
1 ms324 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)1e5+5;
int w[MAXN],h[MAXN];
bool visited[MAXN];
vector<int> 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<int> res;
    for (ll len = 1; len<=area; len++) {
        if(area%len==0 and len<=area/len) {
            int a = len;
            int b = area/len;
            mset(visited,false);
            while(true) {
                bool check = false;
                if(a<b) swap(a,b);
                if(a<area) {
                    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-=w[idx];
                        check = true;
                    }
                }
                if(!check) break;
            }
            if(a*b==0) res.push_back(len);
        }
    }
    cout << (int)res.size() << nl;
    for (int x : res) cout << x << nl;
}

Compilation message (stderr)

Main.cpp: In function 'void ccps()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...