QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707124 | #9537. Chinese Chess | ucup-team5243 | WA | 2ms | 3956kb | C++17 | 11.9kb | 2024-11-03 14:46:25 | 2024-11-03 14:46:27 |
Judging History
answer
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;
#include <iterator>
#include <functional>
#include <utility>
#include <type_traits>
template<class Elem> struct vec;
template<class Iter>
struct seq_view{
using Ref = typename std::iterator_traits<Iter>::reference;
using Elem = typename std::iterator_traits<Iter>::value_type;
Iter a, b;
Iter begin() const { return a; }
Iter end() const { return b; }
int size() const { return (int)(b-a); }
seq_view(Iter first, Iter last) : a(first), b(last) {}
seq_view sort() const { std::sort(a, b); return *this; }
Ref& operator[](int x) const { return *(a+x); }
template<class F = std::less<Elem>, class ret = vec<int>> ret sorti(F f = F()) const {
ret x(size()); for(int i=0; i<size(); i++) x[i] = i;
x().sort([&](int l, int r){ return f(a[l],a[r]); });
return x;
}
template<class ret = vec<Elem>> ret col() const { return ret(begin(), end()); }
template<class ret = vec<Elem>> ret cumsum() const {
auto res = ret(size() + 1, Elem(0));
for(int i=0; i<size(); i++) res[i+1] = res[i] + operator[](i);
return res;
}
template<class F = std::equal_to<Elem>, class ret = vec<std::pair<Elem, int>>>
ret rle(F eq = F()) const {
auto x = ret();
for(auto& a : (*this)){
if(x.size() == 0 || !eq(x[x.size()-1].first, a)) x.emp(a, 1); else x[x.size()-1].second++;
} return x;
}
template<class F> seq_view sort(F f) const { std::sort(a, b, f); return *this; }
Iter uni() const { return std::unique(a, b); }
Iter lb(const Elem& x) const { return std::lower_bound(a, b, x); }
Iter ub(const Elem& x) const { return std::upper_bound(a, b, x); }
int lbi(const Elem& x) const { return lb(x) - a; }
int ubi(const Elem& x) const { return ub(x) - a; }
seq_view bound(const Elem& l, const Elem& r) const { return { lb(l), lb(r) }; }
template<class F> Iter lb(const Elem& x, F f) const { return std::lower_bound(a, b, x, f); }
template<class F> Iter ub(const Elem& x, F f) const { return std::upper_bound(a, b, x, f); }
template<class F> Iter when_true_to_false(F f) const {
if(a == b) return a;
return std::lower_bound(a, b, *a,
[&](const Elem& x, const Elem&){ return f(x); });
}
seq_view same(Elem x) const { return { lb(x), ub(x) }; }
template<class F> auto map(F f) const {
vec<decltype(f(std::declval<const typename Iter::value_type&>()))> r;
for(auto& x : *this) r.emp(f(x));
return r;
}
Iter max() const { return std::max_element(a, b); }
Iter min() const { return std::min_element(a, b); }
template<class F = std::less<Elem>>
Iter min(F f) const { return std::min_element(a, b, f); }
seq_view rev() const { std::reverse(a, b); return *this; }
};
template<class Elem>
struct vec {
public:
using Base = typename std::vector<Elem>;
using Iter = typename Base::iterator;
using CIter = typename Base::const_iterator;
using View = seq_view<Iter>;
using CView = seq_view<CIter>;
vec(){}
explicit vec(int n, const Elem& value = Elem()) : a(0<n?n:0, value) {}
template <class I2> vec(I2 first, I2 last) : a(first, last) {}
vec(std::initializer_list<Elem> il) : a(std::move(il)) {}
vec(Base b) : a(std::move(b)) {}
operator Base() const { return a; }
Iter begin(){ return a.begin(); }
CIter begin() const { return a.begin(); }
Iter end(){ return a.end(); }
CIter end() const { return a.end(); }
int size() const { return a.size(); }
bool empty() const { return a.empty(); }
Elem& back(){ return a.back(); }
const Elem& back() const { return a.back(); }
vec& sortuni(){ (*this)().sort(); a.erase((*this)().uni(), end()); return *this; }
vec sortunied(){ vec x = *this; x.sortuni(); return x; }
Iter operator()(int x){ return a.begin() + x; }
CIter operator()(int x) const { return a.begin() + x; }
View operator()(int l, int r){ return { (*this)(l), (*this)(r) }; }
CView operator()(int l, int r) const { return { (*this)(l), (*this)(r) }; }
View operator()(){ return (*this)(0,size()); }
CView operator()() const { return (*this)(0,size()); }
Elem& operator[](int x){ return a[x]; }
const Elem& operator[](int x) const { return a[x]; }
Base& operator*(){ return a; }
const Base& operator*() const { return a; }
vec& push(Elem args){
a.push_back(std::move(args));
return *this;
}
template<class... Args>
vec& emp(Args &&... args){
a.emplace_back(std::forward<Args>(args) ...);
return *this;
}
template<class Range>
vec& app(Range& x){ for(auto& v : x){ emp(v); } return *this; }
Elem pop(){ Elem x = std::move(a.back()); a.pop_back(); return x; }
void resize(int sz){ a.resize(sz); }
void reserve(int sz){ a.reserve(sz); }
bool operator==(const vec& r) const { return a == r.a; }
bool operator!=(const vec& r) const { return a != r.a; }
bool operator<(const vec& r) const { return a < r.a; }
bool operator<=(const vec& r) const { return a <= r.a; }
bool operator>(const vec& r) const { return a > r.a; }
bool operator>=(const vec& r) const { return a >= r.a; }
vec<vec<Elem>> pile(int n) const { return vec<vec<Elem>>(n, *this); }
template<class F> vec& filter(F f){
int p = 0;
for(auto& x : a) if(f(x)) std::swap(a[p++],x);
resize(p); return *this;
}
vec& operator+=(const vec& r){ return app(r); }
vec operator+(const vec& r) const { vec x = *this; x += r; return x; }
vec operator*(int t) const { vec res; while(t--){ res += *this; } return res; }
private: Base a;
};
template<class IStr, class U, class T>
IStr& operator>>(IStr& is, vec<std::pair<U,T>>& v){ for(auto& x:v){ is >> x.first >> x.second; } return is; }
template<class IStr, class T>
IStr& operator>>(IStr& is, vec<T>& v){ for(auto& x:v){ is >> x; } return is; }
template<class OStr, class T>
OStr& operator<<(OStr& os, const vec<T>& v){
for(int i=0; i<v.size(); i++){
if(i){ os << ' '; } os << v[i];
} return os;
}
template<class OStr, class U, class T>
OStr& operator<<(OStr& os, const vec<std::pair<U,T>>& v){
for(int i=0; i<v.size(); i++){
if(i){ os << ' '; } os << '(' << v[i].first << ',' << v[i].second << ')';
} return os;
}
namespace nachia{
template<class Int = long long, class Int2 = long long>
struct VecI2 {
Int x, y;
VecI2() : x(0), y(0) {}
VecI2(std::pair<Int, Int> _p) : x(std::move(_p.first)), y(std::move(_p.second)) {}
VecI2(Int _x, Int _y) : x(std::move(_x)), y(std::move(_y)) {}
VecI2& operator+=(VecI2 r){ x+=r.x; y+=r.y; return *this; }
VecI2& operator-=(VecI2 r){ x-=r.x; y-=r.y; return *this; }
VecI2& operator*=(Int r){ x*=r; y*=r; return *this; }
VecI2 operator+(VecI2 r) const { return VecI2(x+r.x, y+r.y); }
VecI2 operator-(VecI2 r) const { return VecI2(x-r.x, y-r.y); }
VecI2 operator*(Int r) const { return VecI2(x*r, y*r); }
VecI2 operator-() const { return VecI2(-x, -y); }
Int2 operator*(VecI2 r) const { return Int2(x) * Int2(r.x) + Int2(y) * Int2(r.y); }
Int2 operator^(VecI2 r) const { return Int2(x) * Int2(r.y) - Int2(y) * Int2(r.x); }
bool operator<(VecI2 r) const { return x < r.x || (!(r.x < x) && y < r.y); }
Int2 norm() const { return Int2(x) * Int2(x) + Int2(y) * Int2(y); }
Int2 manhattan() const { return std::abs(x) + std::abs(y); }
static bool compareYX(VecI2 a, VecI2 b){ return a.y < b.y || (!(b.y < a.y) && a.x < b.x); }
static bool compareXY(VecI2 a, VecI2 b){ return a.x < b.x || (!(b.x < a.x) && a.y < b.y); }
bool operator==(VecI2 r) const { return x == r.x && y == r.y; }
bool operator!=(VecI2 r) const { return x != r.x || y != r.y; }
};
} // namespace nachia
#include <bitset>
#include <array>
#include <map>
void testcase(){
using Vec2 = nachia::VecI2<int,int>;
constexpr int NUM_KIND_PIECE = 6;
auto dist = vec<int>(90,-1).pile(90).pile(NUM_KIND_PIECE);
auto Index = [](Vec2 p){ return p.y * 9 + p.x; };
vec<Vec2> pos(90);
rep(y,10) rep(x,9) pos[Index({x,y})] = {x,y};
string symbol = "JSCMXB";
// construct dist
{
vec<vec<Vec2>> a(10);
for(int i=-2; i<=2; i++) for(int j=-2; j<=2; j++) a[i*i+j*j].push({i,j});
auto InRange = [](Vec2 p){ return 0 <= p.x && p.x <= 8 && 0 <= p.y && p.y <= 9; };
//rep(d,10){
// for(auto [u,v] : a[d]) cout << "(" << u << "," << v << ")";
// cout << endl;
//}
vec<pair<int,int>> maps = {{0,1},{1,2},{3,5},{4,8}};
for(auto [ty,eu] : maps){ // King J , Mandarin S, Knight M, Boshop X
rep(s,90){
vec<int> bfs = {s};
dist[ty][s][s] = 0;
rep(i,bfs.size()){
int v = bfs[i];
for(auto d : a[eu]) if(InRange(pos[v] + d)){
int t = Index(pos[v] + d);
if(dist[ty][s][t] >= 0) continue;
dist[ty][s][t] = dist[ty][s][v] + 1;
bfs.push(t);
}
}
}
}
rep(s,90) rep(t,90){ // Rook C
dist[2][s][t] = (pos[s].x == pos[t].x ? 0 : 1) + (pos[s].y == pos[t].y ? 0 : 1);
}
rep(s,90) rep(t,90){ // Pawn B
if(pos[s].y <= pos[t].y && (pos[t].y > 4 || pos[s].x == pos[t].x)){
dist[5][s][t] = (pos[s] - pos[t]).manhattan();
}
}
//rep(ty,NUM_KIND_PIECE){
// rep(y,10){
// rep(x,9) cout << dist[ty][0][Index({x,y})] << " ";
// cout << endl;
// } cout << endl << endl;
//}
}
//rep(i,NUM_KIND_PIECE) cout << dist[i][Index({0,9})][Index({1,8})] << " ";
//cout << endl;
using Board = bitset<90>;
using Cand = array<Board, NUM_KIND_PIECE>;
vec<map<int,Cand>> questions(90);
rep(t,90){
map<int,Cand> buf;
rep(ty,NUM_KIND_PIECE) rep(s,90){
buf[dist[ty][s][t]][ty].set(s);
}
questions[t] = buf;
}
auto dfs = [&](auto& dfs, int k, Cand a) -> int {
{
int cnt = 0;
rep(ty,NUM_KIND_PIECE) if(a[ty].any()) cnt += 1;
if(cnt <= 1) return 0;
}
if(k == 0) return -1;
rep(f,90){
bool ok = true;
for(auto [t,c] : questions[f]) if(ok){
Cand b = a;
rep(i,NUM_KIND_PIECE) b[i] &= c[i];
if(dfs(dfs, k-1, b) == -1) ok = false;
}
if(ok) return f;
}
return -1;
};
Cand cand;
//rep(t,6) rep(a,90) cand[t].set(a);
//cout << dfs(dfs, 4, cand) << endl;
//return;
int N; cin >> N;
rep(i,N){
int r,c; cin >> r >> c;
rep(t,6) cand[t].set(Index({c,r}));
}
while(true){
int k = 0;
int nx = -1;
while(true){
nx = dfs(dfs, k, cand);
if(nx != -1) break;
k++;
}
if(k == 0) break;
cout << "? " << pos[nx].y << " " << pos[nx].x << endl;
int res; cin >> res;
rep(ty,NUM_KIND_PIECE) cand[ty] &= questions[nx][res][ty];
}
rep(ty,NUM_KIND_PIECE) if(cand[ty].any()){
cout << "! " << symbol[ty] << endl;
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
testcase();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3956kb
input:
1 9 0
output:
? 1 8
result:
wrong answer format Expected integer, but "?" found