結果
| 問題 |
No.2848 Birthday Hit and Blow
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2024-08-23 23:50:50 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,383 bytes |
| コンパイル時間 | 3,872 ms |
| コンパイル使用メモリ | 298,620 KB |
| 実行使用メモリ | 25,476 KB |
| 平均クエリ数 | 203.50 |
| 最終ジャッジ日時 | 2024-08-23 23:50:55 |
| 合計ジャッジ時間 | 4,447 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 1 |
ソースコード
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
pair<int, int> Compare(const string& s, const string& t) {
int h = 0, b = 0;
for (int i : Rep(0, 4)) {
for (int j : Rep(0, 4)) {
if (s[i] == t[j]) {
++(i == j ? h : b);
}
}
}
return {h, b};
}
void Solve() {
constexpr array D{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static vector<string> U;
if (U.empty()) {
for (int m : Rep1(1, 12)) {
for (int d : Rep1(1, D[m - 1])) {
string s;
s += char('0' + m / 10);
s += char('0' + m % 10);
s += char('0' + d / 10);
s += char('0' + d % 10);
if (Sz(set(ALL(s))) == 4) {
U.push_back(s);
}
}
}
}
static vector<string> P;
if (P.empty()) {
for (int a : Rep1(0, 2)) {
for (int b : Rep1(0, 9)) {
for (int c : Rep1(0, 4)) {
for (int d : Rep1(0, 9)) {
string s;
s += char('0' + a);
s += char('0' + b);
s += char('0' + c);
s += char('0' + d);
if (Sz(set(ALL(s))) == 4) {
P.push_back(s);
}
}
}
}
}
}
assert(ranges::is_sorted(U) && ranges::is_sorted(P));
auto Best = [&](const vector<string>& S) -> string {
static map<vector<string>, string> memo;
if (memo.contains(S)) {
return memo[S];
}
int mn = INF;
string ret;
for (const string& p : P) {
map<pair<int, int>, int> occ;
for (const string& s : S) {
++occ[Compare(s, p)];
}
if (SetMin(mn, ranges::max(occ | views::values))) {
ret = p;
}
}
return memo[S] = ret;
};
auto S = U;
while (Sz(S) > 1) {
auto p = Best(S);
OUT('?', p);
pair<int, int> res;
IN(res);
S.erase(remove_if(ALL(S), [&](const string& s) { return Compare(s, p) != res; }), S.end());
}
OUT('!', S[0]);
}
int main() {
ios::sync_with_stdio(false);
int t;
IN(t);
while (t--) {
Solve();
}
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
template <class T> concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;
namespace std {
istream& operator>>(istream& is, Range auto&& r) {
for (auto&& e : r) is >> e;
return is;
}
istream& operator>>(istream& is, Tuple auto&& t) {
apply([&](auto&... xs) { (is >> ... >> xs); }, t);
return is;
}
ostream& operator<<(ostream& os, Range auto&& r) {
auto sep = "";
for (auto&& e : r) os << exchange(sep, " ") << e;
return os;
}
ostream& operator<<(ostream& os, Tuple auto&& t) {
auto sep = "";
apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
return os;
}
} // namespace std
using namespace std;
#define LAMBDA2(x, y, ...) [&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; }
#define ALL(r) begin(r), end(r)
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__)
#define Sz(r) int(size(r))
#define SetMin(...) LAMBDA2(x, y, y < x && (x = y, 1))(__VA_ARGS__)
#define INF (INT_MAX / 2)
#define IN(...) cin >> forward_as_tuple(__VA_ARGS__)
#define OUT(...) cout << forward_as_tuple(__VA_ARGS__) << '\n'
#endif // __INCLUDE_LEVEL__ == 1
risujiroh