이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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, stack<pii>> ar, br;
FOR(i, 0, n)
{
ar[inf[i].f].push({inf[i].s, i});
br[inf[i].s].push({inf[i].f, i});
}
map<int, bool> v;
while(x>0 && y>0){
while(!ar[x].empty() && v[ar[x].top().s]) ar[x].pop();
while(!br[x].empty() && v[br[x].top().s]) br[x].pop();
while(!ar[y].empty() && v[ar[y].top().s]) ar[y].pop();
while(!br[y].empty() && v[br[y].top().s]) br[y].pop();
if(x<y) swap(x, y);
if(sz(ar[x])){
pii tp=ar[x].top();
v[tp.s]=true;
y-=tp.f;
ar[x].pop();
continue;
}
if(sz(br[y])){
pii tp=br[y].top();
v[tp.s]=true;
x-=tp.f;
br[y].pop();
continue;
}
if(sz(ar[y])){
pii tp=ar[y].top();
v[tp.s]=true;
x-=tp.f;
ar[y].pop();
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |