結果

問題 No.5017 Tool-assisted Shooting
ユーザー komori3
提出日時 2023-07-21 04:59:26
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 9,507 bytes
コンパイル時間 2,784 ms
コンパイル使用メモリ 216,680 KB
実行使用メモリ 24,336 KB
スコア 74,830
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-21 04:59:41
合計ジャッジ時間 14,021 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _CRT_NONSTDC_NO_WARNINGS
#define _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING
#include <bits/stdc++.h>
#include <random>
#include <unordered_set>
#include <array>
#include <optional>
#ifdef _MSC_VER
#include <opencv2/core.hpp>
#include <opencv2/core/utils/logger.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <conio.h>
#include <ppl.h>
#include <filesystem>
#include <intrin.h>
/* g++ functions */
int __builtin_clz(unsigned int n) { unsigned long index; _BitScanReverse(&index, n); return 31 - index; }
int __builtin_ctz(unsigned int n) { unsigned long index; _BitScanForward(&index, n); return index; }
namespace std { inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); } }
/* enable __uint128_t in MSVC */
//#include <boost/multiprecision/cpp_int.hpp>
//using __uint128_t = boost::multiprecision::uint128_t;
#else
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
/** compro io **/
namespace aux {
template<typename T, unsigned N, unsigned L> struct tp { static void output(std::ostream& os, const T& v) { os << std::get<N>(v) << ", "; tp<T, N
        + 1, L>::output(os, v); } };
template<typename T, unsigned N> struct tp<T, N, N> { static void output(std::ostream& os, const T& v) { os << std::get<N>(v); } };
}
template<typename... Ts> std::ostream& operator<<(std::ostream& os, const std::tuple<Ts...>& t) { os << '{'; aux::tp<std::tuple<Ts...>, 0, sizeof
    ...(Ts) - 1>::output(os, t); return os << '}'; } // tuple out
template<class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x); //
    container out (fwd decl)
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return os << '{' << p.first << ", " << p.second <<
    '}'; } // pair out
template<class S, class T> std::istream& operator>>(std::istream& is, std::pair<S, T>& p) { return is >> p.first >> p.second; } // pair in
std::ostream& operator<<(std::ostream& os, const std::vector<bool>::reference& v) { os << (v ? '1' : '0'); return os; } // bool (vector) out
std::ostream& operator<<(std::ostream& os, const std::vector<bool>& v) { bool f = true; os << '{'; for (const auto& x : v) { os << (f ? "" : ", ") <<
    x; f = false; } os << '}'; return os; } // vector<bool> out
template<class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr>& operator<<(std::basic_ostream<Ch, Tr>& os, const Container& x) { bool f =
    true; os << '{'; for (auto& y : x) { os << (f ? "" : ", ") << y; f = false; } return os << '}'; } // container out
template<class T, class = decltype(std::begin(std::declval<T&>())), class = typename std::enable_if<!std::is_same<T, std::string>::value>::type> std
    ::istream& operator>>(std::istream& is, T& a) { for (auto& x : a) is >> x; return is; } // container in
template<typename T> auto operator<<(std::ostream& out, const T& t) -> decltype(out << t.stringify()) { out << t.stringify(); return out; } // struct
    (has stringify() func) out
/** io setup **/
struct IOSetup { IOSetup(bool f) { if (f) { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); } std::cout << std::fixed << std::setprecision
    (15); } }
iosetup(true); // set false when solving interective problems
/** string formatter **/
template<typename... Ts> std::string format(const std::string& f, Ts... t) { size_t l = std::snprintf(nullptr, 0, f.c_str(), t...); std::vector<char>
    b(l + 1); std::snprintf(&b[0], l + 1, f.c_str(), t...); return std::string(&b[0], &b[0] + l); }
/** dump **/
#define DUMPOUT std::cerr
std::ostringstream DUMPBUF;
#define dump(...) do{DUMPBUF<<" ";DUMPBUF<<#__VA_ARGS__<<" :[DUMP - "<<__LINE__<<":"<<__FUNCTION__<<']'<<std::endl;DUMPBUF<<" ";dump_func
    (__VA_ARGS__);DUMPOUT<<DUMPBUF.str();DUMPBUF.str("");DUMPBUF.clear();}while(0);
void dump_func() { DUMPBUF << std::endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPBUF << head; if (sizeof...(Tail) == 0) { DUMPBUF << " "; }
    else { DUMPBUF << ", "; } dump_func(std::move(tail)...); }
/** timer **/
class Timer {
double t = 0, paused = 0, tmp;
public:
Timer() { reset(); }
static double time() {
#ifdef _MSC_VER
return __rdtsc() / 3.0e9;
#else
unsigned long long a, d;
__asm__ volatile("rdtsc"
: "=a"(a), "=d"(d));
return (d << 32 | a) / 3.0e9;
#endif
}
void reset() { t = time(); }
void pause() { tmp = time(); }
void restart() { paused += time() - tmp; }
double elapsed_ms() const { return (time() - t - paused) * 1000.0; }
};
/** rand **/
struct Xorshift {
static constexpr uint64_t M = INT_MAX;
static constexpr double e = 1.0 / M;
uint64_t x = 88172645463325252LL;
Xorshift() {}
Xorshift(uint64_t seed) { reseed(seed); }
inline void reseed(uint64_t seed) { x = 0x498b3bc5 ^ seed; for (int i = 0; i < 20; i++) next(); }
inline uint64_t next() { x = x ^ (x << 7); return x = x ^ (x >> 9); }
inline int next_int() { return next() & M; }
inline int next_int(int mod) { return next() % mod; }
inline int next_int(int l, int r) { return l + next_int(r - l + 1); }
inline double next_double() { return next_int() * e; }
};
/** shuffle **/
template<typename T> void shuffle_vector(std::vector<T>& v, Xorshift& rnd) { int n = v.size(); for (int i = n - 1; i >= 1; i--) { int r = rnd
    .next_int(i); std::swap(v[i], v[r]); } }
/** split **/
std::vector<std::string> split(const std::string& str, const std::string& delim) {
std::vector<std::string> res;
std::string buf;
for (const auto& c : str) {
if (delim.find(c) != std::string::npos) {
if (!buf.empty()) res.push_back(buf);
buf.clear();
}
else buf += c;
}
if (!buf.empty()) res.push_back(buf);
return res;
}
/** misc **/
template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } // fill array
template<typename T, typename ...Args> auto make_vector(T x, int arg, Args ...args) { if constexpr (sizeof...(args) == 0)return std::vector<T>(arg, x
    ); else return std::vector(arg, make_vector<T>(x, args...)); }
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
/* fast queue */
class FastQueue {
int front = 0;
int back = 0;
int v[4096];
public:
inline bool empty() { return front == back; }
inline void push(int x) { v[front++] = x; }
inline int pop() { return v[back++]; }
inline void reset() { front = back = 0; }
inline int size() { return front - back; }
};
class RandomQueue {
int sz = 0;
int v[4096];
public:
inline bool empty() const { return !sz; }
inline int size() const { return sz; }
inline void push(int x) { v[sz++] = x; }
inline void reset() { sz = 0; }
inline int pop(int i) {
std::swap(v[i], v[sz - 1]);
return v[--sz];
}
inline int pop(Xorshift& rnd) {
return pop(rnd.next_int(sz));
}
};
constexpr int T = 1000;
constexpr int H = 60;
constexpr int W = 25;
struct Enemy {
int hp;
int power;
int x;
Enemy(int hp = -1, int power = -1, int x = -1) : hp(hp), power(power), x(x) {}
std::string stringify() const {
return format("Enemy [hp=%d, power=%d, x=%d]", hp, power, x);
}
};
struct Tester;
using TesterPtr = std::shared_ptr<Tester>;
struct Tester {
std::istream& in;
std::ostream& out;
Tester(std::istream& in_, std::ostream& out_) : in(in_), out(out_) {}
virtual std::vector<Enemy> receive() {
int n;
in >> n;
std::vector<Enemy> es;
for (int i = 0; i < n; i++) {
int hp, power, x;
in >> hp >> power >> x;
es.emplace_back(hp, power, x);
}
dump(es);
return es;
}
virtual void send(char cmd) const {
out << cmd << std::endl;
}
};
struct LocalTester;
using LocalTesterPtr = std::shared_ptr<LocalTester>;
struct LocalTester : public Tester {
int turn = 0;
int P[W];
std::vector<Enemy> E[T];
LocalTester(std::istream& in_, std::ostream& out_) : Tester(in_, out_) {
in >> P;
for (int t = 0; t < T; t++) {
int n;
in >> n;
auto& es = E[t];
for (int i = 0; i < n; i++) {
int hp, power, x;
in >> hp >> power >> x;
es.emplace_back(hp, power, x);
}
}
}
std::vector<Enemy> receive() override {
return E[turn++];
}
void send(char cmd) const override {}
};
int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
Timer timer;
#ifdef HAVE_OPENCV_HIGHGUI
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_SILENT);
#endif
#ifdef _MSC_VER
std::ifstream ifs("../../tools/tools/in/0000.txt");
std::istream& in = ifs;
std::ofstream ofs("../../tools/tools/out/0000.txt");
std::ostream& out = ofs;
auto tester = std::make_shared<LocalTester>(in, out);
#else
std::istream& in = std::cin;
std::ostream& out = std::cout;
auto tester = std::make_shared<Tester>(in, out);
#endif
for (int t = 0; t < T; t++) {
auto es = tester->receive();
tester->send('S');
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0