Submission #823635

#TimeUsernameProblemLanguageResultExecution timeMemory
823635FischerCutting a rectangle (LMIO18_staciakampis)C++14
0 / 100
68 ms156872 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxa = 5e6 + 1; int a[maxn][2]; int d[2 * maxa]; int vis[maxn]; int vis1[maxa]; int n; vector<int> valid; vector<int> ba[maxa]; int T; long long get(long long x) { if (vis1[x] == T) return 0; vis1[x] = T; long long sum = 0; for (int id : ba[x]) { if (vis[id] < T) { vis[id] = T; sum += a[id][0]; } } return sum; } bool check(long long l, long long r) { for (int i=0; i<n; ++i) { if (vis[i] == T) continue; vis[i] = T; if (r < l) swap(l, r); if (l < 0) return 0; if (a[i][0] == r) { l -= a[i][1]; } else if (a[i][0] == l) { r -= a[i][1]; } else if (a[i][1] == l) { r -= a[i][0]; } else { if (l < a[i][1]) return 0; long long el = l; long long er = r - a[i][0]; if (l >= maxa) return 0; long long len = get(l); if (len > er) return 0; if (len < er) { int need_id = d[er - len]; if (need_id == -1) return 0; if (a[need_id][1] != l) return 0; if (vis[need_id] == T) return 0; vis[need_id] = T; } l -= a[i][1]; r = a[i][0]; } } if (r < 0 || l < 0) return 0; return l == 0 || r == 0; } const long long maxA = 5e13; void solve(long long area) { if (area >= maxA) return; for (int i = 1; i*1ll*i <= area; ++i) { if (area % i) continue; if (i >= maxa) continue; T++; if (check(i, area / i)) { valid.push_back(i); } } } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin>>n; long long area = 0; memset(d, -1, sizeof d); for (int i=0; i<n; ++i) { cin>>a[n-i-1][0]>>a[n-i-1][1]; } d[0] = n; for (int i=0; i<n; ++i) { d[a[i][0]] = i; ba[a[i][1]].push_back(i); area += a[i][0]*1ll*a[i][1]; } solve(area); cout << valid.size() << '\n'; for (auto e : valid) { cout << e << '\n'; } return 0; }

Compilation message (stderr)

staciakampis.cpp: In function 'bool check(long long int, long long int)':
staciakampis.cpp:42:23: warning: unused variable 'el' [-Wunused-variable]
   42 |             long long el = l;
      |                       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...