제출 #823649

#제출 시각아이디문제언어결과실행 시간메모리
823649FischerCutting a rectangle (LMIO18_staciakampis)C++14
45 / 100
1102 ms140148 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxa = 5e6 + 1; int a[maxn][2]; int d[maxa]; int vis[maxn]; int vis1[maxa]; int n; long long suma[maxa]; 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] || r < a[i][0]) 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[l]; if (need_id == -1) return 0; if (a[need_id][1] != er - len) 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; } void solve(long long area) { for (int i = 1; i*1ll*i <= area; ++i) { if (area % i) continue; if (i >= maxa) continue; if (suma[i] + 2 * a[0][0] < area / i) 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); suma[a[i][1]] += a[i][0]; area += a[i][0]*1ll*a[i][1]; } solve(area); cout << valid.size() << '\n'; for (auto e : valid) { cout << e << '\n'; } return 0; }

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

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