QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#877045 | #7696. Forest for the Trees | LaVuna47 | WA | 96ms | 43404kb | C++20 | 3.6kb | 2025-01-31 19:04:32 | 2025-01-31 19:04:32 |
Judging History
answer
//A tree without skin will surely die.
//A man without face is invincible.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
namespace std
{
// Define a hash function for std::pair
template<typename T>
inline void hash_combine(std::size_t &seed, const T &v)
{
seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template<typename T1, typename T2>
struct hash<std::pair<T1, T2>>
{
std::size_t operator()(const std::pair<T1, T2> &key) const
{
std::size_t seed = 0;
hash_combine(seed, key.first);
hash_combine(seed, key.second);
return seed;
}
};
}
int solve()
{
int n, m, R;
if(!(cin>>n>>m>>R))return 1;
vector<pii> trees(n);
FOR(i,0,n)cin>>trees[i].x>>trees[i].y;
unordered_set<pii> de;
de.reserve(5e6);
FOR(i,0,m)
{
int x,y;
cin>>x>>y;
de.insert({x,y});
}
vector<pii> D={{1, 1}, {-1, -1}, {-1, 1}, {1,-1}};
auto check=[&](pii pos, int d) -> bool{
int det_ctr=0;
for(auto [x,y]: trees)
{
if(abs(x-pos.x)+abs(y-pos.y) <= R)
{
int xx,yy;
if(d==0)
{
xx = abs(x-pos.x);
yy = abs(y-pos.y);
}
else if(d==1)
{
xx = -abs(x-pos.x);
yy = -abs(y-pos.y);
swap(xx,yy);
}
else if(d==2)
{
xx = -abs(x-pos.x);
yy = abs(y-pos.y);
}
else if(d==3)
{
xx = abs(x-pos.x);
yy = -abs(y-pos.y);
swap(xx,yy);
}
//cout<<xx<<" "<<yy<<'\n';
if(de.find({xx,yy})==de.end())
return false;
++det_ctr;
}
}
return det_ctr==sz(de);
};
int x0=de.begin()->x;
int y0=de.begin()->y;
set<array<int,3>> ob;
FOR(d,0,4)
{
for(auto tr: trees)
{
int xx=1e9,yy=1e9;
if(d==0)
{
xx = tr.x-x0;
yy = tr.y-y0;
}
else if(d==1)
{
xx = tr.x+x0;
yy = tr.y+y0;
}
else if(d==2)
{
xx = tr.x-y0;
yy = tr.y+x0;
}
else if(d==3)
{
xx = tr.x+y0;
yy = tr.y-x0;
}
FOR(ori,0,4)
{
if(check({xx,yy}, ori))
{
ob.insert({xx,yy,ori});
}
}
}
}
if(sz(ob)==1)
{
cout<<(*ob.begin())[0]<<" "<<(*ob.begin())[1]<<'\n';
}
else if(sz(ob)==0)
{
cout<<"Impossible\n";
}
else
{
cout<<"Ambiguous\n";
}
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 43232kb
input:
4 4 100 1 1 2 2 2 1 3 3 0 1 0 2 -1 2 -2 3
output:
0 1
result:
ok single line: '0 1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 43364kb
input:
4 4 4 0 1 1 0 0 -1 -1 0 0 1 1 0 0 -1 -1 0
output:
Ambiguous
result:
ok single line: 'Ambiguous'
Test #3:
score: -100
Wrong Answer
time: 96ms
memory: 43404kb
input:
4899 957 32 -9961 -9999 -9970 -9968 -9942 -9986 -9991 -9991 -9950 -9990 -9958 -9994 -9939 -9944 -9992 -9987 -9973 -9937 -9981 -9941 -9940 -9940 -9989 -9945 -9961 -9963 -9970 -9932 -9969 -9967 -9977 -9971 -9949 -9989 -9958 -9958 -9957 -9993 -9937 -9935 -9938 -9980 -9965 -9997 -9992 -9951 -9946 -9984 ...
output:
Impossible
result:
wrong answer 1st lines differ - expected: '-9929 -9959', found: 'Impossible'