제출 #538229

#제출 시각아이디문제언어결과실행 시간메모리
538229idasCutting a rectangle (LMIO18_staciakampis)C++11
25 / 100
1091 ms46480 KiB
#include <bits/stdc++.h> #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define TSTS int ttt; cin >> ttt; while(ttt--) solve() #define all(x) (x).begin(), (x).end() #define le(vec) vec[vec.size()-1] #define sz(x) ((int)((x).size())) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int INF=1e9, MOD=1e9+7, mod=998244353; const ll LINF=1e13; void setIO() { FAST_IO; } void setIO(string s) { FAST_IO; freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } #define int long long const int N=1e5+10; int n, a[N], b[N]; vector<pii> inf; ll area; bool can(int x, int y) { if(x*y!=area) return false; map<int, set<pii, greater<pii>>> ar, br; FOR(i, 0, n) { ar[inf[i].f].insert({inf[i].s, i}); br[inf[i].s].insert({inf[i].f, i}); } map<int, bool> v; while(x>0 && y>0){ while(!ar[x].empty() && v[pii(*ar[x].begin()).s]) ar[x].erase(ar[x].begin()); while(!br[x].empty() && v[pii(*br[x].begin()).s]) br[x].erase(br[x].begin()); while(!ar[y].empty() && v[pii(*ar[y].begin()).s]) ar[y].erase(ar[y].begin()); while(!br[y].empty() && v[pii(*br[y].begin()).s]) br[y].erase(br[y].begin()); if(x<y) swap(x, y); if(sz(ar[x])){ pii tp=*ar[x].begin(); v[tp.s]=true; y-=tp.f; ar[x].erase(ar[x].begin()); continue; } if(sz(br[y])){ pii tp=*br[y].begin(); v[tp.s]=true; x-=tp.f; br[y].erase(br[y].begin()); continue; } if(sz(ar[y])){ pii tp=*ar[y].begin(); v[tp.s]=true; x-=tp.f; ar[y].erase(ar[y].begin()); continue; } return false; } return true; } signed main() { setIO(); cin >> n; FOR(i, 0, n) { cin >> a[i] >> b[i]; inf.pb({a[i],b[i]}); area+=a[i]*b[i]; } set<int> ans; for(ll i=1; i*i<=area; i++){ if(area%i==0){ ll x=i, y=area/x; if(can(x, y)){ ans.insert(x); } } } cout << sz(ans) << '\n'; for(auto x : ans){ cout << x << '\n'; } }

컴파일 시 표준 에러 (stderr) 메시지

staciakampis.cpp: In function 'void setIO(std::string)':
staciakampis.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
staciakampis.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...