이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=1e5+10;
int n, a[N], b[N];
vector<pii> inf;
unordered_set<int> ans;
set<int> inss;
bool can(int tx, int ty, int vis)
{
if(tx<0||ty<0) return false;
vi ins(all(inss));
do{
bool bad=false;
int x=tx, y=ty;
for(auto i : ins){
if(i==0) continue;
if(i==vis) continue;
if(a[i]==x){
y-=b[i];
}
else if(a[i]==y){
x-=b[i];
}
else if(b[i]==x){
y-=a[i];
}
else if(b[i]==y){
x-=a[i];
}
else{
bad=true;
}
}
if(!bad && (x==0 && y>=0) || (y==0 && x>=0)){
return true;
}
}
while(next_permutation(all(ins)));
return false;
}
int main()
{
setIO();
cin >> n;
FOR(i, 1, n) inss.insert(i);
FOR(i, 0, n)
{
int aa, bb;
cin >> aa >> bb;
inf.pb({aa,bb});
}
sort(all(inf), greater<pii>());
FOR(i, 0, n)
{
a[i]=inf[i].f; b[i]=inf[i].s;
}
FOR(i, 1, n)
{
inss.erase(i);
int x=a[i], y=a[0]-b[i];
if(can(x, y, i)){
ans.insert(min(a[i]+b[0], a[0]));
}
x=a[0]; y=a[i]-b[0];
if(can(x, y, i)){
ans.insert(min(a[i], a[0]+b[i]));
}
x=a[0]-a[i]; y=b[i];
if(can(x, y, i)){
ans.insert(min(a[0], b[0]+b[i]));
}
inss.insert(i);
}
bool ok=true;
int sm=b[0];
FOR(i, 1, n)
{
if(a[i]!=sm && b[i]!=sm){
ok=false;
break;
}
}
if(ok) ans.insert(sm);
vi cc(all(ans));
sort(all(cc));
cout << sz(cc) << "\n";
for(auto x : cc){
cout << x << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
staciakampis.cpp: In function 'bool can(int, int, int)':
staciakampis.cpp:69:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
69 | if(!bad && (x==0 && y>=0) || (y==0 && x>=0)){
| ~~~~~^~~~~~~~~~~~~~~~~
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... |