結果
問題 | No.355 数当てゲーム(2) |
ユーザー |
![]() |
提出日時 | 2021-02-24 21:57:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 2,542 bytes |
コンパイル時間 | 1,774 ms |
コンパイル使用メモリ | 197,792 KB |
最終ジャッジ日時 | 2025-01-19 04:20:32 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
コンパイルメッセージ
main.cpp: In lambda function: main.cpp:31:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%d %d", &X, &Y); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) begin(v),end(v)template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }using ll = long long;using pii = pair<int, int>;constexpr ll INF = 1ll<<30;constexpr ll longINF = 1ll<<60;constexpr ll MOD = 1000000007;constexpr bool debug = false;//---------------------------------//int main() {int dbans[4]{};auto query = [&](int a, int b, int c, int d) -> pii {if (debug) {int X = 0, Y = 0;int ary[4] {a, b, c, d};REP(i, 4) X += dbans[i] == ary[i];REP(i, 4) FOR(j, i + 1, 4) if (i != j) Y += dbans[i] == ary[j];return {X, Y};}else {printf("%d %d %d %d\n", a, b, c, d);fflush(stdout);int X, Y;scanf("%d %d", &X, &Y);if (X == 4 && Y == 0) exit(0);return {X, Y};}};auto solve = [&]() {vector<int> x, y;FOR(i, 3, 10) {auto [X, Y] = query(0, 1, 2, i);x.emplace_back(X);y.emplace_back(Y);}int minx = *min_element(ALL(x)), miny = *min_element(ALL(y));vector<int> pred;FOR(i, 3, 10) if (x[i - 3] == minx && y[i - 3] == miny) pred.emplace_back(i);assert(pred.size() >= 3);// printf("%d %d %d\n", pred[0], pred[1], pred[2]);int ans[4];bool done[10] {};REP(i, pred.size()) done[pred[i]] = true;REP(t, 4) {int N[4];REP(i, 4) if (t != i) N[i] = pred[i - (i > t)];REP(i, 10) {if (done[i]) continue;N[t] = i;auto [x, y] = query(N[0], N[1], N[2], N[3]);// printf(" %d %d %d %d, %d %d\n", N[0], N[1], N[2], N[3], x, y);assert(x == 0 && y == 0 || x == 0 && y == 1 || x == 1 && y == 0);if (x == 1) {ans[t] = i;done[i] = true;break;}}}auto [a, b] = query(ans[0], ans[1], ans[2], ans[3]);if (debug && (a != 4 || b != 0)) {REP(i, 4) printf("%d ", ans[i]); puts("");assert(false);}};bool d[10] {};auto dfs = [&](auto self, int k) -> void {if (k == 4) {// printf("start %d %d %d %d\n", dbans[0], dbans[1], dbans[2], dbans[3]);solve();// printf("done %d %d %d %d\n", dbans[0], dbans[1], dbans[2], dbans[3]);return;}REP(i, 10) {if (d[i]) continue;d[i] = true;dbans[k] = i;self(self, k + 1);d[i] = false;}};if (debug) {dfs(dfs, 0);puts("OK");}else solve();}